Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: interruption events #3122

Merged
merged 32 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
4e16454
feat: handling interruption events
amar-1995 Jul 24, 2024
a1fb3ab
fix: added audio disabling for mweb
amar-1995 Jul 24, 2024
e682d46
fix: remove load
amar-1995 Jul 24, 2024
11fe214
fix: cleanup
amar-1995 Jul 25, 2024
2a927b6
fix: testing
amar-1995 Jul 25, 2024
5fc0f43
fix: testing audio context state
amar-1995 Jul 25, 2024
0856aee
fix: updated to sinek manager
amar-1995 Jul 26, 2024
1a3ff2d
fix: added log
amar-1995 Jul 26, 2024
d6f7650
fix: added logs
amar-1995 Jul 26, 2024
45fe477
fix: interruption eventing testing
amar-1995 Jul 29, 2024
0123bba
fix: remove logs
amar-1995 Jul 29, 2024
03738b8
fix: remote audio
amar-1995 Jul 29, 2024
fa37aac
fix: wrong line removed
amar-1995 Jul 29, 2024
e09d5b9
fix: type
amar-1995 Jul 29, 2024
0cab862
fix: remove local screenshare video check
amar-1995 Jul 29, 2024
4b9c215
fix: remove extra variable
amar-1995 Jul 29, 2024
c64d562
Merge branch 'dev' into feat/WEB-2945-interruption-events
amar-1995 Jul 29, 2024
f45b31b
fix: unsaved file
amar-1995 Jul 29, 2024
8f4ed01
fix: complexity
raviteja83 Jul 29, 2024
7496816
fix: add source check in audio
raviteja83 Jul 29, 2024
4a0cdcc
fix: check
raviteja83 Jul 29, 2024
1026377
fix: check
raviteja83 Jul 29, 2024
0c736d4
fix: add log
raviteja83 Jul 29, 2024
4f4f76d
fix: check with replace sender track
amar-1995 Jul 29, 2024
4b70e07
fix: revert replace sender
amar-1995 Jul 29, 2024
b8e349d
fix: remove replace track
amar-1995 Jul 29, 2024
8b09203
fix: local video not publishing
raviteja83 Jul 29, 2024
249a564
fix: complexity
raviteja83 Jul 29, 2024
20dfe89
Merge branch 'dev' into feat/WEB-2945-interruption-events
raviteja83 Jul 29, 2024
281aa50
fix: render sinks after track replace
raviteja83 Jul 30, 2024
d079327
Merge branch 'dev' into feat/WEB-2945-interruption-events
amar-1995 Jul 31, 2024
03c2d0d
Merge branch 'dev' into feat/WEB-2945-interruption-events
raviteja83 Jul 31, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/prebuilt-react-integration/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!doctype html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
Expand Down
12 changes: 12 additions & 0 deletions packages/hms-video-store/src/analytics/AnalyticsEventFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,18 @@ export default class AnalyticsEventFactory {
level: AnalyticsEventLevel.INFO,
});
}

static interruption(started: boolean, type: string, deviceInfo: Partial<MediaDeviceInfo>) {
return new AnalyticsEvent({
name: `${started ? 'interruption.start' : 'interruption.stop'}`,
level: AnalyticsEventLevel.INFO,
properties: {
type,
...deviceInfo,
},
});
}

private static eventNameFor(name: string, ok: boolean) {
const suffix = ok ? 'success' : 'failed';
return `${name}.${suffix}`;
Expand Down
30 changes: 24 additions & 6 deletions packages/hms-video-store/src/media/tracks/HMSLocalAudioTrack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { HMSAudioPlugin, HMSPluginSupportResult } from '../../plugins';
import { HMSAudioPluginsManager } from '../../plugins/audio';
import Room from '../../sdk/models/HMSRoom';
import HMSLogger from '../../utils/logger';
import { isBrowser, isIOS } from '../../utils/support';
import { getAudioTrack, isEmptyTrack } from '../../utils/track';
import { TrackAudioLevelMonitor } from '../../utils/track-audio-level-monitor';
import { HMSAudioTrackSettings, HMSAudioTrackSettingsBuilder } from '../settings';
Expand Down Expand Up @@ -60,7 +59,7 @@ export class HMSLocalAudioTrack extends HMSAudioTrack {
}
this.pluginsManager = new HMSAudioPluginsManager(this, eventBus, room);
this.setFirstTrackId(track.id);
if (isIOS() && isBrowser) {
if (source === 'regular') {
document.addEventListener('visibilitychange', this.handleVisibilityChange);
}
}
Expand All @@ -73,9 +72,30 @@ export class HMSLocalAudioTrack extends HMSAudioTrack {
this.manuallySelectedDeviceId = undefined;
}

private isTrackNotPublishing = () => {
return this.nativeTrack.readyState === 'ended' || this.nativeTrack.muted;
};

private handleVisibilityChange = async () => {
if (document.visibilityState === 'visible') {
// track state is fine do nothing
if (!this.isTrackNotPublishing()) {
HMSLogger.d(this.TAG, `visibiltiy: ${document.visibilityState}`, `${this}`);
return;
}
if (document.visibilityState === 'hidden') {
this.eventBus.analytics.publish(
this.sendInterruptionEvent({
raviteja83 marked this conversation as resolved.
Show resolved Hide resolved
started: true,
}),
);
} else {
HMSLogger.d(this.TAG, 'On visibile replacing track as it is not publishing');
await this.replaceTrackWith(this.settings);
this.eventBus.analytics.publish(
this.sendInterruptionEvent({
started: false,
}),
);
}
};

Expand Down Expand Up @@ -230,9 +250,7 @@ export class HMSLocalAudioTrack extends HMSAudioTrack {
this.processedTrack?.stop();
this.isPublished = false;
this.destroyAudioLevelMonitor();
if (isIOS() && isBrowser) {
document.removeEventListener('visibilitychange', this.handleVisibilityChange);
}
document.removeEventListener('visibilitychange', this.handleVisibilityChange);
}

/**
Expand Down
35 changes: 28 additions & 7 deletions packages/hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export class HMSLocalVideoTrack extends HMSVideoTrack {
this.pluginsManager = new HMSVideoPluginsManager(this, eventBus);
this.mediaStreamPluginsManager = new HMSMediaStreamPluginsManager(eventBus, room);
this.setFirstTrackId(this.trackId);
if (isBrowser && isMobile()) {
if (isBrowser && source === 'regular') {
document.addEventListener('visibilitychange', this.handleVisibilityChange);
}
}
Expand Down Expand Up @@ -495,13 +495,34 @@ export class HMSLocalVideoTrack extends HMSVideoTrack {
};

private handleVisibilityChange = async () => {
if (document.visibilityState === 'hidden' && this.source === 'regular') {
this.enabledStateBeforeBackground = this.enabled;
this.nativeTrack.enabled = false;
this.replaceSenderTrack(this.nativeTrack);
if (document.visibilityState === 'hidden') {
if (isMobile()) {
this.enabledStateBeforeBackground = this.enabled;
this.nativeTrack.enabled = false;
HMSLogger.d(this.TAG, 'visibility hidden muting track');
this.replaceSenderTrack(this.nativeTrack);
// started interruption event
this.eventBus.analytics.publish(
this.sendInterruptionEvent({
started: true,
}),
);
}
} else {
this.nativeTrack.enabled = this.enabledStateBeforeBackground;
this.replaceSenderTrack(this.processedTrack || this.nativeTrack);
if (this.nativeTrack.muted || this.nativeTrack.readyState === 'ended') {
HMSLogger.d(this.TAG, 'visibility visible, restarting track', `${this}`);
const track = await this.replaceTrackWith(this.settings);
this.nativeTrack?.stop();
this.nativeTrack = track;
}
if (isMobile()) {
this.nativeTrack.enabled = this.enabledStateBeforeBackground;
await this.replaceSender(this.nativeTrack, this.enabledStateBeforeBackground);
} else {
await this.replaceSender(this.nativeTrack, this.enabled);
}
await this.processPlugins();
this.videoHandler.updateSinks();
}
this.eventBus.localVideoEnabled.publish({ enabled: this.nativeTrack.enabled, track: this });
};
Expand Down
12 changes: 11 additions & 1 deletion packages/hms-video-store/src/media/tracks/HMSTrack.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { HMSTrackType } from './HMSTrackType';
import AnalyticsEventFactory from '../../analytics/AnalyticsEventFactory';
import { stringifyMediaStreamTrack } from '../../utils/json';
import HMSLogger from '../../utils/logger';
import { HMSMediaStream } from '../streams';
Expand Down Expand Up @@ -84,7 +85,16 @@ export abstract class HMSTrack {
protected setFirstTrackId(trackId: string) {
this.firstTrackId = trackId;
}

/**
* @internal
* It will send event to analytics when interruption start/stop
*/
sendInterruptionEvent({ started, isRemoteAudio = false }: { started: boolean; isRemoteAudio?: boolean }) {
return AnalyticsEventFactory.interruption(started, isRemoteAudio ? 'remote.audio' : this.type, {
deviceId: this.nativeTrack.getSettings().deviceId,
groupId: this.nativeTrack.getSettings().groupId,
});
}
/**
* @internal
* take care of -
Expand Down
Loading