@@ -20,11 +20,12 @@ import {
2020import { OutgoingRequestDelegate } from 'sip.js/lib/core' ;
2121import { SessionDescriptionHandler } from 'sip.js/lib/platform/web' ;
2222
23- import { ICallEventDelegate } from './CallEventDelegate' ;
2423import { CallState } from './Callstate' ;
25- import { IConnectionDelegate } from './ConnectionDelegate' ;
24+ import { ICallEventDelegate } from './ICallEventDelegate' ;
25+ import { IConnectionDelegate } from './IConnectionDelegate' ;
26+ import { IRegisterHandlerDelegate } from './IRegisterHandlerDelegate' ;
2627import { Operation } from './Operations' ;
27- import { IRegisterHandlerDeligate } from './RegisterHandlerDelegate ' ;
28+ import { VoIPUserConfiguration } from './VoIPUserConfiguration ' ;
2829import Stream from './media/Stream' ;
2930import { Logger } from './utils/Logger' ;
3031// User state is based on whether the User has sent an invite(UAC) or it
@@ -34,18 +35,18 @@ enum UserState {
3435 UAC ,
3536 UAS ,
3637}
37- export class User implements UserAgentDelegate , OutgoingRequestDelegate {
38+ export class VoIPUser implements UserAgentDelegate , OutgoingRequestDelegate {
3839 private connectionDelegate : IConnectionDelegate ;
3940
40- private registrationDelegate : IRegisterHandlerDeligate ;
41+ private registrationDelegate : IRegisterHandlerDelegate ;
4142
4243 private callEventDelegate : ICallEventDelegate ;
4344
4445 private session : Session | undefined ;
4546
4647 private remoteStream : Stream | undefined ;
4748
48- private config : any = { } ;
49+ private config : VoIPUserConfiguration = { } ;
4950
5051 userAgentOptions : UserAgentOptions = { } ;
5152
@@ -69,7 +70,7 @@ export class User implements UserAgentDelegate, OutgoingRequestDelegate {
6970
7071 private _userState : UserState | undefined ;
7172
72- get userState ( ) : any {
73+ get userState ( ) : UserState | undefined {
7374 return this . _userState ;
7475 }
7576
@@ -88,24 +89,23 @@ export class User implements UserAgentDelegate, OutgoingRequestDelegate {
8889
8990 /* Media Stream functions end */
9091 constructor (
91- config : any ,
92+ config : VoIPUserConfiguration ,
9293 cDelegate : IConnectionDelegate ,
93- rDelegate : IRegisterHandlerDeligate ,
94+ rDelegate : IRegisterHandlerDelegate ,
9495 cEventDelegate : ICallEventDelegate ,
9596 ) {
9697 this . config = config ;
9798 this . connectionDelegate = cDelegate ;
9899 this . registrationDelegate = rDelegate ;
99100 this . callEventDelegate = cEventDelegate ;
100101 this . _userState = UserState . IDLE ;
101- this . logger = new Logger ( 'User ' ) ;
102+ this . logger = new Logger ( 'VoIPUser ' ) ;
102103 }
103104
104105 /* UserAgentDelegate methods begin */
105106 onConnect ( ) : void {
106107 this . _callState = CallState . SERVER_CONNECTED ;
107108 this . logger ?. info ( 'onConnect() Connected' ) ;
108- console . log ( 'Connected' ) ;
109109 this . connectionDelegate . onConnected ?.( ) ;
110110 if ( this . userAgent ) {
111111 this . registerer = new Registerer ( this . userAgent ) ;
@@ -245,7 +245,7 @@ export class User implements UserAgentDelegate, OutgoingRequestDelegate {
245245 }
246246
247247 this . remoteStream = new Stream ( remoteStream ) ;
248- const mediaElement = this . config . media ?. remote_video_element ;
248+ const mediaElement = this . config . mediaElements ?. remoteStreamMediaElement ;
249249
250250 if ( mediaElement ) {
251251 this . remoteStream . init ( mediaElement ) ;
@@ -267,28 +267,27 @@ export class User implements UserAgentDelegate, OutgoingRequestDelegate {
267267
268268 async init ( ) : Promise < any > {
269269 this . logger ?. debug ( 'init()' ) ;
270- const sipUri = `sip:${ this . config . auth_user_name } @${ this . config . sip_registrar_hostname_ip } ` ;
270+ const sipUri = `sip:${ this . config . authUserName } @${ this . config . sipRegistrarHostnameOrIP } ` ;
271271 this . logger ?. verbose ( 'init() endpoint identity = ' , sipUri ) ;
272272 const transportOptions = {
273- server : this . config . websocket_uri ,
273+ server : this . config . webSocketURI ,
274274 connectionTimeout : 10 , // Replace this with config
275275 keepAliveInterval : 20 ,
276276 // traceSip: true
277277 } ;
278278 const sdpFactoryOptions = {
279279 iceGatheringTimeout : 10 ,
280280 peerConnectionConfiguration : {
281- iceServers : this . config . ice_servers ,
281+ iceServers : this . config . iceServers ,
282282 } ,
283283 } ;
284284 this . userAgentOptions = {
285285 delegate : this ,
286- authorizationPassword : this . config . password ,
287- authorizationUsername : this . config . auth_user_name ,
286+ authorizationPassword : this . config . authPassword ,
287+ authorizationUsername : this . config . authUserName ,
288288 uri : UserAgent . makeURI ( sipUri ) ,
289289 transportOptions,
290290 sessionDescriptionHandlerFactoryOptions : sdpFactoryOptions ,
291- displayName : this . config . display_name ,
292291 logConfiguration : false ,
293292 } ;
294293
@@ -340,7 +339,7 @@ export class User implements UserAgentDelegate, OutgoingRequestDelegate {
340339 sessionDescriptionHandlerOptions : {
341340 constraints : {
342341 audio : true ,
343- video : ! ! this . config . enable_video ,
342+ video : ! ! this . config . enableVideo ,
344343 } ,
345344 } ,
346345 } ;
@@ -380,11 +379,11 @@ export class User implements UserAgentDelegate, OutgoingRequestDelegate {
380379 }
381380 return this . session . reject ( ) ;
382381 }
382+
383383 /**
384384 * Public method called from outside to end a call.
385385 * @remarks
386386 */
387-
388387 async endCall ( ) : Promise < any > {
389388 if ( ! this . session ) {
390389 this . logger ?. warn ( 'rejectCall() Session does not exist' ) ;
@@ -401,14 +400,12 @@ export class User implements UserAgentDelegate, OutgoingRequestDelegate {
401400 }
402401 this . logger ?. warn ( 'rejectCall() Session not instance of Invitation.' ) ;
403402 throw new Error ( 'Session not instance of Invitation.' ) ;
404-
405403 case SessionState . Establishing :
406404 if ( this . session instanceof Invitation ) {
407405 return this . session . reject ( ) ;
408406 }
409407 this . logger ?. warn ( 'rejectCall() Session not instance of Invitation.' ) ;
410408 throw new Error ( 'Session not instance of Invitation.' ) ;
411-
412409 case SessionState . Established :
413410 return this . session . bye ( ) ;
414411 case SessionState . Terminating :
@@ -419,6 +416,6 @@ export class User implements UserAgentDelegate, OutgoingRequestDelegate {
419416 this . logger ?. warn ( 'rejectCall() Unknown state' ) ;
420417 throw new Error ( 'Unknown state' ) ;
421418 }
422- console . log ( 'Ended ') ;
419+ this . logger ?. debug ( 'ended ') ;
423420 }
424421}
0 commit comments