Skip to content

Commit 011b8f8

Browse files
committed
Description: Handling code-review comments. 1. Renamed delegate interface classes and files. Prefixed I before the name. 2. Removed unused files. 3. Renamed User.ts to VoIPUser.ts to avoid confusion. 4. Added interface for voip configuration. 5. Side effect changes in VoIPLayout.ts because of the above changes.
1 parent d2c8d0c commit 011b8f8

File tree

8 files changed

+107
-101
lines changed

8 files changed

+107
-101
lines changed
File renamed without changes.
File renamed without changes.
File renamed without changes.

client/components/voip/IncomingInviteHandler.ts

Lines changed: 0 additions & 27 deletions
This file was deleted.

client/components/voip/UserInfo.ts

Lines changed: 0 additions & 19 deletions
This file was deleted.
Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@ import {
2020
import { OutgoingRequestDelegate } from 'sip.js/lib/core';
2121
import { SessionDescriptionHandler } from 'sip.js/lib/platform/web';
2222

23-
import { ICallEventDelegate } from './CallEventDelegate';
2423
import { CallState } from './Callstate';
25-
import { IConnectionDelegate } from './ConnectionDelegate';
24+
import { ICallEventDelegate } from './ICallEventDelegate';
25+
import { IConnectionDelegate } from './IConnectionDelegate';
26+
import { IRegisterHandlerDelegate } from './IRegisterHandlerDelegate';
2627
import { Operation } from './Operations';
27-
import { IRegisterHandlerDeligate } from './RegisterHandlerDelegate';
28+
import { VoIPUserConfiguration } from './VoIPUserConfiguration';
2829
import Stream from './media/Stream';
2930
import { 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
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { IConnectionDelegate } from './IConnectionDelegate';
2+
3+
// eslint-disable-next-line @typescript-eslint/interface-name-prefix
4+
export interface VoIPUserConfiguration {
5+
/**
6+
* Authorization username.
7+
* @defaultValue `""`
8+
*/
9+
authUserName?: string;
10+
/**
11+
* Authorization password.
12+
* @defaultValue `""`
13+
*/
14+
authPassword?: string;
15+
/**
16+
* SIP Registrar address.
17+
* @defaultValue `""`
18+
*/
19+
sipRegistrarHostnameOrIP?: string;
20+
/**
21+
* SIP WebSocket Path
22+
* @defaultValue `""`
23+
*/
24+
webSocketURI?: string;
25+
/**
26+
* Option to turn on video
27+
* @defaultValue undefined
28+
*/
29+
enableVideo?: boolean;
30+
/**
31+
* ConnectionDelegate
32+
* @defaultValue null
33+
*/
34+
connectionDelegate?: IConnectionDelegate;
35+
/**
36+
* ICE Server Array
37+
* @defaultValue undefined
38+
*/
39+
iceServers?: Array<object>;
40+
41+
/**
42+
* mediaElements to render local and remote stream
43+
* @defaultValue undefined
44+
*/
45+
mediaElements?: {
46+
remoteStreamMediaElement?: HTMLMediaElement;
47+
localStreamMediaElement?: HTMLMediaElement;
48+
};
49+
}

0 commit comments

Comments
 (0)