Browse Source

Changes the recording to report the status via event instead of Promise. Fixes JS errors

dev1
hristoterezov 9 years ago
parent
commit
dd1bcb0414
6 changed files with 127 additions and 104 deletions
  1. 7
    3
      JitsiConference.js
  2. 6
    3
      JitsiConnection.js
  3. 62
    47
      lib-jitsi-meet.js
  4. 12
    12
      lib-jitsi-meet.min.js
  5. 9
    7
      modules/xmpp/ChatRoom.js
  6. 31
    32
      modules/xmpp/recording.js

+ 7
- 3
JitsiConference.js View File

@@ -571,9 +571,13 @@ JitsiConference.prototype.getRecordingURL = function () {
571 571
  */
572 572
 JitsiConference.prototype.toggleRecording = function (options) {
573 573
     if(this.room)
574
-        return this.room.toggleRecording(options);
575
-    return new Promise(function(resolve, reject){
576
-        reject(new Error("The conference is not created yet!"))});
574
+        return this.room.toggleRecording(options, function (status, error) {
575
+            this.eventEmitter.emit(
576
+                JitsiConferenceEvents.RECORDING_STATE_CHANGED, status, error);
577
+        }.bind(this));
578
+    this.eventEmitter.emit(
579
+        JitsiConferenceEvents.RECORDING_STATE_CHANGED, "error",
580
+        new Error("The conference is not created yet!"));
577 581
 }
578 582
 
579 583
 /**

+ 6
- 3
JitsiConnection.js View File

@@ -45,12 +45,15 @@ JitsiConnection.prototype.setToken = function (token) {
45 45
 
46 46
 /**
47 47
  * Creates and joins new conference.
48
- * @param name the name of the conference; if null - a generated name will be provided from the api
49
- * @param options Object with properties / settings related to the conference that will be created.
48
+ * @param name the name of the conference; if null - a generated name will be
49
+ * provided from the api
50
+ * @param options Object with properties / settings related to the conference
51
+ * that will be created.
50 52
  * @returns {JitsiConference} returns the new conference object.
51 53
  */
52 54
 JitsiConnection.prototype.initJitsiConference = function (name, options) {
53
-    this.conferences[name] = new JitsiConference({name: name, config: options, connection: this});
55
+    this.conferences[name] = new JitsiConference({name: name, config: options,
56
+        connection: this});
54 57
     return this.conferences[name];
55 58
 }
56 59
 

+ 62
- 47
lib-jitsi-meet.js View File

@@ -573,9 +573,13 @@ JitsiConference.prototype.getRecordingURL = function () {
573 573
  */
574 574
 JitsiConference.prototype.toggleRecording = function (options) {
575 575
     if(this.room)
576
-        return this.room.toggleRecording(options);
577
-    return new Promise(function(resolve, reject){
578
-        reject(new Error("The conference is not created yet!"))});
576
+        return this.room.toggleRecording(options, function (status, error) {
577
+            this.eventEmitter.emit(
578
+                JitsiConferenceEvents.RECORDING_STATE_CHANGED, status, error);
579
+        }.bind(this));
580
+    this.eventEmitter.emit(
581
+        JitsiConferenceEvents.RECORDING_STATE_CHANGED, "error",
582
+        new Error("The conference is not created yet!"));
579 583
 }
580 584
 
581 585
 /**
@@ -903,7 +907,11 @@ var JitsiConferenceEvents = {
903 907
     /**
904 908
      * Indicates that phone number changed.
905 909
      */
906
-    PHONE_NUMBER_CHANGED: "conference.phoneNumberChanged"
910
+    PHONE_NUMBER_CHANGED: "conference.phoneNumberChanged",
911
+    /**
912
+     * Indicates that recording status changed.
913
+     */
914
+    RECORDING_STATE_CHANGED: "conferenece.recordingStateChanged"
907 915
 };
908 916
 
909 917
 module.exports = JitsiConferenceEvents;
@@ -956,12 +964,15 @@ JitsiConnection.prototype.setToken = function (token) {
956 964
 
957 965
 /**
958 966
  * Creates and joins new conference.
959
- * @param name the name of the conference; if null - a generated name will be provided from the api
960
- * @param options Object with properties / settings related to the conference that will be created.
967
+ * @param name the name of the conference; if null - a generated name will be
968
+ * provided from the api
969
+ * @param options Object with properties / settings related to the conference
970
+ * that will be created.
961 971
  * @returns {JitsiConference} returns the new conference object.
962 972
  */
963 973
 JitsiConnection.prototype.initJitsiConference = function (name, options) {
964
-    this.conferences[name] = new JitsiConference({name: name, config: options, connection: this});
974
+    this.conferences[name] = new JitsiConference({name: name, config: options,
975
+        connection: this});
965 976
     return this.conferences[name];
966 977
 }
967 978
 
@@ -6173,15 +6184,16 @@ ChatRoom.prototype.join = function (password) {
6173 6184
     var self = this;
6174 6185
     this.moderator.allocateConferenceFocus(function()
6175 6186
     {
6176
-        self.sendPresence();
6187
+        self.sendPresence(true);
6177 6188
     }.bind(this));
6178 6189
 };
6179 6190
 
6180
-ChatRoom.prototype.sendPresence = function () {
6181
-    if (!this.presMap['to']) {
6191
+ChatRoom.prototype.sendPresence = function (fromJoin) {
6192
+    if (!this.presMap['to'] || (!this.joined && !fromJoin)) {
6182 6193
         // Too early to send presence - not initialized
6183 6194
         return;
6184 6195
     }
6196
+
6185 6197
     var pres = $pres({to: this.presMap['to'] });
6186 6198
     pres.c('x', {xmlns: this.presMap['xns']});
6187 6199
 
@@ -6753,13 +6765,14 @@ ChatRoom.prototype.getRecordingURL = function () {
6753 6765
 /**
6754 6766
  * Starts/stops the recording
6755 6767
  * @param token token for authentication
6768
+ * @param statusChangeHandler {function} receives the new status as argument.
6756 6769
  */
6757
-ChatRoom.prototype.toggleRecording = function (options) {
6770
+ChatRoom.prototype.toggleRecording = function (options, statusChangeHandler) {
6758 6771
     if(this.recording)
6759
-        return this.recording.toggleRecording(options);
6772
+        return this.recording.toggleRecording(options, statusChangeHandler);
6760 6773
 
6761
-    return new Promise(function(resolve, reject){
6762
-        reject(new Error("The conference is not created yet!"))});
6774
+    return statusChangeHandler("error",
6775
+        new Error("The conference is not created yet!"));
6763 6776
 }
6764 6777
 
6765 6778
 /**
@@ -11005,7 +11018,8 @@ function Recording(type, eventEmitter, connection, focusMucJid, jirecon,
11005 11018
     this.jirecon = jirecon;
11006 11019
     this.url = null;
11007 11020
     this.type = type;
11008
-    this._isSupported = false;
11021
+    this._isSupported = ((type === Recording.types.JIBRI)
11022
+        || (type === Recording.types.JIRECON && !this.jirecon))? false : true;
11009 11023
     /**
11010 11024
      * The ID of the jirecon recording session. Jirecon generates it when we
11011 11025
      * initially start recording, and it needs to be used in subsequent requests
@@ -11019,7 +11033,7 @@ Recording.types = {
11019 11033
     COLIBRI: "colibri",
11020 11034
     JIRECON: "jirecon",
11021 11035
     JIBRI: "jibri"
11022
-}
11036
+};
11023 11037
 
11024 11038
 Recording.prototype.handleJibriPresence = function (jibri) {
11025 11039
     var attributes = jibri.attributes;
@@ -11101,7 +11115,7 @@ function (state, callback, errCallback, options) {
11101 11115
             console.log('Failed to start recording, error: ', error);
11102 11116
             errCallback(error);
11103 11117
         });
11104
-}
11118
+};
11105 11119
 
11106 11120
 // Sends a COLIBRI message which enables or disables (according to 'state')
11107 11121
 // the recording on the bridge. Waits for the result IQ and calls 'callback'
@@ -11125,7 +11139,7 @@ function (state, callback, errCallback, options) {
11125 11139
             callback(newState);
11126 11140
 
11127 11141
             if (newState === 'pending') {
11128
-                connection.addHandler(function(iq){
11142
+                self.connection.addHandler(function(iq){
11129 11143
                     var state = $(iq).find('recording').attr('state');
11130 11144
                     if (state) {
11131 11145
                         self.state = newState;
@@ -11139,7 +11153,7 @@ function (state, callback, errCallback, options) {
11139 11153
             errCallback(error);
11140 11154
         }
11141 11155
     );
11142
-}
11156
+};
11143 11157
 
11144 11158
 Recording.prototype.setRecording =
11145 11159
 function (state, callback, errCallback, options) {
@@ -11157,36 +11171,37 @@ function (state, callback, errCallback, options) {
11157 11171
             console.error("Unknown recording type!");
11158 11172
             return;
11159 11173
     }
11160
-}
11161
-
11162
-Recording.prototype.toggleRecording = function (options) {
11163
-    var self = this;
11164
-    return new Promise(function(resolve, reject) {
11165
-        if (!token && self.type === Recording.types.COLIBRI) {
11166
-            reject(new Error("No token passed!"));
11167
-            logger.error("No token passed!");
11168
-            return;
11169
-        }
11174
+};
11170 11175
 
11171
-        var oldState = self.state;
11172
-        var newState = (oldState === 'off' || !oldState) ? 'on' : 'off';
11176
+/**
11177
+ *Starts/stops the recording
11178
+ * @param token token for authentication
11179
+ * @param statusChangeHandler {function} receives the new status as argument.
11180
+ */
11181
+Recording.prototype.toggleRecording = function (options, statusChangeHandler) {
11182
+    if ((!options.token && this.type === Recording.types.COLIBRI) ||
11183
+        (!options.streamId && this.type === Recording.types.JIBRI)){
11184
+        statusChangeHandler("error", new Error("No token passed!"));
11185
+        logger.error("No token passed!");
11186
+        return;
11187
+    }
11173 11188
 
11174
-        self.setRecording(newState,
11175
-            function (state, url) {
11176
-                logger.log("New recording state: ", state);
11177
-                if (state && state !== oldState) {
11178
-                    if(state !== "on" && state !== "off") //state === "pending" we are waiting for the real state
11179
-                        return;
11180
-                    self.state = state;
11181
-                    self.url = url;
11182
-                    resolve();
11183
-                } else {
11184
-                    reject(new Error("State not changed!"));
11185
-                }
11186
-            }, function (error) {
11187
-                reject(error);
11188
-            }, options);
11189
-    });
11189
+    var oldState = this.state;
11190
+    var newState = (oldState === 'off' || !oldState) ? 'on' : 'off';
11191
+    var self = this;
11192
+    this.setRecording(newState,
11193
+        function (state, url) {
11194
+            logger.log("New recording state: ", state);
11195
+            if (state && state !== oldState) {
11196
+                self.state = state;
11197
+                self.url = url;
11198
+                statusChangeHandler(state);
11199
+            } else {
11200
+                statusChangeHandler("error", new Error("Status not changed!"));
11201
+            }
11202
+        }, function (error) {
11203
+            statusChangeHandler("error", error);
11204
+        }, options);
11190 11205
 };
11191 11206
 
11192 11207
 /**

+ 12
- 12
lib-jitsi-meet.min.js
File diff suppressed because it is too large
View File


+ 9
- 7
modules/xmpp/ChatRoom.js View File

@@ -118,15 +118,16 @@ ChatRoom.prototype.join = function (password) {
118 118
     var self = this;
119 119
     this.moderator.allocateConferenceFocus(function()
120 120
     {
121
-        self.sendPresence();
121
+        self.sendPresence(true);
122 122
     }.bind(this));
123 123
 };
124 124
 
125
-ChatRoom.prototype.sendPresence = function () {
126
-    if (!this.presMap['to']) {
125
+ChatRoom.prototype.sendPresence = function (fromJoin) {
126
+    if (!this.presMap['to'] || (!this.joined && !fromJoin)) {
127 127
         // Too early to send presence - not initialized
128 128
         return;
129 129
     }
130
+
130 131
     var pres = $pres({to: this.presMap['to'] });
131 132
     pres.c('x', {xmlns: this.presMap['xns']});
132 133
 
@@ -698,13 +699,14 @@ ChatRoom.prototype.getRecordingURL = function () {
698 699
 /**
699 700
  * Starts/stops the recording
700 701
  * @param token token for authentication
702
+ * @param statusChangeHandler {function} receives the new status as argument.
701 703
  */
702
-ChatRoom.prototype.toggleRecording = function (options) {
704
+ChatRoom.prototype.toggleRecording = function (options, statusChangeHandler) {
703 705
     if(this.recording)
704
-        return this.recording.toggleRecording(options);
706
+        return this.recording.toggleRecording(options, statusChangeHandler);
705 707
 
706
-    return new Promise(function(resolve, reject){
707
-        reject(new Error("The conference is not created yet!"))});
708
+    return statusChangeHandler("error",
709
+        new Error("The conference is not created yet!"));
708 710
 }
709 711
 
710 712
 /**

+ 31
- 32
modules/xmpp/recording.js View File

@@ -12,7 +12,8 @@ function Recording(type, eventEmitter, connection, focusMucJid, jirecon,
12 12
     this.jirecon = jirecon;
13 13
     this.url = null;
14 14
     this.type = type;
15
-    this._isSupported = false;
15
+    this._isSupported = ((type === Recording.types.JIBRI)
16
+        || (type === Recording.types.JIRECON && !this.jirecon))? false : true;
16 17
     /**
17 18
      * The ID of the jirecon recording session. Jirecon generates it when we
18 19
      * initially start recording, and it needs to be used in subsequent requests
@@ -132,7 +133,7 @@ function (state, callback, errCallback, options) {
132 133
             callback(newState);
133 134
 
134 135
             if (newState === 'pending') {
135
-                connection.addHandler(function(iq){
136
+                self.connection.addHandler(function(iq){
136 137
                     var state = $(iq).find('recording').attr('state');
137 138
                     if (state) {
138 139
                         self.state = newState;
@@ -166,37 +167,35 @@ function (state, callback, errCallback, options) {
166 167
     }
167 168
 };
168 169
 
169
-Recording.prototype.toggleRecording = function (options) {
170
-    var self = this;
171
-    return new Promise(function(resolve, reject) {
172
-        if ((!options.token && self.type === Recording.types.COLIBRI) ||
173
-            (!options.streamId && self.type === Recording.types.JIBRI)){
174
-            reject(new Error("No token passed!"));
175
-            logger.error("No token passed!");
176
-            return;
177
-        }
178
-
179
-        var oldState = self.state;
180
-        var newState = (oldState === 'off' || !oldState) ? 'on' : 'off';
170
+/**
171
+ *Starts/stops the recording
172
+ * @param token token for authentication
173
+ * @param statusChangeHandler {function} receives the new status as argument.
174
+ */
175
+Recording.prototype.toggleRecording = function (options, statusChangeHandler) {
176
+    if ((!options.token && this.type === Recording.types.COLIBRI) ||
177
+        (!options.streamId && this.type === Recording.types.JIBRI)){
178
+        statusChangeHandler("error", new Error("No token passed!"));
179
+        logger.error("No token passed!");
180
+        return;
181
+    }
181 182
 
182
-        self.setRecording(newState,
183
-            function (state, url) {
184
-                logger.log("New recording state: ", state);
185
-                if (state && state !== oldState) {
186
-                    if(state !== "on" && state !== "off") {
187
-                     //state === "pending" we are waiting for the real state
188
-                        return;
189
-                    }
190
-                    self.state = state;
191
-                    self.url = url;
192
-                    resolve();
193
-                } else {
194
-                    reject(new Error("State not changed!"));
195
-                }
196
-            }, function (error) {
197
-                reject(error);
198
-            }, options);
199
-    });
183
+    var oldState = this.state;
184
+    var newState = (oldState === 'off' || !oldState) ? 'on' : 'off';
185
+    var self = this;
186
+    this.setRecording(newState,
187
+        function (state, url) {
188
+            logger.log("New recording state: ", state);
189
+            if (state && state !== oldState) {
190
+                self.state = state;
191
+                self.url = url;
192
+                statusChangeHandler(state);
193
+            } else {
194
+                statusChangeHandler("error", new Error("Status not changed!"));
195
+            }
196
+        }, function (error) {
197
+            statusChangeHandler("error", error);
198
+        }, options);
200 199
 };
201 200
 
202 201
 /**

Loading…
Cancel
Save