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

Channels: Make bridging more reactive #18

Closed
danbarua opened this issue Jul 2, 2015 · 1 comment
Closed

Channels: Make bridging more reactive #18

danbarua opened this issue Jul 2, 2015 · 1 comment

Comments

@danbarua
Copy link
Owner

danbarua commented Jul 2, 2015

The bridging api is a bit clunky at the moment:

await channel.BridgeTo(
  "user/1003", //destination
  bridgeOptions, //options
  (e) => ColorConsole.WriteLine("Bridge Progress Ringing...".DarkGreen()) // optionally notify on ringing
);

if (!channel.Bridge.IsBridged)
{
  // handle failure
}
else
{
  channel.Bridge.Channel.DoStuff();
}

In particular, we need a better way to handle externally initiated bridges, possibly via attended transfer, or maybe via a command from another EventSocket client.

For example, my use case is this:

When a channel is bridged to another channel,
I need to subscribe to Feature Codes on the b-leg (agent side) channel
So that I can pause/resume recording and initiate attended transfers

Give I have transferred the caller to another agent
When the caller is connected
Then the Feature Codes should be enabled on that agent's channel

The use of the word When in the above example implies that we can and should be handling this in a more functionally reactive manner. Instead of interrogating the Channel.Bridge status object, we can follow Tell Don't Ask by letting the Channel tell us when we have been bridged.

The proposed API could look like this:

channel.Bridge.Subscribe(async bridgedChannel =>
{
  bridgedChannel.DoStuff();
});

await channel.BridgeTo("destination");

So that's the happy path, nice and clean.

We need some way to notify of failure, and there are a few options for this.

  1. Produce an exception in the Channel.Bridge observable
channel.Bridge.Subscribe(
  async bridgedChannel => { bridgedChannel.DoStuff(); },
  ex => { //handle ex.HangupCause etc }
);
  1. Throw an exception in the Channel.BridgeTo Task:

csharp
try
{
await channel.BridgeTo("destination");
}
catch(BridgeFailedException ex)
{
//handle ex.HangupCause etc
}


I am not such a fan of (2) and (3) as currently, the only error handling that consumers of the library need to be aware of is `OperationCanceledException`, and the aim of this library is to allow people to write telephony applications with nice clean C# code. I do not want to be littering my code with ``try/catch`  any more than the bare minimum.

3) Expose `LastBridgeHangupCause` on the  Channel for interrogation, so the proposed api would look like this:

``` csharp
channel.Bridge.Subscribe(
  async bridgedChannel => { bridgedChannel.DoStuff(); }
);

await channel.BridgeTo("destination");
if (!channel.IsBridged)
{
   Console.WriteLine(channel.LastBridgeHangupCause);
  //otherwise success is handled in the Subscription callback
}
danbarua added a commit that referenced this issue Mar 10, 2016
danbarua added a commit that referenced this issue Mar 15, 2016
Use uuid_dump to get CHANNEL_DATA when bridge event not received on other leg.
re #18
@danbarua
Copy link
Owner Author

Done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant