"Fossies" - the Fresh Open Source Software Archive

Member "jitsi-meet-7561/react/features/rtcstats/RTCStats.ts" (29 Sep 2023, 4890 Bytes) of package /linux/misc/jitsi-meet-7561.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) TypeScript source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the last Fossies "Diffs" side-by-side code changes report for "RTCStats.ts": jitsi-meet_8922_vs_jitsi-meet_8960.

    1 /* eslint-disable lines-around-comment */
    2 import {
    3     PC_CON_STATE_CHANGE,
    4     PC_STATE_CONNECTED,
    5     PC_STATE_FAILED
    6     // @ts-expect-error
    7 } from '@jitsi/rtcstats/events';
    8 
    9 import JitsiMeetJS, { RTCStatsEvents } from '../base/lib-jitsi-meet';
   10 
   11 import logger from './logger';
   12 import {
   13     DominantSpeakerData,
   14     E2ERTTData,
   15     FaceLandmarksData,
   16     VideoTypeData
   17 } from './types';
   18 
   19 /**
   20  * Handle lib-jitsi-meet rtcstats events and send jitsi-meet specific statistics.
   21  */
   22 class RTCStats {
   23     private _connStateEvents: Array<any> = [];
   24     private _initialized = false;
   25 
   26     /**
   27      * Handles rtcstats events.
   28      *
   29      * @returns {void}
   30      */
   31     init() {
   32         this._connStateEvents = [];
   33 
   34         if (!this._initialized) {
   35             JitsiMeetJS.rtcstats.on(
   36                 RTCStatsEvents.RTC_STATS_PC_EVENT,
   37                 (pcEvent: any) => this.handleRTCStatsEvent(pcEvent));
   38             this._initialized = true;
   39         }
   40     }
   41 
   42     /**
   43      * Send console logs to rtcstats server.
   44      *
   45      * @param {Array<string|any>} logEntries - The log entries to send to the rtcstats server.
   46      * @returns {void}
   47      */
   48     sendLogs(logEntries: Array<string | any>) {
   49         JitsiMeetJS.rtcstats.sendStatsEntry('logs', logEntries);
   50     }
   51 
   52     /**
   53      * Send dominant speaker data, the data will be processed by rtcstats-server and saved in the dump file.
   54      *
   55      * @param {Object} dominantSpeakerData - Dominant speaker data to be saved in the rtcstats dump.
   56      * @returns {void}
   57      */
   58     sendDominantSpeakerData(dominantSpeakerData: DominantSpeakerData) {
   59         JitsiMeetJS.rtcstats.sendStatsEntry('dominantSpeaker', dominantSpeakerData);
   60     }
   61 
   62     /**
   63      * Send e2e rtt data, the data will be processed by rtcstats-server and saved in the dump file.
   64      *
   65      * @param {Object} e2eRttData - The object that holds the e2e data.
   66      * @returns {void}
   67      */
   68     sendE2ERTTData(e2eRttData: E2ERTTData) {
   69         JitsiMeetJS.rtcstats.sendStatsEntry('e2eRtt', e2eRttData);
   70     }
   71 
   72     /**
   73      * Send the timestamp of the start of the conference, the data will be processed by the rtcstats-server
   74      * and saved in the dump file.
   75      *
   76      * @param {Object} timestamp - The object which contains the timestamp.
   77      * @returns {void}
   78      */
   79     sendConferenceTimestamp(timestamp: number) {
   80         JitsiMeetJS.rtcstats.sendStatsEntry('conferenceStartTimestamp', timestamp);
   81     }
   82 
   83     /**
   84      * Send videoType data, the data will be processed by rtcstats-server and saved in the dump file.
   85      *
   86      * @param {Object} videoTypeData - The object that holds the videoType data.
   87      * @returns {void}
   88      */
   89     sendVideoTypeData(videoTypeData: VideoTypeData) {
   90         JitsiMeetJS.rtcstats.sendStatsEntry('setVideoType', videoTypeData);
   91     }
   92 
   93     /**
   94      * Send face landmarks data, the data will be processed by rtcstats-server and saved in the dump file.
   95      *
   96      * @param {Object} faceLandmarksData - Face landmarks data to be saved in the rtcstats dump.
   97      * @returns {void}
   98      */
   99     sendFaceLandmarksData(faceLandmarksData: FaceLandmarksData) {
  100         JitsiMeetJS.rtcstats.sendStatsEntry('faceLandmarks', faceLandmarksData);
  101     }
  102 
  103     /**
  104      * RTCStats client can notify the APP of any PeerConnection related event that occurs.
  105      *
  106      * @param {Object} event - The PeerConnection event.
  107      * @param {string} event.type - The event type.
  108      * @param {Object} event.body - Event body.
  109      * @param {string} event.body.isP2P - PeerConnection type.
  110      * @param {string} event.body.state - PeerConnection state change which triggered the event.
  111      * @returns {void}
  112      */
  113     handleRTCStatsEvent(event: any) {
  114         switch (event.type) {
  115         case PC_CON_STATE_CHANGE: {
  116             const { body: { isP2P = null, state = null } } = event;
  117 
  118             this._connStateEvents.push(event.body);
  119 
  120             // We only report PC related connection issues. If the rtcstats websocket is not connected at this point
  121             // it usually means that none of our services can be reached i.e. there's problem with the internet
  122             // connection and not necessarily with reaching the JVB (due to a firewall or other reasons).
  123             if (state === PC_STATE_FAILED) {
  124                 const connectionType = isP2P ? 'P2P' : 'JVB';
  125                 const wasConnected = this._connStateEvents.some((connectionEvent: { isP2P: any; state: string; }) =>
  126                     (connectionEvent.isP2P === isP2P) && (connectionEvent.state === PC_STATE_CONNECTED));
  127 
  128                 logger.info(`${connectionType} PeerConnection failed, previously connected: ${wasConnected}`);
  129 
  130                 if (typeof APP !== 'undefined') {
  131                     APP.API.notifyPeerConnectionFailure(isP2P, wasConnected);
  132                 }
  133             }
  134 
  135             break;
  136         }
  137         }
  138     }
  139 }
  140 
  141 export default new RTCStats();