2014-05-19 13:53:45 +00:00
|
|
|
/* global connection, Strophe, updateLargeVideo, focusedVideoSrc*/
|
2014-05-08 09:26:15 +00:00
|
|
|
/**
|
|
|
|
* Callback triggered by PeerConnection when new data channel is opened
|
|
|
|
* on the bridge.
|
|
|
|
* @param event the event info object.
|
|
|
|
*/
|
|
|
|
function onDataChannel(event)
|
|
|
|
{
|
|
|
|
var dataChannel = event.channel;
|
|
|
|
|
|
|
|
dataChannel.onopen = function ()
|
|
|
|
{
|
|
|
|
console.info("Data channel opened by the bridge !!!", dataChannel);
|
|
|
|
|
2014-06-04 09:03:33 +00:00
|
|
|
// Code sample for sending string and/or binary data
|
2014-05-08 09:26:15 +00:00
|
|
|
// Sends String message to the bridge
|
2014-06-04 09:03:33 +00:00
|
|
|
//dataChannel.send("Hello bridge!");
|
2014-05-08 09:26:15 +00:00
|
|
|
// Sends 12 bytes binary message to the bridge
|
2014-06-04 09:03:33 +00:00
|
|
|
//dataChannel.send(new ArrayBuffer(12));
|
2014-05-08 09:26:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
dataChannel.onerror = function (error)
|
|
|
|
{
|
|
|
|
console.error("Data Channel Error:", error, dataChannel);
|
|
|
|
};
|
|
|
|
|
|
|
|
dataChannel.onmessage = function (event)
|
|
|
|
{
|
|
|
|
var msgData = event.data;
|
|
|
|
console.info("Got Data Channel Message:", msgData, dataChannel);
|
2014-05-13 14:54:35 +00:00
|
|
|
|
|
|
|
// Active speaker event
|
2014-06-24 11:59:14 +00:00
|
|
|
if (msgData.indexOf('activeSpeaker') === 0)
|
2014-05-13 14:54:35 +00:00
|
|
|
{
|
|
|
|
// Endpoint ID from the bridge
|
2014-06-24 11:59:14 +00:00
|
|
|
var resourceJid = msgData.split(":")[1];
|
2014-05-13 14:54:35 +00:00
|
|
|
|
2014-06-24 11:59:14 +00:00
|
|
|
console.info(
|
|
|
|
"Data channel new active speaker event: " + resourceJid);
|
|
|
|
$(document).trigger('activespeakerchanged', [resourceJid]);
|
2014-05-13 14:54:35 +00:00
|
|
|
}
|
2014-05-08 09:26:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
dataChannel.onclose = function ()
|
|
|
|
{
|
|
|
|
console.info("The Data Channel closed", dataChannel);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Binds "ondatachannel" event listener to given PeerConnection instance.
|
|
|
|
* @param peerConnection WebRTC peer connection instance.
|
|
|
|
*/
|
|
|
|
function bindDataChannelListener(peerConnection)
|
|
|
|
{
|
|
|
|
peerConnection.ondatachannel = onDataChannel;
|
|
|
|
|
|
|
|
// Sample code for opening new data channel from Jitsi Meet to the bridge.
|
|
|
|
// Although it's not a requirement to open separate channels from both bridge
|
|
|
|
// and peer as single channel can be used for sending and receiving data.
|
|
|
|
// So either channel opened by the bridge or the one opened here is enough
|
|
|
|
// for communication with the bridge.
|
2014-05-13 14:54:35 +00:00
|
|
|
/*var dataChannelOptions =
|
2014-05-08 09:26:15 +00:00
|
|
|
{
|
|
|
|
reliable: true
|
|
|
|
};
|
|
|
|
var dataChannel
|
|
|
|
= peerConnection.createDataChannel("myChannel", dataChannelOptions);
|
|
|
|
|
|
|
|
// Can be used only when is in open state
|
|
|
|
dataChannel.onopen = function ()
|
|
|
|
{
|
|
|
|
dataChannel.send("My channel !!!");
|
|
|
|
};
|
2014-05-13 14:54:35 +00:00
|
|
|
dataChannel.onmessage = function (event)
|
|
|
|
{
|
|
|
|
var msgData = event.data;
|
|
|
|
console.info("Got My Data Channel Message:", msgData, dataChannel);
|
|
|
|
};*/
|
2014-05-08 09:26:15 +00:00
|
|
|
}
|