@momo2555/koppeliajs 0.0.161 → 0.0.163
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/components/ResizableText.svelte +24 -6
- package/dist/scripts/console.d.ts +89 -32
- package/dist/scripts/console.js +174 -68
- package/dist/scripts/customCallback.d.ts +18 -0
- package/dist/scripts/customCallback.js +22 -4
- package/dist/scripts/device.d.ts +47 -12
- package/dist/scripts/device.js +49 -19
- package/dist/scripts/koppelia.d.ts +157 -37
- package/dist/scripts/koppelia.js +160 -49
- package/dist/scripts/koppeliaWebsocket.d.ts +33 -28
- package/dist/scripts/koppeliaWebsocket.js +37 -41
- package/dist/scripts/message.d.ts +46 -29
- package/dist/scripts/message.js +47 -31
- package/dist/scripts/option.d.ts +26 -11
- package/dist/scripts/option.js +26 -14
- package/dist/scripts/play.d.ts +46 -4
- package/dist/scripts/play.js +46 -4
- package/dist/scripts/resident.d.ts +19 -0
- package/dist/scripts/resident.js +21 -1
- package/dist/scripts/song.d.ts +36 -0
- package/dist/scripts/song.js +36 -0
- package/dist/scripts/stage.d.ts +29 -0
- package/dist/scripts/stage.js +29 -2
- package/dist/scripts/state.d.ts +26 -9
- package/dist/scripts/state.js +28 -14
- package/dist/stores/routeStore.d.ts +13 -0
- package/dist/stores/routeStore.js +23 -13
- package/package.json +1 -1
package/dist/scripts/koppelia.js
CHANGED
|
@@ -12,6 +12,11 @@ import { Option } from "./option.js";
|
|
|
12
12
|
import { logger, setDebugMode } from "./logger.js";
|
|
13
13
|
import { CustomCallbacks } from "./customCallback.js";
|
|
14
14
|
import { Song } from "./song.js";
|
|
15
|
+
/**
|
|
16
|
+
* The main Koppelia framework entry point.
|
|
17
|
+
* Implements a Singleton pattern to provide global access to the console, state, stages,
|
|
18
|
+
* devices, and game synchronization features across the Svelte application.
|
|
19
|
+
*/
|
|
15
20
|
export class Koppelia {
|
|
16
21
|
_console;
|
|
17
22
|
_state;
|
|
@@ -40,78 +45,105 @@ export class Koppelia {
|
|
|
40
45
|
this._stage = new Stage(this._console);
|
|
41
46
|
this._option = new Option(this._console);
|
|
42
47
|
}
|
|
48
|
+
/**
|
|
49
|
+
* Retrieves the singleton instance of the Koppelia class.
|
|
50
|
+
* Instantiates it if it does not yet exist.
|
|
51
|
+
*/
|
|
43
52
|
static get instance() {
|
|
44
53
|
if (!Koppelia._instance) {
|
|
45
54
|
Koppelia._instance = new Koppelia();
|
|
46
55
|
}
|
|
47
56
|
return Koppelia._instance;
|
|
48
57
|
}
|
|
58
|
+
/**
|
|
59
|
+
* Retrieves the global Svelte writable store representing the synchronized game state.
|
|
60
|
+
*/
|
|
49
61
|
get state() {
|
|
50
62
|
return this._state.state;
|
|
51
63
|
}
|
|
64
|
+
/**
|
|
65
|
+
* Merges a partial update into the current global state and broadcasts the change.
|
|
66
|
+
* @param stateUpdate A dictionary containing the keys/values to update.
|
|
67
|
+
*/
|
|
52
68
|
updateState(stateUpdate) {
|
|
53
69
|
this._state.updateState(stateUpdate);
|
|
54
70
|
}
|
|
71
|
+
/**
|
|
72
|
+
* Completely overwrites the global state with a new state object.
|
|
73
|
+
* @param newState The new state object to apply.
|
|
74
|
+
*/
|
|
55
75
|
setState(newState) {
|
|
56
76
|
this._state.setState(newState);
|
|
57
77
|
}
|
|
78
|
+
/**
|
|
79
|
+
* Checks if the underlying WebSocket console connection is fully established.
|
|
80
|
+
*/
|
|
58
81
|
get ready() {
|
|
59
82
|
return this._console.ready;
|
|
60
83
|
}
|
|
84
|
+
/**
|
|
85
|
+
* Enables or disables debug mode for extended console logging.
|
|
86
|
+
* @param enable True to enable debug logs, false to disable.
|
|
87
|
+
*/
|
|
61
88
|
setDebugMode(enable) {
|
|
62
89
|
setDebugMode(enable);
|
|
63
90
|
}
|
|
64
91
|
/**
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
* @param callback
|
|
92
|
+
* Registers a callback to execute when the console connection is fully ready.
|
|
93
|
+
* @param callback The function to execute.
|
|
68
94
|
*/
|
|
69
95
|
onReady(callback) {
|
|
70
96
|
this._console.onReady(callback);
|
|
71
97
|
}
|
|
72
98
|
/**
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
* @param defaultState
|
|
76
|
-
* @param stages
|
|
99
|
+
* Initializes the default state and the routing stages of the game.
|
|
100
|
+
* Specifically executes for "monitor" peers to ensure the primary game view sets the rules.
|
|
101
|
+
* @param defaultState The initial state structure.
|
|
102
|
+
* @param stages An array of valid stage names for application routing.
|
|
77
103
|
*/
|
|
78
104
|
init(defaultState, stages) {
|
|
79
105
|
this._console.onReady(() => {
|
|
80
106
|
let type = get(routeType);
|
|
81
107
|
if (type == "monitor") {
|
|
82
|
-
this._state.setState(defaultState, true);
|
|
83
|
-
this._stage.initStages(stages);
|
|
108
|
+
this._state.setState(defaultState, true);
|
|
109
|
+
this._stage.initStages(stages);
|
|
84
110
|
}
|
|
85
111
|
});
|
|
86
112
|
}
|
|
87
113
|
/**
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
* @param stageName
|
|
114
|
+
* Requests a transition to a specific stage (view) across the network.
|
|
115
|
+
* Note: All active console event listeners will be destroyed before transition.
|
|
116
|
+
* @param stageName The target stage to navigate to.
|
|
92
117
|
*/
|
|
93
118
|
goto(stageName) {
|
|
94
119
|
this._stage.goto(stageName);
|
|
95
120
|
}
|
|
121
|
+
/**
|
|
122
|
+
* Normalizes a media URL to ensure cross-client compatibility.
|
|
123
|
+
* @param mediaUrl The raw media URL.
|
|
124
|
+
* @returns The corrected URL.
|
|
125
|
+
*/
|
|
96
126
|
fixMediaUrl(mediaUrl) {
|
|
97
127
|
return this._console.fixMediaUrl(mediaUrl);
|
|
98
128
|
}
|
|
129
|
+
/**
|
|
130
|
+
* Constructs the full URL for a given relative media path.
|
|
131
|
+
* @param path The relative media path.
|
|
132
|
+
* @returns The full URL string.
|
|
133
|
+
*/
|
|
99
134
|
getMediaLink(path) {
|
|
100
135
|
return this._console.getMediaUrl(path);
|
|
101
136
|
}
|
|
102
137
|
/**
|
|
103
|
-
*
|
|
104
|
-
* @
|
|
138
|
+
* Asynchronously fetches the list of available connected devices from the master peer.
|
|
139
|
+
* @returns A promise resolving to an array of instantiated Device objects.
|
|
105
140
|
*/
|
|
106
141
|
async getDevices() {
|
|
107
142
|
return new Promise((resolve, reject) => {
|
|
108
|
-
// create the message to request the devices
|
|
109
143
|
let getDevicesRequest = new Message();
|
|
110
144
|
getDevicesRequest.setRequest("getDevices");
|
|
111
145
|
getDevicesRequest.setDestination(PeerType.MASTER, "");
|
|
112
|
-
// send the message to the console
|
|
113
146
|
this._console.sendMessage(getDevicesRequest, (response) => {
|
|
114
|
-
// convert the response to al list of device objects
|
|
115
147
|
let devices_raw = response.getParam("devices", []);
|
|
116
148
|
let devices = [];
|
|
117
149
|
for (let device_raw of devices_raw) {
|
|
@@ -124,19 +156,19 @@ export class Koppelia {
|
|
|
124
156
|
});
|
|
125
157
|
}
|
|
126
158
|
/**
|
|
127
|
-
*
|
|
128
|
-
* @returns
|
|
159
|
+
* Retrieves the unique identifier of the currently loaded game.
|
|
160
|
+
* @returns The game ID string provided by public environment variables.
|
|
129
161
|
*/
|
|
130
162
|
getGameId() {
|
|
131
163
|
return PUBLIC_GAME_ID;
|
|
132
164
|
}
|
|
133
165
|
/**
|
|
134
|
-
*
|
|
135
|
-
*
|
|
136
|
-
* @param count
|
|
137
|
-
* @param index
|
|
138
|
-
* @param orderBy
|
|
139
|
-
* @returns
|
|
166
|
+
* Asynchronously fetches a paginated list of Play sessions.
|
|
167
|
+
* Note: This only fetches metadata. Specific Play content must be downloaded via Play methods.
|
|
168
|
+
* @param count Maximum number of plays to retrieve (default: 10).
|
|
169
|
+
* @param index The starting offset index (default: 0).
|
|
170
|
+
* @param orderBy Sorting criteria, e.g., "date" or "name" (default: "date").
|
|
171
|
+
* @returns A promise resolving to an array of Play instances.
|
|
140
172
|
*/
|
|
141
173
|
async getPlays(count = 10, index = 0, orderBy = "date") {
|
|
142
174
|
return new Promise((resolve, reject) => {
|
|
@@ -157,6 +189,10 @@ export class Koppelia {
|
|
|
157
189
|
});
|
|
158
190
|
});
|
|
159
191
|
}
|
|
192
|
+
/**
|
|
193
|
+
* Asynchronously fetches the list of registered residents/players.
|
|
194
|
+
* @returns A promise resolving to an array of Resident instances.
|
|
195
|
+
*/
|
|
160
196
|
async getResidents() {
|
|
161
197
|
return new Promise((resolve, reject) => {
|
|
162
198
|
let getResidentsRequest = new Message();
|
|
@@ -175,6 +211,11 @@ export class Koppelia {
|
|
|
175
211
|
});
|
|
176
212
|
});
|
|
177
213
|
}
|
|
214
|
+
/**
|
|
215
|
+
* Asynchronously fetches a specific song by its unique ID.
|
|
216
|
+
* @param songId The ID of the song to retrieve.
|
|
217
|
+
* @returns A promise resolving to the corresponding Song instance.
|
|
218
|
+
*/
|
|
178
219
|
async getSongById(songId) {
|
|
179
220
|
return new Promise((resolve, reject) => {
|
|
180
221
|
let getSongRequest = new Message();
|
|
@@ -190,6 +231,10 @@ export class Koppelia {
|
|
|
190
231
|
});
|
|
191
232
|
});
|
|
192
233
|
}
|
|
234
|
+
/**
|
|
235
|
+
* Asynchronously fetches a dictionary of all songs associated with the currently active play.
|
|
236
|
+
* @returns A promise resolving to a map of song IDs to Song instances.
|
|
237
|
+
*/
|
|
193
238
|
getCurrentPlaySongs() {
|
|
194
239
|
return new Promise((resolve, reject) => {
|
|
195
240
|
let getSongRequest = new Message();
|
|
@@ -209,8 +254,8 @@ export class Koppelia {
|
|
|
209
254
|
});
|
|
210
255
|
}
|
|
211
256
|
/**
|
|
212
|
-
*
|
|
213
|
-
* @returns the
|
|
257
|
+
* Asynchronously retrieves the currently active Play instance set on the server.
|
|
258
|
+
* @returns A promise resolving to the active Play.
|
|
214
259
|
*/
|
|
215
260
|
async getCurrentPlay() {
|
|
216
261
|
return new Promise((resolve, reject) => {
|
|
@@ -226,24 +271,23 @@ export class Koppelia {
|
|
|
226
271
|
});
|
|
227
272
|
}
|
|
228
273
|
/**
|
|
229
|
-
*
|
|
230
|
-
* @param callback
|
|
274
|
+
* Enables a live difficulty cursor, allowing difficulty changes during gameplay.
|
|
275
|
+
* @param callback Function to execute when the difficulty changes.
|
|
231
276
|
*/
|
|
232
277
|
async enableDifficultyCursor(callback) {
|
|
233
278
|
}
|
|
234
279
|
/**
|
|
235
|
-
*
|
|
236
|
-
* @param
|
|
280
|
+
* Registers a new growable element on the network and listens for state changes.
|
|
281
|
+
* @param id The unique identifier for the growable element.
|
|
282
|
+
* @param onGrowChange Callback triggered when the 'grown' state of the element changes.
|
|
237
283
|
*/
|
|
238
284
|
async registerNewGrowableElement(id, onGrowChange) {
|
|
239
285
|
return new Promise((resolve, reject) => {
|
|
240
|
-
// create the message to request the devices
|
|
241
286
|
if (get(routeType) == "controller") {
|
|
242
287
|
let addGrowableElRequest = new Message();
|
|
243
288
|
addGrowableElRequest.setRequest("addGrowableElement");
|
|
244
289
|
addGrowableElRequest.addParam("id", id);
|
|
245
290
|
addGrowableElRequest.setDestination(PeerType.MASTER, "");
|
|
246
|
-
// send the message to the console (only the controller sends the )
|
|
247
291
|
this._console.sendMessage(addGrowableElRequest, (response) => {
|
|
248
292
|
});
|
|
249
293
|
}
|
|
@@ -261,26 +305,26 @@ export class Koppelia {
|
|
|
261
305
|
});
|
|
262
306
|
}
|
|
263
307
|
/**
|
|
264
|
-
*
|
|
265
|
-
* @param
|
|
308
|
+
* Updates the 'grown' state of a registered growable element across the network.
|
|
309
|
+
* @param id The unique identifier of the element.
|
|
310
|
+
* @param grown True if the element is in a grown state, false otherwise.
|
|
266
311
|
*/
|
|
267
312
|
async updateGrowableElement(id, grown) {
|
|
268
313
|
return new Promise((resolve, reject) => {
|
|
269
|
-
// create the message to request the devices
|
|
270
314
|
let addGrowableElRequest = new Message();
|
|
271
315
|
addGrowableElRequest.setRequest("updateGrowableElement");
|
|
272
316
|
addGrowableElRequest.addParam("id", id);
|
|
273
317
|
addGrowableElRequest.addParam("grown", grown);
|
|
274
318
|
addGrowableElRequest.setDestination(PeerType.MASTER, "");
|
|
275
|
-
// send the message to the console
|
|
276
319
|
this._console.sendMessage(addGrowableElRequest, (response) => {
|
|
277
320
|
resolve();
|
|
278
321
|
});
|
|
279
322
|
});
|
|
280
323
|
}
|
|
281
324
|
/**
|
|
282
|
-
*
|
|
283
|
-
*
|
|
325
|
+
* Registers a new resizable text element with a default font size (Monitor only).
|
|
326
|
+
* @param id The unique identifier for the text element.
|
|
327
|
+
* @param defaultSize The default font size.
|
|
284
328
|
*/
|
|
285
329
|
async registerNewResizableText(id, defaultSize) {
|
|
286
330
|
return new Promise((resolve, reject) => {
|
|
@@ -290,15 +334,20 @@ export class Koppelia {
|
|
|
290
334
|
addGrowableElRequest.addParam("id", id);
|
|
291
335
|
addGrowableElRequest.addParam("defaultSize", defaultSize);
|
|
292
336
|
addGrowableElRequest.setDestination(PeerType.MASTER, "");
|
|
293
|
-
// send the message to the console (only the controller sends the )
|
|
294
337
|
this._console.sendMessage(addGrowableElRequest, (response) => {
|
|
295
338
|
});
|
|
296
339
|
}
|
|
297
340
|
resolve();
|
|
298
341
|
});
|
|
299
342
|
}
|
|
343
|
+
/**
|
|
344
|
+
* Subscribes to size change notifications for a specific resizable text element.
|
|
345
|
+
* @param id The unique identifier of the text element.
|
|
346
|
+
* @param onTextResized Callback executed with the new font size.
|
|
347
|
+
* @returns The unique subscription ID used for unsubscribing.
|
|
348
|
+
*/
|
|
300
349
|
onResizableTextChanged(id, onTextResized) {
|
|
301
|
-
this._console.onRequest((req, params) => {
|
|
350
|
+
return this._console.onRequest((req, params) => {
|
|
302
351
|
if (req == "resizableTextNotification") {
|
|
303
352
|
if (params.id !== undefined && params.id == id &&
|
|
304
353
|
params.fontSize != undefined) {
|
|
@@ -308,18 +357,34 @@ export class Koppelia {
|
|
|
308
357
|
}
|
|
309
358
|
});
|
|
310
359
|
}
|
|
360
|
+
/**
|
|
361
|
+
* Unsubscribes a previously registered resizable text listener.
|
|
362
|
+
* @param callbackId The subscription ID returned by onResizableTextChanged.
|
|
363
|
+
*/
|
|
364
|
+
unsubResizableText(callbackId) {
|
|
365
|
+
this._console.unsubscribeCallback(callbackId);
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* Retrieves the list of all registered resizable text elements from the master.
|
|
369
|
+
* @returns A promise resolving to an array of resizable element data objects.
|
|
370
|
+
*/
|
|
311
371
|
async getResizableTexts() {
|
|
312
372
|
return new Promise((resolve, reject) => {
|
|
313
373
|
let addGrowableElRequest = new Message();
|
|
314
374
|
addGrowableElRequest.setRequest("getResizableTexts");
|
|
315
375
|
addGrowableElRequest.setDestination(PeerType.MASTER, "");
|
|
316
|
-
// send the message to the console (only the controller sends the )
|
|
317
376
|
this._console.sendMessage(addGrowableElRequest, (response) => {
|
|
318
377
|
let resizables = response.getParam("resizableTexts", []);
|
|
319
378
|
resolve(resizables);
|
|
320
379
|
});
|
|
321
380
|
});
|
|
322
381
|
}
|
|
382
|
+
/**
|
|
383
|
+
* Writes configuration data to the master peer, optionally binding it to the current play.
|
|
384
|
+
* @param config_id The unique identifier for this configuration data.
|
|
385
|
+
* @param config_value The dictionary containing the configuration payload.
|
|
386
|
+
* @param current_play Whether to bind this configuration to the active play session (default: true).
|
|
387
|
+
*/
|
|
323
388
|
async writeGameConfig(config_id, config_value, current_play = true) {
|
|
324
389
|
let setGameConfigRequest = new Message();
|
|
325
390
|
setGameConfigRequest.setRequest("setGameData");
|
|
@@ -329,6 +394,12 @@ export class Koppelia {
|
|
|
329
394
|
setGameConfigRequest.setDestination(PeerType.MASTER, "");
|
|
330
395
|
this._console.sendMessage(setGameConfigRequest);
|
|
331
396
|
}
|
|
397
|
+
/**
|
|
398
|
+
* Retrieves persistent configuration data from the master peer.
|
|
399
|
+
* @param config_id The unique identifier of the configuration data to fetch.
|
|
400
|
+
* @param current_play True to fetch data bound specifically to the active play, false otherwise.
|
|
401
|
+
* @returns A promise resolving to the configuration dictionary.
|
|
402
|
+
*/
|
|
332
403
|
async getGameConfig(config_id, current_play) {
|
|
333
404
|
return new Promise((resolve, reject) => {
|
|
334
405
|
let getGameConfigRequest = new Message();
|
|
@@ -343,25 +414,33 @@ export class Koppelia {
|
|
|
343
414
|
});
|
|
344
415
|
}
|
|
345
416
|
/**
|
|
346
|
-
*
|
|
417
|
+
* Broadcasts a Text-to-Speech synthesis request to the Maestro peer.
|
|
418
|
+
* @param sentence The text string to be spoken out loud.
|
|
347
419
|
*/
|
|
348
420
|
say(sentence) {
|
|
349
|
-
// create the message to request the devices
|
|
350
421
|
let sayRequest = new Message();
|
|
351
422
|
sayRequest.setRequest("sayRequest");
|
|
352
423
|
sayRequest.addParam("sentence", sentence);
|
|
353
424
|
sayRequest.setDestination(PeerType.MAESTRO, "");
|
|
354
|
-
// send the message to the console
|
|
355
425
|
this._console.sendMessage(sayRequest);
|
|
356
426
|
}
|
|
357
427
|
/**
|
|
358
|
-
*
|
|
359
|
-
* @param name
|
|
360
|
-
* @param value
|
|
428
|
+
* Assigns a basic value to a registered game option via the option manager.
|
|
429
|
+
* @param name The unique name of the option.
|
|
430
|
+
* @param value The value to set.
|
|
361
431
|
*/
|
|
362
432
|
setOption(name, value) {
|
|
363
433
|
this._option.setOption(name, value, null, {});
|
|
364
434
|
}
|
|
435
|
+
/**
|
|
436
|
+
* Creates or updates an interactive slider option.
|
|
437
|
+
* @param name The unique identifier for the slider.
|
|
438
|
+
* @param label The display label for the UI.
|
|
439
|
+
* @param value The current numeric value.
|
|
440
|
+
* @param min The minimum allowed value.
|
|
441
|
+
* @param max The maximum allowed value.
|
|
442
|
+
* @param step The increment step size.
|
|
443
|
+
*/
|
|
365
444
|
createSliderOtption(name, label, value, min, max, step) {
|
|
366
445
|
this._option.setOption(name, value, "slider", {
|
|
367
446
|
"min": min,
|
|
@@ -370,26 +449,58 @@ export class Koppelia {
|
|
|
370
449
|
"label": label,
|
|
371
450
|
});
|
|
372
451
|
}
|
|
452
|
+
/**
|
|
453
|
+
* Creates or updates an interactive toggle switch option.
|
|
454
|
+
* @param name The unique identifier for the switch.
|
|
455
|
+
* @param label The display label for the UI.
|
|
456
|
+
* @param value The current boolean state.
|
|
457
|
+
*/
|
|
373
458
|
createSwitchOption(name, label, value) {
|
|
374
459
|
this._option.setOption(name, value, "switch", {
|
|
375
460
|
"label": label,
|
|
376
461
|
});
|
|
377
462
|
}
|
|
463
|
+
/**
|
|
464
|
+
* Creates or updates a multiple-choice selection option.
|
|
465
|
+
* @param name The unique identifier for the option.
|
|
466
|
+
* @param label The display label for the UI.
|
|
467
|
+
* @param value The currently selected choice.
|
|
468
|
+
* @param choices An array of available string choices.
|
|
469
|
+
*/
|
|
378
470
|
createChoicesOption(name, label, value, choices) {
|
|
379
471
|
this._option.setOption(name, value, "choices", {
|
|
380
472
|
"choices": choices,
|
|
381
473
|
"label": label,
|
|
382
474
|
});
|
|
383
475
|
}
|
|
476
|
+
/**
|
|
477
|
+
* Registers a callback listener to trigger whenever a specific option's value changes.
|
|
478
|
+
* @param name The name of the option to observe.
|
|
479
|
+
* @param callback The function to execute on change.
|
|
480
|
+
*/
|
|
384
481
|
onOptionChanged(name, callback) {
|
|
385
482
|
this._option.onOptionChanged(name, callback);
|
|
386
483
|
}
|
|
484
|
+
/**
|
|
485
|
+
* Executes a broadcasted network request to trigger a registered custom callback.
|
|
486
|
+
* @param callbackName The unique registered name of the custom callback.
|
|
487
|
+
* @param args Dictionary of arguments to pass to the callback.
|
|
488
|
+
*/
|
|
387
489
|
run(callbackName, args) {
|
|
388
490
|
this._callbacks.runCustomCallback(callbackName, args);
|
|
389
491
|
}
|
|
492
|
+
/**
|
|
493
|
+
* Registers a local function to listen for network execution of a custom callback.
|
|
494
|
+
* @param callbackName The identifier for this callback.
|
|
495
|
+
* @param callback The local function to execute.
|
|
496
|
+
*/
|
|
390
497
|
on(callbackName, callback) {
|
|
391
498
|
this._callbacks.registerCustomCallback(callbackName, callback);
|
|
392
499
|
}
|
|
500
|
+
/**
|
|
501
|
+
* Unregisters a locally listening custom callback.
|
|
502
|
+
* @param callbackName The identifier of the callback to remove.
|
|
503
|
+
*/
|
|
393
504
|
unsub(callbackName) {
|
|
394
505
|
this._callbacks.unregisterCustomCallback(callbackName);
|
|
395
506
|
}
|
|
@@ -12,62 +12,67 @@ export declare class KoppeliaWebsocket {
|
|
|
12
12
|
websocketUrl: string;
|
|
13
13
|
openCallback?: () => void;
|
|
14
14
|
/**
|
|
15
|
-
*
|
|
16
|
-
* @param websocketUrl
|
|
17
|
-
* @param timeout
|
|
15
|
+
* Initializes the Koppelia WebSocket client.
|
|
16
|
+
* @param websocketUrl The URL of the WebSocket server to connect to.
|
|
17
|
+
* @param timeout The maximum time in milliseconds to wait for a response before timing out a request. Defaults to 20000ms.
|
|
18
18
|
*/
|
|
19
19
|
constructor(websocketUrl: string, timeout?: number);
|
|
20
20
|
/**
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
* @param data
|
|
24
|
-
* @param callback
|
|
21
|
+
* Sends a new message request through the WebSocket.
|
|
22
|
+
* Automatically generates a request ID, registers the request as ongoing, and sets a timeout.
|
|
23
|
+
* @param data The message payload to send.
|
|
24
|
+
* @param callback Optional callback to be executed when a response to this specific request is received.
|
|
25
25
|
*/
|
|
26
26
|
send(data: Message, callback?: Callback): void;
|
|
27
27
|
/**
|
|
28
|
-
*
|
|
29
|
-
* @param callback
|
|
28
|
+
* Registers a global callback to be triggered whenever a message is received.
|
|
29
|
+
* @param callback The function to execute upon receiving a message.
|
|
30
30
|
*/
|
|
31
31
|
onReceive(callback: Callback): void;
|
|
32
32
|
/**
|
|
33
|
-
*
|
|
34
|
-
* @param callback
|
|
33
|
+
* Registers a callback to be triggered when the WebSocket connection successfully opens.
|
|
34
|
+
* @param callback The function to execute upon connection.
|
|
35
35
|
*/
|
|
36
36
|
onOpen(callback: () => void): void;
|
|
37
|
+
/**
|
|
38
|
+
* Establishes the WebSocket connection.
|
|
39
|
+
* @param websockerUrl The URL of the WebSocket server.
|
|
40
|
+
*/
|
|
37
41
|
private _connectWebsocket;
|
|
38
42
|
/**
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
* @param data
|
|
43
|
-
* @returns
|
|
43
|
+
* Handles incoming WebSocket responses.
|
|
44
|
+
* Checks if the message corresponds to an ongoing request. If so, triggers its specific callback.
|
|
45
|
+
* Otherwise, broadcasts the message to all global receive callbacks.
|
|
46
|
+
* @param data The raw data payload received from the WebSocket.
|
|
44
47
|
*/
|
|
45
48
|
private _handleWebsocketResponse;
|
|
46
49
|
/**
|
|
47
|
-
*
|
|
50
|
+
* Initializes all WebSocket event listeners (open, message, close).
|
|
51
|
+
* Handles automatic reconnection on connection close or error.
|
|
48
52
|
*/
|
|
49
53
|
private _setupEvents;
|
|
50
54
|
/**
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
* @
|
|
55
|
+
* Retrieves the index of an ongoing request in the internal list.
|
|
56
|
+
* @param requestId The unique identifier of the request.
|
|
57
|
+
* @returns The array index of the request, or -1 if not found.
|
|
54
58
|
*/
|
|
55
59
|
private _getRequestIndex;
|
|
56
60
|
/**
|
|
57
|
-
*
|
|
58
|
-
*
|
|
61
|
+
* Removes a request from the ongoing requests list.
|
|
62
|
+
* Used both when a request is successfully resolved or when it times out.
|
|
63
|
+
* @param requestId The unique identifier of the request to remove.
|
|
59
64
|
*/
|
|
60
65
|
private _deleteRequest;
|
|
61
66
|
/**
|
|
62
|
-
*
|
|
63
|
-
* @param requestId
|
|
64
|
-
* @returns
|
|
67
|
+
* Retrieves an ongoing request object by its ID.
|
|
68
|
+
* @param requestId The unique identifier of the request.
|
|
69
|
+
* @returns The ongoing request object, or undefined if not found.
|
|
65
70
|
*/
|
|
66
71
|
private _getOnGoingRequest;
|
|
67
72
|
/**
|
|
68
|
-
*
|
|
69
|
-
* @param requestId
|
|
70
|
-
* @param callback
|
|
73
|
+
* Registers a new request in the ongoing requests list.
|
|
74
|
+
* @param requestId The unique identifier generated for the request.
|
|
75
|
+
* @param callback Optional callback to trigger when the response arrives.
|
|
71
76
|
*/
|
|
72
77
|
private _addNewRequest;
|
|
73
78
|
}
|