Преглед изворни кода

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,6 +38,7 @@ import TalkMutedDetection from './modules/TalkMutedDetection';
38 38
 import Transcriber from './modules/transcription/transcriber';
39 39
 import VideoType from './service/RTC/VideoType';
40 40
 import VideoSIPGW from './modules/videosipgw/VideoSIPGW';
41
+import * as VideoSIPGWConstants from './modules/videosipgw/VideoSIPGWConstants';
41 42
 import * as XMPPEvents from './service/xmpp/XMPPEvents';
42 43
 
43 44
 import SpeakerStatsCollector from './modules/statistics/SpeakerStatsCollector';
@@ -194,6 +195,8 @@ export default function JitsiConference(options) {
194 195
      * @type {JingleSessionPC}
195 196
      */
196 197
     this.p2pJingleSession = null;
198
+
199
+    this.videoSIPGWHandler = new VideoSIPGW(this.room);
197 200
 }
198 201
 
199 202
 // FIXME convert JitsiConference to ES6 - ASAP !
@@ -2701,29 +2704,6 @@ JitsiConference.prototype.setReceiverVideoConstraint = function(
2701 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 2708
  * Creates a video SIP GW session and returns it if service is enabled. Before
2729 2709
  * creating a session one need to check whether video SIP GW service is
@@ -2734,15 +2714,15 @@ JitsiConference.prototype.isVideoSIPGWAvailable = function() {
2734 2714
  *
2735 2715
  * @param {string} sipAddress - The sip address to be used.
2736 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 2718
  * initialised and there is no room.
2739 2719
  */
2740 2720
 JitsiConference.prototype.createVideoSIPGWSession
2741 2721
     = function(sipAddress, displayName) {
2742 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 2727
             .createVideoSIPGWSession(sipAddress, displayName);
2748 2728
     };

+ 4
- 0
JitsiConferenceEventManager.js Прегледај датотеку

@@ -214,6 +214,10 @@ JitsiConferenceEventManager.prototype.setupChatRoomListeners = function() {
214 214
     this.chatRoomForwarder.forward(XMPPEvents.VIDEO_SIP_GW_AVAILABILITY_CHANGED,
215 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 221
     this.chatRoomForwarder.forward(XMPPEvents.PHONE_NUMBER_CHANGED,
218 222
         JitsiConferenceEvents.PHONE_NUMBER_CHANGED);
219 223
 

+ 12
- 0
JitsiConferenceEvents.js Прегледај датотеку

@@ -177,6 +177,18 @@ export const RECORDER_STATE_CHANGED = 'conference.recorderStateChanged';
177 177
 export const VIDEO_SIP_GW_AVAILABILITY_CHANGED
178 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 193
  * Indicates that start muted settings changed.
182 194
  */

+ 8
- 15
modules/videosipgw/JitsiVideoSIPGWSession.js Прегледај датотеку

@@ -1,4 +1,3 @@
1
-/* global $ */
2 1
 import { getLogger } from 'jitsi-meet-logger';
3 2
 import { $iq } from 'strophe.js';
4 3
 
@@ -91,11 +90,12 @@ export default class JitsiVideoSIPGWSession extends Listenable {
91 90
         const oldState = this.state;
92 91
 
93 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 96
                 oldState,
98
-                newState: this.state
97
+                newState: this.state,
98
+                displayName: this.displayName
99 99
             }
100 100
         );
101 101
     }
@@ -140,20 +140,13 @@ export default class JitsiVideoSIPGWSession extends Listenable {
140 140
             .c('jibri', attributes)
141 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 144
         this.chatRoom.connection.sendIQ(
145 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 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 150
                 this.setState(VideoSIPGWConstants.STATE_FAILED);
158 151
             });
159 152
     }

+ 21
- 22
modules/videosipgw/VideoSIPGW.js Прегледај датотеку

@@ -18,7 +18,7 @@ export default class VideoSIPGW {
18 18
     constructor(chatRoom) {
19 19
         this.chatRoom = chatRoom;
20 20
         this.eventEmitter = chatRoom.eventEmitter;
21
-        logger.info('creating VideoSIPGW');
21
+        logger.debug('creating VideoSIPGW');
22 22
         this.sessions = {};
23 23
 
24 24
         this.sessionStateChangeListener = this.sessionStateChanged.bind(this);
@@ -45,7 +45,7 @@ export default class VideoSIPGW {
45 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 49
         const newStatus = attributes.status;
50 50
 
51 51
         // check for global availability of the service
@@ -72,7 +72,7 @@ export default class VideoSIPGW {
72 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 77
         const newState = attributes.state;
78 78
 
@@ -105,45 +105,40 @@ export default class VideoSIPGW {
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 111
      * @param {string} sipAddress - The sip address to use.
111 112
      * @param {string} displayName - The display name to use.
112
-     * @returns {JitsiVideoSIPGWSession}
113
+     * @returns {JitsiVideoSIPGWSession|Error}
113 114
      */
114 115
     createVideoSIPGWSession(sipAddress, displayName) {
115
-        const session = new JitsiVideoSIPGWSession(
116
-            sipAddress, displayName, this.chatRoom);
117
-
118
-        session.addStateListener(this.sessionStateChangeListener);
119
-
120 116
         if (this.sessions[sipAddress]) {
121 117
             logger.warn('There was already a Video SIP GW session for address',
122 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 128
         this.sessions[sipAddress] = session;
126 129
 
127 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 134
      * Listener for session state changed. When a session goes to off or failed
141 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 142
         if (event.newState === Constants.STATE_OFF
148 143
             || event.newState === Constants.STATE_FAILED) {
149 144
             const session = this.sessions[address];
@@ -158,5 +153,9 @@ export default class VideoSIPGW {
158 153
             session.removeStateListener(this.sessionStateChangeListener);
159 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,3 +47,17 @@ export const STATE_RETRYING = 'retrying';
47 47
  * @type {string}
48 48
  */
49 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,6 +216,17 @@ const XMPPEvents = {
216 216
      */
217 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 230
     // Designates an event indicating that the local ICE connection state has
220 231
     // changed.
221 232
     ICE_CONNECTION_STATE_CHANGED: 'xmpp.ice_connection_state_changed',

Loading…
Откажи
Сачувај