Reputation: 63
I have a user interface with a "Hang Up" button used to end a call.
The "Hang Up" button calls session.disconnect()
On calling session.disconnect()
the other participant in the call listens for the streamDestroyed
event which returns a reason of "clientDisconnected"
According to the docs:
"clientDisconnected" — A client disconnected from the session by calling the disconnect()
method of the Session
object or by closing the browser.
Thing is, I need to differentiate across these two scenarios so that I can provide different messaging to the call participant.
How do I tell if the call ended by 1) explicit hang up (calling session.disconnect()
) or 2) closing of the browser?
Upvotes: 2
Views: 428
Reputation: 1537
The only other options for a reason are "networkDisconnected" which means that the other participant lost their internet connection, and "forceDisconnected" which means the participant was force disconnected using session.forceDisconnect(). Neither of these are what you want.
You could keep track of hangups yourself though if you send a signal to everyone in the session before you hangup. Then on the receiving side keep track of whether someone has sent the hangup signal. ie.
// On the hangup side
function hangup() {
session.signal({type: 'hangup'}, function() {
session.disconnect();
});
}
// On the receiving side...
var hangups = {};
session.on('signal:hangup', function(event) {
hangups[event.from.connectionId] = true;
});
session.on('streamDestroyed', function(event) {
if (hangups[event.stream.connection.connectionId] === true) {
// They pressed the hangup button!
}
});
Upvotes: 1