From 6afcfb259803f798c5e2158373c73519e2cad083 Mon Sep 17 00:00:00 2001 From: paweldomas Date: Fri, 28 Nov 2014 16:05:10 +0100 Subject: [PATCH] Basic recording. --- app.js | 65 ++++++++----------------------------- config.js | 4 +-- index.html | 1 + muc.js | 8 +++++ recording.js | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 115 insertions(+), 53 deletions(-) create mode 100644 recording.js diff --git a/app.js b/app.js index 05ff6372a..970f96fce 100644 --- a/app.js +++ b/app.js @@ -6,7 +6,7 @@ var activecall = null; var RTC = null; var nickname = null; var sharedKey = ''; -var recordingToken =''; +var focusJid = null; var roomUrl = null; var roomName = null; var ssrc2jid = {}; @@ -676,6 +676,16 @@ $(document).bind('joined.muc', function (event, jid, info) { document.createTextNode(Strophe.getResourceFromJid(jid) + ' (me)') ); + if (connection.emuc.isModerator()) + { + Toolbar.showSipCallButton(true); + Toolbar.showRecordingButton(true); + } + else + { + Toolbar.showSipCallButton(false); + Toolbar.showRecordingButton(false); + } /* if (Object.keys(connection.emuc.members).length < 1) { focus = new ColibriFocus(connection, config.hosts.bridge); if (nickname !== null) { @@ -737,7 +747,8 @@ $(document).bind('entered.muc', function (event, jid, info, pres) { if (Strophe.getResourceFromJid(jid).indexOf('focus') != -1) { - console.info("Ignore focus"); + focusJid = jid; + console.info("Ignore focus " + jid); return; } @@ -1036,51 +1047,7 @@ function isAudioMuted() // Starts or stops the recording for the conference. function toggleRecording() { - if (focus === null || focus.confid === null) { - console.log('non-focus, or conference not yet organized: not enabling recording'); - return; - } - - if (!recordingToken) - { - messageHandler.openTwoButtonDialog(null, - '

Enter recording token

' + - '', - false, - "Save", - function (e, v, m, f) { - if (v) { - var token = document.getElementById('recordingToken'); - - if (token.value) { - setRecordingToken(Util.escapeHtml(token.value)); - toggleRecording(); - } - } - }, - function (event) { - document.getElementById('recordingToken').focus(); - } - ); - - return; - } - - var oldState = focus.recordingEnabled; - Toolbar.toggleRecordingButtonState(); - focus.setRecording(!oldState, - recordingToken, - function (state) { - console.log("New recording state: ", state); - if (state == oldState) //failed to change, reset the token because it might have been wrong - { - Toolbar.toggleRecordingButtonState(); - setRecordingToken(null); - } - } - ); - - + Recording.toggleRecording(); } /** @@ -1472,10 +1439,6 @@ function setSharedKey(sKey) { sharedKey = sKey; } -function setRecordingToken(token) { - recordingToken = token; -} - /** * Updates the room invite url. */ diff --git a/config.js b/config.js index 009412d0a..c7abd9350 100644 --- a/config.js +++ b/config.js @@ -25,7 +25,7 @@ var config = { adaptiveSimulcast: false, useRtcpMux: true, useBundle: true, - enableRecording: false, - enableWelcomePage: true, + enableRecording: true, + enableWelcomePage: false, enableSimulcast: false }; diff --git a/index.html b/index.html index 1a6d99f79..67ce73050 100644 --- a/index.html +++ b/index.html @@ -57,6 +57,7 @@ + diff --git a/muc.js b/muc.js index 9ce52cff9..c99731751 100644 --- a/muc.js +++ b/muc.js @@ -12,6 +12,7 @@ Strophe.addConnectionPlugin('emuc', { preziMap: {}, joined: false, isOwner: false, + role: null, init: function (conn) { this.connection = conn; }, @@ -127,6 +128,10 @@ Strophe.addConnectionPlugin('emuc', { if (from == this.myroomjid) { if (member.affiliation == 'owner') this.isOwner = true; + if (this.role !== member.role) { + this.role = member.role; + console.info("My role: " + this.role); + } if (!this.joined) { this.joined = true; $(document).trigger('joined.muc', [from, member]); @@ -456,5 +461,8 @@ Strophe.addConnectionPlugin('emuc', { }, addBridgeIsDownToPresence: function() { this.presMap['bridgeIsDown'] = true; + }, + isModerator: function() { + return this.role === 'moderator'; } }); diff --git a/recording.js b/recording.js new file mode 100644 index 000000000..92c3f0771 --- /dev/null +++ b/recording.js @@ -0,0 +1,90 @@ +/* global $, $iq, config, connection, focusJid, messageHandler, Toolbar, Util */ +var Recording = (function (my) { + var status = false; + var recordingToken = null; + var recordingEnabled = false; + + my.setRecordingToken = function (token) { + recordingToken = token; + }; + + // Sends a COLIBRI message which enables or disables (according to 'state') + // the recording on the bridge. Waits for the result IQ and calls 'callback' + // with the new recording state, according to the IQ. + my.setRecording = function (state, token, callback) { + var self = this; + var elem = $iq({to: focusJid, type: 'set'}); + elem.c('conference', { + xmlns: 'http://jitsi.org/protocol/colibri' + }); + elem.c('recording', {state: state, token: token}); + elem.up(); + + connection.sendIQ(elem, + function (result) { + console.log('Set recording "', state, '". Result:', result); + var recordingElem = $(result).find('>conference>recording'); + var newState = ('true' === recordingElem.attr('state')); + + recordingEnabled = newState; + callback(newState); + }, + function (error) { + console.warn(error); + } + ); + }; + + my.toggleRecording = function () { + if (!connection.emuc.isModerator()) { + console.log( + 'non-focus, or conference not yet organized:' + + ' not enabling recording'); + return; + } + + if (!recordingToken) + { + messageHandler.openTwoButtonDialog(null, + '

Enter recording token

' + + '', + false, + "Save", + function (e, v, m, f) { + if (v) { + var token = document.getElementById('recordingToken'); + + if (token.value) { + my.setRecordingToken( + Util.escapeHtml(token.value)); + my.toggleRecording(); + } + } + }, + function (event) { + document.getElementById('recordingToken').focus(); + } + ); + + return; + } + + var oldState = recordingEnabled; + Toolbar.toggleRecordingButtonState(); + my.setRecording(!oldState, + recordingToken, + function (state) { + console.log("New recording state: ", state); + if (state == oldState) + { + // Failed to change, reset the token because it might + // have been wrong + Toolbar.toggleRecordingButtonState(); + my.setRecordingToken(null); + } + } + ); + }; + + return my; +}(Recording || {}));