@flighthq/media 0.3.0 → 0.3.1-next.1041.35b950c

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flighthq/media",
3
- "version": "0.3.0",
3
+ "version": "0.3.1-next.1041.35b950c",
4
4
  "author": "Joshua Granick and other contributors",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -38,11 +38,11 @@
38
38
  "clean:dist": "tsx ../../scripts/clean-package-dist.ts"
39
39
  },
40
40
  "dependencies": {
41
- "@flighthq/audio": "0.3.0",
42
- "@flighthq/log": "0.3.0",
43
- "@flighthq/signals": "0.3.0",
44
- "@flighthq/types": "0.3.0",
45
- "@flighthq/video": "0.3.0"
41
+ "@flighthq/audio": "0.3.1-next.1041.35b950c",
42
+ "@flighthq/log": "0.3.1-next.1041.35b950c",
43
+ "@flighthq/signals": "0.3.1-next.1041.35b950c",
44
+ "@flighthq/types": "0.3.1-next.1041.35b950c",
45
+ "@flighthq/video": "0.3.1-next.1041.35b950c"
46
46
  },
47
47
  "devDependencies": {
48
48
  "typescript": "^5.3.0"
@@ -21,19 +21,30 @@ class MockAudioBufferSourceNode {
21
21
  buffer: AudioBuffer | null = null;
22
22
  onended: (() => void) | null = null;
23
23
  playbackRate = { value: 1 };
24
+ starts: Array<{ duration?: number; offset: number; when: number }> = [];
24
25
 
25
26
  connect(): void {}
26
- start(): void {}
27
+ start(when = 0, offset = 0, duration?: number): void {
28
+ if (this.starts.length > 0)
29
+ throw new DOMException('AudioBufferSourceNode cannot be started more than once', 'InvalidStateError');
30
+ if (when < 0 || offset < 0 || (duration !== undefined && duration < 0)) {
31
+ throw new RangeError('AudioBufferSourceNode start times must be non-negative');
32
+ }
33
+ this.starts.push({ duration, offset, when });
34
+ }
27
35
  stop(): void {}
28
36
  }
29
37
 
30
38
  class MockAudioContext {
31
39
  currentTime = 0;
32
40
  destination = {};
41
+ sources: MockAudioBufferSourceNode[] = [];
33
42
  state = 'running';
34
43
 
35
44
  createBufferSource(): AudioBufferSourceNode {
36
- return new MockAudioBufferSourceNode() as unknown as AudioBufferSourceNode;
45
+ const source = new MockAudioBufferSourceNode();
46
+ this.sources.push(source);
47
+ return source as unknown as AudioBufferSourceNode;
37
48
  }
38
49
 
39
50
  createGain(): GainNode {
@@ -49,7 +60,8 @@ class MockAudioContext {
49
60
  }
50
61
  }
51
62
 
52
- const ctx = new MockAudioContext() as unknown as AudioContext;
63
+ const mockContext = new MockAudioContext();
64
+ const ctx = mockContext as unknown as AudioContext;
53
65
 
54
66
  function createMockAudioBuffer(): AudioBuffer {
55
67
  return { duration: 1 } as AudioBuffer;
@@ -147,6 +159,15 @@ describe('pauseAudioChannel', () => {
147
159
  });
148
160
 
149
161
  describe('playAudioResource', () => {
162
+ it('converts the millisecond current time to the source offset in seconds', () => {
163
+ const sourceIndex = mockContext.sources.length;
164
+
165
+ const channel = playAudioResource(ctx, createAudioResource(createMockAudioBuffer()), { currentTime: 250 });
166
+
167
+ expect(channel).not.toBeNull();
168
+ expect(mockContext.sources[sourceIndex].starts).toEqual([{ duration: undefined, offset: 0.25, when: 0 }]);
169
+ });
170
+
150
171
  it('returns null when buffer is null', () => {
151
172
  const source = createAudioResource();
152
173
  expect(playAudioResource(ctx, source)).toBeNull();