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