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 7 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 interrupion(started: boolean, type: string, deviceInfo: Partial<MediaDeviceInfo>) {
amar-1995 marked this conversation as resolved.
Show resolved Hide resolved
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
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,22 @@ export class AudioSinkManager {

private handleAudioPaused = async (event: any) => {
// this means the audio paused because of external factors(headset removal, incoming phone call)
HMSLogger.d(this.TAG, 'Audio Paused', event.target.id);
const audioTrack = this.store.getTrackById(event.target.id);
if (audioTrack) {
this.autoPausedTracks.add(audioTrack as HMSRemoteAudioTrack);
// started interruption event
audioTrack.sendInterruptionEvent(true, true);
}
};

private handleAudioPlay = async (event: any) => {
// this means the audio replayed because of external factors(headset removal, incoming phone call)
const audioTrack = this.store.getTrackById(event.target.id);
if (audioTrack) {
// stopped interruption event
audioTrack.sendInterruptionEvent(false, true);
raviteja83 marked this conversation as resolved.
Show resolved Hide resolved
}
};
private handleTrackUpdate = ({ track }: { track: HMSRemoteAudioTrack; enabled: boolean }) => {
HMSLogger.d(this.TAG, 'Track updated', `${track}`);
};
Expand All @@ -140,6 +149,7 @@ export class AudioSinkManager {
audioEl.style.display = 'none';
audioEl.id = track.trackId;
audioEl.addEventListener('pause', this.handleAudioPaused);
audioEl.addEventListener('play', this.handleAudioPlay);
amar-1995 marked this conversation as resolved.
Show resolved Hide resolved

audioEl.onerror = async () => {
HMSLogger.e(this.TAG, 'error on audio element', audioEl.error);
Expand Down Expand Up @@ -259,6 +269,7 @@ export class AudioSinkManager {
if (audioEl) {
HMSLogger.d(this.TAG, 'removing audio element', `${track}`);
audioEl.removeEventListener('pause', this.handleAudioPaused);
audioEl.removeEventListener('play', this.handleAudioPlay);
audioEl.srcObject = null;
audioEl.remove();
track.setAudioElement(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ export class HMSLocalAudioTrack extends HMSAudioTrack {
private handleVisibilityChange = async () => {
if (document.visibilityState === 'visible') {
await this.replaceTrackWith(this.settings);
this.sendInterruptionEvent(false);
} else {
// started interruption event
this.sendInterruptionEvent(true);
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -499,9 +499,13 @@ export class HMSLocalVideoTrack extends HMSVideoTrack {
this.enabledStateBeforeBackground = this.enabled;
amar-1995 marked this conversation as resolved.
Show resolved Hide resolved
this.nativeTrack.enabled = false;
this.replaceSenderTrack(this.nativeTrack);
raviteja83 marked this conversation as resolved.
Show resolved Hide resolved
// started interruption event
this.sendInterruptionEvent(true);
} else {
this.nativeTrack.enabled = this.enabledStateBeforeBackground;
this.replaceSenderTrack(this.processedTrack || this.nativeTrack);
// stopped interruption event
this.sendInterruptionEvent(false);
}
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: boolean, isRemoteAudio = false) {
AnalyticsEventFactory.interrupion(started, isRemoteAudio ? 'remote.audio' : this.type, {
amar-1995 marked this conversation as resolved.
Show resolved Hide resolved
deviceId: this.nativeTrack.getSettings().deviceId,
groupId: this.nativeTrack.getSettings().groupId,
});
}
/**
* @internal
* take care of -
Expand Down
Loading