Bläddra i källkod

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

dev1
hristoterezov 9 år sedan
förälder
incheckning
dd1bcb0414
6 ändrade filer med 127 tillägg och 104 borttagningar
  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 Visa fil

571
  */
571
  */
572
 JitsiConference.prototype.toggleRecording = function (options) {
572
 JitsiConference.prototype.toggleRecording = function (options) {
573
     if(this.room)
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 Visa fil

45
 
45
 
46
 /**
46
 /**
47
  * Creates and joins new conference.
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
  * @returns {JitsiConference} returns the new conference object.
52
  * @returns {JitsiConference} returns the new conference object.
51
  */
53
  */
52
 JitsiConnection.prototype.initJitsiConference = function (name, options) {
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
     return this.conferences[name];
57
     return this.conferences[name];
55
 }
58
 }
56
 
59
 

+ 62
- 47
lib-jitsi-meet.js Visa fil

573
  */
573
  */
574
 JitsiConference.prototype.toggleRecording = function (options) {
574
 JitsiConference.prototype.toggleRecording = function (options) {
575
     if(this.room)
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
     /**
907
     /**
904
      * Indicates that phone number changed.
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
 module.exports = JitsiConferenceEvents;
917
 module.exports = JitsiConferenceEvents;
956
 
964
 
957
 /**
965
 /**
958
  * Creates and joins new conference.
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
  * @returns {JitsiConference} returns the new conference object.
971
  * @returns {JitsiConference} returns the new conference object.
962
  */
972
  */
963
 JitsiConnection.prototype.initJitsiConference = function (name, options) {
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
     return this.conferences[name];
976
     return this.conferences[name];
966
 }
977
 }
967
 
978
 
6173
     var self = this;
6184
     var self = this;
6174
     this.moderator.allocateConferenceFocus(function()
6185
     this.moderator.allocateConferenceFocus(function()
6175
     {
6186
     {
6176
-        self.sendPresence();
6187
+        self.sendPresence(true);
6177
     }.bind(this));
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
         // Too early to send presence - not initialized
6193
         // Too early to send presence - not initialized
6183
         return;
6194
         return;
6184
     }
6195
     }
6196
+
6185
     var pres = $pres({to: this.presMap['to'] });
6197
     var pres = $pres({to: this.presMap['to'] });
6186
     pres.c('x', {xmlns: this.presMap['xns']});
6198
     pres.c('x', {xmlns: this.presMap['xns']});
6187
 
6199
 
6753
 /**
6765
 /**
6754
  * Starts/stops the recording
6766
  * Starts/stops the recording
6755
  * @param token token for authentication
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
     if(this.recording)
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
     this.jirecon = jirecon;
11018
     this.jirecon = jirecon;
11006
     this.url = null;
11019
     this.url = null;
11007
     this.type = type;
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
      * The ID of the jirecon recording session. Jirecon generates it when we
11024
      * The ID of the jirecon recording session. Jirecon generates it when we
11011
      * initially start recording, and it needs to be used in subsequent requests
11025
      * initially start recording, and it needs to be used in subsequent requests
11019
     COLIBRI: "colibri",
11033
     COLIBRI: "colibri",
11020
     JIRECON: "jirecon",
11034
     JIRECON: "jirecon",
11021
     JIBRI: "jibri"
11035
     JIBRI: "jibri"
11022
-}
11036
+};
11023
 
11037
 
11024
 Recording.prototype.handleJibriPresence = function (jibri) {
11038
 Recording.prototype.handleJibriPresence = function (jibri) {
11025
     var attributes = jibri.attributes;
11039
     var attributes = jibri.attributes;
11101
             console.log('Failed to start recording, error: ', error);
11115
             console.log('Failed to start recording, error: ', error);
11102
             errCallback(error);
11116
             errCallback(error);
11103
         });
11117
         });
11104
-}
11118
+};
11105
 
11119
 
11106
 // Sends a COLIBRI message which enables or disables (according to 'state')
11120
 // Sends a COLIBRI message which enables or disables (according to 'state')
11107
 // the recording on the bridge. Waits for the result IQ and calls 'callback'
11121
 // the recording on the bridge. Waits for the result IQ and calls 'callback'
11125
             callback(newState);
11139
             callback(newState);
11126
 
11140
 
11127
             if (newState === 'pending') {
11141
             if (newState === 'pending') {
11128
-                connection.addHandler(function(iq){
11142
+                self.connection.addHandler(function(iq){
11129
                     var state = $(iq).find('recording').attr('state');
11143
                     var state = $(iq).find('recording').attr('state');
11130
                     if (state) {
11144
                     if (state) {
11131
                         self.state = newState;
11145
                         self.state = newState;
11139
             errCallback(error);
11153
             errCallback(error);
11140
         }
11154
         }
11141
     );
11155
     );
11142
-}
11156
+};
11143
 
11157
 
11144
 Recording.prototype.setRecording =
11158
 Recording.prototype.setRecording =
11145
 function (state, callback, errCallback, options) {
11159
 function (state, callback, errCallback, options) {
11157
             console.error("Unknown recording type!");
11171
             console.error("Unknown recording type!");
11158
             return;
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
Filskillnaden har hållits tillbaka eftersom den är för stor
Visa fil


+ 9
- 7
modules/xmpp/ChatRoom.js Visa fil

118
     var self = this;
118
     var self = this;
119
     this.moderator.allocateConferenceFocus(function()
119
     this.moderator.allocateConferenceFocus(function()
120
     {
120
     {
121
-        self.sendPresence();
121
+        self.sendPresence(true);
122
     }.bind(this));
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
         // Too early to send presence - not initialized
127
         // Too early to send presence - not initialized
128
         return;
128
         return;
129
     }
129
     }
130
+
130
     var pres = $pres({to: this.presMap['to'] });
131
     var pres = $pres({to: this.presMap['to'] });
131
     pres.c('x', {xmlns: this.presMap['xns']});
132
     pres.c('x', {xmlns: this.presMap['xns']});
132
 
133
 
698
 /**
699
 /**
699
  * Starts/stops the recording
700
  * Starts/stops the recording
700
  * @param token token for authentication
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
     if(this.recording)
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 Visa fil

12
     this.jirecon = jirecon;
12
     this.jirecon = jirecon;
13
     this.url = null;
13
     this.url = null;
14
     this.type = type;
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
      * The ID of the jirecon recording session. Jirecon generates it when we
18
      * The ID of the jirecon recording session. Jirecon generates it when we
18
      * initially start recording, and it needs to be used in subsequent requests
19
      * initially start recording, and it needs to be used in subsequent requests
132
             callback(newState);
133
             callback(newState);
133
 
134
 
134
             if (newState === 'pending') {
135
             if (newState === 'pending') {
135
-                connection.addHandler(function(iq){
136
+                self.connection.addHandler(function(iq){
136
                     var state = $(iq).find('recording').attr('state');
137
                     var state = $(iq).find('recording').attr('state');
137
                     if (state) {
138
                     if (state) {
138
                         self.state = newState;
139
                         self.state = newState;
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
 /**

Laddar…
Avbryt
Spara