@clockworkdog/cogs-client 3.0.0-alpha.8 → 3.0.0-alpha.9

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
@@ -3,7 +3,7 @@
3
3
  "description": "Connect to COGS to build a custom Media Master",
4
4
  "author": "Clockwork Dog <info@clockwork.dog>",
5
5
  "homepage": "https://github.com/clockwork-dog/cogs-sdk/tree/main/packages/javascript",
6
- "version": "3.0.0-alpha.8",
6
+ "version": "3.0.0-alpha.9",
7
7
  "keywords": [],
8
8
  "license": "MIT",
9
9
  "repository": {
@@ -37,7 +37,7 @@
37
37
  "cy:generate": "cypress run --e2e"
38
38
  },
39
39
  "dependencies": {
40
- "@clockworkdog/timesync": "^3.0.0-alpha.8",
40
+ "@clockworkdog/timesync": "^3.0.0-alpha.9",
41
41
  "howler": "clockwork-dog/howler.js#fix-looping-clips",
42
42
  "reconnecting-websocket": "^4.4.0",
43
43
  "zod": "^4.1.13"
@@ -1,14 +0,0 @@
1
- import { MediaClientConfig } from '../types/CogsClientMessage';
2
- export declare class MediaPreloader {
3
- private _state;
4
- private _elements;
5
- private _constructAssetURL;
6
- constructor(constructAssetURL: (file: string) => string, testState?: MediaClientConfig['files']);
7
- get state(): {
8
- [x: string]: import("../types/CogsClientMessage").Media;
9
- };
10
- setState(newState: MediaClientConfig['files']): void;
11
- private update;
12
- getElement(file: string, type: 'audio' | 'video'): HTMLAudioElement;
13
- releaseElement(resource: string | HTMLMediaElement): void;
14
- }
@@ -1,86 +0,0 @@
1
- export class MediaPreloader {
2
- _state;
3
- _elements = {};
4
- _constructAssetURL;
5
- constructor(constructAssetURL, testState = {}) {
6
- this._constructAssetURL = constructAssetURL;
7
- this._state = testState;
8
- }
9
- get state() {
10
- return { ...this._state };
11
- }
12
- setState(newState) {
13
- this._state = newState;
14
- this.update();
15
- }
16
- update() {
17
- // Clean up previous elements
18
- for (const [filename, media] of Object.entries(this._elements)) {
19
- if (!(filename in this._state)) {
20
- media.element.src = '';
21
- delete this._elements[filename];
22
- }
23
- media.inUse = media.element.isConnected;
24
- }
25
- for (const [filename, fileConfig] of Object.entries(this._state)) {
26
- if (filename in this._elements) {
27
- continue;
28
- }
29
- // Create new elements
30
- let preloadAttr;
31
- if (fileConfig.preload === true) {
32
- preloadAttr = 'auto';
33
- }
34
- else if (fileConfig.preload === false) {
35
- preloadAttr = 'none';
36
- }
37
- else {
38
- preloadAttr = fileConfig.preload;
39
- }
40
- switch (fileConfig.type) {
41
- case 'audio': {
42
- const element = document.createElement('audio');
43
- element.src = this._constructAssetURL(filename);
44
- element.preload = preloadAttr;
45
- this._elements[filename] = { element, inUse: false, type: 'audio' };
46
- break;
47
- }
48
- case 'video': {
49
- const element = document.createElement('video');
50
- element.src = this._constructAssetURL(filename);
51
- element.preload = preloadAttr;
52
- this._elements[filename] = { element, inUse: false, type: 'video' };
53
- break;
54
- }
55
- }
56
- }
57
- }
58
- getElement(file, type) {
59
- const media = this._elements[file];
60
- if (media && media.inUse === false) {
61
- media.inUse = true;
62
- return media.element;
63
- }
64
- else {
65
- const element = document.createElement(type);
66
- element.src = this._constructAssetURL(file);
67
- this._elements[file] = { element, type, inUse: true };
68
- return element;
69
- }
70
- }
71
- releaseElement(resource) {
72
- if (typeof resource === 'string') {
73
- const media = this._elements[resource];
74
- if (media) {
75
- media.inUse = false;
76
- }
77
- }
78
- else {
79
- Object.entries(this._elements).forEach(([file, media]) => {
80
- if (media.element === resource) {
81
- delete this._elements[file];
82
- }
83
- });
84
- }
85
- }
86
- }