Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow use of kz_moh - 4.3 #6395

Merged
merged 1 commit into from
Mar 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -621,9 +621,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 @@ -36,6 +36,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
]).
-export([unserialize_fs_array/1, unserialize_fs_props/1]).
Expand Down Expand Up @@ -74,6 +75,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, 'false')).

-type send_cmd_ret() :: fs_sendmsg_ret() | fs_api_ret().
-export_type([send_cmd_ret/0]).

Expand Down Expand Up @@ -655,9 +660,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 All @@ -681,7 +685,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 @@ -1593,3 +1598,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.