Skip to content

Commit 240abc0

Browse files
authored
feat(ts) migrate modules\videosipgw\JitsiVideoSIPGWSession to TS
1 parent ba3415b commit 240abc0

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed

modules/videosipgw/JitsiVideoSIPGWSession.js renamed to modules/videosipgw/JitsiVideoSIPGWSession.ts

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { getLogger } from '@jitsi/logger';
22
import { $iq } from 'strophe.js';
3-
3+
import ChatRoom from '../xmpp/ChatRoom';
44
import Listenable from '../util/Listenable';
55

66
import * as VideoSIPGWConstants from './VideoSIPGWConstants';
@@ -11,13 +11,17 @@ const logger = getLogger('modules/videosipgw/JitsiVideoSIPGWSession');
1111
* The event name for current sip video session state changed.
1212
* @type {string} event name for sip video session state changed.
1313
*/
14-
const STATE_CHANGED = 'STATE_CHANGED';
14+
const STATE_CHANGED: string = 'STATE_CHANGED';
1515

1616
/**
1717
* Jitsi video SIP GW session. Holding its state and able to start/stop it.
1818
* When session is in OFF or FAILED stated it cannot be used anymore.
1919
*/
2020
export default class JitsiVideoSIPGWSession extends Listenable {
21+
sipAddress: string;
22+
displayName: string;
23+
chatRoom: ChatRoom;
24+
state?: string;
2125

2226
/**
2327
* Creates new session with the desired sip address and display name.
@@ -28,7 +32,7 @@ export default class JitsiVideoSIPGWSession extends Listenable {
2832
* that participant.
2933
* @param {ChatRoom} chatRoom - The chat room this session is bound to.
3034
*/
31-
constructor(sipAddress, displayName, chatRoom) {
35+
constructor(sipAddress: string, displayName: string, chatRoom: ChatRoom) {
3236
super();
3337

3438
this.sipAddress = sipAddress;
@@ -48,7 +52,7 @@ export default class JitsiVideoSIPGWSession extends Listenable {
4852
/**
4953
* Stops the current session.
5054
*/
51-
stop() {
55+
stop(): void {
5256
if (this.state === VideoSIPGWConstants.STATE_OFF
5357
|| this.state === VideoSIPGWConstants.STATE_FAILED) {
5458
logger.warn('Video SIP GW session already stopped or failed!');
@@ -62,7 +66,7 @@ export default class JitsiVideoSIPGWSession extends Listenable {
6266
/**
6367
* Starts a new session. Sends an iq to the focus.
6468
*/
65-
start() {
69+
start(): void {
6670
// if state is off, this session was active for some reason
6771
// and we should create new one, rather than reusing it
6872
if (this.state === VideoSIPGWConstants.STATE_ON
@@ -85,7 +89,7 @@ export default class JitsiVideoSIPGWSession extends Listenable {
8589
* was entered.
8690
* @returns {void}
8791
*/
88-
setState(newState, failureReason) {
92+
setState(newState: string, failureReason?: string): void {
8993
if (newState === this.state) {
9094
return;
9195
}
@@ -108,18 +112,18 @@ export default class JitsiVideoSIPGWSession extends Listenable {
108112
* Subscribes the passed listener to the event for state change of this
109113
* session.
110114
*
111-
* @param {Function} listener - The function that will receive the event.
115+
* @param {EventListener} listener - The function that will receive the event.
112116
*/
113-
addStateListener(listener) {
117+
addStateListener(listener: EventListener): void {
114118
this.addListener(STATE_CHANGED, listener);
115119
}
116120

117121
/**
118122
* Unsubscribes the passed handler.
119123
*
120-
* @param {Function} listener - The function to be removed.
124+
* @param {EventListener} listener - The function to be removed.
121125
*/
122-
removeStateListener(listener) {
126+
removeStateListener(listener: EventListener): void {
123127
this.removeListener(STATE_CHANGED, listener);
124128
}
125129

@@ -129,15 +133,14 @@ export default class JitsiVideoSIPGWSession extends Listenable {
129133
* @private
130134
* @param {string} action - The action to send ('start' or 'stop').
131135
*/
132-
_sendJibriIQ(action) {
136+
private _sendJibriIQ(action: string): void {
133137
const attributes = {
134138
'xmlns': 'http://jitsi.org/protocol/jibri',
135139
'action': action,
136-
sipaddress: this.sipAddress
140+
'sipaddress': this.sipAddress,
141+
'displayname': this.displayName
137142
};
138143

139-
attributes.displayname = this.displayName;
140-
141144
const iq = $iq({
142145
to: this.chatRoom.focusMucJid,
143146
type: 'set' })
@@ -147,11 +150,12 @@ export default class JitsiVideoSIPGWSession extends Listenable {
147150
logger.debug(`${action} video SIP GW session`, iq.nodeTree);
148151
this.chatRoom.connection.sendIQ(
149152
iq,
150-
() => {}, // eslint-disable-line no-empty-function
151-
error => {
153+
() => {}, // eslint-disable-line @typescript-eslint/no-empty-function
154+
(error: any) => {
152155
logger.error(
153156
`Failed to ${action} video SIP GW session, error: `, error);
154157
this.setState(VideoSIPGWConstants.STATE_FAILED);
155-
});
158+
},
159+
undefined);
156160
}
157161
}

0 commit comments

Comments
 (0)