Skip to content

Commit c2c81f4

Browse files
committed
initial migration
1 parent b1ec36e commit c2c81f4

File tree

1 file changed

+54
-14
lines changed

1 file changed

+54
-14
lines changed

modules/proxyconnection/ProxyConnectionService.js renamed to modules/proxyconnection/ProxyConnectionService.ts

Lines changed: 54 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,62 @@
11
import { getLogger } from '@jitsi/logger';
22
import { $iq } from 'strophe.js';
33

4-
import $ from '../../modules/util/XMLParser';
4+
import JitsiConnection from '../../JitsiConnection';
55
import { MediaType } from '../../service/RTC/MediaType';
66
import { getSourceNameForJitsiTrack } from '../../service/RTC/SignalingLayer';
77
import { VideoType } from '../../service/RTC/VideoType';
8+
import JitsiLocalTrack from '../RTC/JitsiLocalTrack';
9+
import JitsiRemoteTrack from '../RTC/JitsiRemoteTrack';
810
import RTC from '../RTC/RTC';
11+
import $ from '../util/XMLParser';
912

1013
import ProxyConnectionPC from './ProxyConnectionPC';
1114
import { ACTIONS } from './constants';
1215

1316
const logger = getLogger('modules/proxyconnection/ProxyConnectionService');
1417

18+
/**
19+
* Options for initializing a ProxyConnectionService instance.
20+
*/
21+
interface IProxyConnectionServiceOptions {
22+
convertVideoToDesktop?: boolean;
23+
jitsiConnection?: JitsiConnection;
24+
onConnectionClosed?: () => void;
25+
onRemoteStream?: (jitsiLocalTrack: JitsiLocalTrack) => void;
26+
onSendMessage?: (peerJid: string, message: { iq: string; }) => void;
27+
pcConfig?: RTCConfiguration;
28+
}
29+
30+
/**
31+
* Message object for proxy connection communication.
32+
*/
33+
interface IProxyConnectionMessage {
34+
data: {
35+
iq: string;
36+
};
37+
from: string;
38+
}
39+
1540
/**
1641
* Instantiates a new ProxyConnectionPC and ensures only one exists at a given
1742
* time. Currently it assumes ProxyConnectionPC is used only for screensharing
1843
* and assumes IQs to be used for communication.
1944
*/
2045
export default class ProxyConnectionService {
46+
/**
47+
* Holds a reference to the collection of all callbacks.
48+
*
49+
* @type {Object}
50+
*/
51+
private _options: IProxyConnectionServiceOptions;
52+
53+
/**
54+
* The active instance of {@code ProxyConnectionService}.
55+
*
56+
* @type {ProxyConnectionPC|null}
57+
*/
58+
private _peerConnection?: ProxyConnectionPC;
59+
2160
/**
2261
* Initializes a new {@code ProxyConnectionService} instance.
2362
*
@@ -32,7 +71,7 @@ export default class ProxyConnectionService {
3271
* @param {Function} options.onSendMessage - Callback to invoke when a message has to be sent (signaled) out. The
3372
* arguments passed in are the jid to send the message to and the message.
3473
*/
35-
constructor(options = {}) {
74+
constructor(options: IProxyConnectionServiceOptions = {}) {
3675
const {
3776
jitsiConnection,
3877
...otherOptions
@@ -44,7 +83,8 @@ export default class ProxyConnectionService {
4483
* @type {Object}
4584
*/
4685
this._options = {
47-
pcConfig: jitsiConnection && jitsiConnection.xmpp.connection.jingle.p2pIceConfig,
86+
// @ts-ignore -- jitsiconf needed
87+
pcConfig: jitsiConnection?.xmpp.connection.jingle.p2pIceConfig,
4888
...otherOptions
4989
};
5090

@@ -75,7 +115,7 @@ export default class ProxyConnectionService {
75115
* sending replies.
76116
* @returns {void}
77117
*/
78-
processMessage(message) {
118+
processMessage(message: IProxyConnectionMessage): void {
79119
const peerJid = message.from;
80120

81121
if (!peerJid) {
@@ -97,8 +137,8 @@ export default class ProxyConnectionService {
97137
}
98138

99139
const iq = this._convertStringToXML(message.data.iq);
100-
const $jingle = iq && iq.find('jingle');
101-
const action = $jingle && $jingle.attr('action');
140+
const $jingle = iq?.find('jingle');
141+
const action = $jingle?.attr('action');
102142

103143
if (action === ACTIONS.INITIATE) {
104144
this._peerConnection = this._createPeerConnection(peerJid, {
@@ -133,7 +173,7 @@ export default class ProxyConnectionService {
133173
* send through to the peer.
134174
* @returns {void}
135175
*/
136-
start(peerJid, localTracks = []) {
176+
start(peerJid: string, localTracks: JitsiLocalTrack[] = []): void {
137177
this._peerConnection = this._createPeerConnection(peerJid, {
138178
isInitiator: true,
139179
receiveVideo: false
@@ -153,7 +193,7 @@ export default class ProxyConnectionService {
153193
*
154194
* @returns {void}
155195
*/
156-
stop() {
196+
stop(): void {
157197
if (this._peerConnection) {
158198
this._peerConnection.stop();
159199
}
@@ -169,7 +209,7 @@ export default class ProxyConnectionService {
169209
* @returns {Object|null} An element version of the xml. Null will be returned
170210
* if an error is encountered during transformation.
171211
*/
172-
_convertStringToXML(xml) {
212+
private _convertStringToXML(xml: string): any {
173213
try {
174214
const xmlDom = new DOMParser().parseFromString(xml, 'text/xml');
175215

@@ -192,7 +232,7 @@ export default class ProxyConnectionService {
192232
* @private
193233
* @returns {ProxyConnectionPC}
194234
*/
195-
_createPeerConnection(peerJid, options = {}) {
235+
private _createPeerConnection(peerJid: string, options: any = {}): ProxyConnectionPC { // todo
196236
if (!peerJid) {
197237
throw new Error('Cannot create ProxyConnectionPC without a peer.');
198238
}
@@ -223,7 +263,7 @@ export default class ProxyConnectionService {
223263
* @private
224264
* @returns {void}
225265
*/
226-
_onFatalError(peerJid, errorType, details = '') {
266+
private _onFatalError(peerJid: string, errorType: string, details: string = ''): void {
227267
logger.error(
228268
'Received a proxy connection error', peerJid, errorType, details);
229269

@@ -258,7 +298,7 @@ export default class ProxyConnectionService {
258298
* @private
259299
* @returns {void}
260300
*/
261-
_onRemoteStream(jitsiRemoteTrack) {
301+
private _onRemoteStream(jitsiRemoteTrack: JitsiRemoteTrack): void {
262302
if (!this._options.onRemoteStream) {
263303
logger.error('Remote track received without callback.');
264304
jitsiRemoteTrack.dispose();
@@ -301,7 +341,7 @@ export default class ProxyConnectionService {
301341
* @private
302342
* @returns {void}
303343
*/
304-
_onSendMessage(peerJid, iq) {
344+
private _onSendMessage(peerJid: string, iq: any): void { // todo
305345
if (!this._options.onSendMessage) {
306346
return;
307347
}
@@ -322,7 +362,7 @@ export default class ProxyConnectionService {
322362
* @private
323363
* @returns {void}
324364
*/
325-
_selfCloseConnection() {
365+
private _selfCloseConnection(): void {
326366
this.stop();
327367

328368
this._options.onConnectionClosed

0 commit comments

Comments
 (0)