Skip to content

Commit

Permalink
allow use of kz_moh (2600hz#6399)
Browse files Browse the repository at this point in the history
  • Loading branch information
Luis Azedo authored and jamesaimonetti committed Mar 23, 2020
1 parent a5c001f commit 73abf59
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
5 changes: 2 additions & 3 deletions applications/ecallmgr/src/ecallmgr_fs_xml.erl
Original file line number Diff line number Diff line change
Expand Up @@ -656,9 +656,8 @@ kazoo_var_to_fs_var({<<"origination_uuid">> = K, UUID}, Vars) ->
[ <<K/binary, "=", UUID/binary>> | Vars];

kazoo_var_to_fs_var({<<"Hold-Media">>, Media}, Vars) ->
[list_to_binary(["hold_music="
,kz_term:to_list(ecallmgr_util:media_path(Media, 'extant', get('callid'), kz_json:new()))
])
MediaPath = ecallmgr_util:moh_media_path(Media, 'extant', get('callid'), kz_json:new()),
[list_to_binary(["hold_music=", MediaPath])
| Vars];

kazoo_var_to_fs_var({<<"Codecs">>, []}, Vars) ->
Expand Down
27 changes: 23 additions & 4 deletions applications/ecallmgr/src/ecallmgr_util.erl
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
-export([build_bridge_channels/1, build_simple_channels/1]).
-export([create_masquerade_event/2, create_masquerade_event/3]).
-export([media_path/1, media_path/2, media_path/3, media_path/4
,moh_media_path/4
,lookup_media/4
,request_media_url/4
]).
Expand Down Expand Up @@ -78,6 +79,10 @@
,kapps_config:get_boolean(?APP_NAME, <<"failover_when_all_unreg">>, 'false')
).
-define(KZ_MOH_KEY, <<"Hold-Media-Preserve-Position">>).
-define(KZ_MOH_CONFIG_KEY, kz_json:normalize_key(?KZ_MOH_KEY)).
-define(KZ_MOH_DEFAULT, kapps_config:get_boolean(?APP_NAME, ?KZ_MOH_CONFIG_KEY, 'true')).
-type send_cmd_ret() :: fs_sendmsg_ret() | fs_api_ret().
-export_type([send_cmd_ret/0]).
Expand Down Expand Up @@ -537,9 +542,8 @@ get_fs_kv(Key, Value) ->

-spec get_fs_kv(kz_term:ne_binary(), kz_term:ne_binary(), kz_term:api_binary()) -> binary().
get_fs_kv(<<"Hold-Media">>, Media, UUID) ->
list_to_binary(["hold_music="
,kz_term:to_list(media_path(Media, 'extant', UUID, kz_json:new()))
]);
MediaPath = moh_media_path(Media, 'extant', UUID, kz_json:new()),
list_to_binary(["hold_music=", MediaPath]);
get_fs_kv(?CCV(Key), Val, UUID) ->
get_fs_kv(Key, Val, UUID);
get_fs_kv(Key, Val, _) ->
Expand Down Expand Up @@ -568,7 +572,8 @@ get_fs_key(Key) ->
[{kz_term:ne_binary(), binary()}] |
'skip'.
get_fs_key_and_value(<<"Hold-Media">>=Key, Media, UUID) ->
{get_fs_key(Key), media_path(Media, 'extant', UUID, kz_json:new())};
MediaPath = moh_media_path(Media, 'extant', UUID, kz_json:new()),
{get_fs_key(Key), list_to_binary(["hold_music=", MediaPath])};
get_fs_key_and_value(<<"Diversions">>=Key, Diversions, _UUID) ->
K = get_fs_key(Key),
lager:debug("setting diversions ~p on the channel", [Diversions]),
Expand Down Expand Up @@ -1494,3 +1499,17 @@ fix_contact([Contact | Options], Username, Realm) ->
list_to_binary([kzsip_uri:ruri(Uri)] ++ [<<";", Option/binary>> || Option <- Options]);
_Else -> 'undefined'
end.

-spec moh_media_path(kz_term:api_binary(), media_types(), kz_term:ne_binary(), kz_json:object()) -> kz_term:ne_binary().
moh_media_path(Media, Types, UUID, JObj) ->
case media_path(Media, Types, UUID, JObj) of
<<"http_cache", _/binary>> = Media -> maybe_use_kz_moh(Media, JObj);
Media -> Media
end.

-spec maybe_use_kz_moh(kz_term:ne_binary(), kz_json:object()) -> kz_term:ne_binary().
maybe_use_kz_moh(Media, JObj) ->
case kz_json:is_true(?KZ_MOH_KEY, JObj, ?KZ_MOH_DEFAULT) of
'true' -> list_to_binary(["kz_moh::", Media]);
'false' -> Media
end.

0 comments on commit 73abf59

Please sign in to comment.