Browse Source

feat(jaas) add simple zero-config mechanism for JaaS users

Technically anyone can use it as long as they provide connection
options, but we don't need any of that for JaaS.
master
Saúl Ibarra Corretgé 8 months ago
parent
commit
0e1c37eb62
3 changed files with 106 additions and 3 deletions
  1. 1
    1
      JitsiConference.js
  2. 104
    1
      JitsiMeetJS.ts
  3. 1
    1
      modules/RTCStats/RTCStats.ts

+ 1
- 1
JitsiConference.js View File

592
  * @param replaceParticipant {boolean} whether the current join replaces
592
  * @param replaceParticipant {boolean} whether the current join replaces
593
  * an existing participant with same jwt from the meeting.
593
  * an existing participant with same jwt from the meeting.
594
  */
594
  */
595
-JitsiConference.prototype.join = function(password, replaceParticipant = false) {
595
+JitsiConference.prototype.join = function(password = '', replaceParticipant = false) {
596
     if (this.room) {
596
     if (this.room) {
597
         this.room.join(password, replaceParticipant).then(() => this._maybeSetSITimeout());
597
         this.room.join(password, replaceParticipant).then(() => this._maybeSetSITimeout());
598
     }
598
     }

+ 104
- 1
JitsiMeetJS.ts View File

1
 import Logger from '@jitsi/logger';
1
 import Logger from '@jitsi/logger';
2
+import { merge } from 'lodash-es';
2
 
3
 
4
+import JitsiConference from './JitsiConference';
3
 import * as JitsiConferenceErrors from './JitsiConferenceErrors';
5
 import * as JitsiConferenceErrors from './JitsiConferenceErrors';
4
 import * as JitsiConferenceEvents from './JitsiConferenceEvents';
6
 import * as JitsiConferenceEvents from './JitsiConferenceEvents';
5
 import JitsiConnection from './JitsiConnection';
7
 import JitsiConnection from './JitsiConnection';
6
 import * as JitsiConnectionErrors from './JitsiConnectionErrors';
8
 import * as JitsiConnectionErrors from './JitsiConnectionErrors';
7
-import * as JitsiConnectionEvents from './JitsiConnectionEvents';
9
+import { JitsiConnectionEvents } from './JitsiConnectionEvents';
8
 import JitsiMediaDevices from './JitsiMediaDevices';
10
 import JitsiMediaDevices from './JitsiMediaDevices';
9
 import * as JitsiMediaDevicesEvents from './JitsiMediaDevicesEvents';
11
 import * as JitsiMediaDevicesEvents from './JitsiMediaDevicesEvents';
10
 import JitsiTrackError from './JitsiTrackError';
12
 import JitsiTrackError from './JitsiTrackError';
11
 import * as JitsiTrackErrors from './JitsiTrackErrors';
13
 import * as JitsiTrackErrors from './JitsiTrackErrors';
12
 import * as JitsiTrackEvents from './JitsiTrackEvents';
14
 import * as JitsiTrackEvents from './JitsiTrackEvents';
13
 import * as JitsiTranscriptionStatus from './JitsiTranscriptionStatus';
15
 import * as JitsiTranscriptionStatus from './JitsiTranscriptionStatus';
16
+import JitsiLocalTrack from './modules/RTC/JitsiLocalTrack';
14
 import RTC from './modules/RTC/RTC';
17
 import RTC from './modules/RTC/RTC';
15
 import RTCStats from './modules/RTCStats/RTCStats';
18
 import RTCStats from './modules/RTCStats/RTCStats';
16
 import * as RTCStatsEvents from './modules/RTCStats/RTCStatsEvents';
19
 import * as RTCStatsEvents from './modules/RTCStats/RTCStatsEvents';
27
 import LocalStatsCollector from './modules/statistics/LocalStatsCollector';
30
 import LocalStatsCollector from './modules/statistics/LocalStatsCollector';
28
 import runPreCallTest, { IIceServer, IPreCallResult } from './modules/statistics/PreCallTest';
31
 import runPreCallTest, { IIceServer, IPreCallResult } from './modules/statistics/PreCallTest';
29
 import Statistics from './modules/statistics/statistics';
32
 import Statistics from './modules/statistics/statistics';
33
+import Deferred from './modules/util/Deferred';
30
 import ScriptUtil from './modules/util/ScriptUtil';
34
 import ScriptUtil from './modules/util/ScriptUtil';
31
 import * as VideoSIPGWConstants from './modules/videosipgw/VideoSIPGWConstants';
35
 import * as VideoSIPGWConstants from './modules/videosipgw/VideoSIPGWConstants';
32
 import AudioMixer from './modules/webaudio/AudioMixer';
36
 import AudioMixer from './modules/webaudio/AudioMixer';
106
     videoType?: VideoType;
110
     videoType?: VideoType;
107
 }
111
 }
108
 
112
 
113
+export interface IJoinConferenceOptions {
114
+    conferenceOptions?: any;
115
+    connectionOptions?: any;
116
+    jaas?: {
117
+        release?: boolean;
118
+        useStaging?: boolean;
119
+    };
120
+    tracks?: JitsiLocalTrack[];
121
+}
122
+
109
 /**
123
 /**
110
  * The public API of the Jitsi Meet library (a.k.a. {@code JitsiMeetJS}).
124
  * The public API of the Jitsi Meet library (a.k.a. {@code JitsiMeetJS}).
111
  */
125
  */
495
         return Statistics.audioLevelsEnabled && LocalStatsCollector.isLocalStatsSupported();
509
         return Statistics.audioLevelsEnabled && LocalStatsCollector.isLocalStatsSupported();
496
     },
510
     },
497
 
511
 
512
+    /**
513
+     * Simple way to create a {JitsiConference}. All options are optional and sane defaults
514
+     * will be chosen for JaaS users.
515
+     *
516
+     * @param roomName - The name of the conference.
517
+     * @param appId - The application id (also known as tenant).
518
+     * @param token - The token (JWT) to use for authentication.
519
+     * @param options - The options to use for joining the conference.
520
+     */
521
+    async joinConference(
522
+            roomName: string,
523
+            appId: string = '',
524
+            token: string | null = null,
525
+            options: IJoinConferenceOptions = {}): Promise<JitsiConference> {
526
+        const d = new Deferred();
527
+        let connectionOptions = options.connectionOptions ?? {};
528
+
529
+        // Provide a solid default config in case of JaaS.
530
+        if (appId.startsWith('vpaas-magic-cookie')) {
531
+            // Initialize RTCStats logging.
532
+            Logger.addGlobalTransport(RTCStats.getDefaultLogCollector());
533
+
534
+            const useStage = options.jaas?.useStaging ?? false;
535
+            const jaasDomain = useStage ? 'staging.8x8.vc' : '8x8.vc';
536
+            const opts = {
537
+                hosts: {
538
+                    domain: jaasDomain,
539
+                    muc: `conference.${appId}.${jaasDomain}`
540
+                },
541
+                conferenceRequestUrl: `https://${jaasDomain}/${appId}/conference-request/v1?room=${roomName}`,
542
+                serviceUrl: `wss://${jaasDomain}/${appId}/xmpp-websocket?room=${roomName}`,
543
+                websocketKeepAliveUrl: `https://${jaasDomain}/${appId}/_unlock?room=${roomName}`,
544
+                analytics: {
545
+                    rtcstatsEnabled: true,
546
+                    rtcstatsEndpoint: `wss://rtcstats-server-${useStage ? 'pilot' : '8x8'}.jitsi.net/`,
547
+                    rtcstatsSendSdp: true,
548
+                },
549
+            };
550
+
551
+            connectionOptions = merge(connectionOptions, opts);
552
+        }
553
+
554
+        const conn = new JitsiConnection(appId, token, connectionOptions);
555
+
556
+        function cleanupListeners() {
557
+            conn.removeEventListener(
558
+                JitsiConnectionEvents.CONNECTION_ESTABLISHED, onConnectionEstablished);
559
+            conn.removeEventListener(
560
+                JitsiConnectionEvents.CONNECTION_FAILED, onConnectionFailed);
561
+        }
562
+
563
+        function onConnectionEstablished() {
564
+            cleanupListeners();
565
+
566
+            const conf = conn.initJitsiConference(roomName, options.conferenceOptions ?? {});
567
+
568
+            d.resolve(conf);
569
+
570
+            // Make sure this runs after the promise was resolved so that local track events can be
571
+            // listened to.
572
+            queueMicrotask(() => {
573
+                for (const track of options.tracks || []) {
574
+                    conf.addTrack(track);
575
+                }
576
+
577
+                conf.join();
578
+
579
+                // Default to receiving 720p for everyone.
580
+                conf.setReceiverConstraints({
581
+                    lastN: -1,
582
+                    defaultConstraints: { maxHeight: 720 },
583
+                });
584
+            });
585
+        }
586
+
587
+        function onConnectionFailed(error: string) {
588
+            cleanupListeners();
589
+            d.reject(error);
590
+        }
591
+
592
+        conn.addEventListener(
593
+            JitsiConnectionEvents.CONNECTION_ESTABLISHED, onConnectionEstablished);
594
+        conn.addEventListener(
595
+            JitsiConnectionEvents.CONNECTION_FAILED, onConnectionFailed);
596
+        conn.connect({ name: roomName });
597
+
598
+        return d as unknown as Promise<JitsiConference>;
599
+    },
600
+
498
     /**
601
     /**
499
      * Informs lib-jitsi-meet about the current network status.
602
      * Informs lib-jitsi-meet about the current network status.
500
      *
603
      *

+ 1
- 1
modules/RTCStats/RTCStats.ts View File

273
     /**
273
     /**
274
      * Creates a new log collector with the default log storage.
274
      * Creates a new log collector with the default log storage.
275
      */
275
      */
276
-    getDefaultLogCollector(maxEntryLength) {
276
+    getDefaultLogCollector(maxEntryLength: number = 10000) {
277
         if (!this._defaultLogCollector) {
277
         if (!this._defaultLogCollector) {
278
             // If undefined is passed  as maxEntryLength LogCollector will default to 10000 bytes
278
             // If undefined is passed  as maxEntryLength LogCollector will default to 10000 bytes
279
             this._defaultLogCollector = new Logger.LogCollector(new DefaultLogStorage(this), { maxEntryLength });
279
             this._defaultLogCollector = new Logger.LogCollector(new DefaultLogStorage(this), { maxEntryLength });

Loading…
Cancel
Save