@100mslive/hms-video-store 0.12.3-alpha.2 → 0.12.3-alpha.4

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.
@@ -25,7 +25,7 @@ export interface HMSAudioPlugin {
25
25
  * variables, loading ML models etc. This can be used by a plugin to ensure it's prepared at the time
26
26
  * processAudio is called.
27
27
  */
28
- init(): Promise<void> | void;
28
+ init(sessionID?: string): Promise<void> | void;
29
29
  /**
30
30
  * The name is meant to uniquely specify a plugin instance. This will be used to track number of plugins
31
31
  * added to the track, and same name won't be allowed twice.
@@ -4,6 +4,6 @@ export interface HMSMediaStreamPlugin {
4
4
  * added to the track, and same name won't be allowed twice.
5
5
  */
6
6
  getName(): string;
7
- apply(stream: MediaStream): MediaStream;
7
+ apply(stream: MediaStream, sessionID?: string): MediaStream;
8
8
  stop(): void;
9
9
  }
@@ -25,7 +25,7 @@ export interface HMSVideoPlugin {
25
25
  * variables, loading ML models etc. This can be used by a plugin to ensure it's prepared at the time
26
26
  * processVideoFrame is called.
27
27
  */
28
- init(): Promise<void>;
28
+ init(sessionID?: string): Promise<void>;
29
29
  /**
30
30
  * @see HMSVideoPluginType
31
31
  */
@@ -38,6 +38,7 @@ export declare class HMSSdk implements HMSInterface {
38
38
  private wakeLockManager;
39
39
  private sessionStore;
40
40
  private interactivityCenter;
41
+ private pluginUsageTracker;
41
42
  private sdkState;
42
43
  private frameworkInfo?;
43
44
  private playlistSettings;
@@ -2,6 +2,7 @@ import ITransportObserver from './ITransportObserver';
2
2
  import { AdditionalAnalyticsProperties } from '../analytics/AdditionalAnalyticsProperties';
3
3
  import { AnalyticsEventsService } from '../analytics/AnalyticsEventsService';
4
4
  import { AnalyticsTimer } from '../analytics/AnalyticsTimer';
5
+ import { PluginUsageTracker } from '../common/PluginUsageTracker';
5
6
  import HMSSubscribeConnection from '../connection/subscribe/subscribeConnection';
6
7
  import { DeviceManager } from '../device-manager';
7
8
  import { EventBus } from '../events/EventBus';
@@ -18,6 +19,7 @@ export default class HMSTransport {
18
19
  private eventBus;
19
20
  private analyticsEventsService;
20
21
  private analyticsTimer;
22
+ private pluginUsageTracker;
21
23
  private state;
22
24
  private trackStates;
23
25
  private publishConnection;
@@ -31,7 +33,7 @@ export default class HMSTransport {
31
33
  private subscribeStatsAnalytics?;
32
34
  private maxSubscribeBitrate;
33
35
  joinRetryCount: number;
34
- constructor(observer: ITransportObserver, deviceManager: DeviceManager, store: Store, eventBus: EventBus, analyticsEventsService: AnalyticsEventsService, analyticsTimer: AnalyticsTimer);
36
+ constructor(observer: ITransportObserver, deviceManager: DeviceManager, store: Store, eventBus: EventBus, analyticsEventsService: AnalyticsEventsService, analyticsTimer: AnalyticsTimer, pluginUsageTracker: PluginUsageTracker);
35
37
  /**
36
38
  * Map of callbacks used to wait for an event to fire.
37
39
  * Used here for:
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.12.3-alpha.2",
2
+ "version": "0.12.3-alpha.4",
3
3
  "license": "MIT",
4
4
  "repository": {
5
5
  "type": "git",
@@ -73,5 +73,5 @@
73
73
  "conferencing",
74
74
  "100ms"
75
75
  ],
76
- "gitHead": "ada10fb3dc34984fd59f37f08629e8bd2a0f6c4c"
76
+ "gitHead": "f402d418c294acc6ce73bc81ab286d26431a6f53"
77
77
  }
@@ -3,7 +3,6 @@ import { AdditionalAnalyticsProperties } from './AdditionalAnalyticsProperties';
3
3
  import AnalyticsEvent from './AnalyticsEvent';
4
4
  import { AnalyticsEventLevel } from './AnalyticsEventLevel';
5
5
  import { IAnalyticsPropertiesProvider } from './IAnalyticsPropertiesProvider';
6
- import { pluginUsageTracker } from '../common';
7
6
  import { HMSException } from '../error/HMSException';
8
7
  import { DeviceMap, SelectedDevices } from '../interfaces';
9
8
  import { HMSTrackSettings } from '../media/settings/HMSTrackSettings';
@@ -236,8 +235,7 @@ export default class AnalyticsEventFactory {
236
235
  });
237
236
  }
238
237
 
239
- static getKrispUsage(sessionID: string) {
240
- const duration = pluginUsageTracker.getPluginUsage('HMSKrispPlugin', sessionID);
238
+ static getKrispUsage(duration: number) {
241
239
  return new AnalyticsEvent({
242
240
  name: 'krisp.usage',
243
241
  level: AnalyticsEventLevel.INFO,
@@ -1,53 +1,57 @@
1
1
  import AnalyticsEvent from '../analytics/AnalyticsEvent';
2
+ import { EventBus } from '../events/EventBus';
2
3
 
3
- class PluginUsageTracker {
4
+ export class PluginUsageTracker {
4
5
  private pluginUsage: Map<string, number> = new Map<string, number>();
5
6
  private pluginLastAddedAt: Map<string, number> = new Map<string, number>();
6
7
 
7
- getPluginUsage = (name: string, sessionID: string) => {
8
- const pluginKey = `${sessionID}-${name}`;
8
+ constructor(private eventBus: EventBus) {
9
+ this.eventBus.analytics.subscribe(e => this.updatePluginUsageData(e));
10
+ }
9
11
 
10
- if (!this.pluginUsage.has(pluginKey)) {
11
- this.pluginUsage.set(pluginKey, 0);
12
+ getPluginUsage = (name: string) => {
13
+ if (!this.pluginUsage.has(name)) {
14
+ this.pluginUsage.set(name, 0);
12
15
  }
13
- if (this.pluginLastAddedAt.has(pluginKey)) {
14
- const lastAddedAt = this.pluginLastAddedAt.get(pluginKey) || 0;
16
+ if (this.pluginLastAddedAt.has(name)) {
17
+ const lastAddedAt = this.pluginLastAddedAt.get(name) || 0;
15
18
  const extraDuration = lastAddedAt ? Date.now() - lastAddedAt : 0;
16
- this.pluginUsage.set(pluginKey, (this.pluginUsage.get(pluginKey) || 0) + extraDuration);
17
- this.pluginLastAddedAt.delete(pluginKey);
19
+ this.pluginUsage.set(name, (this.pluginUsage.get(name) || 0) + extraDuration);
20
+ this.pluginLastAddedAt.delete(name);
18
21
  }
19
- return this.pluginUsage.get(pluginKey);
22
+ return this.pluginUsage.get(name);
20
23
  };
21
24
 
22
- updatePluginUsageData = (event: AnalyticsEvent, sessionID: string) => {
23
- // Sent on leave, after krisp usage is sent
24
- if (event.name === 'transport.leave') {
25
- this.cleanup(sessionID);
26
- return;
27
- }
28
-
29
- const name = event.properties.plugin_name;
30
- const pluginKey = `${sessionID}-${name}`;
31
- if (event.name === 'mediaPlugin.added') {
32
- const addedAt = event.properties.added_at;
33
- this.pluginLastAddedAt.set(pluginKey, addedAt);
34
- } else if (event.name === 'mediaPlugin.stats') {
35
- const duration = event.properties.duration;
36
- if (duration > 0) {
37
- this.pluginUsage.set(pluginKey, (this.pluginUsage.get(pluginKey) || 0) + duration * 1000);
38
- this.pluginLastAddedAt.delete(pluginKey);
25
+ // eslint-disable-next-line complexity
26
+ updatePluginUsageData = (event: AnalyticsEvent) => {
27
+ const name = event.properties?.plugin_name || '';
28
+ switch (event.name) {
29
+ // Sent on leave, after krisp usage is sent
30
+ case 'transport.leave': {
31
+ this.cleanup();
32
+ return;
33
+ }
34
+ case 'mediaPlugin.toggled.on':
35
+ case 'mediaPlugin.added': {
36
+ const addedAt = event.properties.added_at || Date.now();
37
+ this.pluginLastAddedAt.set(name, addedAt);
38
+ break;
39
+ }
40
+ case 'mediaPlugin.toggled.off':
41
+ case 'mediaPlugin.stats': {
42
+ if (this.pluginLastAddedAt.has(name)) {
43
+ const duration = event.properties.duration || (Date.now() - (this.pluginLastAddedAt.get(name) || 0)) / 1000;
44
+ this.pluginUsage.set(name, (this.pluginUsage.get(name) || 0) + Math.max(duration, 0) * 1000);
45
+ this.pluginLastAddedAt.delete(name);
46
+ }
47
+ break;
39
48
  }
49
+ default:
40
50
  }
41
51
  };
42
52
 
43
- private cleanup = (sessionID: string) => {
44
- for (const key of this.pluginUsage.keys()) {
45
- if (sessionID.length && key.includes(sessionID)) {
46
- this.pluginUsage.delete(key);
47
- this.pluginLastAddedAt.delete(key);
48
- }
49
- }
53
+ cleanup = () => {
54
+ this.pluginLastAddedAt.clear();
55
+ this.pluginUsage.clear();
50
56
  };
51
57
  }
52
-
53
- export const pluginUsageTracker = new PluginUsageTracker();
package/src/index.ts CHANGED
@@ -53,7 +53,7 @@ export type {
53
53
  HMSQuizLeaderboardSummary,
54
54
  } from './internal';
55
55
 
56
- export { pluginUsageTracker } from './common';
56
+ export { EventBus } from './events/EventBus';
57
57
  export { HMSReactiveStore } from './reactive-store/HMSReactiveStore';
58
58
  export { HMSPluginUnsupportedTypes, HMSRecordingState, HLSPlaylistType } from './internal';
59
59
  export type {
@@ -29,7 +29,7 @@ export interface HMSAudioPlugin {
29
29
  * variables, loading ML models etc. This can be used by a plugin to ensure it's prepared at the time
30
30
  * processAudio is called.
31
31
  */
32
- init(): Promise<void> | void;
32
+ init(sessionID?: string): Promise<void> | void;
33
33
 
34
34
  /**
35
35
  * The name is meant to uniquely specify a plugin instance. This will be used to track number of plugins
@@ -87,6 +87,8 @@ export class HMSAudioPluginsManager {
87
87
  }
88
88
 
89
89
  await this.validateAndThrow(name, plugin);
90
+ // @ts-ignore
91
+ plugin.setEventBus?.(this.eventBus);
90
92
 
91
93
  try {
92
94
  if (this.pluginsMap.size === 0) {
@@ -5,7 +5,7 @@ export interface HMSMediaStreamPlugin {
5
5
  */
6
6
  getName(): string;
7
7
 
8
- apply(stream: MediaStream): MediaStream;
8
+ apply(stream: MediaStream, sessionID?: string): MediaStream;
9
9
 
10
10
  stop(): void;
11
11
  }
@@ -29,7 +29,7 @@ export interface HMSVideoPlugin {
29
29
  * variables, loading ML models etc. This can be used by a plugin to ensure it's prepared at the time
30
30
  * processVideoFrame is called.
31
31
  */
32
- init(): Promise<void>;
32
+ init(sessionID?: string): Promise<void>;
33
33
 
34
34
  /**
35
35
  * @see HMSVideoPluginType
package/src/sdk/index.ts CHANGED
@@ -12,7 +12,7 @@ import { HMSAnalyticsLevel } from '../analytics/AnalyticsEventLevel';
12
12
  import { AnalyticsEventsService } from '../analytics/AnalyticsEventsService';
13
13
  import { AnalyticsTimer, TimedEvent } from '../analytics/AnalyticsTimer';
14
14
  import { AudioSinkManager } from '../audio-sink-manager';
15
- import { pluginUsageTracker } from '../common/PluginUsageTracker';
15
+ import { PluginUsageTracker } from '../common/PluginUsageTracker';
16
16
  import { DeviceManager } from '../device-manager';
17
17
  import { AudioOutputManager } from '../device-manager/AudioOutputManager';
18
18
  import { DeviceStorageManager } from '../device-manager/DeviceStorage';
@@ -119,6 +119,7 @@ export class HMSSdk implements HMSInterface {
119
119
  private wakeLockManager!: WakeLockManager;
120
120
  private sessionStore!: SessionStore;
121
121
  private interactivityCenter!: InteractivityCenter;
122
+ private pluginUsageTracker!: PluginUsageTracker;
122
123
  private sdkState = { ...INITIAL_STATE };
123
124
  private frameworkInfo?: HMSFrameworkInfo;
124
125
  private playlistSettings: HMSPlaylistSettings = {
@@ -156,6 +157,7 @@ export class HMSSdk implements HMSInterface {
156
157
  this.sdkState.isInitialised = true;
157
158
  this.store = new Store();
158
159
  this.eventBus = new EventBus();
160
+ this.pluginUsageTracker = new PluginUsageTracker(this.eventBus);
159
161
  this.wakeLockManager = new WakeLockManager();
160
162
  this.networkTestManager = new NetworkTestManager(this.eventBus, this.listener);
161
163
  this.playlistManager = new PlaylistManager(this, this.eventBus);
@@ -179,6 +181,7 @@ export class HMSSdk implements HMSInterface {
179
181
  this.eventBus,
180
182
  this.analyticsEventsService,
181
183
  this.analyticsTimer,
184
+ this.pluginUsageTracker,
182
185
  );
183
186
  this.sessionStore = new SessionStore(this.transport);
184
187
  this.interactivityCenter = new InteractivityCenter(this.transport, this.store, this.listener);
@@ -572,8 +575,6 @@ export class HMSSdk implements HMSInterface {
572
575
  throw error;
573
576
  }
574
577
  HMSLogger.timeEnd(`join-room-${roomId}`);
575
- const sessionID = this.store.getRoom()?.sessionId || '';
576
- this.eventBus.analytics.subscribe(e => pluginUsageTracker.updatePluginUsageData(e, sessionID));
577
578
  }
578
579
 
579
580
  private stringifyMetadata(config: HMSConfig) {
@@ -587,6 +588,7 @@ export class HMSSdk implements HMSInterface {
587
588
  private cleanup() {
588
589
  this.cleanDeviceManagers();
589
590
  this.eventBus.analytics.unsubscribe(this.sendAnalyticsEvent);
591
+ this.pluginUsageTracker?.cleanup();
590
592
  this.analyticsTimer.cleanup();
591
593
  DeviceStorageManager.cleanup();
592
594
  this.playlistManager.cleanup();
@@ -11,6 +11,7 @@ import { AnalyticsTimer, TimedEvent } from '../analytics/AnalyticsTimer';
11
11
  import { HTTPAnalyticsTransport } from '../analytics/HTTPAnalyticsTransport';
12
12
  import { SignalAnalyticsTransport } from '../analytics/signal-transport/SignalAnalyticsTransport';
13
13
  import { PublishStatsAnalytics, SubscribeStatsAnalytics } from '../analytics/stats';
14
+ import { PluginUsageTracker } from '../common/PluginUsageTracker';
14
15
  import { HMSConnectionRole, HMSTrickle } from '../connection/model';
15
16
  import { IPublishConnectionObserver } from '../connection/publish/IPublishConnectionObserver';
16
17
  import HMSPublishConnection from '../connection/publish/publishConnection';
@@ -86,6 +87,7 @@ export default class HMSTransport {
86
87
  private eventBus: EventBus,
87
88
  private analyticsEventsService: AnalyticsEventsService,
88
89
  private analyticsTimer: AnalyticsTimer,
90
+ private pluginUsageTracker: PluginUsageTracker,
89
91
  ) {
90
92
  this.webrtcInternals = new HMSWebrtcInternals(
91
93
  this.store,
@@ -495,8 +497,9 @@ export default class HMSTransport {
495
497
  this.joinParameters = undefined;
496
498
  HMSLogger.d(TAG, 'leaving in transport');
497
499
  try {
498
- const sessionID = this.store.getRoom()?.sessionId || '';
499
- this.eventBus.analytics.publish(AnalyticsEventFactory.getKrispUsage(sessionID));
500
+ this.eventBus.analytics.publish(
501
+ AnalyticsEventFactory.getKrispUsage(this.pluginUsageTracker.getPluginUsage('HMSKrispPlugin')!),
502
+ );
500
503
  this.eventBus.analytics.publish(AnalyticsEventFactory.transportLeave());
501
504
  this.state = TransportState.Leaving;
502
505
  this.publishStatsAnalytics?.stop();
@@ -1 +0,0 @@
1
- export { pluginUsageTracker } from './PluginUsageTracker';
@@ -1 +0,0 @@
1
- export { pluginUsageTracker } from './PluginUsageTracker';