twilio-video 2.32.1 → 2.34.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +45 -1
- package/LICENSE.md +1 -1
- package/README.md +3 -3
- package/dist/twilio-video.js +2783 -1136
- package/dist/twilio-video.min.js +24 -23
- package/es5/cancelableroompromise.js.map +1 -1
- package/es5/connect.js +18 -9
- package/es5/connect.js.map +1 -1
- package/es5/createlocaltrack.js.map +1 -1
- package/es5/createlocaltracks.js +24 -18
- package/es5/createlocaltracks.js.map +1 -1
- package/es5/data/receiver.js.map +1 -1
- package/es5/data/sender.js.map +1 -1
- package/es5/data/transceiver.js.map +1 -1
- package/es5/data/transport.js.map +1 -1
- package/es5/encodingparameters.js.map +1 -1
- package/es5/eventtarget.js +10 -6
- package/es5/eventtarget.js.map +1 -1
- package/es5/index.js.map +1 -1
- package/es5/insights/applicationmonitor.js +93 -0
- package/es5/insights/applicationmonitor.js.map +1 -0
- package/es5/insights/computepressuremonitor.js +185 -0
- package/es5/insights/computepressuremonitor.js.map +1 -0
- package/es5/insights/events/application.js +46 -0
- package/es5/insights/events/application.js.map +1 -0
- package/es5/insights/events/getusermedia.js +51 -0
- package/es5/insights/events/getusermedia.js.map +1 -0
- package/es5/insights/events/network.js +54 -0
- package/es5/insights/events/network.js.map +1 -0
- package/es5/insights/events/peerconnection.js +164 -0
- package/es5/insights/events/peerconnection.js.map +1 -0
- package/es5/insights/events/quality.js +56 -0
- package/es5/insights/events/quality.js.map +1 -0
- package/es5/insights/events/room.js +56 -0
- package/es5/insights/events/room.js.map +1 -0
- package/es5/insights/events/system.js +31 -0
- package/es5/insights/events/system.js.map +1 -0
- package/es5/insights/events/track.js +58 -0
- package/es5/insights/events/track.js.map +1 -0
- package/es5/insights/monitorregistry.js +43 -0
- package/es5/insights/monitorregistry.js.map +1 -0
- package/es5/insights/networkmonitor.js +73 -0
- package/es5/insights/networkmonitor.js.map +1 -0
- package/es5/insights/resourcemonitor.js +56 -0
- package/es5/insights/resourcemonitor.js.map +1 -0
- package/es5/insights/statsmonitor.js +441 -0
- package/es5/insights/statsmonitor.js.map +1 -0
- package/es5/insights/telemetry.js +164 -0
- package/es5/insights/telemetry.js.map +1 -0
- package/es5/localparticipant.js +16 -16
- package/es5/localparticipant.js.map +1 -1
- package/es5/media/track/audiotrack.js.map +1 -1
- package/es5/media/track/capturevideoframes.js.map +1 -1
- package/es5/media/track/index.js.map +1 -1
- package/es5/media/track/localaudiotrack.js +6 -6
- package/es5/media/track/localaudiotrack.js.map +1 -1
- package/es5/media/track/localaudiotrackpublication.js +1 -1
- package/es5/media/track/localaudiotrackpublication.js.map +1 -1
- package/es5/media/track/localdatatrack.js.map +1 -1
- package/es5/media/track/localdatatrackpublication.js +1 -1
- package/es5/media/track/localdatatrackpublication.js.map +1 -1
- package/es5/media/track/localmediatrack.js +4 -4
- package/es5/media/track/localmediatrack.js.map +1 -1
- package/es5/media/track/localtrackpublication.js +10 -6
- package/es5/media/track/localtrackpublication.js.map +1 -1
- package/es5/media/track/localvideotrack.js +1 -1
- package/es5/media/track/localvideotrack.js.map +1 -1
- package/es5/media/track/localvideotrackpublication.js +1 -1
- package/es5/media/track/localvideotrackpublication.js.map +1 -1
- package/es5/media/track/mediatrack.js +4 -5
- package/es5/media/track/mediatrack.js.map +1 -1
- package/es5/media/track/noisecancellationimpl.js +8 -8
- package/es5/media/track/noisecancellationimpl.js.map +1 -1
- package/es5/media/track/receiver.js.map +1 -1
- package/es5/media/track/remoteaudiotrack.js +1 -1
- package/es5/media/track/remoteaudiotrack.js.map +1 -1
- package/es5/media/track/remoteaudiotrackpublication.js +1 -1
- package/es5/media/track/remoteaudiotrackpublication.js.map +1 -1
- package/es5/media/track/remotedatatrack.js +9 -5
- package/es5/media/track/remotedatatrack.js.map +1 -1
- package/es5/media/track/remotedatatrackpublication.js +1 -1
- package/es5/media/track/remotedatatrackpublication.js.map +1 -1
- package/es5/media/track/remotemediatrack.js +12 -8
- package/es5/media/track/remotemediatrack.js.map +1 -1
- package/es5/media/track/remotetrackpublication.js +2 -2
- package/es5/media/track/remotetrackpublication.js.map +1 -1
- package/es5/media/track/remotevideotrack.js +1 -1
- package/es5/media/track/remotevideotrack.js.map +1 -1
- package/es5/media/track/remotevideotrackpublication.js +1 -1
- package/es5/media/track/remotevideotrackpublication.js.map +1 -1
- package/es5/media/track/sender.js +1 -1
- package/es5/media/track/sender.js.map +1 -1
- package/es5/media/track/trackpublication.js +1 -1
- package/es5/media/track/trackpublication.js.map +1 -1
- package/es5/media/track/transceiver.js.map +1 -1
- package/es5/media/track/videoprocessoreventobserver.js +2 -2
- package/es5/media/track/videoprocessoreventobserver.js.map +1 -1
- package/es5/media/track/videotrack.js +2 -3
- package/es5/media/track/videotrack.js.map +1 -1
- package/es5/networkqualityconfiguration.js.map +1 -1
- package/es5/noisecancellationadapter.js +11 -12
- package/es5/noisecancellationadapter.js.map +1 -1
- package/es5/participant.js +20 -16
- package/es5/participant.js.map +1 -1
- package/es5/preflight/getCombinedConnectionStats.js +10 -11
- package/es5/preflight/getCombinedConnectionStats.js.map +1 -1
- package/es5/preflight/getturncredentials.js +2 -3
- package/es5/preflight/getturncredentials.js.map +1 -1
- package/es5/preflight/makestat.js +11 -8
- package/es5/preflight/makestat.js.map +1 -1
- package/es5/preflight/mos.js +2 -3
- package/es5/preflight/mos.js.map +1 -1
- package/es5/preflight/preflighttest.js +16 -16
- package/es5/preflight/preflighttest.js.map +1 -1
- package/es5/preflight/syntheticaudio.js +1 -2
- package/es5/preflight/syntheticaudio.js.map +1 -1
- package/es5/preflight/syntheticvideo.js +2 -3
- package/es5/preflight/syntheticvideo.js.map +1 -1
- package/es5/queueingeventemitter.js +10 -6
- package/es5/queueingeventemitter.js.map +1 -1
- package/es5/remoteparticipant.js +11 -7
- package/es5/remoteparticipant.js.map +1 -1
- package/es5/room.js +30 -10
- package/es5/room.js.map +1 -1
- package/es5/signaling/index.js +3 -3
- package/es5/signaling/index.js.map +1 -1
- package/es5/signaling/localparticipant.js.map +1 -1
- package/es5/signaling/localtrackpublication.js.map +1 -1
- package/es5/signaling/participant.js.map +1 -1
- package/es5/signaling/recording.js.map +1 -1
- package/es5/signaling/remoteparticipant.js.map +1 -1
- package/es5/signaling/remotetrackpublication.js.map +1 -1
- package/es5/signaling/room.js +1 -1
- package/es5/signaling/room.js.map +1 -1
- package/es5/signaling/track.js.map +1 -1
- package/es5/signaling/v2/cancelableroomsignalingpromise.js +3 -3
- package/es5/signaling/v2/cancelableroomsignalingpromise.js.map +1 -1
- package/es5/signaling/v2/dominantspeakersignaling.js.map +1 -1
- package/es5/signaling/v2/iceconnectionmonitor.js +0 -1
- package/es5/signaling/v2/iceconnectionmonitor.js.map +1 -1
- package/es5/signaling/v2/index.js.map +1 -1
- package/es5/signaling/v2/localparticipant.js +2 -2
- package/es5/signaling/v2/localparticipant.js.map +1 -1
- package/es5/signaling/v2/localtrackpublication.js +2 -2
- package/es5/signaling/v2/localtrackpublication.js.map +1 -1
- package/es5/signaling/v2/mediasignaling.js +2 -2
- package/es5/signaling/v2/mediasignaling.js.map +1 -1
- package/es5/signaling/v2/networkqualitymonitor.js.map +1 -1
- package/es5/signaling/v2/networkqualitysignaling.js.map +1 -1
- package/es5/signaling/v2/peerconnection.js +181 -48
- package/es5/signaling/v2/peerconnection.js.map +1 -1
- package/es5/signaling/v2/peerconnectionmanager.js +10 -6
- package/es5/signaling/v2/peerconnectionmanager.js.map +1 -1
- package/es5/signaling/v2/publisherhintsignaling.js.map +1 -1
- package/es5/signaling/v2/recording.js.map +1 -1
- package/es5/signaling/v2/remoteparticipant.js.map +1 -1
- package/es5/signaling/v2/remotetrackpublication.js.map +1 -1
- package/es5/signaling/v2/renderhintssignaling.js +0 -1
- package/es5/signaling/v2/renderhintssignaling.js.map +1 -1
- package/es5/signaling/v2/room.js +20 -176
- package/es5/signaling/v2/room.js.map +1 -1
- package/es5/signaling/v2/trackprioritysignaling.js.map +1 -1
- package/es5/signaling/v2/trackswitchoffsignaling.js.map +1 -1
- package/es5/signaling/v2/transcriptionsignaling.js.map +1 -1
- package/es5/signaling/v2/twilioconnectiontransport.js +2 -2
- package/es5/signaling/v2/twilioconnectiontransport.js.map +1 -1
- package/es5/statemachine.js +19 -15
- package/es5/statemachine.js.map +1 -1
- package/es5/stats/icereportfactory.js.map +1 -1
- package/es5/stats/localaudiotrackstats.js.map +1 -1
- package/es5/stats/localtrackstats.js.map +1 -1
- package/es5/stats/localvideotrackstats.js +5 -0
- package/es5/stats/localvideotrackstats.js.map +1 -1
- package/es5/stats/networkqualityaudiostats.js.map +1 -1
- package/es5/stats/networkqualityrecvstats.js.map +1 -1
- package/es5/stats/networkqualitysendstats.js.map +1 -1
- package/es5/stats/networkqualityvideostats.js.map +1 -1
- package/es5/stats/peerconnectionreportfactory.js +13 -9
- package/es5/stats/peerconnectionreportfactory.js.map +1 -1
- package/es5/stats/receiverreport.js.map +1 -1
- package/es5/stats/receiverreportfactory.js.map +1 -1
- package/es5/stats/remoteaudiotrackstats.js +0 -7
- package/es5/stats/remoteaudiotrackstats.js.map +1 -1
- package/es5/stats/remotetrackstats.js +7 -0
- package/es5/stats/remotetrackstats.js.map +1 -1
- package/es5/stats/remotevideotrackstats.js +7 -0
- package/es5/stats/remotevideotrackstats.js.map +1 -1
- package/es5/stats/senderreport.js.map +1 -1
- package/es5/stats/senderreportfactory.js.map +1 -1
- package/es5/stats/statsreport.js.map +1 -1
- package/es5/stats/trackstats.js.map +1 -1
- package/es5/transceiver.js.map +1 -1
- package/es5/twilioconnection.js +34 -30
- package/es5/twilioconnection.js.map +1 -1
- package/es5/util/asyncvar.js.map +1 -1
- package/es5/util/backoff.js.map +1 -1
- package/es5/util/browserdetection.js.map +1 -1
- package/es5/util/cancelablepromise.js +11 -7
- package/es5/util/cancelablepromise.js.map +1 -1
- package/es5/util/constants.js +7 -8
- package/es5/util/constants.js.map +1 -1
- package/es5/util/detectsilentaudio.js.map +1 -1
- package/es5/util/detectsilentvideo.js +3 -3
- package/es5/util/detectsilentvideo.js.map +1 -1
- package/es5/util/documentvisibilitymonitor.js +1 -1
- package/es5/util/documentvisibilitymonitor.js.map +1 -1
- package/es5/util/dynamicimport.js +2 -2
- package/es5/util/dynamicimport.js.map +1 -1
- package/es5/util/eventobserver.js +1 -2
- package/es5/util/eventobserver.js.map +1 -1
- package/es5/util/filter.js.map +1 -1
- package/es5/util/index.js +58 -27
- package/es5/util/index.js.map +1 -1
- package/es5/util/insightspublisher/index.js +5 -6
- package/es5/util/insightspublisher/index.js.map +1 -1
- package/es5/util/insightspublisher/null.js.map +1 -1
- package/es5/util/localmediarestartdeferreds.js.map +1 -1
- package/es5/util/log.js +10 -6
- package/es5/util/log.js.map +1 -1
- package/es5/util/networkmonitor.js.map +1 -1
- package/es5/util/nullobserver.js +0 -1
- package/es5/util/nullobserver.js.map +1 -1
- package/es5/util/sdp/index.js +83 -169
- package/es5/util/sdp/index.js.map +1 -1
- package/es5/util/sdp/issue8329.js +11 -11
- package/es5/util/sdp/issue8329.js.map +1 -1
- package/es5/util/sdp/simulcast.js +5 -5
- package/es5/util/sdp/simulcast.js.map +1 -1
- package/es5/util/sid.js +1 -1
- package/es5/util/sid.js.map +1 -1
- package/es5/util/support.js +1 -2
- package/es5/util/support.js.map +1 -1
- package/es5/util/timeout.js.map +1 -1
- package/es5/util/timeoutpromise.js +10 -6
- package/es5/util/timeoutpromise.js.map +1 -1
- package/es5/util/twilio-video-errors.js.map +1 -1
- package/es5/util/twilioerror.js +11 -7
- package/es5/util/twilioerror.js.map +1 -1
- package/es5/util/twiliowarning.js +0 -1
- package/es5/util/twiliowarning.js.map +1 -1
- package/es5/util/validate.js +4 -4
- package/es5/util/validate.js.map +1 -1
- package/es5/vendor/inherits.js.map +1 -1
- package/es5/vendor/loglevel.js.map +1 -1
- package/es5/webaudio/audiocontext.js.map +1 -1
- package/es5/webaudio/detectsilence.js.map +1 -1
- package/es5/webaudio/workaround180748.js +1 -1
- package/es5/webaudio/workaround180748.js.map +1 -1
- package/es5/webrtc/getstats.js +27 -13
- package/es5/webrtc/getstats.js.map +1 -1
- package/es5/webrtc/getusermedia.js.map +1 -1
- package/es5/webrtc/mediastream.js.map +1 -1
- package/es5/webrtc/mediastreamtrack.js.map +1 -1
- package/es5/webrtc/rtcicecandidate.js.map +1 -1
- package/es5/webrtc/rtcpeerconnection/chrome.js +32 -13
- package/es5/webrtc/rtcpeerconnection/chrome.js.map +1 -1
- package/es5/webrtc/rtcpeerconnection/firefox.js +17 -10
- package/es5/webrtc/rtcpeerconnection/firefox.js.map +1 -1
- package/es5/webrtc/rtcpeerconnection/index.js.map +1 -1
- package/es5/webrtc/rtcpeerconnection/safari.js +19 -14
- package/es5/webrtc/rtcpeerconnection/safari.js.map +1 -1
- package/es5/webrtc/rtcsessiondescription/index.js.map +1 -1
- package/es5/webrtc/util/index.js +10 -6
- package/es5/webrtc/util/index.js.map +1 -1
- package/es5/webrtc/util/latch.js +1 -1
- package/es5/webrtc/util/latch.js.map +1 -1
- package/es5/webrtc/util/sdp.js +7 -7
- package/es5/webrtc/util/sdp.js.map +1 -1
- package/eslint.config.js +308 -0
- package/lib/connect.js +18 -4
- package/lib/createlocaltracks.ts +9 -3
- package/lib/index.ts +1 -1
- package/lib/insights/applicationmonitor.js +101 -0
- package/lib/insights/computepressuremonitor.js +149 -0
- package/lib/insights/events/application.js +49 -0
- package/lib/insights/events/getusermedia.js +54 -0
- package/lib/insights/events/network.js +55 -0
- package/lib/insights/events/peerconnection.js +166 -0
- package/lib/insights/events/quality.js +59 -0
- package/lib/insights/events/room.js +61 -0
- package/lib/insights/events/system.js +32 -0
- package/lib/insights/events/track.js +58 -0
- package/lib/insights/monitorregistry.js +44 -0
- package/lib/insights/networkmonitor.js +82 -0
- package/lib/insights/resourcemonitor.js +63 -0
- package/lib/insights/statsmonitor.js +442 -0
- package/lib/insights/telemetry.js +178 -0
- package/lib/media/track/mediatrack.js +0 -1
- package/lib/media/track/videotrack.js +0 -1
- package/lib/noisecancellationadapter.ts +1 -1
- package/lib/preflight/getCombinedConnectionStats.ts +1 -2
- package/lib/preflight/makestat.ts +1 -1
- package/lib/preflight/mos.ts +1 -1
- package/lib/preflight/preflighttest.ts +2 -2
- package/lib/room.js +16 -0
- package/lib/signaling/v2/cancelableroomsignalingpromise.js +3 -3
- package/lib/signaling/v2/iceconnectionmonitor.js +0 -1
- package/lib/signaling/v2/peerconnection.js +169 -27
- package/lib/signaling/v2/renderhintssignaling.js +0 -1
- package/lib/signaling/v2/room.js +23 -200
- package/lib/stats/localvideotrackstats.js +5 -0
- package/lib/stats/remoteaudiotrackstats.js +0 -7
- package/lib/stats/remotetrackstats.js +7 -0
- package/lib/stats/remotevideotrackstats.js +7 -0
- package/lib/util/constants.js +1 -1
- package/lib/util/eventobserver.js +1 -2
- package/lib/util/index.js +41 -13
- package/lib/util/insightspublisher/index.js +1 -2
- package/lib/util/log.js +3 -3
- package/lib/util/nullobserver.js +0 -1
- package/lib/util/sdp/index.js +77 -172
- package/lib/util/support.js +2 -2
- package/lib/util/twiliowarning.js +0 -1
- package/lib/webrtc/getstats.js +27 -10
- package/lib/webrtc/rtcpeerconnection/chrome.js +16 -1
- package/lib/webrtc/rtcpeerconnection/firefox.js +3 -0
- package/lib/webrtc/rtcpeerconnection/safari.js +6 -5
- package/package.json +34 -34
- package/tsdef/AudioProcessor.d.ts +2 -2
- package/tsdef/LocalTrackOptions.d.ts +4 -4
- package/tsdef/PreflightTypes.d.ts +3 -3
- package/tsdef/index.d.ts +1 -1
- package/tsdef/loglevel.d.ts +43 -43
- package/tsdef/types.d.ts +6 -6
- package/.babelrc +0 -3
- package/.eslintrc.json +0 -369
- package/tsdef/.eslintrc.json +0 -17
package/eslint.config.js
ADDED
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
import globals from 'globals';
|
|
2
|
+
import importPlugin from 'eslint-plugin-import';
|
|
3
|
+
import js from '@eslint/js';
|
|
4
|
+
import nPlugin from 'eslint-plugin-n';
|
|
5
|
+
import promisePlugin from 'eslint-plugin-promise';
|
|
6
|
+
import stylistic from '@stylistic/eslint-plugin';
|
|
7
|
+
import tseslint from '@typescript-eslint/eslint-plugin';
|
|
8
|
+
import tsparser from '@typescript-eslint/parser';
|
|
9
|
+
|
|
10
|
+
export default [
|
|
11
|
+
// Global ignores
|
|
12
|
+
{
|
|
13
|
+
ignores: [
|
|
14
|
+
'**/node_modules/**',
|
|
15
|
+
'**/dist/**',
|
|
16
|
+
'**/coverage/**',
|
|
17
|
+
'**/es5/**',
|
|
18
|
+
'**/*.min.js',
|
|
19
|
+
'**/build-output*.log'
|
|
20
|
+
]
|
|
21
|
+
},
|
|
22
|
+
|
|
23
|
+
// Base config for all JavaScript and TypeScript files
|
|
24
|
+
{
|
|
25
|
+
files: ['**/*.js', '**/*.ts'],
|
|
26
|
+
languageOptions: {
|
|
27
|
+
ecmaVersion: 2018,
|
|
28
|
+
sourceType: 'module',
|
|
29
|
+
parser: tsparser,
|
|
30
|
+
globals: {
|
|
31
|
+
...globals.browser,
|
|
32
|
+
...globals.node,
|
|
33
|
+
...globals.es2017,
|
|
34
|
+
Atomics: 'readonly',
|
|
35
|
+
SharedArrayBuffer: 'readonly',
|
|
36
|
+
globalThis: false
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
plugins: {
|
|
40
|
+
'@typescript-eslint': tseslint,
|
|
41
|
+
'@stylistic': stylistic,
|
|
42
|
+
'import': importPlugin,
|
|
43
|
+
'promise': promisePlugin,
|
|
44
|
+
'n': nPlugin
|
|
45
|
+
},
|
|
46
|
+
rules: {
|
|
47
|
+
// ESLint recommended rules
|
|
48
|
+
...js.configs.recommended.rules,
|
|
49
|
+
|
|
50
|
+
// TypeScript rules
|
|
51
|
+
'@typescript-eslint/no-var-requires': 'off',
|
|
52
|
+
'@typescript-eslint/no-empty-function': 'off',
|
|
53
|
+
'@typescript-eslint/no-this-alias': 'off',
|
|
54
|
+
|
|
55
|
+
// Core ESLint rules
|
|
56
|
+
'accessor-pairs': 'error',
|
|
57
|
+
'array-callback-return': 'error',
|
|
58
|
+
'arrow-body-style': 'off',
|
|
59
|
+
'block-scoped-var': 'error',
|
|
60
|
+
'camelcase': 'error',
|
|
61
|
+
'capitalized-comments': 'off',
|
|
62
|
+
'class-methods-use-this': 'off',
|
|
63
|
+
'complexity': 'off',
|
|
64
|
+
'consistent-return': 'warn',
|
|
65
|
+
'consistent-this': ['error', 'self'],
|
|
66
|
+
'curly': 'error',
|
|
67
|
+
'default-case': 'off',
|
|
68
|
+
'dot-notation': ['error', { allowKeywords: true }],
|
|
69
|
+
'eqeqeq': 'error',
|
|
70
|
+
'func-name-matching': 'off',
|
|
71
|
+
'func-names': 'off',
|
|
72
|
+
'func-style': ['error', 'declaration', { allowArrowFunctions: true }],
|
|
73
|
+
'guard-for-in': 'off',
|
|
74
|
+
'id-length': 'off',
|
|
75
|
+
'id-match': 'error',
|
|
76
|
+
'init-declarations': 'off',
|
|
77
|
+
'lines-around-comment': 'off',
|
|
78
|
+
'lines-between-class-members': 'off',
|
|
79
|
+
'max-classes-per-file': 'off',
|
|
80
|
+
'max-depth': 'error',
|
|
81
|
+
'max-len': 'off',
|
|
82
|
+
'max-lines': 'off',
|
|
83
|
+
'max-lines-per-function': 'off',
|
|
84
|
+
'max-nested-callbacks': 'error',
|
|
85
|
+
'max-params': 'off',
|
|
86
|
+
'max-statements': 'off',
|
|
87
|
+
'new-cap': 'error',
|
|
88
|
+
'newline-per-chained-call': 'off',
|
|
89
|
+
'no-alert': 'error',
|
|
90
|
+
'no-array-constructor': 'error',
|
|
91
|
+
'no-await-in-loop': 'error',
|
|
92
|
+
'no-bitwise': 'off',
|
|
93
|
+
'no-caller': 'error',
|
|
94
|
+
'no-confusing-arrow': 'off',
|
|
95
|
+
'no-console': 'error',
|
|
96
|
+
'no-const-assign': 'error',
|
|
97
|
+
'no-continue': 'off',
|
|
98
|
+
'no-div-regex': 'error',
|
|
99
|
+
'no-duplicate-imports': 'error',
|
|
100
|
+
'no-else-return': ['error', { allowElseIf: true }],
|
|
101
|
+
'no-empty-function': 'off',
|
|
102
|
+
'no-eq-null': 'error',
|
|
103
|
+
'no-eval': 'error',
|
|
104
|
+
'no-extend-native': 'error',
|
|
105
|
+
'no-extra-bind': 'error',
|
|
106
|
+
'no-extra-label': 'error',
|
|
107
|
+
'no-extra-parens': 'off',
|
|
108
|
+
'no-global-assign': 'error',
|
|
109
|
+
'no-implicit-globals': 'error',
|
|
110
|
+
'no-implied-eval': 'error',
|
|
111
|
+
'no-inline-comments': 'off',
|
|
112
|
+
'no-inner-declarations': ['error', 'functions'],
|
|
113
|
+
'no-invalid-this': 'error',
|
|
114
|
+
'no-iterator': 'error',
|
|
115
|
+
'no-label-var': 'error',
|
|
116
|
+
'no-labels': 'error',
|
|
117
|
+
'no-lone-blocks': 'error',
|
|
118
|
+
'no-lonely-if': 'error',
|
|
119
|
+
'no-loop-func': 'error',
|
|
120
|
+
'no-magic-numbers': 'off',
|
|
121
|
+
'no-mixed-operators': 'off',
|
|
122
|
+
'no-multi-assign': 'off',
|
|
123
|
+
'no-multi-spaces': 'off',
|
|
124
|
+
'no-multi-str': 'off',
|
|
125
|
+
'no-negated-condition': 'off',
|
|
126
|
+
'no-nested-ternary': 'off',
|
|
127
|
+
'no-new': 'error',
|
|
128
|
+
'no-new-func': 'error',
|
|
129
|
+
'no-new-object': 'error',
|
|
130
|
+
'no-new-wrappers': 'error',
|
|
131
|
+
'no-octal-escape': 'error',
|
|
132
|
+
'no-param-reassign': 'off',
|
|
133
|
+
'no-plusplus': 'off',
|
|
134
|
+
'no-proto': 'error',
|
|
135
|
+
'no-redeclare': ['error', { builtinGlobals: false }],
|
|
136
|
+
'no-restricted-globals': 'error',
|
|
137
|
+
'no-restricted-imports': 'error',
|
|
138
|
+
'no-restricted-properties': 'error',
|
|
139
|
+
'no-restricted-syntax': 'error',
|
|
140
|
+
'no-return-assign': 'error',
|
|
141
|
+
'no-return-await': 'error',
|
|
142
|
+
'no-script-url': 'error',
|
|
143
|
+
'no-self-compare': 'error',
|
|
144
|
+
'no-sequences': 'error',
|
|
145
|
+
'no-shadow': 'off',
|
|
146
|
+
'no-template-curly-in-string': 'error',
|
|
147
|
+
'no-ternary': 'off',
|
|
148
|
+
'no-throw-literal': 'error',
|
|
149
|
+
'no-undef': ['error', { typeof: false }],
|
|
150
|
+
'no-undef-init': 'error',
|
|
151
|
+
'no-underscore-dangle': 'off',
|
|
152
|
+
'no-unmodified-loop-condition': 'error',
|
|
153
|
+
'no-unneeded-ternary': 'error',
|
|
154
|
+
'no-unsafe-negation': 'error',
|
|
155
|
+
'no-unused-expressions': 'error',
|
|
156
|
+
'no-unused-vars': ['warn', { vars: 'all', args: 'after-used', argsIgnorePattern: '^_', varsIgnorePattern: '^_' }],
|
|
157
|
+
'no-use-before-define': ['error', { functions: false }],
|
|
158
|
+
'no-useless-call': 'error',
|
|
159
|
+
'no-useless-computed-key': 'error',
|
|
160
|
+
'no-useless-concat': 'error',
|
|
161
|
+
'no-useless-constructor': 'off',
|
|
162
|
+
'no-useless-rename': 'error',
|
|
163
|
+
'no-useless-return': 'off',
|
|
164
|
+
'no-var': 'off',
|
|
165
|
+
'no-void': 'error',
|
|
166
|
+
'no-warning-comments': 'warn',
|
|
167
|
+
'no-with': 'error',
|
|
168
|
+
'object-shorthand': 'off',
|
|
169
|
+
'one-var': ['error', 'never'],
|
|
170
|
+
'operator-assignment': 'error',
|
|
171
|
+
'prefer-arrow-callback': 'off',
|
|
172
|
+
'prefer-const': 'off',
|
|
173
|
+
'prefer-destructuring': 'off',
|
|
174
|
+
'prefer-named-capture-group': 'off',
|
|
175
|
+
'prefer-numeric-literals': 'error',
|
|
176
|
+
'prefer-object-spread': 'off',
|
|
177
|
+
'prefer-promise-reject-errors': 'off',
|
|
178
|
+
'prefer-rest-params': 'off',
|
|
179
|
+
'prefer-spread': 'off',
|
|
180
|
+
'prefer-template': 'off',
|
|
181
|
+
'radix': 'off',
|
|
182
|
+
'require-await': 'error',
|
|
183
|
+
'require-unicode-regexp': 'off',
|
|
184
|
+
'sort-imports': 'error',
|
|
185
|
+
'sort-keys': 'off',
|
|
186
|
+
'sort-vars': 'error',
|
|
187
|
+
'strict': 'off',
|
|
188
|
+
'symbol-description': 'error',
|
|
189
|
+
'vars-on-top': 'off',
|
|
190
|
+
|
|
191
|
+
// Stylistic rules (moved from core ESLint)
|
|
192
|
+
'@stylistic/array-bracket-newline': 'off',
|
|
193
|
+
'@stylistic/array-bracket-spacing': ['error', 'never'],
|
|
194
|
+
'@stylistic/array-element-newline': 'off',
|
|
195
|
+
'@stylistic/arrow-parens': ['error', 'as-needed'],
|
|
196
|
+
'@stylistic/arrow-spacing': ['error', { after: true, before: true }],
|
|
197
|
+
'@stylistic/block-spacing': ['error', 'always'],
|
|
198
|
+
'@stylistic/brace-style': ['error', '1tbs', { allowSingleLine: true }],
|
|
199
|
+
'@stylistic/comma-dangle': 'off',
|
|
200
|
+
'@stylistic/comma-spacing': ['error', { after: true, before: false }],
|
|
201
|
+
'@stylistic/comma-style': ['error', 'last'],
|
|
202
|
+
'@stylistic/computed-property-spacing': ['error', 'never'],
|
|
203
|
+
'@stylistic/dot-location': ['error', 'property'],
|
|
204
|
+
'@stylistic/eol-last': 'error',
|
|
205
|
+
'@stylistic/func-call-spacing': 'error',
|
|
206
|
+
'@stylistic/function-call-argument-newline': 'off',
|
|
207
|
+
'@stylistic/function-paren-newline': 'off',
|
|
208
|
+
'@stylistic/generator-star-spacing': 'error',
|
|
209
|
+
'@stylistic/implicit-arrow-linebreak': 'off',
|
|
210
|
+
'@stylistic/indent': ['error', 2, { SwitchCase: 1 }],
|
|
211
|
+
'@stylistic/jsx-quotes': 'error',
|
|
212
|
+
'@stylistic/key-spacing': 'error',
|
|
213
|
+
'@stylistic/keyword-spacing': 'error',
|
|
214
|
+
'@stylistic/line-comment-position': 'off',
|
|
215
|
+
'@stylistic/linebreak-style': ['error', 'unix'],
|
|
216
|
+
'@stylistic/max-len': 'off',
|
|
217
|
+
'@stylistic/max-statements-per-line': 'off',
|
|
218
|
+
'@stylistic/multiline-comment-style': 'off',
|
|
219
|
+
'@stylistic/multiline-ternary': 'off',
|
|
220
|
+
'@stylistic/new-parens': 'error',
|
|
221
|
+
'@stylistic/no-confusing-arrow': 'off',
|
|
222
|
+
'@stylistic/no-extra-parens': 'off',
|
|
223
|
+
'@stylistic/no-floating-decimal': 'error',
|
|
224
|
+
'@stylistic/no-mixed-operators': 'off',
|
|
225
|
+
'@stylistic/no-mixed-spaces-and-tabs': 'error',
|
|
226
|
+
'@stylistic/no-multi-spaces': 'off',
|
|
227
|
+
'@stylistic/no-multiple-empty-lines': 'error',
|
|
228
|
+
'@stylistic/no-tabs': 'error',
|
|
229
|
+
'@stylistic/no-trailing-spaces': 'error',
|
|
230
|
+
'@stylistic/no-whitespace-before-property': 'off',
|
|
231
|
+
'@stylistic/nonblock-statement-body-position': 'error',
|
|
232
|
+
'@stylistic/object-curly-newline': ['error', { 'consistent': true }],
|
|
233
|
+
'@stylistic/object-curly-spacing': ['error', 'always'],
|
|
234
|
+
'@stylistic/object-property-newline': 'off',
|
|
235
|
+
'@stylistic/one-var-declaration-per-line': 'error',
|
|
236
|
+
'@stylistic/operator-linebreak': 'off',
|
|
237
|
+
'@stylistic/padded-blocks': 'off',
|
|
238
|
+
'@stylistic/padding-line-between-statements': 'error',
|
|
239
|
+
'@stylistic/quote-props': ['error', 'consistent'],
|
|
240
|
+
'@stylistic/quotes': ['error', 'single'],
|
|
241
|
+
'@stylistic/rest-spread-spacing': ['error', 'never'],
|
|
242
|
+
'@stylistic/semi': 'error',
|
|
243
|
+
'@stylistic/semi-spacing': 'error',
|
|
244
|
+
'@stylistic/semi-style': ['error', 'last'],
|
|
245
|
+
'@stylistic/space-before-blocks': 'error',
|
|
246
|
+
'@stylistic/space-before-function-paren': ['error', {
|
|
247
|
+
anonymous: 'never',
|
|
248
|
+
named: 'never',
|
|
249
|
+
asyncArrow: 'always'
|
|
250
|
+
}],
|
|
251
|
+
'@stylistic/space-in-parens': ['error', 'never'],
|
|
252
|
+
'@stylistic/space-infix-ops': 'error',
|
|
253
|
+
'@stylistic/space-unary-ops': 'error',
|
|
254
|
+
'@stylistic/spaced-comment': ['error', 'always'],
|
|
255
|
+
'@stylistic/switch-colon-spacing': ['error', { after: true, before: false }],
|
|
256
|
+
'@stylistic/template-curly-spacing': ['error', 'never'],
|
|
257
|
+
'@stylistic/template-tag-spacing': 'error',
|
|
258
|
+
'@stylistic/wrap-iife': 'error',
|
|
259
|
+
'@stylistic/yield-star-spacing': 'error'
|
|
260
|
+
}
|
|
261
|
+
},
|
|
262
|
+
|
|
263
|
+
// TypeScript declaration files (.d.ts) and test files
|
|
264
|
+
{
|
|
265
|
+
files: ['**/*.d.ts', 'tsdef/**/*.ts'],
|
|
266
|
+
rules: {
|
|
267
|
+
'no-use-before-define': 'off',
|
|
268
|
+
'no-undef': 'off',
|
|
269
|
+
'no-unused-vars': 'off',
|
|
270
|
+
'no-redeclare': 'off',
|
|
271
|
+
'@typescript-eslint/no-unsafe-declaration-merging': 'off',
|
|
272
|
+
'@typescript-eslint/no-explicit-any': 'off',
|
|
273
|
+
'@typescript-eslint/no-unused-vars': 'off'
|
|
274
|
+
}
|
|
275
|
+
},
|
|
276
|
+
|
|
277
|
+
// Test files
|
|
278
|
+
{
|
|
279
|
+
files: ['test/**/*.js', 'test/**/*.ts'],
|
|
280
|
+
languageOptions: {
|
|
281
|
+
globals: {
|
|
282
|
+
...globals.mocha,
|
|
283
|
+
...globals.node
|
|
284
|
+
}
|
|
285
|
+
},
|
|
286
|
+
rules: {
|
|
287
|
+
'@typescript-eslint/no-unused-vars': 'warn',
|
|
288
|
+
'@typescript-eslint/no-explicit-any': 'warn',
|
|
289
|
+
'consistent-return': 'warn',
|
|
290
|
+
'no-console': 'off',
|
|
291
|
+
'no-unused-vars': 'warn',
|
|
292
|
+
'no-undefined': 'off'
|
|
293
|
+
}
|
|
294
|
+
},
|
|
295
|
+
|
|
296
|
+
// Script files (build/utility scripts)
|
|
297
|
+
{
|
|
298
|
+
files: ['scripts/**/*.js'],
|
|
299
|
+
languageOptions: {
|
|
300
|
+
globals: {
|
|
301
|
+
...globals.node
|
|
302
|
+
}
|
|
303
|
+
},
|
|
304
|
+
rules: {
|
|
305
|
+
'no-console': 'off'
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
];
|
package/lib/connect.js
CHANGED
|
@@ -21,6 +21,7 @@ const SignalingV2 = require('./signaling/v2');
|
|
|
21
21
|
const {
|
|
22
22
|
asLocalTrack,
|
|
23
23
|
buildLogLevels,
|
|
24
|
+
createRoomConnectedEventPayload,
|
|
24
25
|
filterObject,
|
|
25
26
|
isNonArrayObject
|
|
26
27
|
} = require('./util');
|
|
@@ -41,6 +42,7 @@ const CancelablePromise = require('./util/cancelablepromise');
|
|
|
41
42
|
const EventObserver = require('./util/eventobserver');
|
|
42
43
|
const DefaultLog = require('./util/log');
|
|
43
44
|
const { validateBandwidthProfile } = require('./util/validate');
|
|
45
|
+
const telemetry = require('./insights/telemetry');
|
|
44
46
|
|
|
45
47
|
const safariVersion = guessBrowser() === 'safari' && guessBrowserVersion();
|
|
46
48
|
|
|
@@ -275,8 +277,10 @@ function connect(token, options) {
|
|
|
275
277
|
eventPublisherOptions);
|
|
276
278
|
|
|
277
279
|
const wsServer = WS_SERVER(options.environment, options.region);
|
|
278
|
-
const
|
|
280
|
+
const connectTimestamp = Date.now();
|
|
281
|
+
const eventObserver = new EventObserver(eventPublisher, connectTimestamp, log, options.eventListener);
|
|
279
282
|
options = Object.assign({ eventObserver, wsServer }, options);
|
|
283
|
+
|
|
280
284
|
options.log = log;
|
|
281
285
|
|
|
282
286
|
// NOTE(mroberts): Print the Safari warning once if the log-level is at least
|
|
@@ -300,6 +304,10 @@ function connect(token, options) {
|
|
|
300
304
|
return CancelablePromise.reject(E.INVALID_TYPE('token', 'string'));
|
|
301
305
|
}
|
|
302
306
|
|
|
307
|
+
if (options.insights && eventPublisher) {
|
|
308
|
+
telemetry.configure({ publisher: eventPublisher, log, connectTimestamp });
|
|
309
|
+
}
|
|
310
|
+
|
|
303
311
|
// NOTE(mmalavalli): The Room "name" in "options" was being used
|
|
304
312
|
// as the LocalTrack name in asLocalTrack(). So we pass a copy of
|
|
305
313
|
// "options" without the "name".
|
|
@@ -405,13 +413,20 @@ function connect(token, options) {
|
|
|
405
413
|
|
|
406
414
|
cancelableRoomPromise.then(room => {
|
|
407
415
|
eventPublisher.connect(room.sid, room.localParticipant.sid);
|
|
416
|
+
|
|
417
|
+
const connectedEventPayload = createRoomConnectedEventPayload(options);
|
|
418
|
+
options.eventObserver.emit('event', connectedEventPayload);
|
|
419
|
+
|
|
408
420
|
log.info('Connected to Room:', room.toString());
|
|
409
421
|
log.info('Room name:', room.name);
|
|
410
422
|
log.debug('Room:', room);
|
|
411
|
-
room.once('disconnected', () =>
|
|
423
|
+
room.once('disconnected', () => {
|
|
424
|
+
// NOTE(lrivas): Allow pending state change events to be emitted before disconnecting telemetry.
|
|
425
|
+
setTimeout(() => eventPublisher.disconnect(), 50);
|
|
426
|
+
});
|
|
412
427
|
return room;
|
|
413
428
|
}, error => {
|
|
414
|
-
eventPublisher.disconnect();
|
|
429
|
+
setTimeout(() => eventPublisher.disconnect(), 50);
|
|
415
430
|
if (cancelableRoomPromise._isCanceled) {
|
|
416
431
|
log.info('Attempt to connect to a Room was canceled');
|
|
417
432
|
} else {
|
|
@@ -679,7 +694,6 @@ const VideoEncodingMode = {
|
|
|
679
694
|
* Names of the supported video codecs.
|
|
680
695
|
* @enum {string}
|
|
681
696
|
*/
|
|
682
|
-
// eslint-disable-next-line
|
|
683
697
|
const VideoCodec = {
|
|
684
698
|
H264: 'H264',
|
|
685
699
|
VP8: 'VP8'
|
package/lib/createlocaltracks.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
1
|
'use strict';
|
|
3
2
|
|
|
4
3
|
import {
|
|
@@ -24,15 +23,15 @@ const {
|
|
|
24
23
|
const Log = require('./util/log');
|
|
25
24
|
const { DEFAULT_LOG_LEVEL, DEFAULT_LOGGER_NAME, typeErrors: { INVALID_VALUE } } = require('./util/constants');
|
|
26
25
|
const workaround180748 = require('./webaudio/workaround180748');
|
|
26
|
+
const telemetry = require('./insights/telemetry');
|
|
27
27
|
|
|
28
28
|
// This is used to make out which createLocalTracks() call a particular Log
|
|
29
29
|
// statement belongs to. Each call to createLocalTracks() increments this
|
|
30
30
|
// counter.
|
|
31
31
|
let createLocalTrackCalls = 0;
|
|
32
32
|
|
|
33
|
-
|
|
34
33
|
type ExtraLocalTrackOption = CreateLocalTrackOptions & { isCreatedByCreateLocalTracks?: boolean };
|
|
35
|
-
type ExtraLocalAudioTrackOption = ExtraLocalTrackOption & { defaultDeviceCaptureMode
|
|
34
|
+
type ExtraLocalAudioTrackOption = ExtraLocalTrackOption & { defaultDeviceCaptureMode?: DefaultDeviceCaptureMode };
|
|
36
35
|
type ExtraLocalTrackOptions = { audio: ExtraLocalAudioTrackOption; video: ExtraLocalTrackOption; };
|
|
37
36
|
|
|
38
37
|
interface InternalOptions extends CreateLocalTracksOptions {
|
|
@@ -201,6 +200,8 @@ export async function createLocalTracks(options?: CreateLocalTracksOptions): Pro
|
|
|
201
200
|
? workaround180748(log, fullOptions.getUserMedia, mediaStreamConstraints)
|
|
202
201
|
: fullOptions.getUserMedia(mediaStreamConstraints));
|
|
203
202
|
|
|
203
|
+
telemetry.getUserMedia.succeeded();
|
|
204
|
+
|
|
204
205
|
const mediaStreamTracks = [
|
|
205
206
|
...mediaStream.getAudioTracks(),
|
|
206
207
|
...mediaStream.getVideoTracks(),
|
|
@@ -230,6 +231,11 @@ export async function createLocalTracks(options?: CreateLocalTracksOptions): Pro
|
|
|
230
231
|
})
|
|
231
232
|
);
|
|
232
233
|
} catch (error) {
|
|
234
|
+
if (error.name === 'NotAllowedError' || error.name === 'PermissionDeniedError') {
|
|
235
|
+
telemetry.getUserMedia.denied();
|
|
236
|
+
} else {
|
|
237
|
+
telemetry.getUserMedia.failed(error);
|
|
238
|
+
}
|
|
233
239
|
log.warn('Call to getUserMedia failed:', error);
|
|
234
240
|
throw error;
|
|
235
241
|
}
|
package/lib/index.ts
CHANGED
|
@@ -29,7 +29,7 @@ function connect(token: string, options?: ConnectOptions): Promise<Room> {
|
|
|
29
29
|
return internals.connect(token, internalOptions);
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
function createLocalAudioTrack(options?: CreateLocalTrackOptions|CreateLocalAudioTrackOptions): Promise<LocalAudioTrackType> {
|
|
32
|
+
function createLocalAudioTrack(options?: CreateLocalTrackOptions | CreateLocalAudioTrackOptions): Promise<LocalAudioTrackType> {
|
|
33
33
|
const internalOptions = {
|
|
34
34
|
createLocalTracks,
|
|
35
35
|
...options
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const documentVisibilityMonitor = require('../util/documentvisibilitymonitor');
|
|
4
|
+
const telemetry = require('./telemetry');
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* ApplicationMonitor handles publishing application lifecycle events to the Insights gateway.
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
class ApplicationMonitor {
|
|
11
|
+
/**
|
|
12
|
+
* Create an ApplicationMonitor
|
|
13
|
+
* @param {Log} log - Logger instance
|
|
14
|
+
*/
|
|
15
|
+
constructor(log) {
|
|
16
|
+
if (!log) {
|
|
17
|
+
throw new Error('ApplicationMonitor requires a log instance');
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
this._log = log;
|
|
21
|
+
this._visibilityChangeHandler = null;
|
|
22
|
+
this._boundHandleBeforeUnload = this._handleBeforeUnload.bind(this);
|
|
23
|
+
|
|
24
|
+
this._setupVisibilityMonitoring();
|
|
25
|
+
this._setupBeforeUnloadMonitoring();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Setup application visibility monitoring
|
|
30
|
+
* @private
|
|
31
|
+
*/
|
|
32
|
+
_setupVisibilityMonitoring() {
|
|
33
|
+
if (typeof window === 'undefined' || typeof document === 'undefined') {
|
|
34
|
+
this._log.debug('Not in browser environment, skipping setup of ApplicationMonitor');
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
this._visibilityChangeHandler = isVisible => this._handleVisibilityChange(isVisible);
|
|
39
|
+
|
|
40
|
+
try {
|
|
41
|
+
documentVisibilityMonitor.onVisibilityChange(1, this._visibilityChangeHandler);
|
|
42
|
+
this._log.debug('ApplicationMonitor visibility monitoring initialized');
|
|
43
|
+
} catch (error) {
|
|
44
|
+
this._log.error('Error initializing ApplicationMonitor visibility monitoring:', error);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Setup application beforeunload monitoring
|
|
50
|
+
* @private
|
|
51
|
+
*/
|
|
52
|
+
_setupBeforeUnloadMonitoring() {
|
|
53
|
+
try {
|
|
54
|
+
window.addEventListener('beforeunload', this._boundHandleBeforeUnload);
|
|
55
|
+
this._log.debug('ApplicationMonitor beforeunload monitoring initialized');
|
|
56
|
+
} catch (error) {
|
|
57
|
+
this._log.error('Error initializing ApplicationMonitor beforeunload monitoring:', error);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Cleanup all application event monitors
|
|
63
|
+
*/
|
|
64
|
+
cleanup() {
|
|
65
|
+
this._log.debug('Cleaning up application event monitors');
|
|
66
|
+
|
|
67
|
+
if (this._visibilityChangeHandler) {
|
|
68
|
+
documentVisibilityMonitor.offVisibilityChange(1, this._visibilityChangeHandler);
|
|
69
|
+
this._visibilityChangeHandler = null;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (typeof window !== 'undefined' && this._boundHandleBeforeUnload) {
|
|
73
|
+
window.removeEventListener('beforeunload', this._boundHandleBeforeUnload);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Handle document visibility changes.
|
|
79
|
+
* @private
|
|
80
|
+
* @param {boolean} isVisible - Whether the application is visible or not
|
|
81
|
+
* @returns {void}
|
|
82
|
+
*/
|
|
83
|
+
_handleVisibilityChange(isVisible) {
|
|
84
|
+
if (isVisible) {
|
|
85
|
+
telemetry.application.resumed();
|
|
86
|
+
} else {
|
|
87
|
+
telemetry.application.backgrounded();
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Handle beforeunload event
|
|
93
|
+
* @private
|
|
94
|
+
* @returns {void}
|
|
95
|
+
*/
|
|
96
|
+
_handleBeforeUnload() {
|
|
97
|
+
telemetry.application.terminated();
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
module.exports = ApplicationMonitor;
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileOverview
|
|
3
|
+
* Custom Compute Pressure monitor using the Compute Pressure API.
|
|
4
|
+
* @internal
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
'use strict';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @typedef {'cpu' | 'gpu'} PressureSource
|
|
11
|
+
* @typedef {'nominal' | 'fair' | 'serious' | 'critical'} PressureState
|
|
12
|
+
*
|
|
13
|
+
* NOTE(lrivas): Remove once we update to a TypeScript version with definitions for the Compute Pressure API types.
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* @typedef {{
|
|
17
|
+
* source: PressureSource,
|
|
18
|
+
* state: PressureState,
|
|
19
|
+
* time: DOMHighResTimeStamp
|
|
20
|
+
* }} PressureRecord
|
|
21
|
+
*/
|
|
22
|
+
/**
|
|
23
|
+
* @typedef {{ sampleInterval?: number }} PressureObserverOptions
|
|
24
|
+
*/
|
|
25
|
+
/**
|
|
26
|
+
* @callback PressureObserverCallback
|
|
27
|
+
* @param {PressureRecord[]} records
|
|
28
|
+
* @param {PressureObserver} observer
|
|
29
|
+
*/
|
|
30
|
+
/**
|
|
31
|
+
* @typedef {{
|
|
32
|
+
* disconnect(): void,
|
|
33
|
+
* observe(source: PressureSource, options?: PressureObserverOptions): Promise<void>,
|
|
34
|
+
* unobserve(source: PressureSource): void,
|
|
35
|
+
* takeRecords(): PressureRecord[]
|
|
36
|
+
* }} PressureObserver
|
|
37
|
+
*/
|
|
38
|
+
/**
|
|
39
|
+
* @typedef {new (callback: PressureObserverCallback) => PressureObserver} PressureObserverConstructor
|
|
40
|
+
*/
|
|
41
|
+
/**
|
|
42
|
+
* @callback PressureChangeCallback
|
|
43
|
+
* @param {PressureRecord} record
|
|
44
|
+
* @returns {void}
|
|
45
|
+
*/
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Helper to get the PressureObserver constructor from the global scope.
|
|
49
|
+
* @returns {PressureObserverConstructor | null}
|
|
50
|
+
*/
|
|
51
|
+
function getPressureObserver() {
|
|
52
|
+
if (typeof globalThis !== 'undefined' && typeof globalThis.PressureObserver === 'function') {
|
|
53
|
+
return /** @type {PressureObserverConstructor} */ (globalThis.PressureObserver);
|
|
54
|
+
}
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
class ComputePressureMonitor {
|
|
59
|
+
constructor() {
|
|
60
|
+
/** @type {PressureState | null} */
|
|
61
|
+
this._lastCpuPressure = null;
|
|
62
|
+
/** @type {PressureObserver | null} */
|
|
63
|
+
this._cpuPressureObserver = null;
|
|
64
|
+
/** @type {number} */
|
|
65
|
+
this._sampleInterval = 2000; // 2 seconds
|
|
66
|
+
/** @type {PressureChangeCallback[]} */
|
|
67
|
+
this._cpuPressureChangeListeners = [];
|
|
68
|
+
/** @type {PressureObserverConstructor | null} */
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Start watching CPU pressure changes. This is an asynchronous operation.
|
|
73
|
+
* @param {PressureChangeCallback} callback - The callback function to call when the pressure changes.
|
|
74
|
+
* @returns {Promise<void>}
|
|
75
|
+
*/
|
|
76
|
+
async watchCpuPressure(callback) {
|
|
77
|
+
if (typeof callback !== 'function') {
|
|
78
|
+
throw new Error('The CPU pressure change callback must be a function');
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const PressureObserver = getPressureObserver();
|
|
82
|
+
if (!PressureObserver) {
|
|
83
|
+
throw new Error('PressureObserver is not supported in this environment');
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
this._cpuPressureChangeListeners.push(callback);
|
|
87
|
+
|
|
88
|
+
if (!this._cpuPressureObserver) {
|
|
89
|
+
this._cpuPressureObserver = new PressureObserver(records => this._handleCpuPressureRecords(records));
|
|
90
|
+
await this._cpuPressureObserver.observe('cpu', {
|
|
91
|
+
sampleInterval: this._sampleInterval,
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* @returns {boolean}
|
|
98
|
+
*/
|
|
99
|
+
isSupported() {
|
|
100
|
+
return !!getPressureObserver();
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Stop watching CPU pressure changes for the given callback.
|
|
105
|
+
* @param {PressureChangeCallback} callback - The callback function to stop listening to.
|
|
106
|
+
* @returns {void}
|
|
107
|
+
*/
|
|
108
|
+
unwatchCpuPressure(callback) {
|
|
109
|
+
this._cpuPressureChangeListeners = this._cpuPressureChangeListeners.filter(cb => cb !== callback);
|
|
110
|
+
if (this._cpuPressureChangeListeners.length === 0) {
|
|
111
|
+
this.cleanup();
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* @param {PressureRecord[]} records - An array containing all the PressureRecords observed since the last callback.
|
|
117
|
+
* @returns {void}
|
|
118
|
+
*/
|
|
119
|
+
_handleCpuPressureRecords(records) {
|
|
120
|
+
if (!Array.isArray(records) || records.length === 0) {
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
const lastRecord = records[records.length - 1];
|
|
124
|
+
if (!lastRecord) {
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
const hasChanged = lastRecord.state !== this._lastCpuPressure;
|
|
128
|
+
|
|
129
|
+
if (hasChanged) {
|
|
130
|
+
this._lastCpuPressure = lastRecord.state;
|
|
131
|
+
this._cpuPressureChangeListeners.forEach(callback => callback(lastRecord));
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Clean up all the resources created by the monitor.
|
|
137
|
+
* @returns {void}
|
|
138
|
+
*/
|
|
139
|
+
cleanup() {
|
|
140
|
+
if (this._cpuPressureObserver) {
|
|
141
|
+
this._cpuPressureObserver.disconnect();
|
|
142
|
+
this._cpuPressureObserver = null;
|
|
143
|
+
}
|
|
144
|
+
this._cpuPressureChangeListeners = [];
|
|
145
|
+
this._lastCpuPressure = null;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
module.exports = new ComputePressureMonitor();
|