@momo2555/koppeliajs 0.0.138 → 0.0.140

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.
@@ -13,13 +13,15 @@ export declare enum PeerType {
13
13
  export declare enum MessageType {
14
14
  EMPTY = "empty",
15
15
  REQUEST = "request",
16
+ STREAM_RESPONSE = "stream_response",
16
17
  RESPONSE = "response",
17
18
  DATA_EXCHANGE = "data_exchange",
18
19
  DEVICE_EVENT = "device_event",
19
20
  DEVICE_DATA = "device_data",
20
21
  IDENTIFICATION = "identification",
21
22
  MODULE_ENABLE = "module_enable",
22
- ERROR = "error"
23
+ ERROR = "error",
24
+ CLOSE = "close"
23
25
  }
24
26
  type MessagetHeader = {
25
27
  id: string;
@@ -14,6 +14,7 @@ export var MessageType;
14
14
  (function (MessageType) {
15
15
  MessageType["EMPTY"] = "empty";
16
16
  MessageType["REQUEST"] = "request";
17
+ MessageType["STREAM_RESPONSE"] = "stream_response";
17
18
  MessageType["RESPONSE"] = "response";
18
19
  MessageType["DATA_EXCHANGE"] = "data_exchange";
19
20
  MessageType["DEVICE_EVENT"] = "device_event";
@@ -21,6 +22,7 @@ export var MessageType;
21
22
  MessageType["IDENTIFICATION"] = "identification";
22
23
  MessageType["MODULE_ENABLE"] = "module_enable";
23
24
  MessageType["ERROR"] = "error";
25
+ MessageType["CLOSE"] = "close";
24
26
  })(MessageType || (MessageType = {}));
25
27
  /**
26
28
  * The koppelia protocol
@@ -1,9 +1,24 @@
1
+ declare class AudioInstance {
2
+ private audio?;
3
+ private id;
4
+ protected path: string;
5
+ private loop;
6
+ constructor(id: string, loop?: boolean);
7
+ fetch(): void;
8
+ play(): void;
9
+ pause(): void;
10
+ stop(): void;
11
+ setLoop(loop: boolean): void;
12
+ isPlaying(): boolean | undefined;
13
+ getId(): string;
14
+ getDuration(): number | undefined;
15
+ }
1
16
  export declare class AudioManager {
2
17
  private players;
3
18
  /**
4
19
  * Play an audio by id (creates it if doesn't exist)
5
20
  */
6
- play(id: string, loop?: boolean): void;
21
+ play(id: string, loop?: boolean, url?: string): void;
7
22
  /**
8
23
  * Pause a specific audio by id
9
24
  */
@@ -24,5 +39,7 @@ export declare class AudioManager {
24
39
  * Check if a specific audio is playing
25
40
  */
26
41
  isPlaying(id: string): boolean;
42
+ getPlayerInstance(id: string): AudioInstance | undefined;
27
43
  }
28
44
  export declare const audioManager: import("svelte/store").Writable<AudioManager>;
45
+ export {};
@@ -2,40 +2,73 @@ import { writable } from 'svelte/store';
2
2
  class AudioInstance {
3
3
  audio;
4
4
  id;
5
+ path;
6
+ loop;
5
7
  constructor(id, loop = false) {
6
8
  this.id = id;
7
- this.audio = new Audio(`/audios/${id}.mp3`);
8
- this.audio.loop = loop;
9
+ this.path = `/audios/${id}.mp3`;
10
+ this.loop = loop;
11
+ }
12
+ fetch() {
13
+ this.audio = new Audio(this.path);
14
+ this.audio.loop = this.loop;
9
15
  }
10
16
  play() {
11
- this.audio.play().catch(err => console.error(`Error playing ${this.id}:`, err));
17
+ if (this.audio != undefined) {
18
+ this.audio.play().catch(err => console.error(`Error playing ${this.id}:`, err));
19
+ }
12
20
  }
13
21
  pause() {
14
- this.audio.pause();
22
+ if (this.audio != undefined) {
23
+ this.audio.pause();
24
+ }
15
25
  }
16
26
  stop() {
17
- this.audio.pause();
18
- this.audio.currentTime = 0;
27
+ if (this.audio != undefined) {
28
+ this.audio.pause();
29
+ this.audio.currentTime = 0;
30
+ }
19
31
  }
20
32
  setLoop(loop) {
21
- this.audio.loop = loop;
33
+ if (this.audio != undefined) {
34
+ this.audio.loop = loop;
35
+ }
22
36
  }
23
37
  isPlaying() {
24
- return !this.audio.paused;
38
+ if (this.audio != undefined) {
39
+ return !this.audio.paused;
40
+ }
25
41
  }
26
42
  getId() {
27
43
  return this.id;
28
44
  }
45
+ getDuration() {
46
+ if (this.audio !== undefined) {
47
+ return this.audio?.duration;
48
+ }
49
+ }
50
+ }
51
+ class AudioUrlInstance extends AudioInstance {
52
+ constructor(id, url, loop) {
53
+ super(id, loop);
54
+ this.path = url;
55
+ }
29
56
  }
30
57
  export class AudioManager {
31
58
  players = new Map();
32
59
  /**
33
60
  * Play an audio by id (creates it if doesn't exist)
34
61
  */
35
- play(id, loop = false) {
62
+ play(id, loop = false, url) {
36
63
  let player = this.players.get(id);
37
64
  if (!player) {
38
- player = new AudioInstance(id, loop);
65
+ if (url !== undefined) {
66
+ player = new AudioUrlInstance(id, url, loop);
67
+ }
68
+ else {
69
+ player = new AudioInstance(id, loop);
70
+ }
71
+ player.fetch();
39
72
  this.players.set(id, player);
40
73
  }
41
74
  else {
@@ -73,6 +106,9 @@ export class AudioManager {
73
106
  isPlaying(id) {
74
107
  return this.players.get(id)?.isPlaying() ?? false;
75
108
  }
109
+ getPlayerInstance(id) {
110
+ return this.players.get(id);
111
+ }
76
112
  }
77
113
  // Export a writable store with the AudioManager singleton
78
114
  export const audioManager = writable(new AudioManager());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momo2555/koppeliajs",
3
- "version": "0.0.138",
3
+ "version": "0.0.140",
4
4
  "scripts": {
5
5
  "dev": "vite dev",
6
6
  "build": "vite build && npm run package",
@@ -64,4 +64,4 @@
64
64
  "fs": "^0.0.1-security",
65
65
  "uuid": "^11.1.0"
66
66
  }
67
- }
67
+ }