55 *
66 */
77
8- /*
9- * User's callbacks (listener-functions):
10- * - onCallListener(session, extension)
11- * - onAcceptCallListener(session, extension)
12- * - onRejectCallListener(session, extension)
13- * - onStopCallListener(session, extension)
14- * - onUpdateCallListener(session, extension)
15- */
8+ /*
9+ * User's callbacks (listener-functions):
10+ * - onCallListener(session, extension)
11+ * - onAcceptCallListener(session, extension)
12+ * - onRejectCallListener(session, extension)
13+ * - onStopCallListener(session, extension)
14+ * - onUpdateCallListener(session, extension)
15+ */
1616
1717var WebRTCSession = require ( './qbWebRTCSession' ) ;
1818var WebRTCSignalingProcessor = require ( './qbWebRTCSignalingProcessor' ) ;
@@ -42,11 +42,11 @@ function WebRTCClient(service, connection) {
4242 this . sessions = { } ;
4343}
4444
45- /**
46- * A map with all sessions the user had/have.
47- * @type {Object.<string, Object> }
48- */
49- WebRTCClient . prototype . sessions = { } ;
45+ /**
46+ * A map with all sessions the user had/have.
47+ * @type {Object.<string, Object> }
48+ */
49+ WebRTCClient . prototype . sessions = { } ;
5050
5151/**
5252 * Creates the new session.
@@ -63,7 +63,7 @@ WebRTCClient.prototype.createNewSession = function(opponentsIDs, callType) {
6363 } else {
6464 throw new Error ( "Can't create a session with the same opponentsIDs. There is a session already in NEW or ACTIVE state." ) ;
6565 }
66- }
66+ } ;
6767
6868WebRTCClient . prototype . _createAndStoreSession = function ( sessionID , callerID , opponentsIDs , callType ) {
6969 var newSession = new WebRTCSession ( sessionID , callerID , opponentsIDs , callType , this . signalingProvider , Helpers . getIdFromNode ( this . connection . jid ) )
@@ -76,17 +76,17 @@ WebRTCClient.prototype._createAndStoreSession = function(sessionID, callerID, op
7676
7777 this . sessions [ newSession . ID ] = newSession ;
7878 return newSession ;
79- }
79+ } ;
8080
81- /**
82- * Deletes a session
83- * @param {string } Session ID
84- */
85- WebRTCClient . prototype . clearSession = function ( sessionId ) {
86- delete WebRTCClient . sessions [ sessionId ] ;
87- }
81+ /**
82+ * Deletes a session
83+ * @param {string } Session ID
84+ */
85+ WebRTCClient . prototype . clearSession = function ( sessionId ) {
86+ delete WebRTCClient . sessions [ sessionId ] ;
87+ } ;
8888
89- /**
89+ /**
9090 * Check all session and find session with status 'NEW' or 'ACTIVE' which ID != provided
9191 * @param {string } session ID
9292 * @returns {boolean } if active or new session exist
@@ -110,12 +110,11 @@ WebRTCClient.prototype.isExistNewOrActiveSessionExceptSessionID = function(sessi
110110 return exist ;
111111} ;
112112
113+ /**
114+ * DELEGATE (signaling)
115+ */
113116
114- //
115- /////////////////////////// Delegate (signaling) //////////////////////////////
116- //
117-
118- WebRTCClient . prototype . _onCallListener = function ( userID , sessionID , extension ) {
117+ WebRTCClient . prototype . _onCallListener = function ( userID , sessionID , extension ) {
119118 Helpers . trace ( "onCall. UserID:" + userID + ". SessionID: " + sessionID ) ;
120119
121120 if ( this . isExistNewOrActiveSessionExceptSessionID ( sessionID ) ) {
@@ -140,73 +139,76 @@ WebRTCClient.prototype.isExistNewOrActiveSessionExceptSessionID = function(sessi
140139 }
141140 session . processOnCall ( userID , extension ) ;
142141 }
143- } ;
142+ } ;
144143
145- WebRTCClient . prototype . _onAcceptListener = function ( userID , sessionID , extension ) {
146- Helpers . trace ( "onAccept. UserID:" + userID + ". SessionID: " + sessionID ) ;
144+ WebRTCClient . prototype . _onAcceptListener = function ( userID , sessionID , extension ) {
145+ Helpers . trace ( "onAccept. UserID:" + userID + ". SessionID: " + sessionID ) ;
147146
148- var session = this . sessions [ sessionID ] ;
149- if ( session ) {
150- var extensionClone = JSON . parse ( JSON . stringify ( extension ) ) ;
151- this . _cleanupExtension ( extensionClone ) ;
147+ var session = this . sessions [ sessionID ] ;
152148
153- if ( typeof this . onAcceptCallListener === 'function' ) {
154- this . onAcceptCallListener ( session , extensionClone ) ;
155- }
149+ if ( session ) {
150+ var extensionClone = JSON . parse ( JSON . stringify ( extension ) ) ;
151+ this . _cleanupExtension ( extensionClone ) ;
156152
157- session . processOnAccept ( userID , extension ) ;
158- } else {
159- Helpers . traceError ( "Ignore 'onAccept', there is no information about session " + sessionID + " by some reason." ) ;
160- }
161- } ;
153+ if ( typeof this . onAcceptCallListener === 'function' ) {
154+ this . onAcceptCallListener ( session , extensionClone ) ;
155+ }
162156
163- WebRTCClient . prototype . _onRejectListener = function ( userID , sessionID , extension ) {
164- Helpers . trace ( "onReject. UserID:" + userID + ". SessionID: " + sessionID ) ;
157+ session . processOnAccept ( userID , extension ) ;
158+ } else {
159+ Helpers . traceError ( "Ignore 'onAccept', there is no information about session " + sessionID + " by some reason." ) ;
160+ }
161+ } ;
165162
166- var session = this . sessions [ sessionID ] ;
163+ WebRTCClient . prototype . _onRejectListener = function ( userID , sessionID , extension ) {
164+ Helpers . trace ( "onReject. UserID:" + userID + ". SessionID: " + sessionID ) ;
167165
168- if ( session ) {
169- var extensionClone = JSON . parse ( JSON . stringify ( extension ) ) ;
170- this . _cleanupExtension ( extensionClone ) ;
166+ var session = this . sessions [ sessionID ] ;
171167
172- if ( typeof this . onRejectCallListener === 'function' ) {
173- this . onRejectCallListener ( session , extensionClone ) ;
174- }
168+ if ( session ) {
169+ var extensionClone = JSON . parse ( JSON . stringify ( extension ) ) ;
170+ this . _cleanupExtension ( extensionClone ) ;
175171
176- session . processOnReject ( userID , extension ) ;
177- } else {
178- Helpers . traceError ( "Ignore 'onReject', there is no information about session " + sessionID + " by some reason." ) ;
179- }
180- } ;
172+ if ( typeof this . onRejectCallListener === 'function' ) {
173+ this . onRejectCallListener ( session , extensionClone ) ;
174+ }
181175
182- WebRTCClient . prototype . _onStopListener = function ( userID , sessionID , extension ) {
183- Helpers . trace ( "onStop. UserID:" + userID + ". SessionID: " + sessionID ) ;
176+ session . processOnReject ( userID , extension ) ;
177+ } else {
178+ Helpers . traceError ( "Ignore 'onReject', there is no information about session " + sessionID + " by some reason." ) ;
179+ }
180+ } ;
184181
185- var session = this . sessions [ sessionID ] ;
186- if ( session ) {
187- var extensionClone = JSON . parse ( JSON . stringify ( extension ) ) ;
188- this . _cleanupExtension ( extensionClone ) ;
182+ WebRTCClient . prototype . _onStopListener = function ( userID , sessionID , extension ) {
183+ Helpers . trace ( "onStop. UserID:" + userID + ". SessionID: " + sessionID ) ;
189184
190- if ( typeof this . onStopCallListener === 'function' ) {
191- this . onStopCallListener ( session , extensionClone ) ;
192- }
185+ var session = this . sessions [ sessionID ] ;
193186
194- session . processOnStop ( userID , extension ) ;
195- } else {
196- Helpers . traceError ( "Ignore 'onStop', there is no information about session " + sessionID + " by some reason." )
197- }
198- }
187+ if ( session ) {
188+ var extensionClone = JSON . parse ( JSON . stringify ( extension ) ) ;
189+ this . _cleanupExtension ( extensionClone ) ;
190+
191+ if ( typeof this . onStopCallListener === 'function' ) {
192+ this . onStopCallListener ( session , extensionClone ) ;
193+ }
194+
195+ session . processOnStop ( userID , extension ) ;
196+ } else {
197+ Helpers . traceError ( "Ignore 'onStop', there is no information about session " + sessionID + " by some reason." )
198+ }
199+ } ;
199200
200201WebRTCClient . prototype . _onIceCandidatesListener = function ( userID , sessionID , extension ) {
201202 Helpers . trace ( "onIceCandidates. UserID:" + userID + ". SessionID: " + sessionID + ". ICE candidates count: " + extension . iceCandidates . length ) ;
202203
203204 var session = this . sessions [ sessionID ] ;
205+
204206 if ( session ) {
205207 session . processOnIceCandidates ( userID , extension ) ;
206208 } else {
207209 Helpers . traceError ( "Ignore 'OnIceCandidates', there is no information about session " + sessionID + " by some reason." ) ;
208210 }
209- }
211+ } ;
210212
211213WebRTCClient . prototype . _onUpdateListener = function ( userID , sessionID , extension ) {
212214 Helpers . trace ( "onUpdate. UserID:" + userID + ". SessionID: " + sessionID + ". Extension: " + JSON . stringify ( extension ) ) ;
@@ -218,22 +220,21 @@ WebRTCClient.prototype._onUpdateListener = function(userID, sessionID, extension
218220 }
219221
220222 session . processOnUpdate ( userID , extension ) ;
221- }
223+ } ;
222224
223225WebRTCClient . prototype . _cleanupExtension = function ( extension ) {
224226 delete extension . platform ;
225227 delete extension . sdp ;
226228 delete extension . opponentsIDs ;
227229 delete extension . callerID ;
228230 delete extension . callType ;
229- }
231+ } ;
230232
231233module . exports = WebRTCClient ;
232234
233235/**
234236 * PRIVATE FUNCTIONS
235237 */
236-
237238function isOpponentsEqual ( exOpponents , currentOpponents ) {
238239 var ans = false ,
239240 cOpponents = currentOpponents . sort ( ) ;
@@ -249,7 +250,7 @@ function isOpponentsEqual(exOpponents, currentOpponents) {
249250 }
250251
251252 return ans ;
252- } ;
253+ }
253254
254255function getOpponentsIdNASessions ( sessions ) {
255256 var opponents = [ ] ;
@@ -264,4 +265,4 @@ function getOpponentsIdNASessions(sessions) {
264265 }
265266
266267 return opponents ;
267- }
268+ }
0 commit comments