Created
May 30, 2018 19:48
-
-
Save phm200/1465b4bf7fa4ff99af378c47c0712172 to your computer and use it in GitHub Desktop.
Stream PR #61 - Softphone Mute
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Bind events for mute | |
var handleSoftPhoneMuteToggle = function() { | |
var bus = connect.core.getEventBus(); | |
bus.subscribe(connect.EventType.MUTE, muteToggle); | |
}; | |
// Make sure once we disconnected we get the mute state back to normal | |
var deleteLocalMediaStream = function(connectionId) { | |
delete localMediaStream[connectionId]; | |
connect.core.getUpstream().sendUpstream(connect.EventType.BROADCAST, { | |
event: connect.AgentEvents.MUTE_TOGGLE, | |
data: { muted: false } | |
}); | |
}; | |
// Check for the local streams if exists - revert it | |
// And inform other clients about the change | |
var muteToggle = function(data) { | |
var status; | |
if (connect.keys(localMediaStream).length === 0) { | |
return; | |
} | |
if (data && data.mute !== undefined) { | |
status = data.mute; | |
} | |
for (var connectionId in localMediaStream) { | |
if (localMediaStream.hasOwnProperty(connectionId)) { | |
var localMedia = localMediaStream[connectionId].stream; | |
if (localMedia) { | |
var audioTracks = localMedia.getAudioTracks()[0]; | |
if (status !== undefined) { | |
audioTracks.enabled = !status; | |
localMediaStream[connectionId].muted = status; | |
if (status) { | |
logger.info( | |
"Agent has muted the contact, connectionId - " + connectionId | |
); | |
} else { | |
logger.info( | |
"Agent has unmuted the contact, connectionId - " + connectionId | |
); | |
} | |
} else { | |
status = localMediaStream[connectionId].muted || false; | |
} | |
} | |
} | |
} | |
connect.core.getUpstream().sendUpstream(connect.EventType.BROADCAST, { | |
event: connect.AgentEvents.MUTE_TOGGLE, | |
data: { muted: status } | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment