@momo2555/koppeliajs 0.0.134 → 0.0.136
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/dist/index.d.ts
CHANGED
|
@@ -8,6 +8,8 @@ import { Console } from "./scripts/console.js";
|
|
|
8
8
|
import { Message } from "./scripts/message.js";
|
|
9
9
|
import { Device } from "./scripts/device.js";
|
|
10
10
|
import { Play } from "./scripts/play.js";
|
|
11
|
+
import { Resident } from "./scripts/resident.js";
|
|
11
12
|
import { updateRoute, routeType } from './stores/routeStore.js';
|
|
13
|
+
import { audioManager } from '.,/stores/audioManager.js';
|
|
12
14
|
export { KBase, GrowableElement, Button, ResizableText };
|
|
13
|
-
export { updateRoute, routeType, Koppelia, Console, Message, Device, Play };
|
|
15
|
+
export { updateRoute, routeType, Koppelia, Console, Message, Device, Play, audioManager, Resident };
|
package/dist/index.js
CHANGED
|
@@ -9,6 +9,8 @@ import { Console } from "./scripts/console.js";
|
|
|
9
9
|
import { Message } from "./scripts/message.js";
|
|
10
10
|
import { Device } from "./scripts/device.js";
|
|
11
11
|
import { Play } from "./scripts/play.js";
|
|
12
|
+
import { Resident } from "./scripts/resident.js";
|
|
12
13
|
import { updateRoute, routeType } from './stores/routeStore.js';
|
|
14
|
+
import { audioManager } from '.,/stores/audioManager.js';
|
|
13
15
|
export { KBase, GrowableElement, Button, ResizableText }; // Compoenents
|
|
14
|
-
export { updateRoute, routeType, Koppelia, Console, Message, Device, Play }; // libraries and stores
|
|
16
|
+
export { updateRoute, routeType, Koppelia, Console, Message, Device, Play, audioManager, Resident }; // libraries and stores
|
package/dist/scripts/console.js
CHANGED
|
@@ -185,7 +185,6 @@ export class Console {
|
|
|
185
185
|
}
|
|
186
186
|
/* Handle device event */
|
|
187
187
|
else if (type == MessageType.DEVICE_EVENT) {
|
|
188
|
-
console.log("receive device event ! handlers : " + this._deviceEventHandlers);
|
|
189
188
|
this._execDeviceEventHandlers(request.header.device, request.header.from_addr, request.event);
|
|
190
189
|
}
|
|
191
190
|
/* Handle device data */
|
|
@@ -228,6 +227,6 @@ export class Console {
|
|
|
228
227
|
this._deviceDataHandlers = [];
|
|
229
228
|
this._dataExchangeHandlers = [];
|
|
230
229
|
this._anyRequestHandlers = [];
|
|
231
|
-
console.log("destroy events event handlers
|
|
230
|
+
console.log("destroy events event handlers");
|
|
232
231
|
}
|
|
233
232
|
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
declare class AudioManager {
|
|
2
|
+
private players;
|
|
3
|
+
/**
|
|
4
|
+
* Play an audio by id (creates it if doesn't exist)
|
|
5
|
+
*/
|
|
6
|
+
play(id: string, loop?: boolean): void;
|
|
7
|
+
/**
|
|
8
|
+
* Pause a specific audio by id
|
|
9
|
+
*/
|
|
10
|
+
pause(id: string): void;
|
|
11
|
+
/**
|
|
12
|
+
* Stop a specific audio by id
|
|
13
|
+
*/
|
|
14
|
+
stop(id: string): void;
|
|
15
|
+
/**
|
|
16
|
+
* Stop all audios
|
|
17
|
+
*/
|
|
18
|
+
stopAll(): void;
|
|
19
|
+
/**
|
|
20
|
+
* Pause all audios
|
|
21
|
+
*/
|
|
22
|
+
pauseAll(): void;
|
|
23
|
+
/**
|
|
24
|
+
* Check if a specific audio is playing
|
|
25
|
+
*/
|
|
26
|
+
isPlaying(id: string): boolean;
|
|
27
|
+
}
|
|
28
|
+
export declare const audioManager: import("svelte/store").Writable<AudioManager>;
|
|
29
|
+
export {};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { writable } from 'svelte/store';
|
|
2
|
+
class AudioInstance {
|
|
3
|
+
audio;
|
|
4
|
+
id;
|
|
5
|
+
constructor(id, loop = false) {
|
|
6
|
+
this.id = id;
|
|
7
|
+
this.audio = new Audio(`/audios/${id}.mp3`);
|
|
8
|
+
this.audio.loop = loop;
|
|
9
|
+
}
|
|
10
|
+
play() {
|
|
11
|
+
this.audio.play().catch(err => console.error(`Error playing ${this.id}:`, err));
|
|
12
|
+
}
|
|
13
|
+
pause() {
|
|
14
|
+
this.audio.pause();
|
|
15
|
+
}
|
|
16
|
+
stop() {
|
|
17
|
+
this.audio.pause();
|
|
18
|
+
this.audio.currentTime = 0;
|
|
19
|
+
}
|
|
20
|
+
setLoop(loop) {
|
|
21
|
+
this.audio.loop = loop;
|
|
22
|
+
}
|
|
23
|
+
isPlaying() {
|
|
24
|
+
return !this.audio.paused;
|
|
25
|
+
}
|
|
26
|
+
getId() {
|
|
27
|
+
return this.id;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
class AudioManager {
|
|
31
|
+
players = new Map();
|
|
32
|
+
/**
|
|
33
|
+
* Play an audio by id (creates it if doesn't exist)
|
|
34
|
+
*/
|
|
35
|
+
play(id, loop = false) {
|
|
36
|
+
let player = this.players.get(id);
|
|
37
|
+
if (!player) {
|
|
38
|
+
player = new AudioInstance(id, loop);
|
|
39
|
+
this.players.set(id, player);
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
player.setLoop(loop);
|
|
43
|
+
}
|
|
44
|
+
player.play();
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Pause a specific audio by id
|
|
48
|
+
*/
|
|
49
|
+
pause(id) {
|
|
50
|
+
this.players.get(id)?.pause();
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Stop a specific audio by id
|
|
54
|
+
*/
|
|
55
|
+
stop(id) {
|
|
56
|
+
this.players.get(id)?.stop();
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Stop all audios
|
|
60
|
+
*/
|
|
61
|
+
stopAll() {
|
|
62
|
+
this.players.forEach(player => player.stop());
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Pause all audios
|
|
66
|
+
*/
|
|
67
|
+
pauseAll() {
|
|
68
|
+
this.players.forEach(player => player.pause());
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Check if a specific audio is playing
|
|
72
|
+
*/
|
|
73
|
+
isPlaying(id) {
|
|
74
|
+
return this.players.get(id)?.isPlaying() ?? false;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
// Export a writable store with the AudioManager singleton
|
|
78
|
+
export const audioManager = writable(new AudioManager());
|