Allow microphone state to be used in conditions.
This commit is contained in:
@@ -141,6 +141,7 @@ describe('CardElementManager', () => {
|
||||
expect(api.getFullscreenManager().initialize).toBeCalled();
|
||||
expect(api.getExpandManager().initialize).toBeCalled();
|
||||
expect(api.getMediaLoadedInfoManager().initialize).toBeCalled();
|
||||
expect(api.getMicrophoneManager().initialize).toBeCalled();
|
||||
});
|
||||
|
||||
it('should disconnect', () => {
|
||||
|
||||
@@ -377,9 +377,81 @@ describe('ConditionsManager', () => {
|
||||
const manager = new ConditionsManager(createCardAPI());
|
||||
const condition: FrigateCardCondition = { interaction: true };
|
||||
expect(manager.evaluateCondition(condition)).toBeFalsy();
|
||||
manager.setState({ interaction: true })
|
||||
manager.setState({ interaction: true });
|
||||
expect(manager.evaluateCondition(condition)).toBeTruthy();
|
||||
manager.setState({ interaction: false })
|
||||
manager.setState({ interaction: false });
|
||||
expect(manager.evaluateCondition(condition)).toBeFalsy();
|
||||
});
|
||||
|
||||
describe('should evaluate conditions with microphone', () => {
|
||||
it('empty', () => {
|
||||
const manager = new ConditionsManager(createCardAPI());
|
||||
const condition: FrigateCardCondition = { microphone: {} };
|
||||
expect(manager.evaluateCondition(condition)).toBeTruthy();
|
||||
manager.setState({ microphone: { connected: true } });
|
||||
expect(manager.evaluateCondition(condition)).toBeTruthy();
|
||||
manager.setState({ microphone: { connected: false } });
|
||||
expect(manager.evaluateCondition(condition)).toBeTruthy();
|
||||
manager.setState({ microphone: { muted: true } });
|
||||
expect(manager.evaluateCondition(condition)).toBeTruthy();
|
||||
manager.setState({ microphone: { muted: false } });
|
||||
expect(manager.evaluateCondition(condition)).toBeTruthy();
|
||||
});
|
||||
|
||||
it('connected is true', () => {
|
||||
const manager = new ConditionsManager(createCardAPI());
|
||||
const condition: FrigateCardCondition = { microphone: { connected: true } };
|
||||
expect(manager.evaluateCondition(condition)).toBeFalsy();
|
||||
manager.setState({ microphone: { connected: true } });
|
||||
expect(manager.evaluateCondition(condition)).toBeTruthy();
|
||||
manager.setState({ microphone: { connected: false } });
|
||||
expect(manager.evaluateCondition(condition)).toBeFalsy();
|
||||
});
|
||||
|
||||
it('connected is false', () => {
|
||||
const manager = new ConditionsManager(createCardAPI());
|
||||
const condition: FrigateCardCondition = { microphone: { connected: false } };
|
||||
expect(manager.evaluateCondition(condition)).toBeFalsy();
|
||||
manager.setState({ microphone: { connected: true } });
|
||||
expect(manager.evaluateCondition(condition)).toBeFalsy();
|
||||
manager.setState({ microphone: { connected: false } });
|
||||
expect(manager.evaluateCondition(condition)).toBeTruthy();
|
||||
});
|
||||
|
||||
it('muted is true', () => {
|
||||
const manager = new ConditionsManager(createCardAPI());
|
||||
const condition: FrigateCardCondition = { microphone: { muted: true } };
|
||||
expect(manager.evaluateCondition(condition)).toBeFalsy();
|
||||
manager.setState({ microphone: { muted: true } });
|
||||
expect(manager.evaluateCondition(condition)).toBeTruthy();
|
||||
manager.setState({ microphone: { muted: false } });
|
||||
expect(manager.evaluateCondition(condition)).toBeFalsy();
|
||||
});
|
||||
|
||||
it('muted is false', () => {
|
||||
const manager = new ConditionsManager(createCardAPI());
|
||||
const condition: FrigateCardCondition = { microphone: { muted: false } };
|
||||
expect(manager.evaluateCondition(condition)).toBeFalsy();
|
||||
manager.setState({ microphone: { muted: true } });
|
||||
expect(manager.evaluateCondition(condition)).toBeFalsy();
|
||||
manager.setState({ microphone: { muted: false } });
|
||||
expect(manager.evaluateCondition(condition)).toBeTruthy();
|
||||
});
|
||||
|
||||
it('connected and muted', () => {
|
||||
const manager = new ConditionsManager(createCardAPI());
|
||||
const condition: FrigateCardCondition = {
|
||||
microphone: { muted: false, connected: true },
|
||||
};
|
||||
expect(manager.evaluateCondition(condition)).toBeFalsy();
|
||||
manager.setState({ microphone: { muted: true } });
|
||||
expect(manager.evaluateCondition(condition)).toBeFalsy();
|
||||
manager.setState({ microphone: { muted: false } });
|
||||
expect(manager.evaluateCondition(condition)).toBeFalsy();
|
||||
manager.setState({ microphone: { connected: false, muted: false } });
|
||||
expect(manager.evaluateCondition(condition)).toBeFalsy();
|
||||
manager.setState({ microphone: { connected: true, muted: false } });
|
||||
expect(manager.evaluateCondition(condition)).toBeTruthy();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -128,7 +128,7 @@ describe('MicrophoneManager', () => {
|
||||
expect(manager.isConnected()).toBeTruthy();
|
||||
expect(api.getCardElementManager().update).toBeCalledTimes(1);
|
||||
|
||||
await manager.disconnect();
|
||||
manager.disconnect();
|
||||
expect(manager.isConnected()).toBeFalsy();
|
||||
expect(api.getCardElementManager().update).toBeCalledTimes(2);
|
||||
});
|
||||
@@ -202,7 +202,7 @@ describe('MicrophoneManager', () => {
|
||||
await manager.connect();
|
||||
expect(listener).not.toHaveBeenCalled();
|
||||
|
||||
await manager.mute();
|
||||
manager.mute();
|
||||
expect(listener).not.toHaveBeenCalled();
|
||||
|
||||
await manager.unmute();
|
||||
@@ -212,7 +212,7 @@ describe('MicrophoneManager', () => {
|
||||
await manager.unmute();
|
||||
expect(listener).toHaveBeenCalledTimes(1);
|
||||
|
||||
await manager.mute();
|
||||
manager.mute();
|
||||
expect(listener).toHaveBeenCalledTimes(2);
|
||||
expect(listener).toHaveBeenLastCalledWith('muted');
|
||||
|
||||
@@ -221,4 +221,62 @@ describe('MicrophoneManager', () => {
|
||||
await manager.unmute();
|
||||
expect(listener).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
|
||||
it('should initialize', () => {
|
||||
const api = createCardAPI();
|
||||
const manager = new MicrophoneManager(api);
|
||||
|
||||
manager.initialize();
|
||||
expect(api.getConditionsManager().setState).toBeCalledWith({
|
||||
microphone: { connected: false, muted: true },
|
||||
});
|
||||
});
|
||||
|
||||
it('should set condition state', async () => {
|
||||
const api = createCardAPI();
|
||||
const manager = new MicrophoneManager(api);
|
||||
navigatorMock.mediaDevices.getUserMedia.mockReturnValue(createMockStream());
|
||||
|
||||
expect(api.getConditionsManager().setState).not.toBeCalled();
|
||||
|
||||
await manager.connect();
|
||||
expect(api.getConditionsManager().setState).toHaveBeenLastCalledWith(
|
||||
expect.objectContaining({
|
||||
microphone: {
|
||||
connected: true,
|
||||
muted: true,
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
||||
await manager.unmute();
|
||||
expect(api.getConditionsManager().setState).toHaveBeenLastCalledWith(
|
||||
expect.objectContaining({
|
||||
microphone: {
|
||||
connected: true,
|
||||
muted: false,
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
||||
manager.mute();
|
||||
expect(api.getConditionsManager().setState).toHaveBeenLastCalledWith(
|
||||
expect.objectContaining({
|
||||
microphone: {
|
||||
connected: true,
|
||||
muted: true,
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
||||
manager.disconnect();
|
||||
expect(api.getConditionsManager().setState).toHaveBeenLastCalledWith(
|
||||
expect.objectContaining({
|
||||
microphone: {
|
||||
connected: false,
|
||||
muted: true,
|
||||
},
|
||||
}),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -99,7 +99,7 @@ describe('config defaults', () => {
|
||||
lazy_unload: [],
|
||||
microphone: {
|
||||
always_connected: false,
|
||||
disconnect_seconds: 60,
|
||||
disconnect_seconds: 90,
|
||||
mute_after_microphone_mute_seconds: 60,
|
||||
},
|
||||
preload: false,
|
||||
|
||||
Reference in New Issue
Block a user