danbarua / NEventSocket

A reactive FreeSwitch eventsocket library for Modern .Net
Mozilla Public License 2.0
74 stars 37 forks source link

BridgedChannels and OtherLeg #61

Open mguerrieri opened 7 years ago

mguerrieri commented 7 years ago

Is there a reason why BridgedChannels/OtherLeg are not updated appropriately (i.e. remove channel from BridgedChannels/set OtherLeg to null) when a channel is unbridged? In my application, I have a channel generated from an origination to a user, and this channel remains connected indefinitely. While connected, the channel will periodically call BridgeTo to initiate a bridge with an external phone number allowing the user to handle the call. When the call ends (i.e. the external phone hangs up), BridgeTo is called again to connect with a different external phone. This goes on indefinitely without the original user channel hanging up. In this scenario, BridgedChannels will just grow continually, and OtherLeg remains populated even when there is no longer an active bridge. I am really only running into an issue bevcause I am throw an exception if OtherLeg is not null when the user attempts to start a new bridge (since I incorrectly assume one is already in progress). I could probably work around this, but the perpetually growing BridgedChannels concerns me. Wont this also prevent those previously bridged channels from getting garbage collected?

danbarua commented 7 years ago

It looks like an oversight - OtherLeg is not cleared down on receiving an unbridge event - https://github.com/danbarua/NEventSocket/blob/6feb8b330094d82c5992fc602fa1160b2f87d728/src/NEventSocket/Channels/Channel.cs#L242

I'll get that fixed.

As for BridgedChannels - it's an observable. Using Rx + Linq abstractions let you write queries over it as if it is a collection, but it is not - it is a stream of events (new bridged channel) that continues for the life of the channel. So don't worry about it growing indefinitely, event streams do continue indefinitely. :)