Fixes a syntax error. Adds the ability to define a default value for the channel attribute last-n. Parses JSON messages from Videobridge received on the data channel. Fixes unnecessary changing of the value of the channel attribute expire from 15 to 60.

This commit is contained in:
Lyubomir Marinov 2014-07-16 01:36:51 +03:00
parent 9d24910f82
commit 69508d7734
3 changed files with 87 additions and 44 deletions

View File

@ -13,6 +13,7 @@ var config = {
chromeExtensionId: 'diibjkoicjeejcmhdnailmkgecihlobk', // Id of desktop streamer Chrome extension chromeExtensionId: 'diibjkoicjeejcmhdnailmkgecihlobk', // Id of desktop streamer Chrome extension
minChromeExtVersion: '0.1', // Required version of Chrome extension minChromeExtVersion: '0.1', // Required version of Chrome extension
enableRtpStats: false, // Enables RTP stats processing enableRtpStats: false, // Enables RTP stats processing
openSctp: true, //Toggle to enable/disable SCTP channels openSctp: true, // Toggle to enable/disable SCTP channels
// channelLastN: -1, // The default value of the channel attribute last-n.
enableRecording: false enableRecording: false
}; };

View File

@ -10,7 +10,7 @@ function onDataChannel(event)
dataChannel.onopen = function () dataChannel.onopen = function ()
{ {
console.info("Data channel opened by the bridge !!!", dataChannel); console.info("Data channel opened by the Videobridge!", dataChannel);
// Code sample for sending string and/or binary data // Code sample for sending string and/or binary data
// Sends String message to the bridge // Sends String message to the bridge
@ -26,19 +26,42 @@ function onDataChannel(event)
dataChannel.onmessage = function (event) dataChannel.onmessage = function (event)
{ {
var msgData = event.data; var data = event.data;
console.info("Got Data Channel Message:", msgData, dataChannel);
console.info("Got Data Channel Message:", data, dataChannel);
// Active speaker event // Active speaker event
if (msgData.indexOf('activeSpeaker') === 0) if (data.indexOf('activeSpeaker') === 0)
{ {
// Endpoint ID from the bridge // Endpoint ID from the Videobridge.
var resourceJid = msgData.split(":")[1]; var resourceJid = data.split(":")[1];
console.info( console.info(
"Data channel new active speaker event: " + resourceJid); "Data channel new active speaker event: " + resourceJid);
$(document).trigger('activespeakerchanged', [resourceJid]); $(document).trigger('activespeakerchanged', [resourceJid]);
} }
else
{
// JSON
var obj;
try
{
obj = JSON.parse(data);
}
catch (e)
{
console.error(
"Failed to parse data channel message as JSON: ",
data,
dataChannel);
}
if (('undefined' !== typeof(obj)) && (null !== obj))
{
// TODO Consume the JSON-formatted data channel message.
console.debug("Data channel JSON-formatted message: ", obj);
}
}
}; };
dataChannel.onclose = function () dataChannel.onclose = function ()
@ -78,3 +101,4 @@ function bindDataChannelListener(peerConnection)
console.info("Got My Data Channel Message:", msgData, dataChannel); console.info("Got My Data Channel Message:", msgData, dataChannel);
};*/ };*/
} }

View File

@ -54,17 +54,16 @@ function ColibriFocus(connection, bridgejid) {
* Default channel expire value in seconds. * Default channel expire value in seconds.
* @type {number} * @type {number}
*/ */
this.channelExpire = 60; this.channelExpire
= ('number' === typeof(config.channelExpire))
? config.channelExpire
: 15;
// media types of the conference // media types of the conference
if (config.openSctp) if (config.openSctp)
{
this.media = ['audio', 'video', 'data']; this.media = ['audio', 'video', 'data'];
}
else else
{
this.media = ['audio', 'video']; this.media = ['audio', 'video'];
}
this.connection.jingle.sessions[this.sid] = this; this.connection.jingle.sessions[this.sid] = this;
this.mychannel = []; this.mychannel = [];
@ -202,29 +201,38 @@ ColibriFocus.prototype._makeConference = function () {
elem.c('conference', {xmlns: 'http://jitsi.org/protocol/colibri'}); elem.c('conference', {xmlns: 'http://jitsi.org/protocol/colibri'});
this.media.forEach(function (name) { this.media.forEach(function (name) {
var isData = name === 'data'; var elemName;
var channel = isData ? 'sctpconnection' : 'channel'; var elemAttrs = { initiator: 'true', expire: self.channelExpire };
if ('data' === name)
{
elemName = 'sctpconnection';
elemAttrs['port'] = 5000;
}
else
{
elemName = 'channel';
if ('video' === name)
{
// last-n
var lastN = config.channelLastN;
if ('undefined' !== typeof(lastN))
elemAttrs['last-n'] = lastN;
}
}
elem.c('content', {name: name}); elem.c('content', {name: name});
elem.c(channel, { elem.c(elemName, elemAttrs);
initiator: 'true', elem.attrs({ endpoint: self.myMucResource });
expire: '15', elem.up();// end of channel/sctpconnection
endpoint: self.myMucResource
});
if (isData)
elem.attrs({port: 5000});
elem.up();// end of channel
for (var j = 0; j < self.peers.length; j++) { for (var j = 0; j < self.peers.length; j++) {
elem.c(channel, { var peer = self.peers[j];
initiator: 'true',
expire: '15', elem.c(elemName, elemAttrs);
endpoint: self.peers[j].substr(1 + self.peers[j].lastIndexOf('/')) elem.attrs({ endpoint: peer.substr(1 + peer.lastIndexOf('/')) });
}); elem.up(); // end of channel/sctpconnection
if (isData)
elem.attrs({port: 5000});
elem.up(); // end of channel
} }
elem.up(); // end of content elem.up(); // end of content
}); });
@ -233,7 +241,7 @@ ColibriFocus.prototype._makeConference = function () {
localSDP.media.forEach(function (media, channel) { localSDP.media.forEach(function (media, channel) {
var name = SDPUtil.parse_mline(media.split('\r\n')[0]).media; var name = SDPUtil.parse_mline(media.split('\r\n')[0]).media;
elem.c('content', {name: name}); elem.c('content', {name: name});
elem.c('channel', {initiator: 'false', expire: '15'}); elem.c('channel', {initiator: 'false', expire: self.channelExpire});
// FIXME: should reuse code from .toJingle // FIXME: should reuse code from .toJingle
var mline = SDPUtil.parse_mline(media.split('\r\n')[0]); var mline = SDPUtil.parse_mline(media.split('\r\n')[0]);
@ -247,7 +255,7 @@ ColibriFocus.prototype._makeConference = function () {
elem.up(); // end of channel elem.up(); // end of channel
for (j = 0; j < self.peers.length; j++) { for (j = 0; j < self.peers.length; j++) {
elem.c('channel', {initiator: 'true', expire:'15' }).up(); elem.c('channel', {initiator: 'true', expire: self.channelExpire }).up();
} }
elem.up(); // end of content elem.up(); // end of content
}); });
@ -662,24 +670,33 @@ ColibriFocus.prototype.addNewParticipant = function (peer) {
var localSDP = new SDP(this.peerconnection.localDescription.sdp); var localSDP = new SDP(this.peerconnection.localDescription.sdp);
localSDP.media.forEach(function (media, channel) { localSDP.media.forEach(function (media, channel) {
var name = SDPUtil.parse_mid(SDPUtil.find_line(media, 'a=mid:')); var name = SDPUtil.parse_mid(SDPUtil.find_line(media, 'a=mid:'));
elem.c('content', {name: name}); var elemName;
if (name !== 'data') var elemAttrs
{ = {
elem.c('channel', {
initiator: 'true', initiator: 'true',
expire: self.channelExpire, expire: self.channelExpire,
endpoint: peer.substr(1 + peer.lastIndexOf('/')) endpoint: peer.substr(1 + peer.lastIndexOf('/'))
}); };
if ('data' == name)
{
elemName = 'sctpconnection';
elemAttrs['port'] = 5000;
} }
else else
{ {
elem.c('sctpconnection', { elemName = 'channel';
endpoint: peer.substr(1 + peer.lastIndexOf('/')), if ('video' === name)
initiator: 'true', {
expire: self.channelExpire, // last-n
port: 5000 var lastN = config.channelLastN;
}); if ('undefined' !== typeof(lastN))
elemAttrs['last-n'] = lastN;
} }
}
elem.c('content', {name: name});
elem.c(elemName, elemAttrs);
elem.up(); // end of channel/sctpconnection elem.up(); // end of channel/sctpconnection
elem.up(); // end of content elem.up(); // end of content
}); });
@ -1186,4 +1203,5 @@ ColibriFocus.prototype.setRTCPTerminationStrategy = function (strategyFQN) {
console.error('got error', err); console.error('got error', err);
} }
); );
};