@combos-fun/plugin-sound 0.0.46 → 0.0.48
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/agent-skill.md +9 -1
- package/combos-plugin.json +6 -1
- package/dist/plugin-sound.cjs.js +120 -5
- package/dist/plugin-sound.cjs.js.map +1 -1
- package/dist/plugin-sound.cjs.prod.js +1 -1
- package/dist/plugin-sound.d.ts +42 -2
- package/dist/plugin-sound.esm.js +118 -7
- package/dist/plugin-sound.esm.js.map +1 -1
- package/package.json +8 -4
package/agent-skill.md
CHANGED
|
@@ -14,7 +14,7 @@ import { Sound, SoundSystem } from '@combos-fun/plugin-sound';
|
|
|
14
14
|
|
|
15
15
|
`Sound` params: required `resource`; optional `autoplay`, `loop`, `muted`, `volume` (`0..1`), `seek`, `duration`, and `onEnd`. Its `play()`, `pause()`, and `stop()` methods return `void`; `muted`, `volume`, `loop`, `autoplay`, and `resource` are writable.
|
|
16
16
|
|
|
17
|
-
`SoundSystem` accepts optional `onError
|
|
17
|
+
`SoundSystem` accepts optional `onError`, `autoPauseAndStart` (default `true`), `postMessageOrigin`, and `allowedMessageOrigins`. It exposes `resumeAll()`, `pauseAll()`, `stopAll()`, `setMuted()`, global `muted` / `volume`, and `audioLocked`.
|
|
18
18
|
|
|
19
19
|
Parameter interfaces are not exported from the package entry; pass object literals.
|
|
20
20
|
|
|
@@ -35,6 +35,14 @@ resource.addResource([{
|
|
|
35
35
|
|
|
36
36
|
Decoded buffers are cached by resource. Each `play()` replaces the current `AudioBufferSourceNode`; `muted` and `volume` update gain immediately. With `autoPauseAndStart`, game pause/resume calls `pauseAll()` / `resumeAll()`.
|
|
37
37
|
|
|
38
|
+
Host mute (2D and 3D) is owned here. Plugin host types stay on `combos-development-tool:*` (only engine may use `combos-game:*`):
|
|
39
|
+
|
|
40
|
+
- Parent → iframe: `combos-development-tool:set-muted` `{ muted }`
|
|
41
|
+
- iframe → parent: `combos-development-tool:state-changed` `{ muted }`
|
|
42
|
+
- Same command via `window` CustomEvent, `game.emit`, or `SoundSystem.setMuted` / `SoundSystem.muted`
|
|
43
|
+
|
|
44
|
+
Inbound `postMessage` is origin-checked with the engine defaults (`knoffice.tech`, `converge.ai`). Pass `allowedMessageOrigins: ['localhost']` for local hosts; `['*']` disables the check. Outbound `targetOrigin` follows `postMessageOrigin`, then `Game.pluginInitNotifyTargetOrigin`, then `'*'`.
|
|
45
|
+
|
|
38
46
|
## Common pitfalls
|
|
39
47
|
|
|
40
48
|
- Autoplay can be blocked; start from a touch/click path.
|
package/combos-plugin.json
CHANGED
|
@@ -7,5 +7,10 @@
|
|
|
7
7
|
"keywords": ["sound", "audio", "playback", "volume", "web-audio", "sfx", "bgm"],
|
|
8
8
|
"agentSkill": "./agent-skill.md",
|
|
9
9
|
"requires": ["@combos-fun/engine"],
|
|
10
|
-
"exports": [
|
|
10
|
+
"exports": [
|
|
11
|
+
"Sound",
|
|
12
|
+
"SoundSystem",
|
|
13
|
+
"COMBOS_DEVELOPMENT_TOOL_SET_MUTED",
|
|
14
|
+
"COMBOS_DEVELOPMENT_TOOL_STATE_CHANGED"
|
|
15
|
+
]
|
|
11
16
|
}
|
package/dist/plugin-sound.cjs.js
CHANGED
|
@@ -4,14 +4,52 @@ var tslib = require('tslib');
|
|
|
4
4
|
var engine = require('@combos-fun/engine');
|
|
5
5
|
var inspectorDecorator = require('@combos-fun/inspector-decorator');
|
|
6
6
|
|
|
7
|
+
/** Parent → iframe (also `window` CustomEvent / `game.emit`): mute or unmute. Payload: `{ muted: boolean }`. */
|
|
8
|
+
const COMBOS_DEVELOPMENT_TOOL_SET_MUTED = 'combos-development-tool:set-muted';
|
|
9
|
+
/** iframe → parent (and `game.emit`): current mute snapshot after a successful change. */
|
|
10
|
+
const COMBOS_DEVELOPMENT_TOOL_STATE_CHANGED = 'combos-development-tool:state-changed';
|
|
11
|
+
function parseSetMutedMessage(data) {
|
|
12
|
+
if (!data || typeof data !== 'object')
|
|
13
|
+
return null;
|
|
14
|
+
const d = data;
|
|
15
|
+
if (d.type !== COMBOS_DEVELOPMENT_TOOL_SET_MUTED)
|
|
16
|
+
return null;
|
|
17
|
+
if (typeof d.muted !== 'boolean')
|
|
18
|
+
return null;
|
|
19
|
+
return d.muted;
|
|
20
|
+
}
|
|
21
|
+
function parseSetMutedCustomEvent(event) {
|
|
22
|
+
const d = event.detail;
|
|
23
|
+
if (!d || typeof d !== 'object' || typeof d.muted !== 'boolean')
|
|
24
|
+
return null;
|
|
25
|
+
return d.muted;
|
|
26
|
+
}
|
|
27
|
+
function postToParent(payload, targetOrigin) {
|
|
28
|
+
if (typeof window === 'undefined')
|
|
29
|
+
return;
|
|
30
|
+
if (!window.parent || window.parent === window)
|
|
31
|
+
return;
|
|
32
|
+
try {
|
|
33
|
+
window.parent.postMessage(payload, targetOrigin);
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
/* ignore cross-origin or detached frame */
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/** Notifies the embedding page (and `game.emit`) of the current mute flag. */
|
|
40
|
+
function postParentSoundMuted(muted, targetOrigin, emit) {
|
|
41
|
+
const state = { muted };
|
|
42
|
+
postToParent({ type: COMBOS_DEVELOPMENT_TOOL_STATE_CHANGED, ...state }, targetOrigin);
|
|
43
|
+
emit?.(COMBOS_DEVELOPMENT_TOOL_STATE_CHANGED, state);
|
|
44
|
+
}
|
|
45
|
+
|
|
7
46
|
let SoundSystem$1 = class SoundSystem extends engine.System {
|
|
8
47
|
static { this.systemName = 'SoundSystem'; }
|
|
9
48
|
get muted() {
|
|
10
49
|
return this._muted;
|
|
11
50
|
}
|
|
12
51
|
set muted(v) {
|
|
13
|
-
this.
|
|
14
|
-
this.applyGain();
|
|
52
|
+
this.setMuted(v);
|
|
15
53
|
}
|
|
16
54
|
get volume() {
|
|
17
55
|
return this._volume;
|
|
@@ -55,7 +93,50 @@ let SoundSystem$1 = class SoundSystem extends engine.System {
|
|
|
55
93
|
/** Desired mute/volume are the source of truth; the gain node is derived. */
|
|
56
94
|
this._muted = false;
|
|
57
95
|
this._volume = 1;
|
|
58
|
-
|
|
96
|
+
this.postMessageOrigin = '*';
|
|
97
|
+
this.allowedMessageOrigins = engine.mergeAllowedMessageOrigins();
|
|
98
|
+
this.hostMuteBound = false;
|
|
99
|
+
this.onWindowSetMuted = (e) => {
|
|
100
|
+
const muted = parseSetMutedCustomEvent(e);
|
|
101
|
+
if (muted === null)
|
|
102
|
+
return;
|
|
103
|
+
this.setMuted(muted);
|
|
104
|
+
};
|
|
105
|
+
this.onGameSetMuted = (payload) => {
|
|
106
|
+
if (payload && typeof payload.muted === 'boolean') {
|
|
107
|
+
this.setMuted(payload.muted);
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
this.onWindowMessage = (e) => {
|
|
111
|
+
if (!engine.isAllowedMessageOrigin(e.origin, this.allowedMessageOrigins)) {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
const muted = parseSetMutedMessage(e.data);
|
|
115
|
+
if (muted === null)
|
|
116
|
+
return;
|
|
117
|
+
this.setMuted(muted);
|
|
118
|
+
};
|
|
119
|
+
if (!obj)
|
|
120
|
+
return;
|
|
121
|
+
if (typeof obj.autoPauseAndStart === 'boolean') {
|
|
122
|
+
this.autoPauseAndStart = obj.autoPauseAndStart;
|
|
123
|
+
}
|
|
124
|
+
if (obj.onError) {
|
|
125
|
+
this.onError = obj.onError;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Mute or unmute the master gain and notify the embedding host.
|
|
130
|
+
* Same effect as `postMessage({ type: 'combos-development-tool:set-muted', muted })`.
|
|
131
|
+
*/
|
|
132
|
+
setMuted(muted) {
|
|
133
|
+
const next = !!muted;
|
|
134
|
+
if (this._muted === next) {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
this._muted = next;
|
|
138
|
+
this.applyGain();
|
|
139
|
+
this.postMuteStateChanged();
|
|
59
140
|
}
|
|
60
141
|
/**
|
|
61
142
|
* Resume playback of all paused audio.
|
|
@@ -98,7 +179,11 @@ let SoundSystem$1 = class SoundSystem extends engine.System {
|
|
|
98
179
|
/**
|
|
99
180
|
* System init: configure params before the game starts.
|
|
100
181
|
*/
|
|
101
|
-
init() {
|
|
182
|
+
init(params) {
|
|
183
|
+
this.postMessageOrigin =
|
|
184
|
+
params?.postMessageOrigin ?? this.game?.pluginInitNotifyTargetOrigin ?? '*';
|
|
185
|
+
this.allowedMessageOrigins = engine.mergeAllowedMessageOrigins(params?.allowedMessageOrigins);
|
|
186
|
+
this.bindHostMute();
|
|
102
187
|
this.setupAudioContext();
|
|
103
188
|
}
|
|
104
189
|
update() {
|
|
@@ -129,6 +214,7 @@ let SoundSystem$1 = class SoundSystem extends engine.System {
|
|
|
129
214
|
* Called when the system is destroyed.
|
|
130
215
|
*/
|
|
131
216
|
onDestroy() {
|
|
217
|
+
this.unbindHostMute();
|
|
132
218
|
this.components.forEach(component => {
|
|
133
219
|
component.onDestroy();
|
|
134
220
|
});
|
|
@@ -140,6 +226,31 @@ let SoundSystem$1 = class SoundSystem extends engine.System {
|
|
|
140
226
|
this.ctx = null;
|
|
141
227
|
}
|
|
142
228
|
}
|
|
229
|
+
bindHostMute() {
|
|
230
|
+
if (this.hostMuteBound)
|
|
231
|
+
return;
|
|
232
|
+
this.hostMuteBound = true;
|
|
233
|
+
if (typeof window !== 'undefined') {
|
|
234
|
+
window.addEventListener(COMBOS_DEVELOPMENT_TOOL_SET_MUTED, this.onWindowSetMuted);
|
|
235
|
+
window.addEventListener('message', this.onWindowMessage);
|
|
236
|
+
}
|
|
237
|
+
this.game.on(COMBOS_DEVELOPMENT_TOOL_SET_MUTED, this.onGameSetMuted);
|
|
238
|
+
}
|
|
239
|
+
unbindHostMute() {
|
|
240
|
+
if (!this.hostMuteBound)
|
|
241
|
+
return;
|
|
242
|
+
this.hostMuteBound = false;
|
|
243
|
+
if (typeof window !== 'undefined') {
|
|
244
|
+
window.removeEventListener(COMBOS_DEVELOPMENT_TOOL_SET_MUTED, this.onWindowSetMuted);
|
|
245
|
+
window.removeEventListener('message', this.onWindowMessage);
|
|
246
|
+
}
|
|
247
|
+
this.game?.off(COMBOS_DEVELOPMENT_TOOL_SET_MUTED, this.onGameSetMuted);
|
|
248
|
+
}
|
|
249
|
+
postMuteStateChanged() {
|
|
250
|
+
postParentSoundMuted(this._muted, this.postMessageOrigin, (type, payload) => {
|
|
251
|
+
this.game?.emit(type, payload);
|
|
252
|
+
});
|
|
253
|
+
}
|
|
143
254
|
async componentChanged(changed) {
|
|
144
255
|
if (changed.componentName !== 'Sound')
|
|
145
256
|
return;
|
|
@@ -253,7 +364,7 @@ var SoundSystem = SoundSystem$1;
|
|
|
253
364
|
/** Auto-generated by scripts/build-package.mjs — do not edit. */
|
|
254
365
|
Object.assign(SoundSystem, {
|
|
255
366
|
packageName: "@combos-fun/plugin-sound",
|
|
256
|
-
packageVersion: "0.0.
|
|
367
|
+
packageVersion: "0.0.48",
|
|
257
368
|
});
|
|
258
369
|
|
|
259
370
|
class Sound extends engine.Component {
|
|
@@ -487,6 +598,10 @@ tslib.__decorate([
|
|
|
487
598
|
})
|
|
488
599
|
], Sound.prototype, "resource", null);
|
|
489
600
|
|
|
601
|
+
exports.COMBOS_DEVELOPMENT_TOOL_SET_MUTED = COMBOS_DEVELOPMENT_TOOL_SET_MUTED;
|
|
602
|
+
exports.COMBOS_DEVELOPMENT_TOOL_STATE_CHANGED = COMBOS_DEVELOPMENT_TOOL_STATE_CHANGED;
|
|
490
603
|
exports.Sound = Sound;
|
|
491
604
|
exports.SoundSystem = SoundSystem;
|
|
605
|
+
exports.parseSetMutedMessage = parseSetMutedMessage;
|
|
606
|
+
exports.postParentSoundMuted = postParentSoundMuted;
|
|
492
607
|
//# sourceMappingURL=plugin-sound.cjs.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin-sound.cjs.js","sources":["../lib/SoundSystem.ts","../lib/__combosPackageMeta.gen.ts","../lib/Sound.ts"],"sourcesContent":["import { System, decorators, ComponentChanged, OBSERVER_TYPE, resource } from '@combos-fun/engine';\nimport SoundComponent from './Sound';\n\ninterface SoundSystemParams {\n autoPauseAndStart?: boolean;\n onError?: (error: any) => void;\n}\n\n@decorators.componentObserver({\n Sound: [],\n})\nclass SoundSystem extends System {\n static systemName = 'SoundSystem';\n\n private ctx: AudioContext;\n\n private gainNode: GainNode;\n\n /** Whether to pause/resume in sync with the game. */\n private autoPauseAndStart = true;\n\n private onError: (error: any) => void;\n\n private components: SoundComponent[] = [];\n\n private pausedComponents: SoundComponent[] = [];\n\n private audioBufferCache = {};\n\n private decodeAudioPromiseMap = {};\n\n /** Desired mute/volume are the source of truth; the gain node is derived. */\n private _muted = false;\n\n private _volume = 1;\n\n get muted(): boolean {\n return this._muted;\n }\n\n set muted(v: boolean) {\n this._muted = v;\n this.applyGain();\n }\n\n get volume(): number {\n return this._volume;\n }\n\n set volume(v: number) {\n if (typeof v !== 'number' || v < 0 || v > 1) {\n return;\n }\n this._volume = v;\n this.applyGain();\n }\n\n /**\n * Apply the effective gain (`muted ? 0 : volume`) to the gain node.\n *\n * Assigns `gain.value` directly rather than `setValueAtTime`: `.value` updates\n * the AudioParam's intrinsic value synchronously, so the `muted` / `volume`\n * getters reflect the change immediately. `setValueAtTime` only schedules an\n * event on the automation timeline and leaves `.value` stale until the next\n * render quantum, which made `muted` report the pre-change value.\n */\n private applyGain() {\n if (!this.gainNode) {\n return;\n }\n this.gainNode.gain.value = this._muted ? 0 : this._volume;\n }\n\n get audioLocked(): boolean {\n if (!this.ctx) {\n return true;\n }\n return this.ctx.state !== 'running';\n }\n\n constructor(obj?: SoundSystemParams) {\n super();\n Object.assign(this, obj);\n }\n\n /**\n * Resume playback of all paused audio.\n */\n resumeAll() {\n const handleResume = () => {\n this.pausedComponents.forEach(component => {\n component.play();\n });\n // Clear the previously cached paused list.\n this.pausedComponents = [];\n };\n this.ctx.resume().then(handleResume, handleResume);\n }\n\n /**\n * Pause all currently playing audio.\n */\n pauseAll() {\n this.components.forEach(component => {\n if (component.playing) {\n this.pausedComponents.push(component);\n component.pause();\n }\n });\n this.ctx.suspend().then();\n }\n\n /**\n * Stop all currently playing audio.\n */\n stopAll() {\n this.components.forEach(component => {\n if (component.playing) {\n component.stop();\n }\n });\n // Clear the previously cached paused list.\n this.pausedComponents = [];\n this.ctx.suspend().then();\n }\n\n /**\n * System init: configure params before the game starts.\n */\n init() {\n this.setupAudioContext();\n }\n\n update() {\n const changes = this.componentObserver.clear();\n for (const changed of changes) {\n this.componentChanged(changed);\n }\n }\n\n /**\n * Called when the game starts or resumes playing after a pause.\n */\n onResume() {\n if (!this.autoPauseAndStart) {\n return;\n }\n this.resumeAll();\n }\n\n /**\n * Called when the game is paused.\n */\n onPause() {\n if (!this.autoPauseAndStart) {\n return;\n }\n this.pauseAll();\n }\n\n /**\n * Called when the system is destroyed.\n */\n onDestroy() {\n this.components.forEach(component => {\n component.onDestroy();\n });\n this.components = [];\n if (this.ctx) {\n this.gainNode.disconnect();\n this.gainNode = null;\n this.ctx.close();\n this.ctx = null;\n }\n }\n\n async componentChanged(changed: ComponentChanged) {\n if (changed.componentName !== 'Sound') return;\n\n if (changed.type === OBSERVER_TYPE.ADD) {\n this.add(changed);\n }\n }\n\n private setupAudioContext() {\n try {\n const AudioContext = window.AudioContext || (window as any).webkitAudioContext;\n this.ctx = new AudioContext();\n } catch (error) {\n console.error(error);\n if (this.onError) {\n this.onError(error);\n }\n }\n\n if (!this.ctx) {\n return;\n }\n this.gainNode =\n typeof this.ctx.createGain === 'undefined' ? (this.ctx as any).createGainNode() : this.ctx.createGain();\n this.applyGain();\n this.gainNode.connect(this.ctx.destination);\n this.unlockAudio();\n }\n\n private unlockAudio() {\n if (!this.ctx || !this.audioLocked) {\n return;\n }\n\n const unlock = () => {\n if (this.ctx) {\n const removeListenerFn = () => {\n document.body.removeEventListener('touchstart', unlock);\n document.body.removeEventListener('touchend', unlock);\n document.body.removeEventListener('click', unlock);\n };\n this.ctx.resume().then(removeListenerFn, removeListenerFn);\n }\n };\n document.body.addEventListener('touchstart', unlock);\n document.body.addEventListener('touchend', unlock);\n document.body.addEventListener('click', unlock);\n }\n\n private async add(changed: ComponentChanged) {\n const component = changed.component as SoundComponent;\n this.components.push(component);\n try {\n const { config } = component;\n component.state = 'loading';\n\n const audio = await resource.getResource(config.resource);\n if (!this.audioBufferCache[audio.name] && audio?.data?.audio) {\n this.audioBufferCache[audio.name] = await this.decodeAudioData(audio.data.audio, audio.name);\n }\n if (this.audioBufferCache[audio.name]) {\n component.systemContext = this.ctx;\n component.systemDestination = this.gainNode;\n component.onload(this.audioBufferCache[audio.name]);\n }\n } catch (error) {\n if (this.onError) {\n this.onError(error);\n }\n }\n }\n\n private decodeAudioData(arraybuffer: ArrayBuffer, name: string) {\n if (this.decodeAudioPromiseMap[name]) {\n return this.decodeAudioPromiseMap[name];\n }\n\n const promise = new Promise<AudioBuffer>((resolve, reject) => {\n if (!this.ctx) {\n reject(new Error('No audio support'));\n }\n\n const success = (decodedData: AudioBuffer) => {\n if (this.decodeAudioPromiseMap[name]) {\n delete this.decodeAudioPromiseMap[name];\n }\n if (decodedData) {\n resolve(decodedData);\n } else {\n reject(new Error(`Error decoding audio ${name}`));\n }\n };\n\n const error = (err: DOMException) => {\n if (this.decodeAudioPromiseMap[name]) {\n delete this.decodeAudioPromiseMap[name];\n }\n reject(new Error(`${err}. arrayBuffer byteLength: ${arraybuffer ? arraybuffer.byteLength : 0}`));\n };\n\n const promise = this.ctx.decodeAudioData(arraybuffer, success, error)\n if (promise instanceof Promise) {\n promise.catch((err) => {\n reject(new Error(`catch ${err}, arrayBuffer byteLength: ${arraybuffer ? arraybuffer.byteLength : 0}`));\n });\n }\n });\n\n this.decodeAudioPromiseMap[name] = promise;\n return promise;\n }\n}\n\nexport default SoundSystem;\n","/** Auto-generated by scripts/build-package.mjs — do not edit. */\n\nimport SoundSystem from './SoundSystem';\n\nObject.assign(SoundSystem, {\n packageName: \"@combos-fun/plugin-sound\",\n packageVersion: \"0.0.46\",\n});\n","import { Component } from '@combos-fun/engine';\nimport { Field } from '@combos-fun/inspector-decorator';\n\nexport interface SoundParams {\n resource: string;\n autoplay?: boolean;\n muted?: boolean;\n volume?: number;\n loop?: boolean;\n seek?: number;\n duration?: number;\n onEnd?: () => void;\n}\n\nclass Sound extends Component<SoundParams> {\n static componentName = 'Sound';\n\n systemContext: AudioContext;\n\n systemDestination: GainNode;\n\n playing: boolean;\n\n state: 'unloaded' | 'loading' | 'loaded' = 'unloaded';\n\n config: SoundParams = {\n resource: '',\n autoplay: false,\n muted: false,\n volume: 1,\n loop: false,\n seek: 0,\n };\n\n private buffer: AudioBuffer;\n\n private sourceNode: AudioBufferSourceNode;\n\n private gainNode: GainNode;\n\n private paused: boolean;\n\n private playTime: number = 0;\n\n private startTime: number = 0;\n\n private duration: number = 0;\n\n private actionQueue: (() => void)[] = [];\n\n private endedListener: () => void;\n\n @Field({\n type: 'boolean',\n group: 'Sound',\n label: 'Muted',\n description: 'Silence this sound without changing its volume setting.',\n editor: 'toggle',\n })\n get muted(): boolean {\n return this.config.muted ?? false;\n }\n\n set muted(v: boolean) {\n this.config.muted = v;\n this.applyGain();\n }\n\n @Field({\n type: 'number',\n min: 0,\n max: 1,\n step: 0.01,\n group: 'Sound',\n label: 'Volume',\n description: 'Loudness of this sound from 0 (silent) to 1 (full).',\n editor: 'volume-slider',\n })\n get volume(): number {\n return this.config.volume ?? 1;\n }\n\n set volume(v: number) {\n if (typeof v !== 'number' || v < 0 || v > 1) {\n return;\n }\n this.config.volume = v;\n this.applyGain();\n }\n\n @Field({\n type: 'boolean',\n group: 'Sound',\n label: 'Loop',\n description: 'Replay the sound continuously when it reaches the end.',\n editor: 'toggle',\n })\n get loop(): boolean {\n return this.config.loop ?? false;\n }\n\n set loop(v: boolean) {\n this.config.loop = v;\n if (this.sourceNode) {\n this.sourceNode.loop = v;\n }\n }\n\n @Field({\n type: 'boolean',\n group: 'Sound',\n label: 'Autoplay',\n description: 'Start playing automatically once the audio has loaded.',\n editor: 'toggle',\n })\n get autoplay(): boolean {\n return this.config.autoplay ?? false;\n }\n\n set autoplay(v: boolean) {\n this.config.autoplay = v;\n }\n\n @Field({\n type: 'string',\n group: 'Sound',\n label: 'Resource',\n description: 'Audio resource id used by the sound system.',\n editor: 'text',\n })\n get resource(): string {\n return this.config.resource ?? '';\n }\n\n set resource(v: string) {\n this.config.resource = v;\n }\n\n /**\n * Apply the effective gain (`muted ? 0 : volume`) to the gain node.\n *\n * `config` is the source of truth and the gain is assigned via `gain.value`\n * (updates the AudioParam intrinsic value synchronously) so the `muted` /\n * `volume` getters — and anything reading them back, e.g. the scene-edit\n * volume slider — reflect the change immediately. `setValueAtTime` only\n * schedules on the automation timeline and leaves `.value` stale.\n */\n private applyGain() {\n if (!this.gainNode) {\n return;\n }\n this.gainNode.gain.value = this.config.muted ? 0 : (this.config.volume ?? 1);\n }\n\n init(obj?: SoundParams) {\n if (!obj) {\n return;\n }\n\n Object.assign(this.config, obj);\n if (this.config.autoplay) {\n this.actionQueue.push(this.play.bind(this));\n }\n }\n\n play() {\n if (this.state !== 'loaded') {\n this.actionQueue.push(this.play.bind(this));\n }\n this.destroySource();\n this.createSource();\n\n if (!this.sourceNode) {\n return;\n }\n const when = this.systemContext.currentTime;\n const offset = this.config.seek;\n const duration = this.config.duration;\n\n this.sourceNode.start(0, offset, duration);\n\n this.startTime = when;\n this.playTime = when - offset;\n this.paused = false;\n this.playing = true;\n this.resetConfig();\n this.endedListener = () => {\n if (!this.sourceNode) {\n return;\n }\n if (this.config.onEnd) {\n this.config.onEnd();\n }\n // Release resources once non-interactive playback finishes.\n if (this.playing) {\n this.destroySource();\n }\n };\n this.sourceNode.addEventListener('ended', this.endedListener);\n }\n\n pause() {\n if (this.state !== 'loaded') {\n this.actionQueue.push(this.pause.bind(this));\n }\n if (this.paused || !this.playing) {\n return;\n }\n this.paused = true;\n this.playing = false;\n this.config.seek = this.getCurrentTime();\n this.destroySource();\n }\n\n stop() {\n if (this.state !== 'loaded') {\n this.actionQueue.push(this.stop.bind(this));\n }\n if (!this.paused && !this.playing) {\n return;\n }\n this.playing = false;\n this.paused = false;\n this.destroySource();\n this.resetConfig();\n }\n\n onload(buffer: AudioBuffer) {\n this.state = 'loaded';\n this.buffer = buffer;\n this.duration = this.buffer.duration;\n this.actionQueue.forEach(action => action());\n this.actionQueue.length = 0;\n }\n\n onDestroy() {\n this.actionQueue.length = 0;\n this.destroySource();\n }\n\n private resetConfig() {\n this.config.seek = 0;\n }\n\n private getCurrentTime() {\n if (this.config.loop && this.duration > 0) {\n return (this.systemContext.currentTime - this.playTime) % this.duration;\n }\n\n return this.systemContext.currentTime - this.playTime;\n }\n\n private createSource() {\n if (!this.systemContext || this.state !== 'loaded') {\n return;\n }\n this.sourceNode = this.systemContext.createBufferSource();\n this.sourceNode.buffer = this.buffer;\n this.sourceNode.loop = this.config.loop;\n\n if (!this.gainNode) {\n this.gainNode = this.systemContext.createGain();\n this.gainNode.connect(this.systemDestination);\n Object.assign(this, this.config);\n }\n this.sourceNode.connect(this.gainNode);\n }\n\n private destroySource() {\n if (!this.sourceNode) return;\n this.sourceNode.removeEventListener('ended', this.endedListener);\n this.sourceNode.stop();\n this.sourceNode.disconnect();\n this.sourceNode = null;\n\n this.startTime = 0;\n this.playTime = 0;\n this.playing = false;\n }\n}\n\nexport default Sound;\n"],"names":["SoundSystem","System","OBSERVER_TYPE","resource","__decorate","decorators","Component","Field"],"mappings":";;;;;;AAWA,IAAMA,aAAW,GAAjB,MAAM,WAAY,SAAQC,aAAM,CAAA;aACvB,IAAA,CAAA,UAAU,GAAG,aAAH,CAAiB;AAwBlC,IAAA,IAAI,KAAK,GAAA;QACP,OAAO,IAAI,CAAC,MAAM;IACpB;IAEA,IAAI,KAAK,CAAC,CAAU,EAAA;AAClB,QAAA,IAAI,CAAC,MAAM,GAAG,CAAC;QACf,IAAI,CAAC,SAAS,EAAE;IAClB;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AA,KAAK,EAAE,UAAU;AACjB,QAAA,WAAW,EAAE,wDAAwD;AACrE,QAAA,MAAM,EAAE,QAAQ;KACjB;AAGA,CAAA,EAAA,KAAA,CAAA,SAAA,EAAA,UAAA,EAAA,IAAA,CAAA;AAaDH,gBAAA,CAAA;AAPC,IAAAG,wBAAK,CAAC;AACL,QAAA,IAAI,EAAE,QAAQ;AACd,QAAA,KAAK,EAAE,OAAO;AACd,QAAA,KAAK,EAAE,UAAU;AACjB,QAAA,WAAW,EAAE,6CAA6C;AAC1D,QAAA,MAAM,EAAE,MAAM;KACf;AAGA,CAAA,EAAA,KAAA,CAAA,SAAA,EAAA,UAAA,EAAA,IAAA,CAAA;;;;;"}
|
|
1
|
+
{"version":3,"file":"plugin-sound.cjs.js","sources":["../lib/hostMessages.ts","../lib/SoundSystem.ts","../lib/__combosPackageMeta.gen.ts","../lib/Sound.ts"],"sourcesContent":["/** Parent → iframe (also `window` CustomEvent / `game.emit`): mute or unmute. Payload: `{ muted: boolean }`. */\nexport const COMBOS_DEVELOPMENT_TOOL_SET_MUTED =\n 'combos-development-tool:set-muted' as const;\n\n/** iframe → parent (and `game.emit`): current mute snapshot after a successful change. */\nexport const COMBOS_DEVELOPMENT_TOOL_STATE_CHANGED =\n 'combos-development-tool:state-changed' as const;\n\nexport interface CombosSoundSetMutedMessage {\n type: typeof COMBOS_DEVELOPMENT_TOOL_SET_MUTED;\n muted: boolean;\n}\n\nexport interface CombosSoundStateChangedMessage {\n type: typeof COMBOS_DEVELOPMENT_TOOL_STATE_CHANGED;\n muted: boolean;\n}\n\nexport function parseSetMutedMessage(data: unknown): boolean | null {\n if (!data || typeof data !== 'object') return null;\n const d = data as { type?: unknown; muted?: unknown };\n if (d.type !== COMBOS_DEVELOPMENT_TOOL_SET_MUTED) return null;\n if (typeof d.muted !== 'boolean') return null;\n return d.muted;\n}\n\nexport function parseSetMutedCustomEvent(event: Event): boolean | null {\n const d = (event as CustomEvent<{ muted?: unknown }>).detail;\n if (!d || typeof d !== 'object' || typeof d.muted !== 'boolean') return null;\n return d.muted;\n}\n\nfunction postToParent(payload: object, targetOrigin: string): void {\n if (typeof window === 'undefined') return;\n if (!window.parent || window.parent === window) return;\n try {\n window.parent.postMessage(payload, targetOrigin);\n } catch {\n /* ignore cross-origin or detached frame */\n }\n}\n\n/** Notifies the embedding page (and `game.emit`) of the current mute flag. */\nexport function postParentSoundMuted(\n muted: boolean,\n targetOrigin: string,\n emit?: (type: string, payload: { muted: boolean }) => void,\n): void {\n const state = { muted };\n postToParent({ type: COMBOS_DEVELOPMENT_TOOL_STATE_CHANGED, ...state }, targetOrigin);\n emit?.(COMBOS_DEVELOPMENT_TOOL_STATE_CHANGED, state);\n}\n","import {\n System,\n decorators,\n ComponentChanged,\n OBSERVER_TYPE,\n resource,\n isAllowedMessageOrigin,\n mergeAllowedMessageOrigins,\n} from '@combos-fun/engine';\nimport SoundComponent from './Sound';\nimport {\n COMBOS_DEVELOPMENT_TOOL_SET_MUTED,\n parseSetMutedCustomEvent,\n parseSetMutedMessage,\n postParentSoundMuted,\n} from './hostMessages';\n\ninterface SoundSystemParams {\n autoPauseAndStart?: boolean;\n onError?: (error: any) => void;\n /** postMessage `targetOrigin` when notifying parent (default: Game `pluginInitNotifyTargetOrigin` or `'*'`). */\n postMessageOrigin?: string;\n /**\n * Extra inbound `postMessage` origins merged with engine defaults (`knoffice.tech`, `converge.ai`).\n * Each entry is a host suffix (e.g. `localhost`) or a full origin. Pass `['*']` to accept any origin.\n */\n allowedMessageOrigins?: string[];\n}\n\n@decorators.componentObserver({\n Sound: [],\n})\nclass SoundSystem extends System {\n static systemName = 'SoundSystem';\n\n private ctx: AudioContext;\n\n private gainNode: GainNode;\n\n /** Whether to pause/resume in sync with the game. */\n private autoPauseAndStart = true;\n\n private onError: (error: any) => void;\n\n private components: SoundComponent[] = [];\n\n private pausedComponents: SoundComponent[] = [];\n\n private audioBufferCache = {};\n\n private decodeAudioPromiseMap = {};\n\n /** Desired mute/volume are the source of truth; the gain node is derived. */\n private _muted = false;\n\n private _volume = 1;\n\n private postMessageOrigin = '*';\n\n private allowedMessageOrigins = mergeAllowedMessageOrigins();\n\n private hostMuteBound = false;\n\n get muted(): boolean {\n return this._muted;\n }\n\n set muted(v: boolean) {\n this.setMuted(v);\n }\n\n get volume(): number {\n return this._volume;\n }\n\n set volume(v: number) {\n if (typeof v !== 'number' || v < 0 || v > 1) {\n return;\n }\n this._volume = v;\n this.applyGain();\n }\n\n /**\n * Apply the effective gain (`muted ? 0 : volume`) to the gain node.\n *\n * Assigns `gain.value` directly rather than `setValueAtTime`: `.value` updates\n * the AudioParam's intrinsic value synchronously, so the `muted` / `volume`\n * getters reflect the change immediately. `setValueAtTime` only schedules an\n * event on the automation timeline and leaves `.value` stale until the next\n * render quantum, which made `muted` report the pre-change value.\n */\n private applyGain() {\n if (!this.gainNode) {\n return;\n }\n this.gainNode.gain.value = this._muted ? 0 : this._volume;\n }\n\n get audioLocked(): boolean {\n if (!this.ctx) {\n return true;\n }\n return this.ctx.state !== 'running';\n }\n\n constructor(obj?: SoundSystemParams) {\n super();\n if (!obj) return;\n if (typeof obj.autoPauseAndStart === 'boolean') {\n this.autoPauseAndStart = obj.autoPauseAndStart;\n }\n if (obj.onError) {\n this.onError = obj.onError;\n }\n }\n\n /**\n * Mute or unmute the master gain and notify the embedding host.\n * Same effect as `postMessage({ type: 'combos-development-tool:set-muted', muted })`.\n */\n setMuted(muted: boolean) {\n const next = !!muted;\n if (this._muted === next) {\n return;\n }\n this._muted = next;\n this.applyGain();\n this.postMuteStateChanged();\n }\n\n /**\n * Resume playback of all paused audio.\n */\n resumeAll() {\n const handleResume = () => {\n this.pausedComponents.forEach(component => {\n component.play();\n });\n // Clear the previously cached paused list.\n this.pausedComponents = [];\n };\n this.ctx.resume().then(handleResume, handleResume);\n }\n\n /**\n * Pause all currently playing audio.\n */\n pauseAll() {\n this.components.forEach(component => {\n if (component.playing) {\n this.pausedComponents.push(component);\n component.pause();\n }\n });\n this.ctx.suspend().then();\n }\n\n /**\n * Stop all currently playing audio.\n */\n stopAll() {\n this.components.forEach(component => {\n if (component.playing) {\n component.stop();\n }\n });\n // Clear the previously cached paused list.\n this.pausedComponents = [];\n this.ctx.suspend().then();\n }\n\n /**\n * System init: configure params before the game starts.\n */\n init(params?: SoundSystemParams) {\n this.postMessageOrigin =\n params?.postMessageOrigin ?? this.game?.pluginInitNotifyTargetOrigin ?? '*';\n this.allowedMessageOrigins = mergeAllowedMessageOrigins(params?.allowedMessageOrigins);\n this.bindHostMute();\n this.setupAudioContext();\n }\n\n update() {\n const changes = this.componentObserver.clear();\n for (const changed of changes) {\n this.componentChanged(changed);\n }\n }\n\n /**\n * Called when the game starts or resumes playing after a pause.\n */\n onResume() {\n if (!this.autoPauseAndStart) {\n return;\n }\n this.resumeAll();\n }\n\n /**\n * Called when the game is paused.\n */\n onPause() {\n if (!this.autoPauseAndStart) {\n return;\n }\n this.pauseAll();\n }\n\n /**\n * Called when the system is destroyed.\n */\n onDestroy() {\n this.unbindHostMute();\n this.components.forEach(component => {\n component.onDestroy();\n });\n this.components = [];\n if (this.ctx) {\n this.gainNode.disconnect();\n this.gainNode = null;\n this.ctx.close();\n this.ctx = null;\n }\n }\n\n private readonly onWindowSetMuted = (e: Event) => {\n const muted = parseSetMutedCustomEvent(e);\n if (muted === null) return;\n this.setMuted(muted);\n };\n\n private readonly onGameSetMuted = (payload: { muted?: boolean }) => {\n if (payload && typeof payload.muted === 'boolean') {\n this.setMuted(payload.muted);\n }\n };\n\n private readonly onWindowMessage = (e: MessageEvent) => {\n if (!isAllowedMessageOrigin(e.origin, this.allowedMessageOrigins)) {\n return;\n }\n const muted = parseSetMutedMessage(e.data);\n if (muted === null) return;\n this.setMuted(muted);\n };\n\n private bindHostMute() {\n if (this.hostMuteBound) return;\n this.hostMuteBound = true;\n if (typeof window !== 'undefined') {\n window.addEventListener(COMBOS_DEVELOPMENT_TOOL_SET_MUTED, this.onWindowSetMuted);\n window.addEventListener('message', this.onWindowMessage);\n }\n this.game.on(COMBOS_DEVELOPMENT_TOOL_SET_MUTED, this.onGameSetMuted);\n }\n\n private unbindHostMute() {\n if (!this.hostMuteBound) return;\n this.hostMuteBound = false;\n if (typeof window !== 'undefined') {\n window.removeEventListener(COMBOS_DEVELOPMENT_TOOL_SET_MUTED, this.onWindowSetMuted);\n window.removeEventListener('message', this.onWindowMessage);\n }\n this.game?.off(COMBOS_DEVELOPMENT_TOOL_SET_MUTED, this.onGameSetMuted);\n }\n\n private postMuteStateChanged() {\n postParentSoundMuted(this._muted, this.postMessageOrigin, (type, payload) => {\n this.game?.emit(type, payload);\n });\n }\n\n async componentChanged(changed: ComponentChanged) {\n if (changed.componentName !== 'Sound') return;\n\n if (changed.type === OBSERVER_TYPE.ADD) {\n this.add(changed);\n }\n }\n\n private setupAudioContext() {\n try {\n const AudioContext = window.AudioContext || (window as any).webkitAudioContext;\n this.ctx = new AudioContext();\n } catch (error) {\n console.error(error);\n if (this.onError) {\n this.onError(error);\n }\n }\n\n if (!this.ctx) {\n return;\n }\n this.gainNode =\n typeof this.ctx.createGain === 'undefined' ? (this.ctx as any).createGainNode() : this.ctx.createGain();\n this.applyGain();\n this.gainNode.connect(this.ctx.destination);\n this.unlockAudio();\n }\n\n private unlockAudio() {\n if (!this.ctx || !this.audioLocked) {\n return;\n }\n\n const unlock = () => {\n if (this.ctx) {\n const removeListenerFn = () => {\n document.body.removeEventListener('touchstart', unlock);\n document.body.removeEventListener('touchend', unlock);\n document.body.removeEventListener('click', unlock);\n };\n this.ctx.resume().then(removeListenerFn, removeListenerFn);\n }\n };\n document.body.addEventListener('touchstart', unlock);\n document.body.addEventListener('touchend', unlock);\n document.body.addEventListener('click', unlock);\n }\n\n private async add(changed: ComponentChanged) {\n const component = changed.component as SoundComponent;\n this.components.push(component);\n try {\n const { config } = component;\n component.state = 'loading';\n\n const audio = await resource.getResource(config.resource);\n if (!this.audioBufferCache[audio.name] && audio?.data?.audio) {\n this.audioBufferCache[audio.name] = await this.decodeAudioData(audio.data.audio, audio.name);\n }\n if (this.audioBufferCache[audio.name]) {\n component.systemContext = this.ctx;\n component.systemDestination = this.gainNode;\n component.onload(this.audioBufferCache[audio.name]);\n }\n } catch (error) {\n if (this.onError) {\n this.onError(error);\n }\n }\n }\n\n private decodeAudioData(arraybuffer: ArrayBuffer, name: string) {\n if (this.decodeAudioPromiseMap[name]) {\n return this.decodeAudioPromiseMap[name];\n }\n\n const promise = new Promise<AudioBuffer>((resolve, reject) => {\n if (!this.ctx) {\n reject(new Error('No audio support'));\n }\n\n const success = (decodedData: AudioBuffer) => {\n if (this.decodeAudioPromiseMap[name]) {\n delete this.decodeAudioPromiseMap[name];\n }\n if (decodedData) {\n resolve(decodedData);\n } else {\n reject(new Error(`Error decoding audio ${name}`));\n }\n };\n\n const error = (err: DOMException) => {\n if (this.decodeAudioPromiseMap[name]) {\n delete this.decodeAudioPromiseMap[name];\n }\n reject(new Error(`${err}. arrayBuffer byteLength: ${arraybuffer ? arraybuffer.byteLength : 0}`));\n };\n\n const promise = this.ctx.decodeAudioData(arraybuffer, success, error)\n if (promise instanceof Promise) {\n promise.catch((err) => {\n reject(new Error(`catch ${err}, arrayBuffer byteLength: ${arraybuffer ? arraybuffer.byteLength : 0}`));\n });\n }\n });\n\n this.decodeAudioPromiseMap[name] = promise;\n return promise;\n }\n}\n\nexport default SoundSystem;\n","/** Auto-generated by scripts/build-package.mjs — do not edit. */\n\nimport SoundSystem from './SoundSystem';\n\nObject.assign(SoundSystem, {\n packageName: \"@combos-fun/plugin-sound\",\n packageVersion: \"0.0.48\",\n});\n","import { Component } from '@combos-fun/engine';\nimport { Field } from '@combos-fun/inspector-decorator';\n\nexport interface SoundParams {\n resource: string;\n autoplay?: boolean;\n muted?: boolean;\n volume?: number;\n loop?: boolean;\n seek?: number;\n duration?: number;\n onEnd?: () => void;\n}\n\nclass Sound extends Component<SoundParams> {\n static componentName = 'Sound';\n\n systemContext: AudioContext;\n\n systemDestination: GainNode;\n\n playing: boolean;\n\n state: 'unloaded' | 'loading' | 'loaded' = 'unloaded';\n\n config: SoundParams = {\n resource: '',\n autoplay: false,\n muted: false,\n volume: 1,\n loop: false,\n seek: 0,\n };\n\n private buffer: AudioBuffer;\n\n private sourceNode: AudioBufferSourceNode;\n\n private gainNode: GainNode;\n\n private paused: boolean;\n\n private playTime: number = 0;\n\n private startTime: number = 0;\n\n private duration: number = 0;\n\n private actionQueue: (() => void)[] = [];\n\n private endedListener: () => void;\n\n @Field({\n type: 'boolean',\n group: 'Sound',\n label: 'Muted',\n description: 'Silence this sound without changing its volume setting.',\n editor: 'toggle',\n })\n get muted(): boolean {\n return this.config.muted ?? false;\n }\n\n set muted(v: boolean) {\n this.config.muted = v;\n this.applyGain();\n }\n\n @Field({\n type: 'number',\n min: 0,\n max: 1,\n step: 0.01,\n group: 'Sound',\n label: 'Volume',\n description: 'Loudness of this sound from 0 (silent) to 1 (full).',\n editor: 'volume-slider',\n })\n get volume(): number {\n return this.config.volume ?? 1;\n }\n\n set volume(v: number) {\n if (typeof v !== 'number' || v < 0 || v > 1) {\n return;\n }\n this.config.volume = v;\n this.applyGain();\n }\n\n @Field({\n type: 'boolean',\n group: 'Sound',\n label: 'Loop',\n description: 'Replay the sound continuously when it reaches the end.',\n editor: 'toggle',\n })\n get loop(): boolean {\n return this.config.loop ?? false;\n }\n\n set loop(v: boolean) {\n this.config.loop = v;\n if (this.sourceNode) {\n this.sourceNode.loop = v;\n }\n }\n\n @Field({\n type: 'boolean',\n group: 'Sound',\n label: 'Autoplay',\n description: 'Start playing automatically once the audio has loaded.',\n editor: 'toggle',\n })\n get autoplay(): boolean {\n return this.config.autoplay ?? false;\n }\n\n set autoplay(v: boolean) {\n this.config.autoplay = v;\n }\n\n @Field({\n type: 'string',\n group: 'Sound',\n label: 'Resource',\n description: 'Audio resource id used by the sound system.',\n editor: 'text',\n })\n get resource(): string {\n return this.config.resource ?? '';\n }\n\n set resource(v: string) {\n this.config.resource = v;\n }\n\n /**\n * Apply the effective gain (`muted ? 0 : volume`) to the gain node.\n *\n * `config` is the source of truth and the gain is assigned via `gain.value`\n * (updates the AudioParam intrinsic value synchronously) so the `muted` /\n * `volume` getters — and anything reading them back, e.g. the scene-edit\n * volume slider — reflect the change immediately. `setValueAtTime` only\n * schedules on the automation timeline and leaves `.value` stale.\n */\n private applyGain() {\n if (!this.gainNode) {\n return;\n }\n this.gainNode.gain.value = this.config.muted ? 0 : (this.config.volume ?? 1);\n }\n\n init(obj?: SoundParams) {\n if (!obj) {\n return;\n }\n\n Object.assign(this.config, obj);\n if (this.config.autoplay) {\n this.actionQueue.push(this.play.bind(this));\n }\n }\n\n play() {\n if (this.state !== 'loaded') {\n this.actionQueue.push(this.play.bind(this));\n }\n this.destroySource();\n this.createSource();\n\n if (!this.sourceNode) {\n return;\n }\n const when = this.systemContext.currentTime;\n const offset = this.config.seek;\n const duration = this.config.duration;\n\n this.sourceNode.start(0, offset, duration);\n\n this.startTime = when;\n this.playTime = when - offset;\n this.paused = false;\n this.playing = true;\n this.resetConfig();\n this.endedListener = () => {\n if (!this.sourceNode) {\n return;\n }\n if (this.config.onEnd) {\n this.config.onEnd();\n }\n // Release resources once non-interactive playback finishes.\n if (this.playing) {\n this.destroySource();\n }\n };\n this.sourceNode.addEventListener('ended', this.endedListener);\n }\n\n pause() {\n if (this.state !== 'loaded') {\n this.actionQueue.push(this.pause.bind(this));\n }\n if (this.paused || !this.playing) {\n return;\n }\n this.paused = true;\n this.playing = false;\n this.config.seek = this.getCurrentTime();\n this.destroySource();\n }\n\n stop() {\n if (this.state !== 'loaded') {\n this.actionQueue.push(this.stop.bind(this));\n }\n if (!this.paused && !this.playing) {\n return;\n }\n this.playing = false;\n this.paused = false;\n this.destroySource();\n this.resetConfig();\n }\n\n onload(buffer: AudioBuffer) {\n this.state = 'loaded';\n this.buffer = buffer;\n this.duration = this.buffer.duration;\n this.actionQueue.forEach(action => action());\n this.actionQueue.length = 0;\n }\n\n onDestroy() {\n this.actionQueue.length = 0;\n this.destroySource();\n }\n\n private resetConfig() {\n this.config.seek = 0;\n }\n\n private getCurrentTime() {\n if (this.config.loop && this.duration > 0) {\n return (this.systemContext.currentTime - this.playTime) % this.duration;\n }\n\n return this.systemContext.currentTime - this.playTime;\n }\n\n private createSource() {\n if (!this.systemContext || this.state !== 'loaded') {\n return;\n }\n this.sourceNode = this.systemContext.createBufferSource();\n this.sourceNode.buffer = this.buffer;\n this.sourceNode.loop = this.config.loop;\n\n if (!this.gainNode) {\n this.gainNode = this.systemContext.createGain();\n this.gainNode.connect(this.systemDestination);\n Object.assign(this, this.config);\n }\n this.sourceNode.connect(this.gainNode);\n }\n\n private destroySource() {\n if (!this.sourceNode) return;\n this.sourceNode.removeEventListener('ended', this.endedListener);\n this.sourceNode.stop();\n this.sourceNode.disconnect();\n this.sourceNode = null;\n\n this.startTime = 0;\n this.playTime = 0;\n this.playing = false;\n }\n}\n\nexport default Sound;\n"],"names":["SoundSystem","System","mergeAllowedMessageOrigins","isAllowedMessageOrigin","OBSERVER_TYPE","resource","__decorate","decorators","Component","Field"],"mappings":";;;;;;AAAA;AACO,MAAM,iCAAiC,GAC5C;AAEF;AACO,MAAM,qCAAqC,GAChD;AAYI,SAAU,oBAAoB,CAAC,IAAa,EAAA;AAChD,IAAA,IAAI,CAAC,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ;AAAE,QAAA,OAAO,IAAI;IAClD,MAAM,CAAC,GAAG,IAA2C;AACrD,IAAA,IAAI,CAAC,CAAC,IAAI,KAAK,iCAAiC;AAAE,QAAA,OAAO,IAAI;AAC7D,IAAA,IAAI,OAAO,CAAC,CAAC,KAAK,KAAK,SAAS;AAAE,QAAA,OAAO,IAAI;IAC7C,OAAO,CAAC,CAAC,KAAK;AAChB;AAEM,SAAU,wBAAwB,CAAC,KAAY,EAAA;AACnD,IAAA,MAAM,CAAC,GAAI,KAA0C,CAAC,MAAM;AAC5D,IAAA,IAAI,CAAC,CAAC,IAAI,OAAO,CAAC,KAAK,QAAQ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AAA;AAaDH,gBAAA,CAAA;AAPC,IAAAG,wBAAK,CAAC;AACL,QAAA,IAAI,EAAE,QAAQ;AACd,QAAA,KAAK,EAAE,OAAO;AACd,QAAA,KAAK,EAAE,UAAU;AACjB,QAAA,WAAW,EAAE,6CAA6C;AAC1D,QAAA,MAAM,EAAE,MAAM;KACf;AAGA,CAAA,EAAA,KAAA,CAAA,SAAA,EAAA,UAAA,EAAA,IAAA,CAAA;;;;;;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var t=require("tslib"),e=require("@combos-fun/engine"),o=require("@combos-fun/inspector-decorator");
|
|
1
|
+
"use strict";var t=require("tslib"),e=require("@combos-fun/engine"),o=require("@combos-fun/inspector-decorator");const s="combos-development-tool:set-muted",i="combos-development-tool:state-changed";function n(t){if(!t||"object"!=typeof t)return null;const e=t;return e.type!==s||"boolean"!=typeof e.muted?null:e.muted}function u(t,e,o){const s={muted:t};!function(t,e){if("undefined"!=typeof window&&window.parent&&window.parent!==window)try{window.parent.postMessage(t,e)}catch{}}({type:i,...s},e),o?.(i,s)}let d=class extends e.System{static{this.systemName="SoundSystem"}get muted(){return this._muted}set muted(t){this.setMuted(t)}get volume(){return this._volume}set volume(t){"number"!=typeof t||t<0||t>1||(this._volume=t,this.applyGain())}applyGain(){this.gainNode&&(this.gainNode.gain.value=this._muted?0:this._volume)}get audioLocked(){return!this.ctx||"running"!==this.ctx.state}constructor(t){super(),this.autoPauseAndStart=!0,this.components=[],this.pausedComponents=[],this.audioBufferCache={},this.decodeAudioPromiseMap={},this._muted=!1,this._volume=1,this.postMessageOrigin="*",this.allowedMessageOrigins=e.mergeAllowedMessageOrigins(),this.hostMuteBound=!1,this.onWindowSetMuted=t=>{const e=function(t){const e=t.detail;return e&&"object"==typeof e&&"boolean"==typeof e.muted?e.muted:null}(t);null!==e&&this.setMuted(e)},this.onGameSetMuted=t=>{t&&"boolean"==typeof t.muted&&this.setMuted(t.muted)},this.onWindowMessage=t=>{if(!e.isAllowedMessageOrigin(t.origin,this.allowedMessageOrigins))return;const o=n(t.data);null!==o&&this.setMuted(o)},t&&("boolean"==typeof t.autoPauseAndStart&&(this.autoPauseAndStart=t.autoPauseAndStart),t.onError&&(this.onError=t.onError))}setMuted(t){const e=!!t;this._muted!==e&&(this._muted=e,this.applyGain(),this.postMuteStateChanged())}resumeAll(){const t=()=>{this.pausedComponents.forEach(t=>{t.play()}),this.pausedComponents=[]};this.ctx.resume().then(t,t)}pauseAll(){this.components.forEach(t=>{t.playing&&(this.pausedComponents.push(t),t.pause())}),this.ctx.suspend().then()}stopAll(){this.components.forEach(t=>{t.playing&&t.stop()}),this.pausedComponents=[],this.ctx.suspend().then()}init(t){this.postMessageOrigin=t?.postMessageOrigin??this.game?.pluginInitNotifyTargetOrigin??"*",this.allowedMessageOrigins=e.mergeAllowedMessageOrigins(t?.allowedMessageOrigins),this.bindHostMute(),this.setupAudioContext()}update(){const t=this.componentObserver.clear();for(const e of t)this.componentChanged(e)}onResume(){this.autoPauseAndStart&&this.resumeAll()}onPause(){this.autoPauseAndStart&&this.pauseAll()}onDestroy(){this.unbindHostMute(),this.components.forEach(t=>{t.onDestroy()}),this.components=[],this.ctx&&(this.gainNode.disconnect(),this.gainNode=null,this.ctx.close(),this.ctx=null)}bindHostMute(){this.hostMuteBound||(this.hostMuteBound=!0,"undefined"!=typeof window&&(window.addEventListener(s,this.onWindowSetMuted),window.addEventListener("message",this.onWindowMessage)),this.game.on(s,this.onGameSetMuted))}unbindHostMute(){this.hostMuteBound&&(this.hostMuteBound=!1,"undefined"!=typeof window&&(window.removeEventListener(s,this.onWindowSetMuted),window.removeEventListener("message",this.onWindowMessage)),this.game?.off(s,this.onGameSetMuted))}postMuteStateChanged(){u(this._muted,this.postMessageOrigin,(t,e)=>{this.game?.emit(t,e)})}async componentChanged(t){"Sound"===t.componentName&&t.type===e.OBSERVER_TYPE.ADD&&this.add(t)}setupAudioContext(){try{const t=window.AudioContext||window.webkitAudioContext;this.ctx=new t}catch(t){console.error(t),this.onError&&this.onError(t)}this.ctx&&(this.gainNode=void 0===this.ctx.createGain?this.ctx.createGainNode():this.ctx.createGain(),this.applyGain(),this.gainNode.connect(this.ctx.destination),this.unlockAudio())}unlockAudio(){if(!this.ctx||!this.audioLocked)return;const t=()=>{if(this.ctx){const e=()=>{document.body.removeEventListener("touchstart",t),document.body.removeEventListener("touchend",t),document.body.removeEventListener("click",t)};this.ctx.resume().then(e,e)}};document.body.addEventListener("touchstart",t),document.body.addEventListener("touchend",t),document.body.addEventListener("click",t)}async add(t){const o=t.component;this.components.push(o);try{const{config:t}=o;o.state="loading";const s=await e.resource.getResource(t.resource);!this.audioBufferCache[s.name]&&s?.data?.audio&&(this.audioBufferCache[s.name]=await this.decodeAudioData(s.data.audio,s.name)),this.audioBufferCache[s.name]&&(o.systemContext=this.ctx,o.systemDestination=this.gainNode,o.onload(this.audioBufferCache[s.name]))}catch(t){this.onError&&this.onError(t)}}decodeAudioData(t,e){if(this.decodeAudioPromiseMap[e])return this.decodeAudioPromiseMap[e];const o=new Promise((o,s)=>{this.ctx||s(new Error("No audio support"));const i=this.ctx.decodeAudioData(t,t=>{this.decodeAudioPromiseMap[e]&&delete this.decodeAudioPromiseMap[e],t?o(t):s(new Error(`Error decoding audio ${e}`))},o=>{this.decodeAudioPromiseMap[e]&&delete this.decodeAudioPromiseMap[e],s(new Error(`${o}. arrayBuffer byteLength: ${t?t.byteLength:0}`))});i instanceof Promise&&i.catch(e=>{s(new Error(`catch ${e}, arrayBuffer byteLength: ${t?t.byteLength:0}`))})});return this.decodeAudioPromiseMap[e]=o,o}};d=t.__decorate([e.decorators.componentObserver({Sound:[]})],d);var a=d;Object.assign(a,{packageName:"@combos-fun/plugin-sound",packageVersion:"0.0.48"});class r extends e.Component{constructor(){super(...arguments),this.state="unloaded",this.config={resource:"",autoplay:!1,muted:!1,volume:1,loop:!1,seek:0},this.playTime=0,this.startTime=0,this.duration=0,this.actionQueue=[]}static{this.componentName="Sound"}get muted(){return this.config.muted??!1}set muted(t){this.config.muted=t,this.applyGain()}get volume(){return this.config.volume??1}set volume(t){"number"!=typeof t||t<0||t>1||(this.config.volume=t,this.applyGain())}get loop(){return this.config.loop??!1}set loop(t){this.config.loop=t,this.sourceNode&&(this.sourceNode.loop=t)}get autoplay(){return this.config.autoplay??!1}set autoplay(t){this.config.autoplay=t}get resource(){return this.config.resource??""}set resource(t){this.config.resource=t}applyGain(){this.gainNode&&(this.gainNode.gain.value=this.config.muted?0:this.config.volume??1)}init(t){t&&(Object.assign(this.config,t),this.config.autoplay&&this.actionQueue.push(this.play.bind(this)))}play(){if("loaded"!==this.state&&this.actionQueue.push(this.play.bind(this)),this.destroySource(),this.createSource(),!this.sourceNode)return;const t=this.systemContext.currentTime,e=this.config.seek,o=this.config.duration;this.sourceNode.start(0,e,o),this.startTime=t,this.playTime=t-e,this.paused=!1,this.playing=!0,this.resetConfig(),this.endedListener=()=>{this.sourceNode&&(this.config.onEnd&&this.config.onEnd(),this.playing&&this.destroySource())},this.sourceNode.addEventListener("ended",this.endedListener)}pause(){"loaded"!==this.state&&this.actionQueue.push(this.pause.bind(this)),!this.paused&&this.playing&&(this.paused=!0,this.playing=!1,this.config.seek=this.getCurrentTime(),this.destroySource())}stop(){"loaded"!==this.state&&this.actionQueue.push(this.stop.bind(this)),(this.paused||this.playing)&&(this.playing=!1,this.paused=!1,this.destroySource(),this.resetConfig())}onload(t){this.state="loaded",this.buffer=t,this.duration=this.buffer.duration,this.actionQueue.forEach(t=>t()),this.actionQueue.length=0}onDestroy(){this.actionQueue.length=0,this.destroySource()}resetConfig(){this.config.seek=0}getCurrentTime(){return this.config.loop&&this.duration>0?(this.systemContext.currentTime-this.playTime)%this.duration:this.systemContext.currentTime-this.playTime}createSource(){this.systemContext&&"loaded"===this.state&&(this.sourceNode=this.systemContext.createBufferSource(),this.sourceNode.buffer=this.buffer,this.sourceNode.loop=this.config.loop,this.gainNode||(this.gainNode=this.systemContext.createGain(),this.gainNode.connect(this.systemDestination),Object.assign(this,this.config)),this.sourceNode.connect(this.gainNode))}destroySource(){this.sourceNode&&(this.sourceNode.removeEventListener("ended",this.endedListener),this.sourceNode.stop(),this.sourceNode.disconnect(),this.sourceNode=null,this.startTime=0,this.playTime=0,this.playing=!1)}}t.__decorate([o.Field({type:"boolean",group:"Sound",label:"Muted",description:"Silence this sound without changing its volume setting.",editor:"toggle"})],r.prototype,"muted",null),t.__decorate([o.Field({type:"number",min:0,max:1,step:.01,group:"Sound",label:"Volume",description:"Loudness of this sound from 0 (silent) to 1 (full).",editor:"volume-slider"})],r.prototype,"volume",null),t.__decorate([o.Field({type:"boolean",group:"Sound",label:"Loop",description:"Replay the sound continuously when it reaches the end.",editor:"toggle"})],r.prototype,"loop",null),t.__decorate([o.Field({type:"boolean",group:"Sound",label:"Autoplay",description:"Start playing automatically once the audio has loaded.",editor:"toggle"})],r.prototype,"autoplay",null),t.__decorate([o.Field({type:"string",group:"Sound",label:"Resource",description:"Audio resource id used by the sound system.",editor:"text"})],r.prototype,"resource",null),exports.COMBOS_DEVELOPMENT_TOOL_SET_MUTED=s,exports.COMBOS_DEVELOPMENT_TOOL_STATE_CHANGED=i,exports.Sound=r,exports.SoundSystem=a,exports.parseSetMutedMessage=n,exports.postParentSoundMuted=u;
|
package/dist/plugin-sound.d.ts
CHANGED
|
@@ -3,6 +3,13 @@ import { System, ComponentChanged, Component } from '@combos-fun/engine';
|
|
|
3
3
|
interface SoundSystemParams {
|
|
4
4
|
autoPauseAndStart?: boolean;
|
|
5
5
|
onError?: (error: any) => void;
|
|
6
|
+
/** postMessage `targetOrigin` when notifying parent (default: Game `pluginInitNotifyTargetOrigin` or `'*'`). */
|
|
7
|
+
postMessageOrigin?: string;
|
|
8
|
+
/**
|
|
9
|
+
* Extra inbound `postMessage` origins merged with engine defaults (`knoffice.tech`, `converge.ai`).
|
|
10
|
+
* Each entry is a host suffix (e.g. `localhost`) or a full origin. Pass `['*']` to accept any origin.
|
|
11
|
+
*/
|
|
12
|
+
allowedMessageOrigins?: string[];
|
|
6
13
|
}
|
|
7
14
|
declare class SoundSystem extends System {
|
|
8
15
|
static systemName: string;
|
|
@@ -18,6 +25,9 @@ declare class SoundSystem extends System {
|
|
|
18
25
|
/** Desired mute/volume are the source of truth; the gain node is derived. */
|
|
19
26
|
private _muted;
|
|
20
27
|
private _volume;
|
|
28
|
+
private postMessageOrigin;
|
|
29
|
+
private allowedMessageOrigins;
|
|
30
|
+
private hostMuteBound;
|
|
21
31
|
get muted(): boolean;
|
|
22
32
|
set muted(v: boolean);
|
|
23
33
|
get volume(): number;
|
|
@@ -34,6 +44,11 @@ declare class SoundSystem extends System {
|
|
|
34
44
|
private applyGain;
|
|
35
45
|
get audioLocked(): boolean;
|
|
36
46
|
constructor(obj?: SoundSystemParams);
|
|
47
|
+
/**
|
|
48
|
+
* Mute or unmute the master gain and notify the embedding host.
|
|
49
|
+
* Same effect as `postMessage({ type: 'combos-development-tool:set-muted', muted })`.
|
|
50
|
+
*/
|
|
51
|
+
setMuted(muted: boolean): void;
|
|
37
52
|
/**
|
|
38
53
|
* Resume playback of all paused audio.
|
|
39
54
|
*/
|
|
@@ -49,7 +64,7 @@ declare class SoundSystem extends System {
|
|
|
49
64
|
/**
|
|
50
65
|
* System init: configure params before the game starts.
|
|
51
66
|
*/
|
|
52
|
-
init(): void;
|
|
67
|
+
init(params?: SoundSystemParams): void;
|
|
53
68
|
update(): void;
|
|
54
69
|
/**
|
|
55
70
|
* Called when the game starts or resumes playing after a pause.
|
|
@@ -63,6 +78,12 @@ declare class SoundSystem extends System {
|
|
|
63
78
|
* Called when the system is destroyed.
|
|
64
79
|
*/
|
|
65
80
|
onDestroy(): void;
|
|
81
|
+
private readonly onWindowSetMuted;
|
|
82
|
+
private readonly onGameSetMuted;
|
|
83
|
+
private readonly onWindowMessage;
|
|
84
|
+
private bindHostMute;
|
|
85
|
+
private unbindHostMute;
|
|
86
|
+
private postMuteStateChanged;
|
|
66
87
|
componentChanged(changed: ComponentChanged): Promise<void>;
|
|
67
88
|
private setupAudioContext;
|
|
68
89
|
private unlockAudio;
|
|
@@ -128,4 +149,23 @@ declare class Sound extends Component<SoundParams> {
|
|
|
128
149
|
private destroySource;
|
|
129
150
|
}
|
|
130
151
|
|
|
131
|
-
|
|
152
|
+
/** Parent → iframe (also `window` CustomEvent / `game.emit`): mute or unmute. Payload: `{ muted: boolean }`. */
|
|
153
|
+
declare const COMBOS_DEVELOPMENT_TOOL_SET_MUTED: "combos-development-tool:set-muted";
|
|
154
|
+
/** iframe → parent (and `game.emit`): current mute snapshot after a successful change. */
|
|
155
|
+
declare const COMBOS_DEVELOPMENT_TOOL_STATE_CHANGED: "combos-development-tool:state-changed";
|
|
156
|
+
interface CombosSoundSetMutedMessage {
|
|
157
|
+
type: typeof COMBOS_DEVELOPMENT_TOOL_SET_MUTED;
|
|
158
|
+
muted: boolean;
|
|
159
|
+
}
|
|
160
|
+
interface CombosSoundStateChangedMessage {
|
|
161
|
+
type: typeof COMBOS_DEVELOPMENT_TOOL_STATE_CHANGED;
|
|
162
|
+
muted: boolean;
|
|
163
|
+
}
|
|
164
|
+
declare function parseSetMutedMessage(data: unknown): boolean | null;
|
|
165
|
+
/** Notifies the embedding page (and `game.emit`) of the current mute flag. */
|
|
166
|
+
declare function postParentSoundMuted(muted: boolean, targetOrigin: string, emit?: (type: string, payload: {
|
|
167
|
+
muted: boolean;
|
|
168
|
+
}) => void): void;
|
|
169
|
+
|
|
170
|
+
export { COMBOS_DEVELOPMENT_TOOL_SET_MUTED, COMBOS_DEVELOPMENT_TOOL_STATE_CHANGED, Sound, SoundSystem, parseSetMutedMessage, postParentSoundMuted };
|
|
171
|
+
export type { CombosSoundSetMutedMessage, CombosSoundStateChangedMessage };
|
package/dist/plugin-sound.esm.js
CHANGED
|
@@ -1,15 +1,53 @@
|
|
|
1
1
|
import { __decorate } from 'tslib';
|
|
2
|
-
import { System, OBSERVER_TYPE, resource, decorators, Component } from '@combos-fun/engine';
|
|
2
|
+
import { System, mergeAllowedMessageOrigins, isAllowedMessageOrigin, OBSERVER_TYPE, resource, decorators, Component } from '@combos-fun/engine';
|
|
3
3
|
import { Field } from '@combos-fun/inspector-decorator';
|
|
4
4
|
|
|
5
|
+
/** Parent → iframe (also `window` CustomEvent / `game.emit`): mute or unmute. Payload: `{ muted: boolean }`. */
|
|
6
|
+
const COMBOS_DEVELOPMENT_TOOL_SET_MUTED = 'combos-development-tool:set-muted';
|
|
7
|
+
/** iframe → parent (and `game.emit`): current mute snapshot after a successful change. */
|
|
8
|
+
const COMBOS_DEVELOPMENT_TOOL_STATE_CHANGED = 'combos-development-tool:state-changed';
|
|
9
|
+
function parseSetMutedMessage(data) {
|
|
10
|
+
if (!data || typeof data !== 'object')
|
|
11
|
+
return null;
|
|
12
|
+
const d = data;
|
|
13
|
+
if (d.type !== COMBOS_DEVELOPMENT_TOOL_SET_MUTED)
|
|
14
|
+
return null;
|
|
15
|
+
if (typeof d.muted !== 'boolean')
|
|
16
|
+
return null;
|
|
17
|
+
return d.muted;
|
|
18
|
+
}
|
|
19
|
+
function parseSetMutedCustomEvent(event) {
|
|
20
|
+
const d = event.detail;
|
|
21
|
+
if (!d || typeof d !== 'object' || typeof d.muted !== 'boolean')
|
|
22
|
+
return null;
|
|
23
|
+
return d.muted;
|
|
24
|
+
}
|
|
25
|
+
function postToParent(payload, targetOrigin) {
|
|
26
|
+
if (typeof window === 'undefined')
|
|
27
|
+
return;
|
|
28
|
+
if (!window.parent || window.parent === window)
|
|
29
|
+
return;
|
|
30
|
+
try {
|
|
31
|
+
window.parent.postMessage(payload, targetOrigin);
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
/* ignore cross-origin or detached frame */
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/** Notifies the embedding page (and `game.emit`) of the current mute flag. */
|
|
38
|
+
function postParentSoundMuted(muted, targetOrigin, emit) {
|
|
39
|
+
const state = { muted };
|
|
40
|
+
postToParent({ type: COMBOS_DEVELOPMENT_TOOL_STATE_CHANGED, ...state }, targetOrigin);
|
|
41
|
+
emit?.(COMBOS_DEVELOPMENT_TOOL_STATE_CHANGED, state);
|
|
42
|
+
}
|
|
43
|
+
|
|
5
44
|
let SoundSystem = class SoundSystem extends System {
|
|
6
45
|
static { this.systemName = 'SoundSystem'; }
|
|
7
46
|
get muted() {
|
|
8
47
|
return this._muted;
|
|
9
48
|
}
|
|
10
49
|
set muted(v) {
|
|
11
|
-
this.
|
|
12
|
-
this.applyGain();
|
|
50
|
+
this.setMuted(v);
|
|
13
51
|
}
|
|
14
52
|
get volume() {
|
|
15
53
|
return this._volume;
|
|
@@ -53,7 +91,50 @@ let SoundSystem = class SoundSystem extends System {
|
|
|
53
91
|
/** Desired mute/volume are the source of truth; the gain node is derived. */
|
|
54
92
|
this._muted = false;
|
|
55
93
|
this._volume = 1;
|
|
56
|
-
|
|
94
|
+
this.postMessageOrigin = '*';
|
|
95
|
+
this.allowedMessageOrigins = mergeAllowedMessageOrigins();
|
|
96
|
+
this.hostMuteBound = false;
|
|
97
|
+
this.onWindowSetMuted = (e) => {
|
|
98
|
+
const muted = parseSetMutedCustomEvent(e);
|
|
99
|
+
if (muted === null)
|
|
100
|
+
return;
|
|
101
|
+
this.setMuted(muted);
|
|
102
|
+
};
|
|
103
|
+
this.onGameSetMuted = (payload) => {
|
|
104
|
+
if (payload && typeof payload.muted === 'boolean') {
|
|
105
|
+
this.setMuted(payload.muted);
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
this.onWindowMessage = (e) => {
|
|
109
|
+
if (!isAllowedMessageOrigin(e.origin, this.allowedMessageOrigins)) {
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
const muted = parseSetMutedMessage(e.data);
|
|
113
|
+
if (muted === null)
|
|
114
|
+
return;
|
|
115
|
+
this.setMuted(muted);
|
|
116
|
+
};
|
|
117
|
+
if (!obj)
|
|
118
|
+
return;
|
|
119
|
+
if (typeof obj.autoPauseAndStart === 'boolean') {
|
|
120
|
+
this.autoPauseAndStart = obj.autoPauseAndStart;
|
|
121
|
+
}
|
|
122
|
+
if (obj.onError) {
|
|
123
|
+
this.onError = obj.onError;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Mute or unmute the master gain and notify the embedding host.
|
|
128
|
+
* Same effect as `postMessage({ type: 'combos-development-tool:set-muted', muted })`.
|
|
129
|
+
*/
|
|
130
|
+
setMuted(muted) {
|
|
131
|
+
const next = !!muted;
|
|
132
|
+
if (this._muted === next) {
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
this._muted = next;
|
|
136
|
+
this.applyGain();
|
|
137
|
+
this.postMuteStateChanged();
|
|
57
138
|
}
|
|
58
139
|
/**
|
|
59
140
|
* Resume playback of all paused audio.
|
|
@@ -96,7 +177,11 @@ let SoundSystem = class SoundSystem extends System {
|
|
|
96
177
|
/**
|
|
97
178
|
* System init: configure params before the game starts.
|
|
98
179
|
*/
|
|
99
|
-
init() {
|
|
180
|
+
init(params) {
|
|
181
|
+
this.postMessageOrigin =
|
|
182
|
+
params?.postMessageOrigin ?? this.game?.pluginInitNotifyTargetOrigin ?? '*';
|
|
183
|
+
this.allowedMessageOrigins = mergeAllowedMessageOrigins(params?.allowedMessageOrigins);
|
|
184
|
+
this.bindHostMute();
|
|
100
185
|
this.setupAudioContext();
|
|
101
186
|
}
|
|
102
187
|
update() {
|
|
@@ -127,6 +212,7 @@ let SoundSystem = class SoundSystem extends System {
|
|
|
127
212
|
* Called when the system is destroyed.
|
|
128
213
|
*/
|
|
129
214
|
onDestroy() {
|
|
215
|
+
this.unbindHostMute();
|
|
130
216
|
this.components.forEach(component => {
|
|
131
217
|
component.onDestroy();
|
|
132
218
|
});
|
|
@@ -138,6 +224,31 @@ let SoundSystem = class SoundSystem extends System {
|
|
|
138
224
|
this.ctx = null;
|
|
139
225
|
}
|
|
140
226
|
}
|
|
227
|
+
bindHostMute() {
|
|
228
|
+
if (this.hostMuteBound)
|
|
229
|
+
return;
|
|
230
|
+
this.hostMuteBound = true;
|
|
231
|
+
if (typeof window !== 'undefined') {
|
|
232
|
+
window.addEventListener(COMBOS_DEVELOPMENT_TOOL_SET_MUTED, this.onWindowSetMuted);
|
|
233
|
+
window.addEventListener('message', this.onWindowMessage);
|
|
234
|
+
}
|
|
235
|
+
this.game.on(COMBOS_DEVELOPMENT_TOOL_SET_MUTED, this.onGameSetMuted);
|
|
236
|
+
}
|
|
237
|
+
unbindHostMute() {
|
|
238
|
+
if (!this.hostMuteBound)
|
|
239
|
+
return;
|
|
240
|
+
this.hostMuteBound = false;
|
|
241
|
+
if (typeof window !== 'undefined') {
|
|
242
|
+
window.removeEventListener(COMBOS_DEVELOPMENT_TOOL_SET_MUTED, this.onWindowSetMuted);
|
|
243
|
+
window.removeEventListener('message', this.onWindowMessage);
|
|
244
|
+
}
|
|
245
|
+
this.game?.off(COMBOS_DEVELOPMENT_TOOL_SET_MUTED, this.onGameSetMuted);
|
|
246
|
+
}
|
|
247
|
+
postMuteStateChanged() {
|
|
248
|
+
postParentSoundMuted(this._muted, this.postMessageOrigin, (type, payload) => {
|
|
249
|
+
this.game?.emit(type, payload);
|
|
250
|
+
});
|
|
251
|
+
}
|
|
141
252
|
async componentChanged(changed) {
|
|
142
253
|
if (changed.componentName !== 'Sound')
|
|
143
254
|
return;
|
|
@@ -251,7 +362,7 @@ var SoundSystem$1 = SoundSystem;
|
|
|
251
362
|
/** Auto-generated by scripts/build-package.mjs — do not edit. */
|
|
252
363
|
Object.assign(SoundSystem$1, {
|
|
253
364
|
packageName: "@combos-fun/plugin-sound",
|
|
254
|
-
packageVersion: "0.0.
|
|
365
|
+
packageVersion: "0.0.48",
|
|
255
366
|
});
|
|
256
367
|
|
|
257
368
|
class Sound extends Component {
|
|
@@ -485,5 +596,5 @@ __decorate([
|
|
|
485
596
|
})
|
|
486
597
|
], Sound.prototype, "resource", null);
|
|
487
598
|
|
|
488
|
-
export { Sound, SoundSystem$1 as SoundSystem };
|
|
599
|
+
export { COMBOS_DEVELOPMENT_TOOL_SET_MUTED, COMBOS_DEVELOPMENT_TOOL_STATE_CHANGED, Sound, SoundSystem$1 as SoundSystem, parseSetMutedMessage, postParentSoundMuted };
|
|
489
600
|
//# sourceMappingURL=plugin-sound.esm.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin-sound.esm.js","sources":["../lib/SoundSystem.ts","../lib/__combosPackageMeta.gen.ts","../lib/Sound.ts"],"sourcesContent":["import { System, decorators, ComponentChanged, OBSERVER_TYPE, resource } from '@combos-fun/engine';\nimport SoundComponent from './Sound';\n\ninterface SoundSystemParams {\n autoPauseAndStart?: boolean;\n onError?: (error: any) => void;\n}\n\n@decorators.componentObserver({\n Sound: [],\n})\nclass SoundSystem extends System {\n static systemName = 'SoundSystem';\n\n private ctx: AudioContext;\n\n private gainNode: GainNode;\n\n /** Whether to pause/resume in sync with the game. */\n private autoPauseAndStart = true;\n\n private onError: (error: any) => void;\n\n private components: SoundComponent[] = [];\n\n private pausedComponents: SoundComponent[] = [];\n\n private audioBufferCache = {};\n\n private decodeAudioPromiseMap = {};\n\n /** Desired mute/volume are the source of truth; the gain node is derived. */\n private _muted = false;\n\n private _volume = 1;\n\n get muted(): boolean {\n return this._muted;\n }\n\n set muted(v: boolean) {\n this._muted = v;\n this.applyGain();\n }\n\n get volume(): number {\n return this._volume;\n }\n\n set volume(v: number) {\n if (typeof v !== 'number' || v < 0 || v > 1) {\n return;\n }\n this._volume = v;\n this.applyGain();\n }\n\n /**\n * Apply the effective gain (`muted ? 0 : volume`) to the gain node.\n *\n * Assigns `gain.value` directly rather than `setValueAtTime`: `.value` updates\n * the AudioParam's intrinsic value synchronously, so the `muted` / `volume`\n * getters reflect the change immediately. `setValueAtTime` only schedules an\n * event on the automation timeline and leaves `.value` stale until the next\n * render quantum, which made `muted` report the pre-change value.\n */\n private applyGain() {\n if (!this.gainNode) {\n return;\n }\n this.gainNode.gain.value = this._muted ? 0 : this._volume;\n }\n\n get audioLocked(): boolean {\n if (!this.ctx) {\n return true;\n }\n return this.ctx.state !== 'running';\n }\n\n constructor(obj?: SoundSystemParams) {\n super();\n Object.assign(this, obj);\n }\n\n /**\n * Resume playback of all paused audio.\n */\n resumeAll() {\n const handleResume = () => {\n this.pausedComponents.forEach(component => {\n component.play();\n });\n // Clear the previously cached paused list.\n this.pausedComponents = [];\n };\n this.ctx.resume().then(handleResume, handleResume);\n }\n\n /**\n * Pause all currently playing audio.\n */\n pauseAll() {\n this.components.forEach(component => {\n if (component.playing) {\n this.pausedComponents.push(component);\n component.pause();\n }\n });\n this.ctx.suspend().then();\n }\n\n /**\n * Stop all currently playing audio.\n */\n stopAll() {\n this.components.forEach(component => {\n if (component.playing) {\n component.stop();\n }\n });\n // Clear the previously cached paused list.\n this.pausedComponents = [];\n this.ctx.suspend().then();\n }\n\n /**\n * System init: configure params before the game starts.\n */\n init() {\n this.setupAudioContext();\n }\n\n update() {\n const changes = this.componentObserver.clear();\n for (const changed of changes) {\n this.componentChanged(changed);\n }\n }\n\n /**\n * Called when the game starts or resumes playing after a pause.\n */\n onResume() {\n if (!this.autoPauseAndStart) {\n return;\n }\n this.resumeAll();\n }\n\n /**\n * Called when the game is paused.\n */\n onPause() {\n if (!this.autoPauseAndStart) {\n return;\n }\n this.pauseAll();\n }\n\n /**\n * Called when the system is destroyed.\n */\n onDestroy() {\n this.components.forEach(component => {\n component.onDestroy();\n });\n this.components = [];\n if (this.ctx) {\n this.gainNode.disconnect();\n this.gainNode = null;\n this.ctx.close();\n this.ctx = null;\n }\n }\n\n async componentChanged(changed: ComponentChanged) {\n if (changed.componentName !== 'Sound') return;\n\n if (changed.type === OBSERVER_TYPE.ADD) {\n this.add(changed);\n }\n }\n\n private setupAudioContext() {\n try {\n const AudioContext = window.AudioContext || (window as any).webkitAudioContext;\n this.ctx = new AudioContext();\n } catch (error) {\n console.error(error);\n if (this.onError) {\n this.onError(error);\n }\n }\n\n if (!this.ctx) {\n return;\n }\n this.gainNode =\n typeof this.ctx.createGain === 'undefined' ? (this.ctx as any).createGainNode() : this.ctx.createGain();\n this.applyGain();\n this.gainNode.connect(this.ctx.destination);\n this.unlockAudio();\n }\n\n private unlockAudio() {\n if (!this.ctx || !this.audioLocked) {\n return;\n }\n\n const unlock = () => {\n if (this.ctx) {\n const removeListenerFn = () => {\n document.body.removeEventListener('touchstart', unlock);\n document.body.removeEventListener('touchend', unlock);\n document.body.removeEventListener('click', unlock);\n };\n this.ctx.resume().then(removeListenerFn, removeListenerFn);\n }\n };\n document.body.addEventListener('touchstart', unlock);\n document.body.addEventListener('touchend', unlock);\n document.body.addEventListener('click', unlock);\n }\n\n private async add(changed: ComponentChanged) {\n const component = changed.component as SoundComponent;\n this.components.push(component);\n try {\n const { config } = component;\n component.state = 'loading';\n\n const audio = await resource.getResource(config.resource);\n if (!this.audioBufferCache[audio.name] && audio?.data?.audio) {\n this.audioBufferCache[audio.name] = await this.decodeAudioData(audio.data.audio, audio.name);\n }\n if (this.audioBufferCache[audio.name]) {\n component.systemContext = this.ctx;\n component.systemDestination = this.gainNode;\n component.onload(this.audioBufferCache[audio.name]);\n }\n } catch (error) {\n if (this.onError) {\n this.onError(error);\n }\n }\n }\n\n private decodeAudioData(arraybuffer: ArrayBuffer, name: string) {\n if (this.decodeAudioPromiseMap[name]) {\n return this.decodeAudioPromiseMap[name];\n }\n\n const promise = new Promise<AudioBuffer>((resolve, reject) => {\n if (!this.ctx) {\n reject(new Error('No audio support'));\n }\n\n const success = (decodedData: AudioBuffer) => {\n if (this.decodeAudioPromiseMap[name]) {\n delete this.decodeAudioPromiseMap[name];\n }\n if (decodedData) {\n resolve(decodedData);\n } else {\n reject(new Error(`Error decoding audio ${name}`));\n }\n };\n\n const error = (err: DOMException) => {\n if (this.decodeAudioPromiseMap[name]) {\n delete this.decodeAudioPromiseMap[name];\n }\n reject(new Error(`${err}. arrayBuffer byteLength: ${arraybuffer ? arraybuffer.byteLength : 0}`));\n };\n\n const promise = this.ctx.decodeAudioData(arraybuffer, success, error)\n if (promise instanceof Promise) {\n promise.catch((err) => {\n reject(new Error(`catch ${err}, arrayBuffer byteLength: ${arraybuffer ? arraybuffer.byteLength : 0}`));\n });\n }\n });\n\n this.decodeAudioPromiseMap[name] = promise;\n return promise;\n }\n}\n\nexport default SoundSystem;\n","/** Auto-generated by scripts/build-package.mjs — do not edit. */\n\nimport SoundSystem from './SoundSystem';\n\nObject.assign(SoundSystem, {\n packageName: \"@combos-fun/plugin-sound\",\n packageVersion: \"0.0.46\",\n});\n","import { Component } from '@combos-fun/engine';\nimport { Field } from '@combos-fun/inspector-decorator';\n\nexport interface SoundParams {\n resource: string;\n autoplay?: boolean;\n muted?: boolean;\n volume?: number;\n loop?: boolean;\n seek?: number;\n duration?: number;\n onEnd?: () => void;\n}\n\nclass Sound extends Component<SoundParams> {\n static componentName = 'Sound';\n\n systemContext: AudioContext;\n\n systemDestination: GainNode;\n\n playing: boolean;\n\n state: 'unloaded' | 'loading' | 'loaded' = 'unloaded';\n\n config: SoundParams = {\n resource: '',\n autoplay: false,\n muted: false,\n volume: 1,\n loop: false,\n seek: 0,\n };\n\n private buffer: AudioBuffer;\n\n private sourceNode: AudioBufferSourceNode;\n\n private gainNode: GainNode;\n\n private paused: boolean;\n\n private playTime: number = 0;\n\n private startTime: number = 0;\n\n private duration: number = 0;\n\n private actionQueue: (() => void)[] = [];\n\n private endedListener: () => void;\n\n @Field({\n type: 'boolean',\n group: 'Sound',\n label: 'Muted',\n description: 'Silence this sound without changing its volume setting.',\n editor: 'toggle',\n })\n get muted(): boolean {\n return this.config.muted ?? false;\n }\n\n set muted(v: boolean) {\n this.config.muted = v;\n this.applyGain();\n }\n\n @Field({\n type: 'number',\n min: 0,\n max: 1,\n step: 0.01,\n group: 'Sound',\n label: 'Volume',\n description: 'Loudness of this sound from 0 (silent) to 1 (full).',\n editor: 'volume-slider',\n })\n get volume(): number {\n return this.config.volume ?? 1;\n }\n\n set volume(v: number) {\n if (typeof v !== 'number' || v < 0 || v > 1) {\n return;\n }\n this.config.volume = v;\n this.applyGain();\n }\n\n @Field({\n type: 'boolean',\n group: 'Sound',\n label: 'Loop',\n description: 'Replay the sound continuously when it reaches the end.',\n editor: 'toggle',\n })\n get loop(): boolean {\n return this.config.loop ?? false;\n }\n\n set loop(v: boolean) {\n this.config.loop = v;\n if (this.sourceNode) {\n this.sourceNode.loop = v;\n }\n }\n\n @Field({\n type: 'boolean',\n group: 'Sound',\n label: 'Autoplay',\n description: 'Start playing automatically once the audio has loaded.',\n editor: 'toggle',\n })\n get autoplay(): boolean {\n return this.config.autoplay ?? false;\n }\n\n set autoplay(v: boolean) {\n this.config.autoplay = v;\n }\n\n @Field({\n type: 'string',\n group: 'Sound',\n label: 'Resource',\n description: 'Audio resource id used by the sound system.',\n editor: 'text',\n })\n get resource(): string {\n return this.config.resource ?? '';\n }\n\n set resource(v: string) {\n this.config.resource = v;\n }\n\n /**\n * Apply the effective gain (`muted ? 0 : volume`) to the gain node.\n *\n * `config` is the source of truth and the gain is assigned via `gain.value`\n * (updates the AudioParam intrinsic value synchronously) so the `muted` /\n * `volume` getters — and anything reading them back, e.g. the scene-edit\n * volume slider — reflect the change immediately. `setValueAtTime` only\n * schedules on the automation timeline and leaves `.value` stale.\n */\n private applyGain() {\n if (!this.gainNode) {\n return;\n }\n this.gainNode.gain.value = this.config.muted ? 0 : (this.config.volume ?? 1);\n }\n\n init(obj?: SoundParams) {\n if (!obj) {\n return;\n }\n\n Object.assign(this.config, obj);\n if (this.config.autoplay) {\n this.actionQueue.push(this.play.bind(this));\n }\n }\n\n play() {\n if (this.state !== 'loaded') {\n this.actionQueue.push(this.play.bind(this));\n }\n this.destroySource();\n this.createSource();\n\n if (!this.sourceNode) {\n return;\n }\n const when = this.systemContext.currentTime;\n const offset = this.config.seek;\n const duration = this.config.duration;\n\n this.sourceNode.start(0, offset, duration);\n\n this.startTime = when;\n this.playTime = when - offset;\n this.paused = false;\n this.playing = true;\n this.resetConfig();\n this.endedListener = () => {\n if (!this.sourceNode) {\n return;\n }\n if (this.config.onEnd) {\n this.config.onEnd();\n }\n // Release resources once non-interactive playback finishes.\n if (this.playing) {\n this.destroySource();\n }\n };\n this.sourceNode.addEventListener('ended', this.endedListener);\n }\n\n pause() {\n if (this.state !== 'loaded') {\n this.actionQueue.push(this.pause.bind(this));\n }\n if (this.paused || !this.playing) {\n return;\n }\n this.paused = true;\n this.playing = false;\n this.config.seek = this.getCurrentTime();\n this.destroySource();\n }\n\n stop() {\n if (this.state !== 'loaded') {\n this.actionQueue.push(this.stop.bind(this));\n }\n if (!this.paused && !this.playing) {\n return;\n }\n this.playing = false;\n this.paused = false;\n this.destroySource();\n this.resetConfig();\n }\n\n onload(buffer: AudioBuffer) {\n this.state = 'loaded';\n this.buffer = buffer;\n this.duration = this.buffer.duration;\n this.actionQueue.forEach(action => action());\n this.actionQueue.length = 0;\n }\n\n onDestroy() {\n this.actionQueue.length = 0;\n this.destroySource();\n }\n\n private resetConfig() {\n this.config.seek = 0;\n }\n\n private getCurrentTime() {\n if (this.config.loop && this.duration > 0) {\n return (this.systemContext.currentTime - this.playTime) % this.duration;\n }\n\n return this.systemContext.currentTime - this.playTime;\n }\n\n private createSource() {\n if (!this.systemContext || this.state !== 'loaded') {\n return;\n }\n this.sourceNode = this.systemContext.createBufferSource();\n this.sourceNode.buffer = this.buffer;\n this.sourceNode.loop = this.config.loop;\n\n if (!this.gainNode) {\n this.gainNode = this.systemContext.createGain();\n this.gainNode.connect(this.systemDestination);\n Object.assign(this, this.config);\n }\n this.sourceNode.connect(this.gainNode);\n }\n\n private destroySource() {\n if (!this.sourceNode) return;\n this.sourceNode.removeEventListener('ended', this.endedListener);\n this.sourceNode.stop();\n this.sourceNode.disconnect();\n this.sourceNode = null;\n\n this.startTime = 0;\n this.playTime = 0;\n this.playing = false;\n }\n}\n\nexport default Sound;\n"],"names":["SoundSystem"],"mappings":";;;;AAWA,IAAM,WAAW,GAAjB,MAAM,WAAY,SAAQ,MAAM,CAAA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AAE,QAAQ;KACjB;AAGA,CAAA,EAAA,KAAA,CAAA,SAAA,EAAA,MAAA,EAAA,IAAA,CAAA;AAgBD,UAAA,CAAA;AAPC,IAAA,KAAK,CAAC;AACL,QAAA,IAAI,EAAE,SAAS;AACf,QAAA,KAAK,EAAE,OAAO;AACd,QAAA,KAAK,EAAE,UAAU;AACjB,QAAA,WAAW,EAAE,wDAAwD;AACrE,QAAA,MAAM,EAAE,QAAQ;KACjB;AAGA,CAAA,EAAA,KAAA,CAAA,SAAA,EAAA,UAAA,EAAA,IAAA,CAAA;AAaD,UAAA,CAAA;AAPC,IAAA,KAAK,CAAC;AACL,QAAA,IAAI,EAAE,QAAQ;AACd,QAAA,KAAK,EAAE,OAAO;AACd,QAAA,KAAK,EAAE,UAAU;AACjB,QAAA,WAAW,EAAE,6CAA6C;AAC1D,QAAA,MAAM,EAAE,MAAM;KACf;AAGA,CAAA,EAAA,KAAA,CAAA,SAAA,EAAA,UAAA,EAAA,IAAA,CAAA;;;;"}
|
|
1
|
+
{"version":3,"file":"plugin-sound.esm.js","sources":["../lib/hostMessages.ts","../lib/SoundSystem.ts","../lib/__combosPackageMeta.gen.ts","../lib/Sound.ts"],"sourcesContent":["/** Parent → iframe (also `window` CustomEvent / `game.emit`): mute or unmute. Payload: `{ muted: boolean }`. */\nexport const COMBOS_DEVELOPMENT_TOOL_SET_MUTED =\n 'combos-development-tool:set-muted' as const;\n\n/** iframe → parent (and `game.emit`): current mute snapshot after a successful change. */\nexport const COMBOS_DEVELOPMENT_TOOL_STATE_CHANGED =\n 'combos-development-tool:state-changed' as const;\n\nexport interface CombosSoundSetMutedMessage {\n type: typeof COMBOS_DEVELOPMENT_TOOL_SET_MUTED;\n muted: boolean;\n}\n\nexport interface CombosSoundStateChangedMessage {\n type: typeof COMBOS_DEVELOPMENT_TOOL_STATE_CHANGED;\n muted: boolean;\n}\n\nexport function parseSetMutedMessage(data: unknown): boolean | null {\n if (!data || typeof data !== 'object') return null;\n const d = data as { type?: unknown; muted?: unknown };\n if (d.type !== COMBOS_DEVELOPMENT_TOOL_SET_MUTED) return null;\n if (typeof d.muted !== 'boolean') return null;\n return d.muted;\n}\n\nexport function parseSetMutedCustomEvent(event: Event): boolean | null {\n const d = (event as CustomEvent<{ muted?: unknown }>).detail;\n if (!d || typeof d !== 'object' || typeof d.muted !== 'boolean') return null;\n return d.muted;\n}\n\nfunction postToParent(payload: object, targetOrigin: string): void {\n if (typeof window === 'undefined') return;\n if (!window.parent || window.parent === window) return;\n try {\n window.parent.postMessage(payload, targetOrigin);\n } catch {\n /* ignore cross-origin or detached frame */\n }\n}\n\n/** Notifies the embedding page (and `game.emit`) of the current mute flag. */\nexport function postParentSoundMuted(\n muted: boolean,\n targetOrigin: string,\n emit?: (type: string, payload: { muted: boolean }) => void,\n): void {\n const state = { muted };\n postToParent({ type: COMBOS_DEVELOPMENT_TOOL_STATE_CHANGED, ...state }, targetOrigin);\n emit?.(COMBOS_DEVELOPMENT_TOOL_STATE_CHANGED, state);\n}\n","import {\n System,\n decorators,\n ComponentChanged,\n OBSERVER_TYPE,\n resource,\n isAllowedMessageOrigin,\n mergeAllowedMessageOrigins,\n} from '@combos-fun/engine';\nimport SoundComponent from './Sound';\nimport {\n COMBOS_DEVELOPMENT_TOOL_SET_MUTED,\n parseSetMutedCustomEvent,\n parseSetMutedMessage,\n postParentSoundMuted,\n} from './hostMessages';\n\ninterface SoundSystemParams {\n autoPauseAndStart?: boolean;\n onError?: (error: any) => void;\n /** postMessage `targetOrigin` when notifying parent (default: Game `pluginInitNotifyTargetOrigin` or `'*'`). */\n postMessageOrigin?: string;\n /**\n * Extra inbound `postMessage` origins merged with engine defaults (`knoffice.tech`, `converge.ai`).\n * Each entry is a host suffix (e.g. `localhost`) or a full origin. Pass `['*']` to accept any origin.\n */\n allowedMessageOrigins?: string[];\n}\n\n@decorators.componentObserver({\n Sound: [],\n})\nclass SoundSystem extends System {\n static systemName = 'SoundSystem';\n\n private ctx: AudioContext;\n\n private gainNode: GainNode;\n\n /** Whether to pause/resume in sync with the game. */\n private autoPauseAndStart = true;\n\n private onError: (error: any) => void;\n\n private components: SoundComponent[] = [];\n\n private pausedComponents: SoundComponent[] = [];\n\n private audioBufferCache = {};\n\n private decodeAudioPromiseMap = {};\n\n /** Desired mute/volume are the source of truth; the gain node is derived. */\n private _muted = false;\n\n private _volume = 1;\n\n private postMessageOrigin = '*';\n\n private allowedMessageOrigins = mergeAllowedMessageOrigins();\n\n private hostMuteBound = false;\n\n get muted(): boolean {\n return this._muted;\n }\n\n set muted(v: boolean) {\n this.setMuted(v);\n }\n\n get volume(): number {\n return this._volume;\n }\n\n set volume(v: number) {\n if (typeof v !== 'number' || v < 0 || v > 1) {\n return;\n }\n this._volume = v;\n this.applyGain();\n }\n\n /**\n * Apply the effective gain (`muted ? 0 : volume`) to the gain node.\n *\n * Assigns `gain.value` directly rather than `setValueAtTime`: `.value` updates\n * the AudioParam's intrinsic value synchronously, so the `muted` / `volume`\n * getters reflect the change immediately. `setValueAtTime` only schedules an\n * event on the automation timeline and leaves `.value` stale until the next\n * render quantum, which made `muted` report the pre-change value.\n */\n private applyGain() {\n if (!this.gainNode) {\n return;\n }\n this.gainNode.gain.value = this._muted ? 0 : this._volume;\n }\n\n get audioLocked(): boolean {\n if (!this.ctx) {\n return true;\n }\n return this.ctx.state !== 'running';\n }\n\n constructor(obj?: SoundSystemParams) {\n super();\n if (!obj) return;\n if (typeof obj.autoPauseAndStart === 'boolean') {\n this.autoPauseAndStart = obj.autoPauseAndStart;\n }\n if (obj.onError) {\n this.onError = obj.onError;\n }\n }\n\n /**\n * Mute or unmute the master gain and notify the embedding host.\n * Same effect as `postMessage({ type: 'combos-development-tool:set-muted', muted })`.\n */\n setMuted(muted: boolean) {\n const next = !!muted;\n if (this._muted === next) {\n return;\n }\n this._muted = next;\n this.applyGain();\n this.postMuteStateChanged();\n }\n\n /**\n * Resume playback of all paused audio.\n */\n resumeAll() {\n const handleResume = () => {\n this.pausedComponents.forEach(component => {\n component.play();\n });\n // Clear the previously cached paused list.\n this.pausedComponents = [];\n };\n this.ctx.resume().then(handleResume, handleResume);\n }\n\n /**\n * Pause all currently playing audio.\n */\n pauseAll() {\n this.components.forEach(component => {\n if (component.playing) {\n this.pausedComponents.push(component);\n component.pause();\n }\n });\n this.ctx.suspend().then();\n }\n\n /**\n * Stop all currently playing audio.\n */\n stopAll() {\n this.components.forEach(component => {\n if (component.playing) {\n component.stop();\n }\n });\n // Clear the previously cached paused list.\n this.pausedComponents = [];\n this.ctx.suspend().then();\n }\n\n /**\n * System init: configure params before the game starts.\n */\n init(params?: SoundSystemParams) {\n this.postMessageOrigin =\n params?.postMessageOrigin ?? this.game?.pluginInitNotifyTargetOrigin ?? '*';\n this.allowedMessageOrigins = mergeAllowedMessageOrigins(params?.allowedMessageOrigins);\n this.bindHostMute();\n this.setupAudioContext();\n }\n\n update() {\n const changes = this.componentObserver.clear();\n for (const changed of changes) {\n this.componentChanged(changed);\n }\n }\n\n /**\n * Called when the game starts or resumes playing after a pause.\n */\n onResume() {\n if (!this.autoPauseAndStart) {\n return;\n }\n this.resumeAll();\n }\n\n /**\n * Called when the game is paused.\n */\n onPause() {\n if (!this.autoPauseAndStart) {\n return;\n }\n this.pauseAll();\n }\n\n /**\n * Called when the system is destroyed.\n */\n onDestroy() {\n this.unbindHostMute();\n this.components.forEach(component => {\n component.onDestroy();\n });\n this.components = [];\n if (this.ctx) {\n this.gainNode.disconnect();\n this.gainNode = null;\n this.ctx.close();\n this.ctx = null;\n }\n }\n\n private readonly onWindowSetMuted = (e: Event) => {\n const muted = parseSetMutedCustomEvent(e);\n if (muted === null) return;\n this.setMuted(muted);\n };\n\n private readonly onGameSetMuted = (payload: { muted?: boolean }) => {\n if (payload && typeof payload.muted === 'boolean') {\n this.setMuted(payload.muted);\n }\n };\n\n private readonly onWindowMessage = (e: MessageEvent) => {\n if (!isAllowedMessageOrigin(e.origin, this.allowedMessageOrigins)) {\n return;\n }\n const muted = parseSetMutedMessage(e.data);\n if (muted === null) return;\n this.setMuted(muted);\n };\n\n private bindHostMute() {\n if (this.hostMuteBound) return;\n this.hostMuteBound = true;\n if (typeof window !== 'undefined') {\n window.addEventListener(COMBOS_DEVELOPMENT_TOOL_SET_MUTED, this.onWindowSetMuted);\n window.addEventListener('message', this.onWindowMessage);\n }\n this.game.on(COMBOS_DEVELOPMENT_TOOL_SET_MUTED, this.onGameSetMuted);\n }\n\n private unbindHostMute() {\n if (!this.hostMuteBound) return;\n this.hostMuteBound = false;\n if (typeof window !== 'undefined') {\n window.removeEventListener(COMBOS_DEVELOPMENT_TOOL_SET_MUTED, this.onWindowSetMuted);\n window.removeEventListener('message', this.onWindowMessage);\n }\n this.game?.off(COMBOS_DEVELOPMENT_TOOL_SET_MUTED, this.onGameSetMuted);\n }\n\n private postMuteStateChanged() {\n postParentSoundMuted(this._muted, this.postMessageOrigin, (type, payload) => {\n this.game?.emit(type, payload);\n });\n }\n\n async componentChanged(changed: ComponentChanged) {\n if (changed.componentName !== 'Sound') return;\n\n if (changed.type === OBSERVER_TYPE.ADD) {\n this.add(changed);\n }\n }\n\n private setupAudioContext() {\n try {\n const AudioContext = window.AudioContext || (window as any).webkitAudioContext;\n this.ctx = new AudioContext();\n } catch (error) {\n console.error(error);\n if (this.onError) {\n this.onError(error);\n }\n }\n\n if (!this.ctx) {\n return;\n }\n this.gainNode =\n typeof this.ctx.createGain === 'undefined' ? (this.ctx as any).createGainNode() : this.ctx.createGain();\n this.applyGain();\n this.gainNode.connect(this.ctx.destination);\n this.unlockAudio();\n }\n\n private unlockAudio() {\n if (!this.ctx || !this.audioLocked) {\n return;\n }\n\n const unlock = () => {\n if (this.ctx) {\n const removeListenerFn = () => {\n document.body.removeEventListener('touchstart', unlock);\n document.body.removeEventListener('touchend', unlock);\n document.body.removeEventListener('click', unlock);\n };\n this.ctx.resume().then(removeListenerFn, removeListenerFn);\n }\n };\n document.body.addEventListener('touchstart', unlock);\n document.body.addEventListener('touchend', unlock);\n document.body.addEventListener('click', unlock);\n }\n\n private async add(changed: ComponentChanged) {\n const component = changed.component as SoundComponent;\n this.components.push(component);\n try {\n const { config } = component;\n component.state = 'loading';\n\n const audio = await resource.getResource(config.resource);\n if (!this.audioBufferCache[audio.name] && audio?.data?.audio) {\n this.audioBufferCache[audio.name] = await this.decodeAudioData(audio.data.audio, audio.name);\n }\n if (this.audioBufferCache[audio.name]) {\n component.systemContext = this.ctx;\n component.systemDestination = this.gainNode;\n component.onload(this.audioBufferCache[audio.name]);\n }\n } catch (error) {\n if (this.onError) {\n this.onError(error);\n }\n }\n }\n\n private decodeAudioData(arraybuffer: ArrayBuffer, name: string) {\n if (this.decodeAudioPromiseMap[name]) {\n return this.decodeAudioPromiseMap[name];\n }\n\n const promise = new Promise<AudioBuffer>((resolve, reject) => {\n if (!this.ctx) {\n reject(new Error('No audio support'));\n }\n\n const success = (decodedData: AudioBuffer) => {\n if (this.decodeAudioPromiseMap[name]) {\n delete this.decodeAudioPromiseMap[name];\n }\n if (decodedData) {\n resolve(decodedData);\n } else {\n reject(new Error(`Error decoding audio ${name}`));\n }\n };\n\n const error = (err: DOMException) => {\n if (this.decodeAudioPromiseMap[name]) {\n delete this.decodeAudioPromiseMap[name];\n }\n reject(new Error(`${err}. arrayBuffer byteLength: ${arraybuffer ? arraybuffer.byteLength : 0}`));\n };\n\n const promise = this.ctx.decodeAudioData(arraybuffer, success, error)\n if (promise instanceof Promise) {\n promise.catch((err) => {\n reject(new Error(`catch ${err}, arrayBuffer byteLength: ${arraybuffer ? arraybuffer.byteLength : 0}`));\n });\n }\n });\n\n this.decodeAudioPromiseMap[name] = promise;\n return promise;\n }\n}\n\nexport default SoundSystem;\n","/** Auto-generated by scripts/build-package.mjs — do not edit. */\n\nimport SoundSystem from './SoundSystem';\n\nObject.assign(SoundSystem, {\n packageName: \"@combos-fun/plugin-sound\",\n packageVersion: \"0.0.48\",\n});\n","import { Component } from '@combos-fun/engine';\nimport { Field } from '@combos-fun/inspector-decorator';\n\nexport interface SoundParams {\n resource: string;\n autoplay?: boolean;\n muted?: boolean;\n volume?: number;\n loop?: boolean;\n seek?: number;\n duration?: number;\n onEnd?: () => void;\n}\n\nclass Sound extends Component<SoundParams> {\n static componentName = 'Sound';\n\n systemContext: AudioContext;\n\n systemDestination: GainNode;\n\n playing: boolean;\n\n state: 'unloaded' | 'loading' | 'loaded' = 'unloaded';\n\n config: SoundParams = {\n resource: '',\n autoplay: false,\n muted: false,\n volume: 1,\n loop: false,\n seek: 0,\n };\n\n private buffer: AudioBuffer;\n\n private sourceNode: AudioBufferSourceNode;\n\n private gainNode: GainNode;\n\n private paused: boolean;\n\n private playTime: number = 0;\n\n private startTime: number = 0;\n\n private duration: number = 0;\n\n private actionQueue: (() => void)[] = [];\n\n private endedListener: () => void;\n\n @Field({\n type: 'boolean',\n group: 'Sound',\n label: 'Muted',\n description: 'Silence this sound without changing its volume setting.',\n editor: 'toggle',\n })\n get muted(): boolean {\n return this.config.muted ?? false;\n }\n\n set muted(v: boolean) {\n this.config.muted = v;\n this.applyGain();\n }\n\n @Field({\n type: 'number',\n min: 0,\n max: 1,\n step: 0.01,\n group: 'Sound',\n label: 'Volume',\n description: 'Loudness of this sound from 0 (silent) to 1 (full).',\n editor: 'volume-slider',\n })\n get volume(): number {\n return this.config.volume ?? 1;\n }\n\n set volume(v: number) {\n if (typeof v !== 'number' || v < 0 || v > 1) {\n return;\n }\n this.config.volume = v;\n this.applyGain();\n }\n\n @Field({\n type: 'boolean',\n group: 'Sound',\n label: 'Loop',\n description: 'Replay the sound continuously when it reaches the end.',\n editor: 'toggle',\n })\n get loop(): boolean {\n return this.config.loop ?? false;\n }\n\n set loop(v: boolean) {\n this.config.loop = v;\n if (this.sourceNode) {\n this.sourceNode.loop = v;\n }\n }\n\n @Field({\n type: 'boolean',\n group: 'Sound',\n label: 'Autoplay',\n description: 'Start playing automatically once the audio has loaded.',\n editor: 'toggle',\n })\n get autoplay(): boolean {\n return this.config.autoplay ?? false;\n }\n\n set autoplay(v: boolean) {\n this.config.autoplay = v;\n }\n\n @Field({\n type: 'string',\n group: 'Sound',\n label: 'Resource',\n description: 'Audio resource id used by the sound system.',\n editor: 'text',\n })\n get resource(): string {\n return this.config.resource ?? '';\n }\n\n set resource(v: string) {\n this.config.resource = v;\n }\n\n /**\n * Apply the effective gain (`muted ? 0 : volume`) to the gain node.\n *\n * `config` is the source of truth and the gain is assigned via `gain.value`\n * (updates the AudioParam intrinsic value synchronously) so the `muted` /\n * `volume` getters — and anything reading them back, e.g. the scene-edit\n * volume slider — reflect the change immediately. `setValueAtTime` only\n * schedules on the automation timeline and leaves `.value` stale.\n */\n private applyGain() {\n if (!this.gainNode) {\n return;\n }\n this.gainNode.gain.value = this.config.muted ? 0 : (this.config.volume ?? 1);\n }\n\n init(obj?: SoundParams) {\n if (!obj) {\n return;\n }\n\n Object.assign(this.config, obj);\n if (this.config.autoplay) {\n this.actionQueue.push(this.play.bind(this));\n }\n }\n\n play() {\n if (this.state !== 'loaded') {\n this.actionQueue.push(this.play.bind(this));\n }\n this.destroySource();\n this.createSource();\n\n if (!this.sourceNode) {\n return;\n }\n const when = this.systemContext.currentTime;\n const offset = this.config.seek;\n const duration = this.config.duration;\n\n this.sourceNode.start(0, offset, duration);\n\n this.startTime = when;\n this.playTime = when - offset;\n this.paused = false;\n this.playing = true;\n this.resetConfig();\n this.endedListener = () => {\n if (!this.sourceNode) {\n return;\n }\n if (this.config.onEnd) {\n this.config.onEnd();\n }\n // Release resources once non-interactive playback finishes.\n if (this.playing) {\n this.destroySource();\n }\n };\n this.sourceNode.addEventListener('ended', this.endedListener);\n }\n\n pause() {\n if (this.state !== 'loaded') {\n this.actionQueue.push(this.pause.bind(this));\n }\n if (this.paused || !this.playing) {\n return;\n }\n this.paused = true;\n this.playing = false;\n this.config.seek = this.getCurrentTime();\n this.destroySource();\n }\n\n stop() {\n if (this.state !== 'loaded') {\n this.actionQueue.push(this.stop.bind(this));\n }\n if (!this.paused && !this.playing) {\n return;\n }\n this.playing = false;\n this.paused = false;\n this.destroySource();\n this.resetConfig();\n }\n\n onload(buffer: AudioBuffer) {\n this.state = 'loaded';\n this.buffer = buffer;\n this.duration = this.buffer.duration;\n this.actionQueue.forEach(action => action());\n this.actionQueue.length = 0;\n }\n\n onDestroy() {\n this.actionQueue.length = 0;\n this.destroySource();\n }\n\n private resetConfig() {\n this.config.seek = 0;\n }\n\n private getCurrentTime() {\n if (this.config.loop && this.duration > 0) {\n return (this.systemContext.currentTime - this.playTime) % this.duration;\n }\n\n return this.systemContext.currentTime - this.playTime;\n }\n\n private createSource() {\n if (!this.systemContext || this.state !== 'loaded') {\n return;\n }\n this.sourceNode = this.systemContext.createBufferSource();\n this.sourceNode.buffer = this.buffer;\n this.sourceNode.loop = this.config.loop;\n\n if (!this.gainNode) {\n this.gainNode = this.systemContext.createGain();\n this.gainNode.connect(this.systemDestination);\n Object.assign(this, this.config);\n }\n this.sourceNode.connect(this.gainNode);\n }\n\n private destroySource() {\n if (!this.sourceNode) return;\n this.sourceNode.removeEventListener('ended', this.endedListener);\n this.sourceNode.stop();\n this.sourceNode.disconnect();\n this.sourceNode = null;\n\n this.startTime = 0;\n this.playTime = 0;\n this.playing = false;\n }\n}\n\nexport default Sound;\n"],"names":["SoundSystem"],"mappings":";;;;AAAA;AACO,MAAM,iCAAiC,GAC5C;AAEF;AACO,MAAM,qCAAqC,GAChD;AAYI,SAAU,oBAAoB,CAAC,IAAa,EAAA;AAChD,IAAA,IAAI,CAAC,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ;AAAE,QAAA,OAAO,IAAI;IAClD,MAAM,CAAC,GAAG,IAA2C;AACrD,IAAA,IAAI,CAAC,CAAC,IAAI,KAAK,iCAAiC;AAAE,QAAA,OAAO,IAAI;AAC7D,IAAA,IAAI,OAAO,CAAC,CAAC,KAAK,KAAK,SAAS;AAAE,QAAA,OAAO,IAAI;IAC7C,OAAO,CAAC,CAAC,KAAK;AAChB;AAEM,SAAU,wBAAwB,CAAC,KAAY,EAAA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AAQ;KACjB;AAGA,CAAA,EAAA,KAAA,CAAA,SAAA,EAAA,UAAA,EAAA,IAAA,CAAA;AAaD,UAAA,CAAA;AAPC,IAAA,KAAK,CAAC;AACL,QAAA,IAAI,EAAE,QAAQ;AACd,QAAA,KAAK,EAAE,OAAO;AACd,QAAA,KAAK,EAAE,UAAU;AACjB,QAAA,WAAW,EAAE,6CAA6C;AAC1D,QAAA,MAAM,EAAE,MAAM;KACf;AAGA,CAAA,EAAA,KAAA,CAAA,SAAA,EAAA,UAAA,EAAA,IAAA,CAAA;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@combos-fun/plugin-sound",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.48",
|
|
4
4
|
"description": "Audio playback",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"module": "dist/plugin-sound.esm.js",
|
|
@@ -38,10 +38,14 @@
|
|
|
38
38
|
"author": "sun668 <q947692259@gmail.com>",
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"eventemitter3": "^5.0.4",
|
|
41
|
-
"@combos-fun/inspector-decorator": "0.0.
|
|
42
|
-
"@combos-fun/engine": "0.0.
|
|
41
|
+
"@combos-fun/inspector-decorator": "0.0.48",
|
|
42
|
+
"@combos-fun/engine": "0.0.48"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"tsx": "^4.20.3"
|
|
43
46
|
},
|
|
44
47
|
"scripts": {
|
|
45
|
-
"build": "node ../../scripts/build-package.mjs"
|
|
48
|
+
"build": "node ../../scripts/build-package.mjs",
|
|
49
|
+
"test": "node --import tsx --test test/hostMessages.test.ts"
|
|
46
50
|
}
|
|
47
51
|
}
|