Skip to content

Commit

Permalink
KAZOO-665: system config option to redirect via the proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
k-anderson committed Feb 28, 2013
1 parent bcdbbfe commit d23e031
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
25 changes: 21 additions & 4 deletions whistle_apps/apps/callflow/src/module/cf_park.erl
Expand Up @@ -152,15 +152,32 @@ retrieve(SlotNumber, ParkedCalls, Call) ->
OtherNode ->
lager:info("the parked call is on node ~s but this call is on node ~s, redirecting", [OtherNode, CallerNode]),
IP = get_node_ip(OtherNode),
Contact = <<"sip:", (whapps_call:to_user(Call))/binary
,"@", (whapps_call:to_realm(Call))/binary>>,
Server = <<"sip:", IP/binary, ":5060">>,
whapps_call_command:redirect(Contact, Server, Call),
send_redirect(IP, Call),
cf_exe:transfer(Call),
{ok, ParkedCalls}
end
end.

-spec send_redirect(ne_binary(), whapps_call:call()) -> 'ok'.
send_redirect(IP, Call) ->
case whapps_config:get_is_true(?MOD_CONFIG_CAT, <<"redirect_via_proxy">>, true) of
'true' -> redirect_via_proxy(IP, Call);
'false' -> redirect_via_endpoint(IP, Call)
end.

-spec redirect_via_proxy(ne_binary(), whapps_call:call()) -> 'ok'.
redirect_via_proxy(IP, Call) ->
Contact = <<"sip:", (whapps_call:to_user(Call))/binary
,"@", (whapps_call:to_realm(Call))/binary>>,
Server = <<"sip:", IP/binary, ":5060">>,
whapps_call_command:redirect(Contact, Server, Call).

-spec redirect_via_endpoint(ne_binary(), whapps_call:call()) -> 'ok'.
redirect_via_endpoint(IP, Call) ->
Contact = <<"sip:", (whapps_call:to_user(Call))/binary
,"@", IP/binary, ":5060">>,
whapps_call_command:redirect(Contact, Call).

%%--------------------------------------------------------------------
%% @private
%% @doc
Expand Down
9 changes: 8 additions & 1 deletion whistle_apps/src/whapps_call_command.erl
Expand Up @@ -22,7 +22,9 @@
-export([pickup/2, pickup/3, pickup/4, pickup/5, pickup/6
,b_pickup/2, b_pickup/3, b_pickup/4, b_pickup/5, b_pickup/6
]).
-export([redirect/3]).
-export([redirect/2
,redirect/3
]).
-export([answer/1, answer_now/1
,hangup/1, hangup/2
,queued_hangup/1
Expand Down Expand Up @@ -356,7 +358,12 @@ b_pickup(TargetCallId, Insert, ContinueOnFail, ContinueOnCancel, ParkAfterPickup
%% Create a redirect request to the Contact on Server
%% @end
%%--------------------------------------------------------------------
-spec redirect(ne_binary(), whapps_call:call()) -> 'ok'.
-spec redirect(ne_binary(), ne_binary(), whapps_call:call()) -> 'ok'.

redirect(Contact, Call) ->
redirect(Contact, 'undefined', Call).

redirect(Contact, Server, Call) ->
lager:debug("redirect to ~s on ~s", [Contact, Server]),
Command = [{<<"Redirect-Contact">>, Contact}
Expand Down

0 comments on commit d23e031

Please sign in to comment.