@startsimpli/integrations 0.2.225 → 0.2.227
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.
- package/package.json +3 -3
- package/src/__tests__/attention-orgs.test.ts +61 -0
- package/src/__tests__/attention-run.test.ts +3 -3
- package/src/__tests__/converse-meeting-interrupted.test.ts +74 -0
- package/src/__tests__/converse-meeting-vad.test.ts +25 -3
- package/src/__tests__/converse-meeting.test.ts +29 -0
- package/src/__tests__/converse-roci-transcript.test.ts +36 -0
- package/src/__tests__/converse-soak.test.ts +28 -0
- package/src/__tests__/converse-tts.test.ts +128 -0
- package/src/__tests__/converse.test.ts +38 -1
- package/src/__tests__/relay-items.test.ts +1 -1
- package/src/corpus/attention/importance.ts +1 -1
- package/src/corpus/attention/index.ts +1 -0
- package/src/corpus/attention/orgs.ts +41 -0
- package/src/corpus/attention/policy.ts +2 -0
- package/src/corpus/attention/push.ts +2 -1
- package/src/corpus/attention/queue.ts +3 -1
- package/src/corpus/attention/run-steps.ts +1 -1
- package/src/corpus/attention/run.ts +4 -3
- package/src/corpus/attention/types.ts +1 -1
- package/src/corpus/converse/handle.ts +12 -4
- package/src/corpus/converse/meeting-config.ts +8 -2
- package/src/corpus/converse/meeting.ts +24 -5
- package/src/corpus/converse/respond.ts +2 -2
- package/src/corpus/converse/speak-chunks.ts +33 -0
- package/src/corpus/converse/speak.ts +17 -4
- package/src/corpus/converse/types.ts +2 -0
- package/src/corpus/converse/vad.ts +16 -1
- package/src/corpus/notify/types.ts +2 -0
- package/src/native/app/FoundryApp.tsx +37 -2
- package/src/native/app/__tests__/briefingServices.test.ts +26 -0
- package/src/native/app/__tests__/haptics.test.tsx +55 -0
- package/src/native/app/__tests__/launch.test.ts +23 -1
- package/src/native/app/briefingServices.ts +9 -0
- package/src/native/app/converseServices.ts +17 -5
- package/src/native/app/device.ts +7 -0
- package/src/native/app/launch.ts +24 -0
- package/src/native/app/registry.tsx +6 -1
- package/src/native/app/services.ts +2 -2
- package/src/native/briefing/__tests__/playerPauseResume.test.ts +47 -0
- package/src/native/briefing/audioPlayer.ts +16 -1
- package/src/native/converse/ConverseScreen.tsx +45 -78
- package/src/native/converse/__tests__/bargeInIO.test.ts +49 -0
- package/src/native/converse/__tests__/liveScreen.test.tsx +59 -63
- package/src/native/converse/__tests__/meetingIO.test.ts +89 -23
- package/src/native/converse/__tests__/mock.test.ts +58 -0
- package/src/native/converse/__tests__/speedScreen.test.tsx +6 -2
- package/src/native/converse/index.ts +4 -1
- package/src/native/converse/io.ts +34 -20
- package/src/native/converse/mock.ts +136 -0
- package/src/native/converse/stateBanner.tsx +41 -0
- package/src/native/index.ts +1 -0
- package/src/native/push/NeedsYouCard.tsx +11 -7
- package/src/native/push/__tests__/decisionsApp.test.tsx +2 -3
- package/src/native/push/__tests__/needsYou.test.tsx +23 -9
- package/src/native/push/fake.ts +5 -5
- package/src/native/recording/recorder.ts +2 -1
- package/src/native/recording/recorderAudio.ts +14 -1
- package/src/native/talk/TalkTab.tsx +16 -13
- package/src/native/talk/__tests__/talk-tab.test.tsx +18 -0
- package/src/native/voice-session/__tests__/bargeIn.test.ts +93 -0
- package/src/native/voice-session/__tests__/bindings.test.ts +84 -0
- package/src/native/voice-session/__tests__/events.test.ts +72 -0
- package/src/native/voice-session/__tests__/inspector.test.ts +28 -0
- package/src/native/voice-session/__tests__/lifecycle.test.ts +197 -0
- package/src/native/voice-session/__tests__/music.test.ts +86 -0
- package/src/native/voice-session/__tests__/routes.test.ts +121 -0
- package/src/native/voice-session/__tests__/voiceSession.test.ts +177 -0
- package/src/native/voice-session/bindMeeting.ts +33 -0
- package/src/native/voice-session/fake.ts +21 -0
- package/src/native/voice-session/index.ts +142 -0
- package/src/native/voice-session/inspector.ts +14 -0
- package/src/native/voice-session/machine.ts +41 -0
- package/src/native/voice-session/nowPlaying.ts +35 -0
- package/src/native/voice-session/types.ts +45 -0
- package/src/native/voice-session/wire.ts +47 -0
- package/src/native/converse/DriveScreen.tsx +0 -47
- package/src/native/converse/__tests__/driveScreen.test.tsx +0 -54
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import { createVoiceSession, type SessionProfile } from '../index';
|
|
3
|
+
import { bindMeeting, type MeetingLike } from '../bindMeeting';
|
|
4
|
+
import { createFakeNativeSession } from '../fake';
|
|
5
|
+
|
|
6
|
+
const setup = (handsFree = true) => {
|
|
7
|
+
const native = createFakeNativeSession();
|
|
8
|
+
const voice = createVoiceSession({ native, log: vi.fn(), handsFree });
|
|
9
|
+
return { native, voice };
|
|
10
|
+
};
|
|
11
|
+
const duck = (n: ReturnType<typeof createFakeNativeSession>) => n.calls.filter((c) => c[0] === 'apply').map((c) => (c[1] as SessionProfile).duckOthers);
|
|
12
|
+
|
|
13
|
+
describe('ensure(role): for callers outside a meeting (voice note, briefing)', () => {
|
|
14
|
+
it('listen from idle applies the listening profile, once', async () => {
|
|
15
|
+
const { voice, native } = setup();
|
|
16
|
+
await voice.ensure('listen'); await voice.ensure('listen');
|
|
17
|
+
expect(voice.state).toBe('listening');
|
|
18
|
+
expect(duck(native)).toEqual([false]);
|
|
19
|
+
});
|
|
20
|
+
it('speak from idle ducks; listen after speak lifts the duck without releasing', async () => {
|
|
21
|
+
const { voice, native } = setup();
|
|
22
|
+
await voice.ensure('speak');
|
|
23
|
+
expect(voice.state).toBe('speaking');
|
|
24
|
+
await voice.ensure('listen');
|
|
25
|
+
expect(voice.state).toBe('listening');
|
|
26
|
+
expect(duck(native)).toEqual([false, true, false]);
|
|
27
|
+
expect(native.calls.some((c) => c[0] === 'release')).toBe(false);
|
|
28
|
+
});
|
|
29
|
+
it('release() returns to idle and notifies others', async () => {
|
|
30
|
+
const { voice, native } = setup();
|
|
31
|
+
await voice.ensure('listen'); await voice.release();
|
|
32
|
+
expect(voice.state).toBe('idle');
|
|
33
|
+
expect(native.calls.at(-1)).toEqual(['release', { notifyOthers: true }]);
|
|
34
|
+
});
|
|
35
|
+
it('settled() resolves after queued events are applied', async () => {
|
|
36
|
+
const { voice, native } = setup();
|
|
37
|
+
void voice.dispatch({ type: 'tap-talk' }); void voice.dispatch({ type: 'armed' });
|
|
38
|
+
await voice.settled();
|
|
39
|
+
expect(native.active).toBe(true);
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
describe('bindMeeting: the meeting controller drives the session, no second phase machine', () => {
|
|
44
|
+
const fakeMeeting = () => {
|
|
45
|
+
let cb: ((s: { phase: string; micOn: boolean }) => void) | null = null;
|
|
46
|
+
const m: MeetingLike = { subscribe: (c) => { cb = c; return () => { cb = null; }; } };
|
|
47
|
+
return { m, emit: (phase: string, micOn = true) => cb?.({ phase, micOn }) };
|
|
48
|
+
};
|
|
49
|
+
it('listening -> thinking -> speaking -> listening: ducks only while speaking', async () => {
|
|
50
|
+
const { voice, native } = setup(); const { m, emit } = fakeMeeting();
|
|
51
|
+
bindMeeting(m, voice);
|
|
52
|
+
emit('listening'); emit('thinking'); emit('speaking'); emit('listening');
|
|
53
|
+
await voice.settled();
|
|
54
|
+
expect(voice.state).toBe('listening');
|
|
55
|
+
expect(duck(native)).toEqual([false, true, false]);
|
|
56
|
+
});
|
|
57
|
+
it('stopped/ended releases the session (music comes back)', async () => {
|
|
58
|
+
const { voice, native } = setup(); const { m, emit } = fakeMeeting();
|
|
59
|
+
bindMeeting(m, voice);
|
|
60
|
+
emit('listening'); emit('stopped', false);
|
|
61
|
+
await voice.settled();
|
|
62
|
+
expect(voice.state).toBe('idle');
|
|
63
|
+
expect(native.active).toBe(false);
|
|
64
|
+
});
|
|
65
|
+
it('mic switched off while idle in a meeting does not keep the session', async () => {
|
|
66
|
+
const { voice, native } = setup(); const { m, emit } = fakeMeeting();
|
|
67
|
+
bindMeeting(m, voice);
|
|
68
|
+
emit('listening'); emit('idle', false);
|
|
69
|
+
await voice.settled();
|
|
70
|
+
expect(native.active).toBe(false);
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
describe('bound flag', () => {
|
|
75
|
+
it('is true while a meeting is bound and false after unbinding', () => {
|
|
76
|
+
const { voice } = setup();
|
|
77
|
+
let cb: (() => void) | null = null;
|
|
78
|
+
const off = bindMeeting({ subscribe: (c) => { cb = () => c({ phase: 'idle', micOn: false }); return () => undefined; } }, voice);
|
|
79
|
+
expect(voice.bound).toBe(true);
|
|
80
|
+
off();
|
|
81
|
+
expect(voice.bound).toBe(false);
|
|
82
|
+
void cb;
|
|
83
|
+
});
|
|
84
|
+
});
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import { createVoiceSession } from '../index';
|
|
3
|
+
import { createFakeNativeSession } from '../fake';
|
|
4
|
+
|
|
5
|
+
/** VoiceSession is the only listener on the OS; recorder and player consume ITS decisions, never raw notifications. */
|
|
6
|
+
const setup = async (role: 'listen' | 'speak' = 'speak') => {
|
|
7
|
+
const native = createFakeNativeSession();
|
|
8
|
+
const voice = createVoiceSession({ native, log: vi.fn() });
|
|
9
|
+
const interruptions: Array<Record<string, unknown>> = [];
|
|
10
|
+
const routes: string[] = [];
|
|
11
|
+
const timeouts = vi.fn();
|
|
12
|
+
voice.onInterruption((e) => interruptions.push(e));
|
|
13
|
+
voice.onRouteChange((e) => routes.push(e.reason));
|
|
14
|
+
voice.onPauseTimeout(timeouts);
|
|
15
|
+
await voice.ensure(role);
|
|
16
|
+
return { native, voice, interruptions, routes, timeouts };
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
describe('VoiceSession re-publishes what it decided', () => {
|
|
20
|
+
it('a call: began (cause interruption), then ended(shouldResume) AFTER the profile is re-applied', async () => {
|
|
21
|
+
const { voice, native, interruptions } = await setup();
|
|
22
|
+
await voice.dispatch({ type: 'interruption-began' });
|
|
23
|
+
expect(interruptions).toEqual([{ type: 'began', cause: 'interruption' }]);
|
|
24
|
+
const applied: number[] = [];
|
|
25
|
+
voice.onInterruption((e) => { if (e.type === 'ended') applied.push(native.calls.filter((c) => c[0] === 'apply').length); });
|
|
26
|
+
const before = native.calls.filter((c) => c[0] === 'apply').length;
|
|
27
|
+
await voice.dispatch({ type: 'interruption-ended', shouldResume: true });
|
|
28
|
+
expect(interruptions[1]).toEqual({ type: 'ended', shouldResume: true });
|
|
29
|
+
expect(applied).toEqual([before + 1]); // the listener saw a session that was already ready
|
|
30
|
+
});
|
|
31
|
+
it('ended without shouldResume says so (the player stays paused, nothing restarts on its own)', async () => {
|
|
32
|
+
const { voice, interruptions } = await setup();
|
|
33
|
+
await voice.dispatch({ type: 'interruption-began' });
|
|
34
|
+
await voice.dispatch({ type: 'interruption-ended' });
|
|
35
|
+
expect(interruptions[1]).toEqual({ type: 'ended', shouldResume: false });
|
|
36
|
+
});
|
|
37
|
+
it('headset unplug mid-reply is a began with cause route; a new device is an ended that resumes', async () => {
|
|
38
|
+
const { voice, interruptions } = await setup();
|
|
39
|
+
await voice.dispatch({ type: 'route-changed', reason: 'oldDeviceUnavailable' });
|
|
40
|
+
await voice.dispatch({ type: 'route-changed', reason: 'newDeviceAvailable' });
|
|
41
|
+
expect(interruptions).toEqual([{ type: 'began', cause: 'route' }, { type: 'ended', shouldResume: true }]);
|
|
42
|
+
});
|
|
43
|
+
it('pause-timeout is published as its own signal and as a not-resumed end', async () => {
|
|
44
|
+
const { voice, interruptions, timeouts } = await setup();
|
|
45
|
+
await voice.dispatch({ type: 'route-changed', reason: 'oldDeviceUnavailable' });
|
|
46
|
+
await voice.dispatch({ type: 'pause-timeout' });
|
|
47
|
+
expect(timeouts).toHaveBeenCalledTimes(1);
|
|
48
|
+
expect(interruptions[1]).toEqual({ type: 'ended', shouldResume: false });
|
|
49
|
+
});
|
|
50
|
+
it('only route changes that matter are published (our own categoryChange never reaches listeners)', async () => {
|
|
51
|
+
const { voice, routes } = await setup();
|
|
52
|
+
for (const reason of ['categoryChange', 'override', 'routeConfigurationChange', 'newDeviceAvailable', 'oldDeviceUnavailable']) await voice.dispatch({ type: 'route-changed', reason });
|
|
53
|
+
expect(routes).toEqual(['newDeviceAvailable', 'oldDeviceUnavailable']);
|
|
54
|
+
});
|
|
55
|
+
it('nothing is published while idle (a stray OS notification is not an event)', async () => {
|
|
56
|
+
const native = createFakeNativeSession();
|
|
57
|
+
const voice = createVoiceSession({ native, log: vi.fn() });
|
|
58
|
+
const seen = vi.fn();
|
|
59
|
+
voice.onInterruption(seen); voice.onRouteChange(seen);
|
|
60
|
+
await voice.dispatch({ type: 'interruption-began' });
|
|
61
|
+
await voice.dispatch({ type: 'route-changed', reason: 'newDeviceAvailable' });
|
|
62
|
+
expect(seen).not.toHaveBeenCalled();
|
|
63
|
+
});
|
|
64
|
+
it('listeners can unsubscribe', async () => {
|
|
65
|
+
const { voice } = await setup();
|
|
66
|
+
const cb = vi.fn();
|
|
67
|
+
const off = voice.onInterruption(cb);
|
|
68
|
+
off();
|
|
69
|
+
await voice.dispatch({ type: 'interruption-began' });
|
|
70
|
+
expect(cb).not.toHaveBeenCalled();
|
|
71
|
+
});
|
|
72
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import { createVoiceSession } from '../index';
|
|
3
|
+
import { createFakeNativeSession } from '../fake';
|
|
4
|
+
import { voiceInspector } from '../inspector';
|
|
5
|
+
|
|
6
|
+
const info = { category: 'playAndRecord', mode: 'default', options: [], sampleRate: 48000, inputs: [] };
|
|
7
|
+
|
|
8
|
+
describe('the SessionInspector the recorder and player use', () => {
|
|
9
|
+
it('reads session facts from the native module but hears interruptions and routes only from VoiceSession', async () => {
|
|
10
|
+
const native = createFakeNativeSession();
|
|
11
|
+
const voice = createVoiceSession({ native, log: vi.fn() });
|
|
12
|
+
const base = { info: vi.fn(async () => info), onInterruption: vi.fn(() => () => undefined), onRouteChange: vi.fn(() => () => undefined) };
|
|
13
|
+
const inspector = voiceInspector(voice, base);
|
|
14
|
+
expect(await inspector.info()).toBe(info);
|
|
15
|
+
const ints: unknown[] = []; const routes: string[] = [];
|
|
16
|
+
inspector.onInterruption((e) => ints.push(e));
|
|
17
|
+
inspector.onRouteChange((e) => routes.push(e.reason));
|
|
18
|
+
await voice.ensure('speak');
|
|
19
|
+
await voice.dispatch({ type: 'interruption-began' });
|
|
20
|
+
await voice.dispatch({ type: 'interruption-ended', shouldResume: true });
|
|
21
|
+
await voice.dispatch({ type: 'route-changed', reason: 'newDeviceAvailable' });
|
|
22
|
+
expect(ints).toEqual([{ type: 'began' }, { type: 'ended', shouldResume: true }]);
|
|
23
|
+
expect(routes).toEqual(['newDeviceAvailable']);
|
|
24
|
+
// The raw native notifications are never subscribed to by the consumers.
|
|
25
|
+
expect(base.onInterruption).not.toHaveBeenCalled();
|
|
26
|
+
expect(base.onRouteChange).not.toHaveBeenCalled();
|
|
27
|
+
});
|
|
28
|
+
});
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import { createVoiceSession, type VoiceState } from '../index';
|
|
3
|
+
import { createFakeNativeSession } from '../fake';
|
|
4
|
+
import { wireVoiceSession, type AppStateSource, type SessionEvents } from '../wire';
|
|
5
|
+
import { createNowPlaying, type NowPlayingNative, type PlaybackControls } from '../nowPlaying';
|
|
6
|
+
|
|
7
|
+
/** A native inspector the test can fire: what AVAudioSession notifications look like to JS. */
|
|
8
|
+
function fakeEvents() {
|
|
9
|
+
const interruption = new Set<(e: { type: 'began' | 'ended'; shouldResume?: boolean }) => void>();
|
|
10
|
+
const route = new Set<(e: { reason: string }) => void>();
|
|
11
|
+
const events: SessionEvents = {
|
|
12
|
+
onInterruption: (cb) => { interruption.add(cb); return () => { interruption.delete(cb); }; },
|
|
13
|
+
onRouteChange: (cb) => { route.add(cb); return () => { route.delete(cb); }; },
|
|
14
|
+
};
|
|
15
|
+
return {
|
|
16
|
+
events,
|
|
17
|
+
interrupt: (e: { type: 'began' | 'ended'; shouldResume?: boolean }) => interruption.forEach((cb) => cb(e)),
|
|
18
|
+
route: (reason: string) => route.forEach((cb) => cb({ reason })),
|
|
19
|
+
listeners: () => interruption.size + route.size,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
function fakeAppState() {
|
|
23
|
+
const subs = new Set<(s: string) => void>();
|
|
24
|
+
const source: AppStateSource = { subscribe: (cb) => { subs.add(cb); return () => { subs.delete(cb); }; } };
|
|
25
|
+
return { source, set: (s: string) => subs.forEach((cb) => cb(s)), listeners: () => subs.size };
|
|
26
|
+
}
|
|
27
|
+
const make = async (until: VoiceState) => {
|
|
28
|
+
const native = createFakeNativeSession();
|
|
29
|
+
const log = vi.fn();
|
|
30
|
+
const voice = createVoiceSession({ native, log });
|
|
31
|
+
const ev = fakeEvents();
|
|
32
|
+
const app = fakeAppState();
|
|
33
|
+
const unwire = wireVoiceSession(voice, { events: ev.events, appState: app.source });
|
|
34
|
+
await voice.ensure(until === 'speaking' ? 'speak' : 'listen');
|
|
35
|
+
await voice.settled();
|
|
36
|
+
return { native, log, voice, ev, app, unwire };
|
|
37
|
+
};
|
|
38
|
+
const applies = (n: ReturnType<typeof createFakeNativeSession>) => n.calls.filter((c) => c[0] === 'apply').length;
|
|
39
|
+
|
|
40
|
+
describe('interruptions (call, Siri, alarm) reach the VoiceSession', () => {
|
|
41
|
+
it('began while Roci speaks pauses the session and leaves the OS alone', async () => {
|
|
42
|
+
const { voice, ev, native } = await make('speaking');
|
|
43
|
+
const before = native.calls.length;
|
|
44
|
+
ev.interrupt({ type: 'began' });
|
|
45
|
+
await voice.settled();
|
|
46
|
+
expect(voice.state).toBe('paused');
|
|
47
|
+
expect(native.calls.length).toBe(before); // we do not fight the system: no apply, no release
|
|
48
|
+
});
|
|
49
|
+
it('ended with shouldResume re-applies the profile and goes back to what we were doing', async () => {
|
|
50
|
+
const { voice, ev, native } = await make('speaking');
|
|
51
|
+
ev.interrupt({ type: 'began' });
|
|
52
|
+
await voice.settled();
|
|
53
|
+
const n = applies(native);
|
|
54
|
+
ev.interrupt({ type: 'ended', shouldResume: true });
|
|
55
|
+
await voice.settled();
|
|
56
|
+
expect(voice.state).toBe('speaking');
|
|
57
|
+
expect(applies(native)).toBe(n + 1);
|
|
58
|
+
expect(native.profile?.duckOthers).toBe(true);
|
|
59
|
+
});
|
|
60
|
+
it('ended without shouldResume does not hang: back to listening (hands-free)', async () => {
|
|
61
|
+
const { voice, ev } = await make('speaking');
|
|
62
|
+
ev.interrupt({ type: 'began' });
|
|
63
|
+
ev.interrupt({ type: 'ended' });
|
|
64
|
+
await voice.settled();
|
|
65
|
+
expect(voice.state).toBe('listening');
|
|
66
|
+
});
|
|
67
|
+
it('an interruption while idle changes nothing and calls nothing', async () => {
|
|
68
|
+
const native = createFakeNativeSession();
|
|
69
|
+
const voice = createVoiceSession({ native, log: vi.fn() });
|
|
70
|
+
const ev = fakeEvents();
|
|
71
|
+
wireVoiceSession(voice, { events: ev.events, appState: fakeAppState().source });
|
|
72
|
+
ev.interrupt({ type: 'began' });
|
|
73
|
+
await voice.settled();
|
|
74
|
+
expect(voice.state).toBe('idle');
|
|
75
|
+
expect(native.calls).toEqual([]);
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
describe('background, lock and return to foreground', () => {
|
|
80
|
+
it('backgrounding or locking keeps the live session untouched (UIBackgroundModes audio)', async () => {
|
|
81
|
+
const { voice, app, native } = await make('listening');
|
|
82
|
+
const before = native.calls.length;
|
|
83
|
+
app.set('inactive'); app.set('background');
|
|
84
|
+
await voice.settled();
|
|
85
|
+
expect(voice.state).toBe('listening');
|
|
86
|
+
expect(native.calls.length).toBe(before);
|
|
87
|
+
});
|
|
88
|
+
it('return to foreground re-applies the profile when the system took the session while we were away', async () => {
|
|
89
|
+
const { voice, app, native } = await make('listening');
|
|
90
|
+
app.set('background');
|
|
91
|
+
native.active = false; // iOS deactivated us while locked
|
|
92
|
+
const n = applies(native);
|
|
93
|
+
app.set('active');
|
|
94
|
+
await voice.settled();
|
|
95
|
+
expect(applies(native)).toBe(n + 1);
|
|
96
|
+
expect(voice.state).toBe('listening');
|
|
97
|
+
});
|
|
98
|
+
it('return to foreground with a healthy session makes no native call', async () => {
|
|
99
|
+
const { voice, app, native } = await make('listening');
|
|
100
|
+
app.set('background');
|
|
101
|
+
const n = native.calls.length;
|
|
102
|
+
app.set('active');
|
|
103
|
+
await voice.settled();
|
|
104
|
+
expect(native.calls.length).toBe(n);
|
|
105
|
+
});
|
|
106
|
+
it('foreground while idle never starts a session', async () => {
|
|
107
|
+
const native = createFakeNativeSession();
|
|
108
|
+
const voice = createVoiceSession({ native, log: vi.fn() });
|
|
109
|
+
const app = fakeAppState();
|
|
110
|
+
wireVoiceSession(voice, { events: fakeEvents().events, appState: app.source });
|
|
111
|
+
app.set('background'); app.set('active');
|
|
112
|
+
await voice.settled();
|
|
113
|
+
expect(native.calls).toEqual([]);
|
|
114
|
+
});
|
|
115
|
+
it('logs background and foreground so a device run can read the story', async () => {
|
|
116
|
+
const { voice, app, log } = await make('listening');
|
|
117
|
+
app.set('background'); app.set('active');
|
|
118
|
+
await voice.settled();
|
|
119
|
+
const triggers = log.mock.calls.filter((c) => c[0] === 'voice.session.transition').map((c) => c[1].trigger);
|
|
120
|
+
expect(triggers).toEqual(expect.arrayContaining(['app-background', 'app-foreground']));
|
|
121
|
+
});
|
|
122
|
+
it('unwiring removes every listener', async () => {
|
|
123
|
+
const { unwire, ev, app } = await make('listening');
|
|
124
|
+
unwire();
|
|
125
|
+
expect(ev.listeners()).toBe(0);
|
|
126
|
+
expect(app.listeners()).toBe(0);
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
describe('Now Playing: only briefing playback, in a non-mixing profile', () => {
|
|
131
|
+
it('ensure(briefing) asks for a profile that does not mix, so the lock screen can own it', async () => {
|
|
132
|
+
const native = createFakeNativeSession();
|
|
133
|
+
const voice = createVoiceSession({ native, log: vi.fn() });
|
|
134
|
+
await voice.ensure('briefing');
|
|
135
|
+
expect(native.profile).toMatchObject({ mixWithOthers: false, duckOthers: false });
|
|
136
|
+
});
|
|
137
|
+
it('a Talk reply after a briefing goes back to the mixing profile', async () => {
|
|
138
|
+
const native = createFakeNativeSession();
|
|
139
|
+
const voice = createVoiceSession({ native, log: vi.fn() });
|
|
140
|
+
await voice.ensure('briefing');
|
|
141
|
+
await voice.release();
|
|
142
|
+
await voice.ensure('speak');
|
|
143
|
+
expect(native.profile).toMatchObject({ mixWithOthers: true, duckOthers: true });
|
|
144
|
+
});
|
|
145
|
+
it('a Talk reply never registers Now Playing (a mixing session cannot own it)', () => {
|
|
146
|
+
const np = fakeNowPlaying();
|
|
147
|
+
const player = fakePlayer();
|
|
148
|
+
createNowPlaying({ native: np.native, player: player.controls, mixing: () => true });
|
|
149
|
+
player.emit({ phase: 'playing', positionMillis: 0, durationMillis: 9000 });
|
|
150
|
+
expect(np.set).not.toHaveBeenCalled();
|
|
151
|
+
});
|
|
152
|
+
it('registers while briefing plays, updates position, and clears when it ends', () => {
|
|
153
|
+
const np = fakeNowPlaying();
|
|
154
|
+
const player = fakePlayer();
|
|
155
|
+
createNowPlaying({ native: np.native, player: player.controls, title: () => 'What is on the plate', mixing: () => false });
|
|
156
|
+
player.emit({ phase: 'playing', positionMillis: 1000, durationMillis: 9000 });
|
|
157
|
+
expect(np.set).toHaveBeenLastCalledWith({ title: 'What is on the plate', positionMs: 1000, durationMs: 9000, rate: 1 });
|
|
158
|
+
player.emit({ phase: 'paused', positionMillis: 2000, durationMillis: 9000 });
|
|
159
|
+
expect(np.set).toHaveBeenLastCalledWith({ title: 'What is on the plate', positionMs: 2000, durationMs: 9000, rate: 0 });
|
|
160
|
+
player.emit({ phase: 'ended', positionMillis: 9000, durationMillis: 9000 });
|
|
161
|
+
expect(np.clear).toHaveBeenCalled();
|
|
162
|
+
});
|
|
163
|
+
it('lock-screen commands drive the player: pause, play, stop ends it', () => {
|
|
164
|
+
const np = fakeNowPlaying();
|
|
165
|
+
const player = fakePlayer();
|
|
166
|
+
createNowPlaying({ native: np.native, player: player.controls, mixing: () => false });
|
|
167
|
+
player.emit({ phase: 'playing', positionMillis: 0, durationMillis: 9000 });
|
|
168
|
+
np.command('pause'); np.command('play'); np.command('stop');
|
|
169
|
+
expect(player.controls.pause).toHaveBeenCalledTimes(1);
|
|
170
|
+
expect(player.controls.resume).toHaveBeenCalledTimes(1);
|
|
171
|
+
expect(player.controls.stop).toHaveBeenCalledTimes(1);
|
|
172
|
+
});
|
|
173
|
+
it('dispose clears Now Playing and drops the command listener', () => {
|
|
174
|
+
const np = fakeNowPlaying();
|
|
175
|
+
const player = fakePlayer();
|
|
176
|
+
const off = createNowPlaying({ native: np.native, player: player.controls, mixing: () => false });
|
|
177
|
+
player.emit({ phase: 'playing', positionMillis: 0, durationMillis: 9000 });
|
|
178
|
+
off();
|
|
179
|
+
expect(np.clear).toHaveBeenCalled();
|
|
180
|
+
expect(np.commandListeners()).toBe(0);
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
function fakeNowPlaying() {
|
|
185
|
+
const cbs = new Set<(c: 'play' | 'pause' | 'stop') => void>();
|
|
186
|
+
const set = vi.fn(); const clear = vi.fn();
|
|
187
|
+
const native: NowPlayingNative = { set, clear, onCommand: (cb) => { cbs.add(cb); return () => { cbs.delete(cb); }; } };
|
|
188
|
+
return { native, set, clear, command: (c: 'play' | 'pause' | 'stop') => cbs.forEach((cb) => cb(c)), commandListeners: () => cbs.size };
|
|
189
|
+
}
|
|
190
|
+
function fakePlayer() {
|
|
191
|
+
const subs = new Set<(s: { phase: string; positionMillis: number; durationMillis: number }) => void>();
|
|
192
|
+
const controls: PlaybackControls = {
|
|
193
|
+
subscribe: (cb) => { subs.add(cb); return () => { subs.delete(cb); }; },
|
|
194
|
+
pause: vi.fn(), resume: vi.fn(), stop: vi.fn(),
|
|
195
|
+
};
|
|
196
|
+
return { controls, emit: (s: { phase: string; positionMillis: number; durationMillis: number }) => subs.forEach((cb) => cb(s)) };
|
|
197
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
// @vitest-environment node
|
|
2
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
3
|
+
import { createVoiceSession, type SessionProfile, type VoiceEvent } from '../index';
|
|
4
|
+
import { createFakeNativeSession } from '../fake';
|
|
5
|
+
|
|
6
|
+
/** Other audio x state matrix (startsim-1x6kv.9). Characterization of the TS half; the native ducking is pinned in tandem-ios. */
|
|
7
|
+
const mk = (otherAudioPlaying: boolean) => {
|
|
8
|
+
const native = createFakeNativeSession({ otherAudioPlaying });
|
|
9
|
+
const voice = createVoiceSession({ native, log: vi.fn() });
|
|
10
|
+
return { native, voice };
|
|
11
|
+
};
|
|
12
|
+
const run = async (voice: ReturnType<typeof mk>['voice'], ...types: VoiceEvent['type'][]) => { for (const type of types) await voice.dispatch({ type } as VoiceEvent); };
|
|
13
|
+
const last = (n: ReturnType<typeof mk>['native']) => n.calls.filter((c) => c[0] === 'apply').at(-1)?.[1] as SessionProfile;
|
|
14
|
+
|
|
15
|
+
describe.each([true, false])('other audio playing = %s', (playing) => {
|
|
16
|
+
it('listening mixes and never ducks: music keeps going, paused music is not started', async () => {
|
|
17
|
+
const { voice, native } = mk(playing);
|
|
18
|
+
await run(voice, 'tap-talk', 'armed');
|
|
19
|
+
expect(voice.state).toBe('listening');
|
|
20
|
+
expect(last(native)).toMatchObject({ mixWithOthers: true, duckOthers: false });
|
|
21
|
+
});
|
|
22
|
+
it('hearing and thinking keep the same profile: no native call, no duck', async () => {
|
|
23
|
+
const { voice, native } = mk(playing);
|
|
24
|
+
await run(voice, 'tap-talk', 'armed');
|
|
25
|
+
const before = native.calls.length;
|
|
26
|
+
await run(voice, 'speech-start', 'speech-end');
|
|
27
|
+
expect(voice.state).toBe('thinking');
|
|
28
|
+
expect(native.calls.length).toBe(before);
|
|
29
|
+
});
|
|
30
|
+
it('only speaking ducks, and the duck is lifted the moment the reply ends, without releasing the session', async () => {
|
|
31
|
+
const { voice, native } = mk(playing);
|
|
32
|
+
await run(voice, 'tap-talk', 'armed', 'speech-start', 'speech-end', 'reply-ready');
|
|
33
|
+
expect(last(native)).toMatchObject({ mixWithOthers: true, duckOthers: true });
|
|
34
|
+
await run(voice, 'reply-done');
|
|
35
|
+
expect(voice.state).toBe('listening');
|
|
36
|
+
expect(last(native).duckOthers).toBe(false);
|
|
37
|
+
expect(native.calls.some((c) => c[0] === 'release')).toBe(false);
|
|
38
|
+
});
|
|
39
|
+
it('a barge-in lifts the duck at once', async () => {
|
|
40
|
+
const { voice, native } = mk(playing);
|
|
41
|
+
await run(voice, 'tap-talk', 'armed', 'speech-start', 'speech-end', 'reply-ready', 'barge-in');
|
|
42
|
+
expect(voice.state).toBe('hearing');
|
|
43
|
+
expect(last(native).duckOthers).toBe(false);
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
describe('giving the session back resumes the music and leaves nothing active', () => {
|
|
48
|
+
const live: Array<[string, VoiceEvent['type'][]]> = [
|
|
49
|
+
['arming', ['tap-talk']], ['listening', ['tap-talk', 'armed']], ['hearing', ['tap-talk', 'armed', 'speech-start']],
|
|
50
|
+
['thinking', ['tap-talk', 'armed', 'speech-start', 'speech-end']], ['speaking', ['tap-talk', 'armed', 'speech-start', 'speech-end', 'reply-ready']],
|
|
51
|
+
];
|
|
52
|
+
it.each(live)('tap-stop from %s releases with notifyOthers and the session is inactive', async (_name, path) => {
|
|
53
|
+
const { voice, native } = mk(true);
|
|
54
|
+
await run(voice, ...path);
|
|
55
|
+
await run(voice, 'tap-stop');
|
|
56
|
+
expect(voice.state).toBe('idle');
|
|
57
|
+
expect(native.calls.at(-1)).toEqual(['release', { notifyOthers: true }]);
|
|
58
|
+
expect(native.active).toBe(false);
|
|
59
|
+
});
|
|
60
|
+
it('a single-shot reply ends in idle with the session released and others notified', async () => {
|
|
61
|
+
const native = createFakeNativeSession({ otherAudioPlaying: true });
|
|
62
|
+
const voice = createVoiceSession({ native, log: vi.fn(), handsFree: false });
|
|
63
|
+
await run(voice, 'tap-talk', 'armed', 'speech-start', 'speech-end', 'reply-ready', 'reply-done');
|
|
64
|
+
expect(voice.state).toBe('idle');
|
|
65
|
+
expect(native.active).toBe(false);
|
|
66
|
+
expect(native.calls.at(-1)).toEqual(['release', { notifyOthers: true }]);
|
|
67
|
+
});
|
|
68
|
+
it('a failed start releases too, so music is not left stuck silent', async () => {
|
|
69
|
+
const native = createFakeNativeSession({ failApply: 2 });
|
|
70
|
+
const voice = createVoiceSession({ native, log: vi.fn() });
|
|
71
|
+
await run(voice, 'tap-talk', 'armed');
|
|
72
|
+
expect(voice.state).toBe('failed');
|
|
73
|
+
expect(native.active).toBe(false);
|
|
74
|
+
expect(native.calls.at(-1)).toEqual(['release', { notifyOthers: true }]);
|
|
75
|
+
});
|
|
76
|
+
it('never deactivates mid-reply: speaking -> listening -> speaking makes no release', async () => {
|
|
77
|
+
const { voice, native } = mk(true);
|
|
78
|
+
await run(voice, 'tap-talk', 'armed', 'speech-start', 'speech-end', 'reply-ready', 'reply-done', 'speech-start', 'speech-end', 'reply-ready');
|
|
79
|
+
expect(native.calls.filter((c) => c[0] === 'release')).toHaveLength(0);
|
|
80
|
+
});
|
|
81
|
+
it('idle holds no session: another app\'s music is untouched until we are asked to talk', async () => {
|
|
82
|
+
const { voice, native } = mk(true);
|
|
83
|
+
expect(voice.state).toBe('idle');
|
|
84
|
+
expect(native.calls).toEqual([]);
|
|
85
|
+
});
|
|
86
|
+
});
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import { createVoiceSession } from '../index';
|
|
3
|
+
import { createFakeNativeSession } from '../fake';
|
|
4
|
+
import { wireVoiceSession, type SessionEvents } from '../wire';
|
|
5
|
+
|
|
6
|
+
/** A manual clock so the pause timeout is tested without waiting. */
|
|
7
|
+
function clock() {
|
|
8
|
+
let next = 1; const timers = new Map<number, { at: number; fn: () => void }>(); let now = 0;
|
|
9
|
+
return {
|
|
10
|
+
setTimer: (fn: () => void, ms: number) => { const id = next++; timers.set(id, { at: now + ms, fn }); return id; },
|
|
11
|
+
clearTimer: (id: unknown) => { timers.delete(id as number); },
|
|
12
|
+
advance: (ms: number) => { now += ms; [...timers].filter(([, t]) => t.at <= now).forEach(([id, t]) => { timers.delete(id); t.fn(); }); },
|
|
13
|
+
pending: () => timers.size,
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
const setup = async (role: 'listen' | 'speak' = 'speak', opts: { carMic?: boolean } = {}) => {
|
|
17
|
+
const native = createFakeNativeSession();
|
|
18
|
+
const log = vi.fn();
|
|
19
|
+
const voice = createVoiceSession({ native, log, carMic: () => opts.carMic === true });
|
|
20
|
+
const rc: Set<(e: { reason: string }) => void> = new Set();
|
|
21
|
+
const ic: Set<(e: { type: 'began' | 'ended'; shouldResume?: boolean }) => void> = new Set();
|
|
22
|
+
const events: SessionEvents = {
|
|
23
|
+
onRouteChange: (cb) => { rc.add(cb); return () => { rc.delete(cb); }; },
|
|
24
|
+
onInterruption: (cb) => { ic.add(cb); return () => { ic.delete(cb); }; },
|
|
25
|
+
};
|
|
26
|
+
const clk = clock();
|
|
27
|
+
wireVoiceSession(voice, { events, appState: { subscribe: () => () => undefined }, setTimer: clk.setTimer, clearTimer: clk.clearTimer, pausedReplayMs: 4000 });
|
|
28
|
+
await voice.ensure(role);
|
|
29
|
+
await voice.settled();
|
|
30
|
+
return { native, voice, log, clk, route: (reason: string) => rc.forEach((cb) => cb({ reason })), interrupt: (e: { type: 'began' | 'ended'; shouldResume?: boolean }) => ic.forEach((cb) => cb(e)) };
|
|
31
|
+
};
|
|
32
|
+
const applies = (n: ReturnType<typeof createFakeNativeSession>) => n.calls.filter((c) => c[0] === 'apply').length;
|
|
33
|
+
|
|
34
|
+
describe('headset / AirPods unplug mid-reply', () => {
|
|
35
|
+
it('pauses the reply, never blasts it from the speaker', async () => {
|
|
36
|
+
const { voice, route, native } = await setup();
|
|
37
|
+
const before = native.calls.length;
|
|
38
|
+
route('oldDeviceUnavailable');
|
|
39
|
+
await voice.settled();
|
|
40
|
+
expect(voice.state).toBe('paused');
|
|
41
|
+
expect(native.calls.length).toBe(before);
|
|
42
|
+
});
|
|
43
|
+
it('a device arriving while paused resumes the reply with the profile re-applied', async () => {
|
|
44
|
+
const { voice, route, native } = await setup();
|
|
45
|
+
route('oldDeviceUnavailable'); await voice.settled();
|
|
46
|
+
const n = applies(native);
|
|
47
|
+
route('newDeviceAvailable'); await voice.settled();
|
|
48
|
+
expect(voice.state).toBe('speaking');
|
|
49
|
+
expect(applies(native)).toBe(n + 1);
|
|
50
|
+
});
|
|
51
|
+
it('no device within the pause timeout: falls back to listening on the phone, not stuck', async () => {
|
|
52
|
+
const { voice, route, clk } = await setup();
|
|
53
|
+
route('oldDeviceUnavailable'); await voice.settled();
|
|
54
|
+
clk.advance(3999); await voice.settled();
|
|
55
|
+
expect(voice.state).toBe('paused');
|
|
56
|
+
clk.advance(1); await voice.settled();
|
|
57
|
+
expect(voice.state).toBe('listening');
|
|
58
|
+
});
|
|
59
|
+
it('resuming cancels the timeout (no late fallback)', async () => {
|
|
60
|
+
const { voice, route, clk } = await setup();
|
|
61
|
+
route('oldDeviceUnavailable'); await voice.settled();
|
|
62
|
+
route('newDeviceAvailable'); await voice.settled();
|
|
63
|
+
expect(clk.pending()).toBe(0);
|
|
64
|
+
clk.advance(10_000); await voice.settled();
|
|
65
|
+
expect(voice.state).toBe('speaking');
|
|
66
|
+
});
|
|
67
|
+
it('unplug while only listening does not pause anything', async () => {
|
|
68
|
+
const { voice, route } = await setup('listen');
|
|
69
|
+
route('oldDeviceUnavailable'); await voice.settled();
|
|
70
|
+
expect(voice.state).toBe('listening');
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
describe('a call is not a route change', () => {
|
|
75
|
+
it('a device arriving during a phone-call interruption does not resume Roci over the call', async () => {
|
|
76
|
+
const { voice, route, interrupt, clk } = await setup();
|
|
77
|
+
interrupt({ type: 'began' }); await voice.settled();
|
|
78
|
+
route('newDeviceAvailable'); await voice.settled();
|
|
79
|
+
expect(voice.state).toBe('paused');
|
|
80
|
+
clk.advance(60_000); await voice.settled();
|
|
81
|
+
expect(voice.state).toBe('paused'); // a long call is not a 4 s route loss
|
|
82
|
+
interrupt({ type: 'ended', shouldResume: true }); await voice.settled();
|
|
83
|
+
expect(voice.state).toBe('speaking');
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
describe('route changes that must not loop', () => {
|
|
88
|
+
it('our own categoryChange / override / config change re-apply nothing', async () => {
|
|
89
|
+
const { voice, route, native } = await setup();
|
|
90
|
+
const n = applies(native);
|
|
91
|
+
route('categoryChange'); route('override'); route('routeConfigurationChange'); route('unknown');
|
|
92
|
+
await voice.settled();
|
|
93
|
+
expect(applies(native)).toBe(n);
|
|
94
|
+
});
|
|
95
|
+
it('a device arriving mid-reply re-applies the profile once (AirPods connect, car A2DP)', async () => {
|
|
96
|
+
const { voice, route, native } = await setup();
|
|
97
|
+
const n = applies(native);
|
|
98
|
+
route('newDeviceAvailable'); await voice.settled();
|
|
99
|
+
expect(applies(native)).toBe(n + 1);
|
|
100
|
+
expect(voice.state).toBe('speaking');
|
|
101
|
+
});
|
|
102
|
+
it('route changes while idle never start a session', async () => {
|
|
103
|
+
const native = createFakeNativeSession();
|
|
104
|
+
const voice = createVoiceSession({ native, log: vi.fn() });
|
|
105
|
+
let cb: (e: { reason: string }) => void = () => undefined;
|
|
106
|
+
wireVoiceSession(voice, { events: { onRouteChange: (c) => { cb = c; return () => undefined; }, onInterruption: () => () => undefined }, appState: { subscribe: () => () => undefined } });
|
|
107
|
+
cb({ reason: 'newDeviceAvailable' }); await voice.settled();
|
|
108
|
+
expect(native.calls).toEqual([]);
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
describe('car audio is opt-in', () => {
|
|
113
|
+
it('speaker/AirPods/A2DP profile never asks for the car mic (HFP) by default', async () => {
|
|
114
|
+
const { native } = await setup();
|
|
115
|
+
expect(native.profile).toMatchObject({ allowBluetoothA2DP: true, allowBluetooth: false, defaultToSpeaker: true });
|
|
116
|
+
});
|
|
117
|
+
it('with the car mic opted in, HFP is allowed', async () => {
|
|
118
|
+
const { native } = await setup('speak', { carMic: true });
|
|
119
|
+
expect(native.profile?.allowBluetooth).toBe(true);
|
|
120
|
+
});
|
|
121
|
+
});
|