From 6347730dc7bcc07fc36a3a97d1daa23583f227ac Mon Sep 17 00:00:00 2001 From: hristoterezov Date: Mon, 19 Jan 2015 18:54:41 +0200 Subject: [PATCH] Fixes some issues related to xmpp module creation. --- index.html | 14 ++++---- libs/modules/RTC.bundle.js | 33 +++++++++-------- libs/modules/UI.bundle.js | 2 +- libs/modules/simulcast.bundle.js | 6 +++- libs/modules/xmpp.bundle.js | 50 +++++++++++++------------- modules/RTC/DataChannels.js | 26 +++++++------- modules/RTC/MediaStream.js | 3 +- modules/RTC/RTC.js | 4 ++- modules/UI/videolayout/VideoLayout.js | 2 +- modules/simulcast/SimulcastReceiver.js | 6 +++- modules/xmpp/strophe.jingle.js | 35 +++++++++--------- modules/xmpp/xmpp.js | 15 ++++---- 12 files changed, 105 insertions(+), 91 deletions(-) diff --git a/index.html b/index.html index 2c4520ac1..df7748e0a 100644 --- a/index.html +++ b/index.html @@ -25,19 +25,19 @@ - - - - - + + + + + - + - + diff --git a/libs/modules/RTC.bundle.js b/libs/modules/RTC.bundle.js index ee09d408a..0a9992545 100644 --- a/libs/modules/RTC.bundle.js +++ b/libs/modules/RTC.bundle.js @@ -184,9 +184,9 @@ var DataChannels = } -function onSelectedEndpointChanged(userJid) +function onSelectedEndpointChanged(userResource) { - console.log('selected endpoint changed: ', userJid); + console.log('selected endpoint changed: ', userResource); if (_dataChannels && _dataChannels.length != 0) { _dataChannels.some(function (dataChannel) { @@ -194,8 +194,9 @@ function onSelectedEndpointChanged(userJid) { dataChannel.send(JSON.stringify({ 'colibriClass': 'SelectedEndpointChangedEvent', - 'selectedEndpoint': (!userJid || userJid == null) - ? null : userJid + 'selectedEndpoint': + (!userResource || userResource === null)? + null : userResource })); return true; @@ -204,13 +205,13 @@ function onSelectedEndpointChanged(userJid) } } -$(document).bind("selectedendpointchanged", function(event, userJid) { - onSelectedEndpointChanged(userJid); +$(document).bind("selectedendpointchanged", function(event, userResource) { + onSelectedEndpointChanged(userResource); }); -function onPinnedEndpointChanged(userJid) +function onPinnedEndpointChanged(userResource) { - console.log('pinned endpoint changed: ', userJid); + console.log('pinned endpoint changed: ', userResource); if (_dataChannels && _dataChannels.length != 0) { _dataChannels.some(function (dataChannel) { @@ -218,8 +219,9 @@ function onPinnedEndpointChanged(userJid) { dataChannel.send(JSON.stringify({ 'colibriClass': 'PinnedEndpointChangedEvent', - 'pinnedEndpoint': (!userJid || userJid == null) - ? null : Strophe.getResourceFromJid(userJid) + 'pinnedEndpoint': + (!userResource || userResource == null)? + null : userResource })); return true; @@ -228,8 +230,8 @@ function onPinnedEndpointChanged(userJid) } } -$(document).bind("pinnedendpointchanged", function(event, userJid) { - onPinnedEndpointChanged(userJid); +$(document).bind("pinnedendpointchanged", function(event, userResource) { + onPinnedEndpointChanged(userResource); }); module.exports = DataChannels; @@ -339,7 +341,7 @@ module.exports = LocalStream; * * @constructor */ -function MediaStream(data, sid, ssrc, eventEmmiter, browser) { +function MediaStream(data, sid, ssrc, browser) { // XXX(gp) to minimize headaches in the future, we should build our // abstractions around tracks and not streams. ORTC is track based API. @@ -358,7 +360,6 @@ function MediaStream(data, sid, ssrc, eventEmmiter, browser) { this.type = (this.stream.getVideoTracks().length > 0)? MediaStreamType.VIDEO_TYPE : MediaStreamType.AUDIO_TYPE; this.muted = false; - eventEmmiter.emit(StreamEventTypes.EVENT_TYPE_REMOTE_CREATED, this); if(browser == RTCBrowserType.RTC_BROWSER_FIREFOX) { if (!this.getVideoTracks) @@ -442,13 +443,15 @@ var RTC = { } }, createRemoteStream: function (data, sid, thessrc) { - var remoteStream = new MediaStream(data, sid, thessrc, eventEmitter, + var remoteStream = new MediaStream(data, sid, thessrc, this.getBrowserType()); var jid = data.peerjid || xmpp.myJid(); if(!this.remoteStreams[jid]) { this.remoteStreams[jid] = {}; } this.remoteStreams[jid][remoteStream.type]= remoteStream; + eventEmitter.emit(StreamEventTypes.EVENT_TYPE_REMOTE_CREATED, remoteStream); + console.debug("ADD remote stream ", remoteStream.type, " ", jid, " ", thessrc); return remoteStream; }, getBrowserType: function () { diff --git a/libs/modules/UI.bundle.js b/libs/modules/UI.bundle.js index 7985aa2f0..ed15d086d 100644 --- a/libs/modules/UI.bundle.js +++ b/libs/modules/UI.bundle.js @@ -6129,7 +6129,7 @@ var VideoLayout = (function (my) { // picked up later by the lastN changed event handler. lastNPickupJid = jid; - $(document).trigger("pinnedendpointchanged", [jid]); + $(document).trigger("pinnedendpointchanged", [Strophe.getResourceFromJid(jid)]); } } else if (jid == xmpp.myJid()) { $("#localVideoContainer").click(); diff --git a/libs/modules/simulcast.bundle.js b/libs/modules/simulcast.bundle.js index d14fae45f..9bdea9d44 100644 --- a/libs/modules/simulcast.bundle.js +++ b/libs/modules/simulcast.bundle.js @@ -219,7 +219,7 @@ SimulcastReceiver.prototype.getReceivingVideoStreamBySSRC = function (ssrc) var sid, electedStream; var i, j, k; var jid = ssrc2jid[ssrc]; - if(jid) + if(jid && RTC.remoteStreams[jid]) { var remoteStreamObject = RTC.remoteStreams[jid][MediaStreamType.VIDEO_TYPE]; var remoteStream = remoteStreamObject.getOriginalStream(); @@ -239,6 +239,10 @@ SimulcastReceiver.prototype.getReceivingVideoStreamBySSRC = function (ssrc) } } + else + { + console.debug(RTC.remoteStreams, jid, ssrc); + } return { sid: sid, diff --git a/libs/modules/xmpp.bundle.js b/libs/modules/xmpp.bundle.js index 086d4d8d9..8c478a641 100644 --- a/libs/modules/xmpp.bundle.js +++ b/libs/modules/xmpp.bundle.js @@ -3827,31 +3827,32 @@ module.exports = function(XMPP, eventEmitter) { var JingleSession = require("./JingleSession"); -function CallIncomingJingle(sid, connection) { - var sess = connection.jingle.sessions[sid]; - - // TODO: do we check activecall == null? - activecall = sess; - - statistics.onConferenceCreated(sess); - RTC.onConferenceCreated(sess); - - // TODO: check affiliation and/or role - console.log('emuc data for', sess.peerjid, connection.emuc.members[sess.peerjid]); - sess.usedrip = true; // not-so-naive trickle ice - sess.sendAnswer(); - sess.accept(); - -}; - module.exports = function(XMPP) { + function CallIncomingJingle(sid, connection) { + var sess = connection.jingle.sessions[sid]; + + // TODO: do we check activecall == null? + connection.jingle.activecall = sess; + + statistics.onConferenceCreated(sess); + RTC.onConferenceCreated(sess); + + // TODO: check affiliation and/or role + console.log('emuc data for', sess.peerjid, connection.emuc.members[sess.peerjid]); + sess.usedrip = true; // not-so-naive trickle ice + sess.sendAnswer(); + sess.accept(); + + }; + Strophe.addConnectionPlugin('jingle', { connection: null, sessions: {}, jid2session: {}, ice_config: {iceServers: []}, pc_constraints: {}, + activecall: null, media_constraints: { mandatory: { 'OfferToReceiveAudio': true, @@ -4389,7 +4390,6 @@ var SDP = require("./SDP"); var eventEmitter = new EventEmitter(); var connection = null; var authenticatedUser = false; -var activecall = null; function connect(jid, password, uiCredentials) { var bosh @@ -4576,7 +4576,7 @@ var XMPP = { }, disposeConference: function (onUnload) { eventEmitter.emit(XMPPEvents.DISPOSE_CONFERENCE, onUnload); - var handler = activecall; + var handler = connection.jingle.activecall; if (handler && handler.peerconnection) { // FIXME: probably removing streams is not required and close() should // be enough @@ -4588,7 +4588,7 @@ var XMPP = { } handler.peerconnection.close(); } - activecall = null; + connection.jingle.activecall = null; if(!onUnload) { this.sessionTerminated = true; @@ -4615,9 +4615,9 @@ var XMPP = { return Moderator.isExternalAuthEnabled(); }, switchStreams: function (stream, oldStream, callback) { - if (activecall) { + if (connection && connection.jingle.activecall) { // FIXME: will block switchInProgress on true value in case of exception - activecall.switchStreams(stream, oldStream, callback); + connection.jingle.activecall.switchStreams(stream, oldStream, callback); } else { // We are done immediately console.error("No conference handler"); @@ -4627,9 +4627,9 @@ var XMPP = { } }, setVideoMute: function (mute, callback, options) { - if(activecall && connection && RTC.localVideo) + if(connection && RTC.localVideo && connection.jingle.activecall) { - activecall.setVideoMute(mute, callback, options); + connection.jingle.activecall.setVideoMute(mute, callback, options); } }, setAudioMute: function (mute, callback) { @@ -4797,7 +4797,7 @@ var XMPP = { connection.moderate.eject(jid); }, findJidFromResource: function (resource) { - connection.emuc.findJidFromResource(resource); + return connection.emuc.findJidFromResource(resource); }, getMembers: function () { return connection.emuc.members; diff --git a/modules/RTC/DataChannels.js b/modules/RTC/DataChannels.js index b9e74e994..8cb75ae90 100644 --- a/modules/RTC/DataChannels.js +++ b/modules/RTC/DataChannels.js @@ -183,9 +183,9 @@ var DataChannels = } -function onSelectedEndpointChanged(userJid) +function onSelectedEndpointChanged(userResource) { - console.log('selected endpoint changed: ', userJid); + console.log('selected endpoint changed: ', userResource); if (_dataChannels && _dataChannels.length != 0) { _dataChannels.some(function (dataChannel) { @@ -193,8 +193,9 @@ function onSelectedEndpointChanged(userJid) { dataChannel.send(JSON.stringify({ 'colibriClass': 'SelectedEndpointChangedEvent', - 'selectedEndpoint': (!userJid || userJid == null) - ? null : userJid + 'selectedEndpoint': + (!userResource || userResource === null)? + null : userResource })); return true; @@ -203,13 +204,13 @@ function onSelectedEndpointChanged(userJid) } } -$(document).bind("selectedendpointchanged", function(event, userJid) { - onSelectedEndpointChanged(userJid); +$(document).bind("selectedendpointchanged", function(event, userResource) { + onSelectedEndpointChanged(userResource); }); -function onPinnedEndpointChanged(userJid) +function onPinnedEndpointChanged(userResource) { - console.log('pinned endpoint changed: ', userJid); + console.log('pinned endpoint changed: ', userResource); if (_dataChannels && _dataChannels.length != 0) { _dataChannels.some(function (dataChannel) { @@ -217,8 +218,9 @@ function onPinnedEndpointChanged(userJid) { dataChannel.send(JSON.stringify({ 'colibriClass': 'PinnedEndpointChangedEvent', - 'pinnedEndpoint': (!userJid || userJid == null) - ? null : Strophe.getResourceFromJid(userJid) + 'pinnedEndpoint': + (!userResource || userResource == null)? + null : userResource })); return true; @@ -227,8 +229,8 @@ function onPinnedEndpointChanged(userJid) } } -$(document).bind("pinnedendpointchanged", function(event, userJid) { - onPinnedEndpointChanged(userJid); +$(document).bind("pinnedendpointchanged", function(event, userResource) { + onPinnedEndpointChanged(userResource); }); module.exports = DataChannels; diff --git a/modules/RTC/MediaStream.js b/modules/RTC/MediaStream.js index cf1755d36..222f013a3 100644 --- a/modules/RTC/MediaStream.js +++ b/modules/RTC/MediaStream.js @@ -14,7 +14,7 @@ * * @constructor */ -function MediaStream(data, sid, ssrc, eventEmmiter, browser) { +function MediaStream(data, sid, ssrc, browser) { // XXX(gp) to minimize headaches in the future, we should build our // abstractions around tracks and not streams. ORTC is track based API. @@ -33,7 +33,6 @@ function MediaStream(data, sid, ssrc, eventEmmiter, browser) { this.type = (this.stream.getVideoTracks().length > 0)? MediaStreamType.VIDEO_TYPE : MediaStreamType.AUDIO_TYPE; this.muted = false; - eventEmmiter.emit(StreamEventTypes.EVENT_TYPE_REMOTE_CREATED, this); if(browser == RTCBrowserType.RTC_BROWSER_FIREFOX) { if (!this.getVideoTracks) diff --git a/modules/RTC/RTC.js b/modules/RTC/RTC.js index 9b269c8a4..bc97c7f1f 100644 --- a/modules/RTC/RTC.js +++ b/modules/RTC/RTC.js @@ -56,13 +56,15 @@ var RTC = { } }, createRemoteStream: function (data, sid, thessrc) { - var remoteStream = new MediaStream(data, sid, thessrc, eventEmitter, + var remoteStream = new MediaStream(data, sid, thessrc, this.getBrowserType()); var jid = data.peerjid || xmpp.myJid(); if(!this.remoteStreams[jid]) { this.remoteStreams[jid] = {}; } this.remoteStreams[jid][remoteStream.type]= remoteStream; + eventEmitter.emit(StreamEventTypes.EVENT_TYPE_REMOTE_CREATED, remoteStream); + console.debug("ADD remote stream ", remoteStream.type, " ", jid, " ", thessrc); return remoteStream; }, getBrowserType: function () { diff --git a/modules/UI/videolayout/VideoLayout.js b/modules/UI/videolayout/VideoLayout.js index 024755dd4..d6f658843 100644 --- a/modules/UI/videolayout/VideoLayout.js +++ b/modules/UI/videolayout/VideoLayout.js @@ -1742,7 +1742,7 @@ var VideoLayout = (function (my) { // picked up later by the lastN changed event handler. lastNPickupJid = jid; - $(document).trigger("pinnedendpointchanged", [jid]); + $(document).trigger("pinnedendpointchanged", [Strophe.getResourceFromJid(jid)]); } } else if (jid == xmpp.myJid()) { $("#localVideoContainer").click(); diff --git a/modules/simulcast/SimulcastReceiver.js b/modules/simulcast/SimulcastReceiver.js index c019a299f..7b7387a73 100644 --- a/modules/simulcast/SimulcastReceiver.js +++ b/modules/simulcast/SimulcastReceiver.js @@ -185,7 +185,7 @@ SimulcastReceiver.prototype.getReceivingVideoStreamBySSRC = function (ssrc) var sid, electedStream; var i, j, k; var jid = ssrc2jid[ssrc]; - if(jid) + if(jid && RTC.remoteStreams[jid]) { var remoteStreamObject = RTC.remoteStreams[jid][MediaStreamType.VIDEO_TYPE]; var remoteStream = remoteStreamObject.getOriginalStream(); @@ -205,6 +205,10 @@ SimulcastReceiver.prototype.getReceivingVideoStreamBySSRC = function (ssrc) } } + else + { + console.debug(RTC.remoteStreams, jid, ssrc); + } return { sid: sid, diff --git a/modules/xmpp/strophe.jingle.js b/modules/xmpp/strophe.jingle.js index 1f9534a02..fd6b6cdb2 100644 --- a/modules/xmpp/strophe.jingle.js +++ b/modules/xmpp/strophe.jingle.js @@ -2,31 +2,32 @@ var JingleSession = require("./JingleSession"); -function CallIncomingJingle(sid, connection) { - var sess = connection.jingle.sessions[sid]; - - // TODO: do we check activecall == null? - activecall = sess; - - statistics.onConferenceCreated(sess); - RTC.onConferenceCreated(sess); - - // TODO: check affiliation and/or role - console.log('emuc data for', sess.peerjid, connection.emuc.members[sess.peerjid]); - sess.usedrip = true; // not-so-naive trickle ice - sess.sendAnswer(); - sess.accept(); - -}; - module.exports = function(XMPP) { + function CallIncomingJingle(sid, connection) { + var sess = connection.jingle.sessions[sid]; + + // TODO: do we check activecall == null? + connection.jingle.activecall = sess; + + statistics.onConferenceCreated(sess); + RTC.onConferenceCreated(sess); + + // TODO: check affiliation and/or role + console.log('emuc data for', sess.peerjid, connection.emuc.members[sess.peerjid]); + sess.usedrip = true; // not-so-naive trickle ice + sess.sendAnswer(); + sess.accept(); + + }; + Strophe.addConnectionPlugin('jingle', { connection: null, sessions: {}, jid2session: {}, ice_config: {iceServers: []}, pc_constraints: {}, + activecall: null, media_constraints: { mandatory: { 'OfferToReceiveAudio': true, diff --git a/modules/xmpp/xmpp.js b/modules/xmpp/xmpp.js index fed7cddae..8ce622727 100644 --- a/modules/xmpp/xmpp.js +++ b/modules/xmpp/xmpp.js @@ -6,7 +6,6 @@ var SDP = require("./SDP"); var eventEmitter = new EventEmitter(); var connection = null; var authenticatedUser = false; -var activecall = null; function connect(jid, password, uiCredentials) { var bosh @@ -193,7 +192,7 @@ var XMPP = { }, disposeConference: function (onUnload) { eventEmitter.emit(XMPPEvents.DISPOSE_CONFERENCE, onUnload); - var handler = activecall; + var handler = connection.jingle.activecall; if (handler && handler.peerconnection) { // FIXME: probably removing streams is not required and close() should // be enough @@ -205,7 +204,7 @@ var XMPP = { } handler.peerconnection.close(); } - activecall = null; + connection.jingle.activecall = null; if(!onUnload) { this.sessionTerminated = true; @@ -232,9 +231,9 @@ var XMPP = { return Moderator.isExternalAuthEnabled(); }, switchStreams: function (stream, oldStream, callback) { - if (activecall) { + if (connection && connection.jingle.activecall) { // FIXME: will block switchInProgress on true value in case of exception - activecall.switchStreams(stream, oldStream, callback); + connection.jingle.activecall.switchStreams(stream, oldStream, callback); } else { // We are done immediately console.error("No conference handler"); @@ -244,9 +243,9 @@ var XMPP = { } }, setVideoMute: function (mute, callback, options) { - if(activecall && connection && RTC.localVideo) + if(connection && RTC.localVideo && connection.jingle.activecall) { - activecall.setVideoMute(mute, callback, options); + connection.jingle.activecall.setVideoMute(mute, callback, options); } }, setAudioMute: function (mute, callback) { @@ -414,7 +413,7 @@ var XMPP = { connection.moderate.eject(jid); }, findJidFromResource: function (resource) { - connection.emuc.findJidFromResource(resource); + return connection.emuc.findJidFromResource(resource); }, getMembers: function () { return connection.emuc.members;