Преглед на файлове

VideoSIPGW updates (#649)

* Changes initialization of videoSIPGW.

* Adds some errors returned on creating videoSIPGW session.

* Fixes sending videoSIPGW session STATE_CHANGED event.

* Fixes sending jibriIQ, no result status is received.

* Adds VIDEO_SIP_GW_SESSION_STATE_CHANGED to JitsiConferenceEvents.

* Fixing comments.
dev1
Дамян Минков преди 8 години
родител
ревизия
dc3397b18b

+ 6
- 26
JitsiConference.js Целия файл

38
 import Transcriber from './modules/transcription/transcriber';
38
 import Transcriber from './modules/transcription/transcriber';
39
 import VideoType from './service/RTC/VideoType';
39
 import VideoType from './service/RTC/VideoType';
40
 import VideoSIPGW from './modules/videosipgw/VideoSIPGW';
40
 import VideoSIPGW from './modules/videosipgw/VideoSIPGW';
41
+import * as VideoSIPGWConstants from './modules/videosipgw/VideoSIPGWConstants';
41
 import * as XMPPEvents from './service/xmpp/XMPPEvents';
42
 import * as XMPPEvents from './service/xmpp/XMPPEvents';
42
 
43
 
43
 import SpeakerStatsCollector from './modules/statistics/SpeakerStatsCollector';
44
 import SpeakerStatsCollector from './modules/statistics/SpeakerStatsCollector';
194
      * @type {JingleSessionPC}
195
      * @type {JingleSessionPC}
195
      */
196
      */
196
     this.p2pJingleSession = null;
197
     this.p2pJingleSession = null;
198
+
199
+    this.videoSIPGWHandler = new VideoSIPGW(this.room);
197
 }
200
 }
198
 
201
 
199
 // FIXME convert JitsiConference to ES6 - ASAP !
202
 // FIXME convert JitsiConference to ES6 - ASAP !
2701
     this.rtc.setReceiverVideoConstraint(maxFrameHeight);
2704
     this.rtc.setReceiverVideoConstraint(maxFrameHeight);
2702
 };
2705
 };
2703
 
2706
 
2704
-/**
2705
- * Get video SIP GW handler, if missing will create one.
2706
- *
2707
- * @returns {VideoSIPGW} video SIP GW handler.
2708
- */
2709
-JitsiConference.prototype._getVideoSIPGWHandle = function() {
2710
-    if (!this.videoSIPGWHandler) {
2711
-        this.videoSIPGWHandler = new VideoSIPGW(this.room);
2712
-        logger.info('Created VideoSIPGW');
2713
-    }
2714
-
2715
-    return this.videoSIPGWHandler;
2716
-};
2717
-
2718
-/**
2719
- * Checks whether video SIP GW service is available.
2720
- *
2721
- * @returns {boolean} whether video SIP GW service is available.
2722
- */
2723
-JitsiConference.prototype.isVideoSIPGWAvailable = function() {
2724
-    return this._getVideoSIPGWHandle().isVideoSIPGWAvailable();
2725
-};
2726
-
2727
 /**
2707
 /**
2728
  * Creates a video SIP GW session and returns it if service is enabled. Before
2708
  * Creates a video SIP GW session and returns it if service is enabled. Before
2729
  * creating a session one need to check whether video SIP GW service is
2709
  * creating a session one need to check whether video SIP GW service is
2734
  *
2714
  *
2735
  * @param {string} sipAddress - The sip address to be used.
2715
  * @param {string} sipAddress - The sip address to be used.
2736
  * @param {string} displayName - The display name to be used for this session.
2716
  * @param {string} displayName - The display name to be used for this session.
2737
- * @returns {JitsiVideoSIPGWSession|null} Returns null if conference is not
2717
+ * @returns {JitsiVideoSIPGWSession|Error} Returns null if conference is not
2738
  * initialised and there is no room.
2718
  * initialised and there is no room.
2739
  */
2719
  */
2740
 JitsiConference.prototype.createVideoSIPGWSession
2720
 JitsiConference.prototype.createVideoSIPGWSession
2741
     = function(sipAddress, displayName) {
2721
     = function(sipAddress, displayName) {
2742
         if (!this.room) {
2722
         if (!this.room) {
2743
-            return null;
2723
+            return new Error(VideoSIPGWConstants.ERROR_NO_CONNECTION);
2744
         }
2724
         }
2745
 
2725
 
2746
-        return this._getVideoSIPGWHandle()
2726
+        return this.videoSIPGWHandler
2747
             .createVideoSIPGWSession(sipAddress, displayName);
2727
             .createVideoSIPGWSession(sipAddress, displayName);
2748
     };
2728
     };

+ 4
- 0
JitsiConferenceEventManager.js Целия файл

214
     this.chatRoomForwarder.forward(XMPPEvents.VIDEO_SIP_GW_AVAILABILITY_CHANGED,
214
     this.chatRoomForwarder.forward(XMPPEvents.VIDEO_SIP_GW_AVAILABILITY_CHANGED,
215
         JitsiConferenceEvents.VIDEO_SIP_GW_AVAILABILITY_CHANGED);
215
         JitsiConferenceEvents.VIDEO_SIP_GW_AVAILABILITY_CHANGED);
216
 
216
 
217
+    this.chatRoomForwarder.forward(
218
+        XMPPEvents.VIDEO_SIP_GW_SESSION_STATE_CHANGED,
219
+        JitsiConferenceEvents.VIDEO_SIP_GW_SESSION_STATE_CHANGED);
220
+
217
     this.chatRoomForwarder.forward(XMPPEvents.PHONE_NUMBER_CHANGED,
221
     this.chatRoomForwarder.forward(XMPPEvents.PHONE_NUMBER_CHANGED,
218
         JitsiConferenceEvents.PHONE_NUMBER_CHANGED);
222
         JitsiConferenceEvents.PHONE_NUMBER_CHANGED);
219
 
223
 

+ 12
- 0
JitsiConferenceEvents.js Целия файл

177
 export const VIDEO_SIP_GW_AVAILABILITY_CHANGED
177
 export const VIDEO_SIP_GW_AVAILABILITY_CHANGED
178
     = 'conference.videoSIPGWAvailabilityChanged';
178
     = 'conference.videoSIPGWAvailabilityChanged';
179
 
179
 
180
+/**
181
+ * Indicates that video SIP GW Session state changed.
182
+ * @param {options} event - {
183
+ *     {string} address,
184
+ *     {VideoSIPGWConstants} oldState,
185
+ *     {VideoSIPGWConstants} newState,
186
+ *     {string} displayName}
187
+ * }.
188
+ */
189
+export const VIDEO_SIP_GW_SESSION_STATE_CHANGED
190
+    = 'conference.videoSIPGWSessionStateChanged';
191
+
180
 /**
192
 /**
181
  * Indicates that start muted settings changed.
193
  * Indicates that start muted settings changed.
182
  */
194
  */

+ 8
- 15
modules/videosipgw/JitsiVideoSIPGWSession.js Целия файл

1
-/* global $ */
2
 import { getLogger } from 'jitsi-meet-logger';
1
 import { getLogger } from 'jitsi-meet-logger';
3
 import { $iq } from 'strophe.js';
2
 import { $iq } from 'strophe.js';
4
 
3
 
91
         const oldState = this.state;
90
         const oldState = this.state;
92
 
91
 
93
         this.state = newState;
92
         this.state = newState;
94
-        this.eventEmitter.emit(this.sipAddress,
93
+        this.eventEmitter.emit(STATE_CHANGED,
95
             {
94
             {
96
-                name: STATE_CHANGED,
95
+                address: this.sipAddress,
97
                 oldState,
96
                 oldState,
98
-                newState: this.state
97
+                newState: this.state,
98
+                displayName: this.displayName
99
             }
99
             }
100
         );
100
         );
101
     }
101
     }
140
             .c('jibri', attributes)
140
             .c('jibri', attributes)
141
             .up();
141
             .up();
142
 
142
 
143
-        logger.log('Stop video SIP GW session', iq.nodeTree);
143
+        logger.debug(`${action} video SIP GW session`, iq.nodeTree);
144
         this.chatRoom.connection.sendIQ(
144
         this.chatRoom.connection.sendIQ(
145
             iq,
145
             iq,
146
-            result => {
147
-                logger.log('Result', result);
148
-                const initialState
149
-                    = $(result).find('jibri')
150
-                        .attr('state');
151
-
152
-                this.setState(initialState);
153
-            },
146
+            () => {}, // eslint-disable-line no-empty-function
154
             error => {
147
             error => {
155
-                logger.log('Failed to start video SIP GW session, error: ',
156
-                    error);
148
+                logger.error(
149
+                    `Failed to ${action} video SIP GW session, error: `, error);
157
                 this.setState(VideoSIPGWConstants.STATE_FAILED);
150
                 this.setState(VideoSIPGWConstants.STATE_FAILED);
158
             });
151
             });
159
     }
152
     }

+ 21
- 22
modules/videosipgw/VideoSIPGW.js Целия файл

18
     constructor(chatRoom) {
18
     constructor(chatRoom) {
19
         this.chatRoom = chatRoom;
19
         this.chatRoom = chatRoom;
20
         this.eventEmitter = chatRoom.eventEmitter;
20
         this.eventEmitter = chatRoom.eventEmitter;
21
-        logger.info('creating VideoSIPGW');
21
+        logger.debug('creating VideoSIPGW');
22
         this.sessions = {};
22
         this.sessions = {};
23
 
23
 
24
         this.sessionStateChangeListener = this.sessionStateChanged.bind(this);
24
         this.sessionStateChangeListener = this.sessionStateChanged.bind(this);
45
             return;
45
             return;
46
         }
46
         }
47
 
47
 
48
-        logger.log('Handle video sip gw status : ', attributes);
48
+        logger.debug('Handle video sip gw status : ', attributes);
49
         const newStatus = attributes.status;
49
         const newStatus = attributes.status;
50
 
50
 
51
         // check for global availability of the service
51
         // check for global availability of the service
72
             return;
72
             return;
73
         }
73
         }
74
 
74
 
75
-        logger.log('Handle video sip gw state : ', attributes);
75
+        logger.debug('Handle video sip gw state : ', attributes);
76
 
76
 
77
         const newState = attributes.state;
77
         const newState = attributes.state;
78
 
78
 
105
     }
105
     }
106
 
106
 
107
     /**
107
     /**
108
-     * Creates new session and stores its reference.
108
+     * Creates new session and stores its reference if it does not exist or
109
+     * returns an error otherwise.
109
      *
110
      *
110
      * @param {string} sipAddress - The sip address to use.
111
      * @param {string} sipAddress - The sip address to use.
111
      * @param {string} displayName - The display name to use.
112
      * @param {string} displayName - The display name to use.
112
-     * @returns {JitsiVideoSIPGWSession}
113
+     * @returns {JitsiVideoSIPGWSession|Error}
113
      */
114
      */
114
     createVideoSIPGWSession(sipAddress, displayName) {
115
     createVideoSIPGWSession(sipAddress, displayName) {
115
-        const session = new JitsiVideoSIPGWSession(
116
-            sipAddress, displayName, this.chatRoom);
117
-
118
-        session.addStateListener(this.sessionStateChangeListener);
119
-
120
         if (this.sessions[sipAddress]) {
116
         if (this.sessions[sipAddress]) {
121
             logger.warn('There was already a Video SIP GW session for address',
117
             logger.warn('There was already a Video SIP GW session for address',
122
                 sipAddress);
118
                 sipAddress);
119
+
120
+            return new Error(Constants.ERROR_SESSION_EXISTS);
123
         }
121
         }
124
 
122
 
123
+        const session = new JitsiVideoSIPGWSession(
124
+            sipAddress, displayName, this.chatRoom);
125
+
126
+        session.addStateListener(this.sessionStateChangeListener);
127
+
125
         this.sessions[sipAddress] = session;
128
         this.sessions[sipAddress] = session;
126
 
129
 
127
         return session;
130
         return session;
128
     }
131
     }
129
 
132
 
130
-    /**
131
-     * Returns whether SIP GW service is available.
132
-     *
133
-     * @returns {boolean} whether SIP GW service is available.
134
-     */
135
-    isVideoSIPGWAvailable() {
136
-        return this.status === Constants.STATUS_AVAILABLE;
137
-    }
138
-
139
     /**
133
     /**
140
      * Listener for session state changed. When a session goes to off or failed
134
      * Listener for session state changed. When a session goes to off or failed
141
      * we delete its reference.
135
      * we delete its reference.
142
      *
136
      *
143
-     * @param {string} address - The SIP address of the session.
144
-     * @param {options} event - { name, oldState, newState }
137
+     * @param {options} event - { address, oldState, newState, displayName }
145
      */
138
      */
146
-    sessionStateChanged(address, event) {
139
+    sessionStateChanged(event) {
140
+        const address = event.address;
141
+
147
         if (event.newState === Constants.STATE_OFF
142
         if (event.newState === Constants.STATE_OFF
148
             || event.newState === Constants.STATE_FAILED) {
143
             || event.newState === Constants.STATE_FAILED) {
149
             const session = this.sessions[address];
144
             const session = this.sessions[address];
158
             session.removeStateListener(this.sessionStateChangeListener);
153
             session.removeStateListener(this.sessionStateChangeListener);
159
             delete this.sessions[address];
154
             delete this.sessions[address];
160
         }
155
         }
156
+
157
+        this.eventEmitter.emit(
158
+            XMPPEvents.VIDEO_SIP_GW_SESSION_STATE_CHANGED,
159
+            event);
161
     }
160
     }
162
 }
161
 }

+ 14
- 0
modules/videosipgw/VideoSIPGWConstants.js Целия файл

47
  * @type {string}
47
  * @type {string}
48
  */
48
  */
49
 export const STATE_FAILED = 'failed';
49
 export const STATE_FAILED = 'failed';
50
+
51
+/**
52
+ * Error on trying to create video SIP GW session in conference where
53
+ * there is no room connection (hasn't joined or has left the room).
54
+ * @type {string}
55
+ */
56
+export const ERROR_NO_CONNECTION = 'error_no_connection';
57
+
58
+/**
59
+ * Error on trying to create video SIP GW session with address for which
60
+ * there is an already created session.
61
+ * @type {string}
62
+ */
63
+export const ERROR_SESSION_EXISTS = 'error_session_already_exists';

+ 11
- 0
service/xmpp/XMPPEvents.js Целия файл

216
      */
216
      */
217
     VIDEO_SIP_GW_AVAILABILITY_CHANGED: 'xmpp.videoSIPGWAvailabilityChanged',
217
     VIDEO_SIP_GW_AVAILABILITY_CHANGED: 'xmpp.videoSIPGWAvailabilityChanged',
218
 
218
 
219
+    /**
220
+     * Indicates that video SIP GW Session state changed.
221
+     * The statuses are any of the following statuses:
222
+     * STATE_ON, STATE_OFF, STATE_PENDING, STATE_RETRYING, STATE_FAILED.
223
+     * {@see VideoSIPGWConstants}
224
+     *
225
+     * @param {options} event - {address, oldState, newState, displayName}.
226
+     */
227
+    VIDEO_SIP_GW_SESSION_STATE_CHANGED:
228
+        'xmpp.videoSIPGWSessionStateChanged',
229
+
219
     // Designates an event indicating that the local ICE connection state has
230
     // Designates an event indicating that the local ICE connection state has
220
     // changed.
231
     // changed.
221
     ICE_CONNECTION_STATE_CHANGED: 'xmpp.ice_connection_state_changed',
232
     ICE_CONNECTION_STATE_CHANGED: 'xmpp.ice_connection_state_changed',

Loading…
Отказ
Запис