Browse Source

feat(ts) migrate modules\videosipgw\JitsiVideoSIPGWSession to TS

master
Naman Jain 4 months ago
parent
commit
240abc0c35
No account linked to committer's email address
1 changed files with 21 additions and 17 deletions
  1. 21
    17
      modules/videosipgw/JitsiVideoSIPGWSession.ts

modules/videosipgw/JitsiVideoSIPGWSession.js → modules/videosipgw/JitsiVideoSIPGWSession.ts View File

1
 import { getLogger } from '@jitsi/logger';
1
 import { getLogger } from '@jitsi/logger';
2
 import { $iq } from 'strophe.js';
2
 import { $iq } from 'strophe.js';
3
-
3
+import ChatRoom from '../xmpp/ChatRoom';
4
 import Listenable from '../util/Listenable';
4
 import Listenable from '../util/Listenable';
5
 
5
 
6
 import * as VideoSIPGWConstants from './VideoSIPGWConstants';
6
 import * as VideoSIPGWConstants from './VideoSIPGWConstants';
11
  * The event name for current sip video session state changed.
11
  * The event name for current sip video session state changed.
12
  * @type {string} event name for sip video session state changed.
12
  * @type {string} event name for sip video session state changed.
13
  */
13
  */
14
-const STATE_CHANGED = 'STATE_CHANGED';
14
+const STATE_CHANGED: string = 'STATE_CHANGED';
15
 
15
 
16
 /**
16
 /**
17
  * Jitsi video SIP GW session. Holding its state and able to start/stop it.
17
  * Jitsi video SIP GW session. Holding its state and able to start/stop it.
18
  * When session is in OFF or FAILED stated it cannot be used anymore.
18
  * When session is in OFF or FAILED stated it cannot be used anymore.
19
  */
19
  */
20
 export default class JitsiVideoSIPGWSession extends Listenable {
20
 export default class JitsiVideoSIPGWSession extends Listenable {
21
+    sipAddress: string;
22
+    displayName: string;
23
+    chatRoom: ChatRoom;
24
+    state?: string;
21
 
25
 
22
     /**
26
     /**
23
      * Creates new session with the desired sip address and display name.
27
      * Creates new session with the desired sip address and display name.
28
      * that participant.
32
      * that participant.
29
      * @param {ChatRoom} chatRoom - The chat room this session is bound to.
33
      * @param {ChatRoom} chatRoom - The chat room this session is bound to.
30
      */
34
      */
31
-    constructor(sipAddress, displayName, chatRoom) {
35
+    constructor(sipAddress: string, displayName: string, chatRoom: ChatRoom) {
32
         super();
36
         super();
33
 
37
 
34
         this.sipAddress = sipAddress;
38
         this.sipAddress = sipAddress;
48
     /**
52
     /**
49
      * Stops the current session.
53
      * Stops the current session.
50
      */
54
      */
51
-    stop() {
55
+    stop(): void {
52
         if (this.state === VideoSIPGWConstants.STATE_OFF
56
         if (this.state === VideoSIPGWConstants.STATE_OFF
53
             || this.state === VideoSIPGWConstants.STATE_FAILED) {
57
             || this.state === VideoSIPGWConstants.STATE_FAILED) {
54
             logger.warn('Video SIP GW session already stopped or failed!');
58
             logger.warn('Video SIP GW session already stopped or failed!');
62
     /**
66
     /**
63
      * Starts a new session. Sends an iq to the focus.
67
      * Starts a new session. Sends an iq to the focus.
64
      */
68
      */
65
-    start() {
69
+    start(): void {
66
         // if state is off, this session was active for some reason
70
         // if state is off, this session was active for some reason
67
         // and we should create new one, rather than reusing it
71
         // and we should create new one, rather than reusing it
68
         if (this.state === VideoSIPGWConstants.STATE_ON
72
         if (this.state === VideoSIPGWConstants.STATE_ON
85
      * was entered.
89
      * was entered.
86
      * @returns {void}
90
      * @returns {void}
87
      */
91
      */
88
-    setState(newState, failureReason) {
92
+    setState(newState: string, failureReason?: string): void {
89
         if (newState === this.state) {
93
         if (newState === this.state) {
90
             return;
94
             return;
91
         }
95
         }
108
      * Subscribes the passed listener to the event for state change of this
112
      * Subscribes the passed listener to the event for state change of this
109
      * session.
113
      * session.
110
      *
114
      *
111
-     * @param {Function} listener - The function that will receive the event.
115
+     * @param {EventListener} listener - The function that will receive the event.
112
      */
116
      */
113
-    addStateListener(listener) {
117
+    addStateListener(listener: EventListener): void {
114
         this.addListener(STATE_CHANGED, listener);
118
         this.addListener(STATE_CHANGED, listener);
115
     }
119
     }
116
 
120
 
117
     /**
121
     /**
118
      * Unsubscribes the passed handler.
122
      * Unsubscribes the passed handler.
119
      *
123
      *
120
-     * @param {Function} listener - The function to be removed.
124
+     * @param {EventListener} listener - The function to be removed.
121
      */
125
      */
122
-    removeStateListener(listener) {
126
+    removeStateListener(listener: EventListener): void {
123
         this.removeListener(STATE_CHANGED, listener);
127
         this.removeListener(STATE_CHANGED, listener);
124
     }
128
     }
125
 
129
 
129
      * @private
133
      * @private
130
      * @param {string} action - The action to send ('start' or 'stop').
134
      * @param {string} action - The action to send ('start' or 'stop').
131
      */
135
      */
132
-    _sendJibriIQ(action) {
136
+    private _sendJibriIQ(action: string): void {
133
         const attributes = {
137
         const attributes = {
134
             'xmlns': 'http://jitsi.org/protocol/jibri',
138
             'xmlns': 'http://jitsi.org/protocol/jibri',
135
             'action': action,
139
             'action': action,
136
-            sipaddress: this.sipAddress
140
+            'sipaddress': this.sipAddress,
141
+            'displayname': this.displayName
137
         };
142
         };
138
 
143
 
139
-        attributes.displayname = this.displayName;
140
-
141
         const iq = $iq({
144
         const iq = $iq({
142
             to: this.chatRoom.focusMucJid,
145
             to: this.chatRoom.focusMucJid,
143
             type: 'set' })
146
             type: 'set' })
147
         logger.debug(`${action} video SIP GW session`, iq.nodeTree);
150
         logger.debug(`${action} video SIP GW session`, iq.nodeTree);
148
         this.chatRoom.connection.sendIQ(
151
         this.chatRoom.connection.sendIQ(
149
             iq,
152
             iq,
150
-            () => {}, // eslint-disable-line no-empty-function
151
-            error => {
153
+            () => {}, // eslint-disable-line @typescript-eslint/no-empty-function
154
+            (error: any) => {
152
                 logger.error(
155
                 logger.error(
153
                     `Failed to ${action} video SIP GW session, error: `, error);
156
                     `Failed to ${action} video SIP GW session, error: `, error);
154
                 this.setState(VideoSIPGWConstants.STATE_FAILED);
157
                 this.setState(VideoSIPGWConstants.STATE_FAILED);
155
-            });
158
+            },
159
+            undefined);
156
     }
160
     }
157
 }
161
 }

Loading…
Cancel
Save