Skip to content

Commit

Permalink
WHISTLE-1121: add playstop dialplan command, which runs uuid_break on…
Browse files Browse the repository at this point in the history
… the leg in FreeSWITCH
  • Loading branch information
James Aimonetti committed Apr 20, 2012
1 parent 9480739 commit c31b0d0
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
12 changes: 12 additions & 0 deletions ecallmgr/src/ecallmgr_call_command.erl
Expand Up @@ -77,6 +77,13 @@ get_fs_app(Node, UUID, JObj, <<"play">>) ->
{<<"playback">>, F}
end;

get_fs_app(_Node, UUID, JObj, <<"playstop">>) ->
case wapi_dialplan:playstop_v(JObj) of
false -> {'error', <<"playstop failed to execute as JObj did not validate">>};
true ->
{<<"playstop">>, UUID}
end;

get_fs_app(_Node, _UUID, _JObj, <<"hangup">>) ->
{<<"hangup">>, <<>>};

Expand Down Expand Up @@ -593,6 +600,11 @@ send_cmd(Node, UUID, <<"record_call">>, Args) ->
Ret = freeswitch:api(Node, uuid_record, wh_util:to_list(Cmd)),
lager:debug("executing uuid_record returned ~p", [Ret]),
Ret;
send_cmd(Node, UUID, <<"playstop">>, Args) ->
lager:debug("execute on node ~s: uuid_break(~s)", [Node, UUID]),
Ret = freeswitch:api(Node, uuid_break, wh_util:to_list(Args)),
lager:debug("executing uuid_break returned ~s", [Ret]),
Ret;
send_cmd(Node, UUID, <<"xferext">>, Dialplan) ->
XferExt = [begin
_ = ecallmgr_util:fs_log(Node, "whistle queuing command in 'xferext' extension: ~s", [V]),
Expand Down
24 changes: 22 additions & 2 deletions lib/whistle-1.0.0/src/api/wapi_dialplan.erl
Expand Up @@ -26,7 +26,7 @@
-export([progress/1, progress_v/1]).
-export([ring/1, ring_v/1]).
-export([execute_extension/1, execute_extension_v/1]).
-export([play/1, play_v/1]).
-export([play/1, play_v/1, playstop/1, playstop_v/1]).
-export([record/1, record_v/1]).
-export([record_call/1, record_call_v/1]).
-export([answer/1, answer_v/1]).
Expand Down Expand Up @@ -289,7 +289,7 @@ queue_v(JObj) ->
play(Prop) when is_list(Prop) ->
case play_v(Prop) of
true -> wh_api:build_message(Prop, ?PLAY_REQ_HEADERS, ?OPTIONAL_PLAY_REQ_HEADERS);
false -> {error, "Proplist failed validation for play_req"}
false -> {error, "Proplist failed validation for play"}
end;
play(JObj) ->
play(wh_json:to_proplist(JObj)).
Expand All @@ -300,6 +300,26 @@ play_v(Prop) when is_list(Prop) ->
play_v(JObj) ->
play_v(wh_json:to_proplist(JObj)).

%%--------------------------------------------------------------------
%% @doc Stop media from playing - see wiki
%% Takes proplist, creates JSON string or error
%% @end
%%--------------------------------------------------------------------
-spec playstop/1 :: (api_terms()) -> api_formatter_return().
playstop(Prop) when is_list(Prop) ->
case playstop_v(Prop) of
true -> wh_api:build_message(Prop, ?PLAY_STOP_REQ_HEADERS, ?OPTIONAL_PLAY_STOP_REQ_HEADERS);
false -> {error, "Proplist failed validation for playstop"}
end;
playstop(JObj) ->
playstop(wh_json:to_proplist(JObj)).

-spec playstop_v/1 :: (api_terms()) -> boolean().
playstop_v(Prop) when is_list(Prop) ->
wh_api:validate(Prop, ?PLAY_STOP_REQ_HEADERS, ?PLAY_STOP_REQ_VALUES, ?PLAY_STOP_REQ_TYPES);
playstop_v(JObj) ->
playstop_v(wh_json:to_proplist(JObj)).

%%--------------------------------------------------------------------
%% @doc Record media - see wiki
%% Takes proplist, creates JSON string or error
Expand Down
10 changes: 10 additions & 0 deletions lib/whistle-1.0.0/src/api/wapi_dialplan.hrl
Expand Up @@ -249,6 +249,16 @@
]).
-define(PLAY_REQ_TYPES, [{<<"Terminators">>, fun is_list/1}]).

%% PlayStop Request
-define(PLAY_STOP_REQ_HEADERS, [<<"Application-Name">>, <<"Call-ID">>]).
-define(OPTIONAL_PLAY_STOP_REQ_HEADERS, [<<"Insert-At">>]).
-define(PLAY_STOP_REQ_VALUES, [{<<"Event-Category">>, <<"call">>}
,{<<"Event-Name">>, <<"command">>}
,{<<"Application-Name">>, <<"playstop">>}
,{<<"Insert-At">>, <<"now">>}
]).
-define(PLAY_STOP_REQ_TYPES, [{<<"Terminators">>, fun is_list/1}]).

%% Record Request
-define(RECORD_REQ_HEADERS, [<<"Application-Name">>, <<"Call-ID">>, <<"Media-Name">>]).
-define(OPTIONAL_RECORD_REQ_HEADERS, [<<"Terminators">>, <<"Time-Limit">>, <<"Silence-Threshold">>
Expand Down

0 comments on commit c31b0d0

Please sign in to comment.