From 932af962b2bd38eaf9bb58a54cf9848456c0c64d Mon Sep 17 00:00:00 2001 From: Boris Grozev Date: Thu, 29 Oct 2015 16:40:59 -0500 Subject: [PATCH] Adds an option to advertise our SSRCs in presence to the MUC (as well as Jingle) for backward compatibility with jirecon. Partially reverts a1b0677442e04c12f275431be380f06a8f4a3959 --- modules/xmpp/JingleSessionPC.js | 18 +++++++++++++ modules/xmpp/strophe.emuc.js | 45 +++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) diff --git a/modules/xmpp/JingleSessionPC.js b/modules/xmpp/JingleSessionPC.js index 6fa0fcdf7..6253096d8 100644 --- a/modules/xmpp/JingleSessionPC.js +++ b/modules/xmpp/JingleSessionPC.js @@ -1406,10 +1406,28 @@ JingleSessionPC.prototype.setLocalDescription = function () { // Bind us as local SSRCs owner if (newssrcs.length > 0) { + + if (config.advertiseSSRCsInPresence) { + // This is only for backward compatibility with clients which + // don't support getting sources from Jingle (i.e. jirecon). + this.connection.emuc.clearPresenceMedia(); + } + for (i = 0; i < newssrcs.length; i++) { var ssrc = newssrcs[i].ssrc; var myJid = self.connection.emuc.myroomjid; self.ssrcOwners[ssrc] = myJid; + + if (config.advertiseSSRCsInPresence) { + // This is only for backward compatibility with clients which + // don't support getting sources from Jingle (i.e. jirecon). + this.connection.emuc.addMediaToPresence( + i+1, newssrcs[i].type, ssrc, newssrcs[i].direction); + } + } + + if (config.advertiseSSRCsInPresence) { + this.connection.emuc.sendPresence(); } } }; diff --git a/modules/xmpp/strophe.emuc.js b/modules/xmpp/strophe.emuc.js index b37918e0d..2b83c049b 100644 --- a/modules/xmpp/strophe.emuc.js +++ b/modules/xmpp/strophe.emuc.js @@ -529,6 +529,31 @@ module.exports = function(XMPP, eventEmitter) { .c('current').t(this.presMap['prezicurrent']).up().up(); } + // This is only for backward compatibility with clients which + // don't support getting sources from Jingle (i.e. jirecon). + if (this.presMap['medians']) { + pres.c('media', {xmlns: this.presMap['medians']}); + var sourceNumber = 0; + Object.keys(this.presMap).forEach(function (key) { + if (key.indexOf('source') >= 0) { + sourceNumber++; + } + }); + if (sourceNumber > 0) { + for (var i = 1; i <= sourceNumber / 3; i++) { + pres.c('source', + { + type: this.presMap['source' + i + '_type'], + ssrc: this.presMap['source' + i + '_ssrc'], + direction: this.presMap['source' + i + '_direction'] + || 'sendrecv' + } + ).up(); + } + } + pres.up(); + } + if(this.presMap["startMuted"] !== undefined) { pres.c("startmuted", {audio: this.presMap["startMuted"].audio, @@ -543,6 +568,26 @@ module.exports = function(XMPP, eventEmitter) { addDisplayNameToPresence: function (displayName) { this.presMap['displayName'] = displayName; }, + // This is only for backward compatibility with clients which + // don't support getting sources from Jingle (i.e. jirecon). + addMediaToPresence: function (sourceNumber, mtype, ssrcs, direction) { + if (!this.presMap['medians']) + this.presMap['medians'] = 'http://estos.de/ns/mjs'; + + this.presMap['source' + sourceNumber + '_type'] = mtype; + this.presMap['source' + sourceNumber + '_ssrc'] = ssrcs; + this.presMap['source' + sourceNumber + '_direction'] = direction; + }, + // This is only for backward compatibility with clients which + // don't support getting sources from Jingle (i.e. jirecon). + clearPresenceMedia: function () { + var self = this; + Object.keys(this.presMap).forEach(function (key) { + if (key.indexOf('source') != -1) { + delete self.presMap[key]; + } + }); + }, addDevicesToPresence: function (devices) { this.presMap['devices'] = devices; },