-
Notifications
You must be signed in to change notification settings - Fork 78
Expand file tree
/
Copy pathLocalVideoStreamVideoEffectsSubscriber.ts
More file actions
85 lines (74 loc) · 3.27 KB
/
LocalVideoStreamVideoEffectsSubscriber.ts
File metadata and controls
85 lines (74 loc) · 3.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
/* @conditional-compile-remove(video-background-effects) */
import { VideoEffectErrorPayload, VideoEffectName, VideoEffectsFeature } from '@azure/communication-calling';
/* @conditional-compile-remove(video-background-effects) */
import { LocalVideoStreamState, LocalVideoStreamVideoEffectsState } from './CallClientState';
/* @conditional-compile-remove(video-background-effects) */
import { CallContext } from './CallContext';
/* @conditional-compile-remove(video-background-effects) */
import { CallIdRef } from './CallIdRef';
/* @conditional-compile-remove(video-background-effects) */
/**
* Subscribes to a LocalVideoStream's video effects events and updates the call context appropriately.
* @private
*/
export class LocalVideoStreamVideoEffectsSubscriber {
private _parent: CallIdRef | 'unparented';
private _context: CallContext;
private _localVideoStream: LocalVideoStreamState;
private _localVideoStreamEffectsAPI: VideoEffectsFeature;
constructor(args: {
/** Owner of the local video stream. This is either the Call (referenced by CallIdRef) or is the device manager's unparented view (referenced by 'unparented') */
parent: CallIdRef | 'unparented';
context: CallContext;
localVideoStream: LocalVideoStreamState;
localVideoStreamEffectsAPI: VideoEffectsFeature;
}) {
this._parent = args.parent;
this._context = args.context;
this._localVideoStream = args.localVideoStream;
this._localVideoStreamEffectsAPI = args.localVideoStreamEffectsAPI;
this.subscribe();
}
private subscribe = (): void => {
this._localVideoStreamEffectsAPI.on('effectsStarted', this.effectsStarted);
this._localVideoStreamEffectsAPI.on('effectsStopped', this.effectsStopped);
this._localVideoStreamEffectsAPI.on('effectsError', this.effectsError);
};
public unsubscribe = (): void => {
this._localVideoStreamEffectsAPI.off('effectsStarted', this.effectsStarted);
this._localVideoStreamEffectsAPI.off('effectsStopped', this.effectsStopped);
this._localVideoStreamEffectsAPI.off('effectsError', this.effectsError);
};
private effectsStarted = (effectName: VideoEffectName): void => {
this.updateEffectsState({
isActive: true,
effectName: effectName
});
};
private effectsStopped = (effectName: VideoEffectName): void => {
this.updateEffectsState({
isActive: false,
effectName: effectName
});
};
private effectsError = (error: VideoEffectErrorPayload): void => {
// When there is an error the effects have stopped. Update the state to reflect this.
this.updateEffectsState({
isActive: false
});
// TODO [video-background-effects]: future PR will tee error to state
console.error(
`LocalVideoStreamVideoEffectsSubscriber effectError: Method not fully implemented. Error needs teed to state. ${error}`
);
};
private updateEffectsState = (newEffectsState: LocalVideoStreamVideoEffectsState): void => {
if (this._parent === 'unparented') {
this._context.setDeviceManagerUnparentedViewVideoEffects(this._localVideoStream, newEffectsState);
} else {
this._context.setCallLocalVideoStreamVideoEffects(this._parent.callId, this._localVideoStream, newEffectsState);
}
};
}
export {};