@momo2555/koppeliajs 0.0.160 → 0.0.162
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 +63 -32
- package/dist/scripts/console.js +154 -70
- package/dist/scripts/koppelia.d.ts +6 -1
- package/dist/scripts/koppelia.js +26 -11
- package/dist/scripts/play.js +3 -0
- package/package.json +1 -1
|
@@ -1,26 +1,44 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
|
|
2
|
+
import { routeType } from '../stores/routeStore.js';
|
|
3
3
|
import { Koppelia } from '../scripts/koppelia.js';
|
|
4
|
+
import { onDestroy } from 'svelte';
|
|
4
5
|
|
|
5
6
|
export let id: string = '';
|
|
6
|
-
|
|
7
|
+
export let defaultFontSize: number = 10;
|
|
7
8
|
|
|
8
9
|
$: fontSize = defaultFontSize;
|
|
10
|
+
$: callbackId = "";
|
|
9
11
|
|
|
10
12
|
let koppelia = Koppelia.instance;
|
|
11
|
-
|
|
13
|
+
|
|
12
14
|
koppelia.onReady(async () => {
|
|
13
|
-
await koppelia.
|
|
15
|
+
let resizableTexts = await koppelia.getResizableTexts();
|
|
16
|
+
let resizableExist = false;
|
|
17
|
+
for (let rt of resizableTexts) {
|
|
18
|
+
if (rt.id !== undefined && rt.id == id) {
|
|
19
|
+
if (rt.fontSize !== undefined) {
|
|
20
|
+
fontSize = rt.fontSize;
|
|
21
|
+
}
|
|
22
|
+
resizableExist = true;
|
|
23
|
+
break;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
if (!resizableExist) {
|
|
27
|
+
await koppelia.registerNewResizableText(id, defaultFontSize);
|
|
28
|
+
}
|
|
29
|
+
callbackId = koppelia.onResizableTextChanged(id, (newFontSize: number) => {
|
|
14
30
|
fontSize = newFontSize;
|
|
15
31
|
});
|
|
16
32
|
});
|
|
17
33
|
|
|
34
|
+
onDestroy(() => {
|
|
35
|
+
koppelia.unsubResizableText(callbackId);
|
|
36
|
+
});
|
|
18
37
|
</script>
|
|
19
38
|
|
|
20
39
|
<div class="resizable-text" id="resizable-text-{id}" style="font-size: {fontSize}px;">
|
|
21
|
-
|
|
40
|
+
<slot />
|
|
22
41
|
</div>
|
|
23
42
|
|
|
24
43
|
<style>
|
|
25
|
-
|
|
26
44
|
</style>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Message, type MessageData, PeerType } from
|
|
3
|
-
import type { AnyState } from
|
|
1
|
+
import { type Callback, KoppeliaWebsocket } from "./koppeliaWebsocket.js";
|
|
2
|
+
import { Message, type MessageData, PeerType } from "./message.js";
|
|
3
|
+
import type { AnyState } from "./state.js";
|
|
4
4
|
export type ChangeStateCallback = (from: string, state: AnyState, update: boolean) => void;
|
|
5
5
|
export type ChangeStageCallback = (from: string, stage: string) => void;
|
|
6
6
|
export type DataExchangeCallback = (from: string, data: any) => void;
|
|
@@ -11,7 +11,7 @@ export type AnyRequestCallback = (request: string, params: {
|
|
|
11
11
|
}, from: string, address: string) => void;
|
|
12
12
|
export type MediaResponseData = string | Blob | ArrayBuffer | any;
|
|
13
13
|
/**
|
|
14
|
-
* This class
|
|
14
|
+
* This class defines the Koppelia console to send and receive requests.
|
|
15
15
|
*/
|
|
16
16
|
export declare class Console {
|
|
17
17
|
consoleHostname: string;
|
|
@@ -22,58 +22,86 @@ export declare class Console {
|
|
|
22
22
|
private _deviceDataHandlers;
|
|
23
23
|
private _dataExchangeHandlers;
|
|
24
24
|
private _anyRequestHandlers;
|
|
25
|
-
private _ready;
|
|
26
25
|
private _onReadyCallback;
|
|
26
|
+
private _ready;
|
|
27
27
|
private _mediaApiUrl;
|
|
28
28
|
constructor();
|
|
29
29
|
/**
|
|
30
|
-
*
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
* Generates a unique random ID for callback registration.
|
|
31
|
+
*/
|
|
32
|
+
private _generateId;
|
|
33
|
+
/**
|
|
34
|
+
* Unsubscribes a previously registered callback using its ID.
|
|
35
|
+
* @param id The identifier returned by the "on..." functions.
|
|
36
|
+
* @returns true if the ID was found and deleted, false otherwise.
|
|
37
|
+
*/
|
|
38
|
+
unsubscribeCallback(id: string): boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Sends a message to the console. Set header.to to dispatch the message.
|
|
41
|
+
* @param message The message to send.
|
|
42
|
+
* @param callback The callback triggered when the websocket receives a response.
|
|
33
43
|
*/
|
|
34
44
|
sendMessage(message: Message, callback?: Callback): void;
|
|
35
45
|
/**
|
|
36
|
-
*
|
|
37
|
-
* @param peer
|
|
46
|
+
* Identifies the page (controller or monitor) to the console.
|
|
47
|
+
* @param peer The peer type to identify as.
|
|
38
48
|
*/
|
|
39
49
|
identify(peer: PeerType): void;
|
|
40
50
|
getConnectedDevices(): void;
|
|
41
51
|
/**
|
|
42
|
-
*
|
|
43
|
-
* @param receiver
|
|
44
|
-
* @param data
|
|
52
|
+
* Sends data to a specific peer.
|
|
53
|
+
* @param receiver The peer type receiving the data.
|
|
54
|
+
* @param data The data payload.
|
|
45
55
|
*/
|
|
46
56
|
sendDataTo(receiver: PeerType, data: MessageData): void;
|
|
47
57
|
/**
|
|
48
|
-
*
|
|
49
|
-
* @param callback
|
|
58
|
+
* Adds a callback to be executed when a new state is received from the console.
|
|
59
|
+
* @param callback Function to execute on state change.
|
|
60
|
+
* @returns The subscription ID.
|
|
61
|
+
*/
|
|
62
|
+
onStateChange(callback: ChangeStateCallback): string;
|
|
63
|
+
/**
|
|
64
|
+
* Adds a callback to be executed when the current stage changes.
|
|
65
|
+
* @param callback Function to execute on stage change.
|
|
66
|
+
* @returns The subscription ID.
|
|
67
|
+
*/
|
|
68
|
+
onStageChange(callback: ChangeStageCallback): string;
|
|
69
|
+
/**
|
|
70
|
+
* Adds a callback to be executed when the console is ready.
|
|
71
|
+
* If the console is already ready, the function is called immediately.
|
|
72
|
+
* @param callback Function to execute.
|
|
73
|
+
* @returns The subscription ID.
|
|
50
74
|
*/
|
|
51
|
-
|
|
75
|
+
onReady(callback: () => void): string;
|
|
52
76
|
/**
|
|
53
|
-
*
|
|
54
|
-
* @param callback
|
|
77
|
+
* Adds a callback to listen for device events.
|
|
78
|
+
* @param callback Function to execute on device event.
|
|
79
|
+
* @returns The subscription ID.
|
|
55
80
|
*/
|
|
56
|
-
|
|
81
|
+
onDeviceEvent(callback: DeviceEventCallback): string;
|
|
57
82
|
/**
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
* @
|
|
83
|
+
* Adds a callback to listen for data exchanges.
|
|
84
|
+
* @param callback Function to execute on data exchange.
|
|
85
|
+
* @returns The subscription ID.
|
|
61
86
|
*/
|
|
62
|
-
|
|
63
|
-
onDeviceEvent(callback: DeviceEventCallback): void;
|
|
64
|
-
onDataExchange(callback: DataExchangeCallback): void;
|
|
65
|
-
onRequest(callback: AnyRequestCallback): void;
|
|
87
|
+
onDataExchange(callback: DataExchangeCallback): string;
|
|
66
88
|
/**
|
|
67
|
-
*
|
|
89
|
+
* Adds a callback to listen for generic requests.
|
|
90
|
+
* @param callback Function to execute on request.
|
|
91
|
+
* @returns The subscription ID.
|
|
92
|
+
*/
|
|
93
|
+
onRequest(callback: AnyRequestCallback): string;
|
|
94
|
+
/**
|
|
95
|
+
* Gets the current readiness state of the console connection.
|
|
68
96
|
*/
|
|
69
97
|
get ready(): boolean;
|
|
70
98
|
getMediaUrl(path: string): string;
|
|
71
99
|
/**
|
|
72
|
-
*
|
|
73
|
-
* Sometimes,
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
* @
|
|
100
|
+
* Normalizes the media URL to ensure it works for both the controller and the monitor.
|
|
101
|
+
* Sometimes, a link retrieved from one client is saved as a game state, but fails
|
|
102
|
+
* when accessed by the other client. Wrapping all media URLs with this function is best practice.
|
|
103
|
+
* @param mediaUrl The original media URL.
|
|
104
|
+
* @returns The corrected URL string.
|
|
77
105
|
*/
|
|
78
106
|
fixMediaUrl(mediaUrl: string): string;
|
|
79
107
|
getMedia(path: string): Promise<MediaResponseData>;
|
|
@@ -85,5 +113,8 @@ export declare class Console {
|
|
|
85
113
|
private _execChangeStageHandlers;
|
|
86
114
|
private _execDataExchangeHandlers;
|
|
87
115
|
private _execAnyRequestHandlers;
|
|
116
|
+
/**
|
|
117
|
+
* Clears all registered event handlers.
|
|
118
|
+
*/
|
|
88
119
|
destroyEvents(): void;
|
|
89
120
|
}
|
package/dist/scripts/console.js
CHANGED
|
@@ -1,25 +1,26 @@
|
|
|
1
|
-
import { KoppeliaWebsocket } from
|
|
2
|
-
import { Message,
|
|
3
|
-
import { page } from
|
|
4
|
-
import { get } from
|
|
5
|
-
import { routeType } from
|
|
6
|
-
import { logger } from
|
|
1
|
+
import { KoppeliaWebsocket } from "./koppeliaWebsocket.js";
|
|
2
|
+
import { Message, MessageType, PeerType } from "./message.js";
|
|
3
|
+
import { page } from "$app/stores";
|
|
4
|
+
import { get } from "svelte/store";
|
|
5
|
+
import { routeType } from "../stores/routeStore.js";
|
|
6
|
+
import { logger } from "./logger.js";
|
|
7
7
|
const PORT = 2225;
|
|
8
8
|
const API_PORT = 8000;
|
|
9
9
|
/**
|
|
10
|
-
* This class
|
|
10
|
+
* This class defines the Koppelia console to send and receive requests.
|
|
11
11
|
*/
|
|
12
12
|
export class Console {
|
|
13
13
|
consoleHostname = "";
|
|
14
14
|
consoleSocket;
|
|
15
|
+
// Event handlers stored as dictionaries (Record) for ID-based subscription management
|
|
15
16
|
_changeStateHandlers;
|
|
16
17
|
_changeStageHandlers;
|
|
17
18
|
_deviceEventHandlers;
|
|
18
19
|
_deviceDataHandlers;
|
|
19
20
|
_dataExchangeHandlers;
|
|
20
21
|
_anyRequestHandlers;
|
|
21
|
-
_ready = false;
|
|
22
22
|
_onReadyCallback;
|
|
23
|
+
_ready = false;
|
|
23
24
|
_mediaApiUrl;
|
|
24
25
|
constructor() {
|
|
25
26
|
this.consoleHostname = "";
|
|
@@ -30,32 +31,79 @@ export class Console {
|
|
|
30
31
|
this.consoleSocket = new KoppeliaWebsocket(consoleUrl);
|
|
31
32
|
this._mediaApiUrl = "http://" + this.consoleHostname + ":" + API_PORT;
|
|
32
33
|
this._ready = false;
|
|
33
|
-
|
|
34
|
-
this.
|
|
35
|
-
this.
|
|
36
|
-
this.
|
|
37
|
-
this.
|
|
38
|
-
this.
|
|
39
|
-
this.
|
|
34
|
+
// Initialize dictionaries
|
|
35
|
+
this._changeStateHandlers = {};
|
|
36
|
+
this._changeStageHandlers = {};
|
|
37
|
+
this._deviceEventHandlers = {};
|
|
38
|
+
this._deviceDataHandlers = {};
|
|
39
|
+
this._dataExchangeHandlers = {};
|
|
40
|
+
this._onReadyCallback = {};
|
|
41
|
+
this._anyRequestHandlers = {};
|
|
40
42
|
this._initEvents();
|
|
41
43
|
}
|
|
42
44
|
/**
|
|
43
|
-
*
|
|
44
|
-
|
|
45
|
-
|
|
45
|
+
* Generates a unique random ID for callback registration.
|
|
46
|
+
*/
|
|
47
|
+
_generateId() {
|
|
48
|
+
return Math.random().toString(36).substring(2, 15) +
|
|
49
|
+
Math.random().toString(36).substring(2, 15);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Unsubscribes a previously registered callback using its ID.
|
|
53
|
+
* @param id The identifier returned by the "on..." functions.
|
|
54
|
+
* @returns true if the ID was found and deleted, false otherwise.
|
|
55
|
+
*/
|
|
56
|
+
unsubscribeCallback(id) {
|
|
57
|
+
let deleted = false;
|
|
58
|
+
if (id in this._changeStateHandlers) {
|
|
59
|
+
delete this._changeStateHandlers[id];
|
|
60
|
+
deleted = true;
|
|
61
|
+
}
|
|
62
|
+
if (id in this._changeStageHandlers) {
|
|
63
|
+
delete this._changeStageHandlers[id];
|
|
64
|
+
deleted = true;
|
|
65
|
+
}
|
|
66
|
+
if (id in this._deviceEventHandlers) {
|
|
67
|
+
delete this._deviceEventHandlers[id];
|
|
68
|
+
deleted = true;
|
|
69
|
+
}
|
|
70
|
+
if (id in this._deviceDataHandlers) {
|
|
71
|
+
delete this._deviceDataHandlers[id];
|
|
72
|
+
deleted = true;
|
|
73
|
+
}
|
|
74
|
+
if (id in this._dataExchangeHandlers) {
|
|
75
|
+
delete this._dataExchangeHandlers[id];
|
|
76
|
+
deleted = true;
|
|
77
|
+
}
|
|
78
|
+
if (id in this._anyRequestHandlers) {
|
|
79
|
+
delete this._anyRequestHandlers[id];
|
|
80
|
+
deleted = true;
|
|
81
|
+
}
|
|
82
|
+
if (id in this._onReadyCallback) {
|
|
83
|
+
delete this._onReadyCallback[id];
|
|
84
|
+
deleted = true;
|
|
85
|
+
}
|
|
86
|
+
return deleted;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Sends a message to the console. Set header.to to dispatch the message.
|
|
90
|
+
* @param message The message to send.
|
|
91
|
+
* @param callback The callback triggered when the websocket receives a response.
|
|
46
92
|
*/
|
|
47
93
|
sendMessage(message, callback) {
|
|
48
94
|
let route = PeerType.NONE;
|
|
49
|
-
if (get(routeType) == "monitor")
|
|
95
|
+
if (get(routeType) == "monitor") {
|
|
50
96
|
route = PeerType.MONITOR;
|
|
51
|
-
|
|
97
|
+
}
|
|
98
|
+
else if (get(routeType) == "controller") {
|
|
52
99
|
route = PeerType.CONTROLLER;
|
|
100
|
+
}
|
|
53
101
|
message.setSource(route, "");
|
|
54
102
|
this.consoleSocket.send(message, callback);
|
|
55
103
|
}
|
|
56
104
|
/**
|
|
57
|
-
*
|
|
58
|
-
* @param peer
|
|
105
|
+
* Identifies the page (controller or monitor) to the console.
|
|
106
|
+
* @param peer The peer type to identify as.
|
|
59
107
|
*/
|
|
60
108
|
identify(peer) {
|
|
61
109
|
let req = new Message();
|
|
@@ -65,9 +113,9 @@ export class Console {
|
|
|
65
113
|
getConnectedDevices() {
|
|
66
114
|
}
|
|
67
115
|
/**
|
|
68
|
-
*
|
|
69
|
-
* @param receiver
|
|
70
|
-
* @param data
|
|
116
|
+
* Sends data to a specific peer.
|
|
117
|
+
* @param receiver The peer type receiving the data.
|
|
118
|
+
* @param data The data payload.
|
|
71
119
|
*/
|
|
72
120
|
sendDataTo(receiver, data) {
|
|
73
121
|
let req = new Message();
|
|
@@ -75,41 +123,73 @@ export class Console {
|
|
|
75
123
|
req.setDestination(receiver);
|
|
76
124
|
}
|
|
77
125
|
/**
|
|
78
|
-
*
|
|
79
|
-
* @param callback
|
|
126
|
+
* Adds a callback to be executed when a new state is received from the console.
|
|
127
|
+
* @param callback Function to execute on state change.
|
|
128
|
+
* @returns The subscription ID.
|
|
80
129
|
*/
|
|
81
130
|
onStateChange(callback) {
|
|
82
|
-
this.
|
|
131
|
+
const id = this._generateId();
|
|
132
|
+
this._changeStateHandlers[id] = callback;
|
|
133
|
+
return id;
|
|
83
134
|
}
|
|
84
135
|
/**
|
|
85
|
-
*
|
|
86
|
-
* @param callback
|
|
136
|
+
* Adds a callback to be executed when the current stage changes.
|
|
137
|
+
* @param callback Function to execute on stage change.
|
|
138
|
+
* @returns The subscription ID.
|
|
87
139
|
*/
|
|
88
140
|
onStageChange(callback) {
|
|
89
|
-
this.
|
|
141
|
+
const id = this._generateId();
|
|
142
|
+
this._changeStageHandlers[id] = callback;
|
|
143
|
+
return id;
|
|
90
144
|
}
|
|
91
145
|
/**
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
* @param callback
|
|
146
|
+
* Adds a callback to be executed when the console is ready.
|
|
147
|
+
* If the console is already ready, the function is called immediately.
|
|
148
|
+
* @param callback Function to execute.
|
|
149
|
+
* @returns The subscription ID.
|
|
95
150
|
*/
|
|
96
151
|
onReady(callback) {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
152
|
+
const id = this._generateId();
|
|
153
|
+
if (!this._ready) {
|
|
154
|
+
this._onReadyCallback[id] = callback;
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
100
157
|
callback();
|
|
158
|
+
}
|
|
159
|
+
return id;
|
|
101
160
|
}
|
|
161
|
+
/**
|
|
162
|
+
* Adds a callback to listen for device events.
|
|
163
|
+
* @param callback Function to execute on device event.
|
|
164
|
+
* @returns The subscription ID.
|
|
165
|
+
*/
|
|
102
166
|
onDeviceEvent(callback) {
|
|
103
|
-
this.
|
|
167
|
+
const id = this._generateId();
|
|
168
|
+
this._deviceEventHandlers[id] = callback;
|
|
169
|
+
return id;
|
|
104
170
|
}
|
|
171
|
+
/**
|
|
172
|
+
* Adds a callback to listen for data exchanges.
|
|
173
|
+
* @param callback Function to execute on data exchange.
|
|
174
|
+
* @returns The subscription ID.
|
|
175
|
+
*/
|
|
105
176
|
onDataExchange(callback) {
|
|
106
|
-
this.
|
|
177
|
+
const id = this._generateId();
|
|
178
|
+
this._dataExchangeHandlers[id] = callback;
|
|
179
|
+
return id;
|
|
107
180
|
}
|
|
181
|
+
/**
|
|
182
|
+
* Adds a callback to listen for generic requests.
|
|
183
|
+
* @param callback Function to execute on request.
|
|
184
|
+
* @returns The subscription ID.
|
|
185
|
+
*/
|
|
108
186
|
onRequest(callback) {
|
|
109
|
-
this.
|
|
187
|
+
const id = this._generateId();
|
|
188
|
+
this._anyRequestHandlers[id] = callback;
|
|
189
|
+
return id;
|
|
110
190
|
}
|
|
111
191
|
/**
|
|
112
|
-
*
|
|
192
|
+
* Gets the current readiness state of the console connection.
|
|
113
193
|
*/
|
|
114
194
|
get ready() {
|
|
115
195
|
return this._ready;
|
|
@@ -120,11 +200,11 @@ export class Console {
|
|
|
120
200
|
return this._mediaApiUrl + path;
|
|
121
201
|
}
|
|
122
202
|
/**
|
|
123
|
-
*
|
|
124
|
-
* Sometimes,
|
|
125
|
-
*
|
|
126
|
-
*
|
|
127
|
-
* @
|
|
203
|
+
* Normalizes the media URL to ensure it works for both the controller and the monitor.
|
|
204
|
+
* Sometimes, a link retrieved from one client is saved as a game state, but fails
|
|
205
|
+
* when accessed by the other client. Wrapping all media URLs with this function is best practice.
|
|
206
|
+
* @param mediaUrl The original media URL.
|
|
207
|
+
* @returns The corrected URL string.
|
|
128
208
|
*/
|
|
129
209
|
fixMediaUrl(mediaUrl) {
|
|
130
210
|
let url = new URL(mediaUrl);
|
|
@@ -140,22 +220,23 @@ export class Console {
|
|
|
140
220
|
}
|
|
141
221
|
const contentType = response.headers.get("Content-Type") || "";
|
|
142
222
|
if (contentType.includes("application/json")) {
|
|
143
|
-
return await response.json(); // Object
|
|
223
|
+
return await response.json(); // Returns an Object
|
|
144
224
|
}
|
|
145
225
|
else if (contentType.startsWith("text/")) {
|
|
146
|
-
return await response.text(); // String
|
|
226
|
+
return await response.text(); // Returns a String
|
|
147
227
|
}
|
|
148
|
-
else if (contentType.startsWith("image/") ||
|
|
149
|
-
|
|
228
|
+
else if (contentType.startsWith("image/") ||
|
|
229
|
+
contentType.includes("application/octet-stream")) {
|
|
230
|
+
return await response.blob(); // Returns a Blob (images, downloads, etc.)
|
|
150
231
|
}
|
|
151
232
|
else {
|
|
152
|
-
return await response.arrayBuffer(); // Generic binary
|
|
233
|
+
return await response.arrayBuffer(); // Returns a Generic binary buffer
|
|
153
234
|
}
|
|
154
235
|
}
|
|
155
236
|
_initEvents() {
|
|
156
237
|
this.consoleSocket.onOpen(() => {
|
|
157
238
|
this._ready = true;
|
|
158
|
-
for (let callback of this._onReadyCallback) {
|
|
239
|
+
for (let callback of Object.values(this._onReadyCallback)) {
|
|
159
240
|
callback();
|
|
160
241
|
}
|
|
161
242
|
});
|
|
@@ -164,9 +245,10 @@ export class Console {
|
|
|
164
245
|
});
|
|
165
246
|
}
|
|
166
247
|
_processReceivedData(request) {
|
|
167
|
-
logger.log("
|
|
168
|
-
if (request.header.type === undefined)
|
|
248
|
+
logger.log("Received new data from console", request);
|
|
249
|
+
if (request.header.type === undefined) {
|
|
169
250
|
return;
|
|
251
|
+
}
|
|
170
252
|
let type = request.header.type;
|
|
171
253
|
/* Handle specific requests */
|
|
172
254
|
if (type == MessageType.REQUEST) {
|
|
@@ -182,54 +264,56 @@ export class Console {
|
|
|
182
264
|
this._execAnyRequestHandlers(request.request.exec, request.request.params, request.header.from, request.header.from_addr);
|
|
183
265
|
break;
|
|
184
266
|
}
|
|
185
|
-
}
|
|
186
|
-
/* Handle data exchange */
|
|
267
|
+
} /* Handle data exchange */
|
|
187
268
|
else if (type == MessageType.DATA_EXCHANGE) {
|
|
188
269
|
this._execDataExchangeHandlers(request.header.from, request.data);
|
|
189
|
-
}
|
|
190
|
-
/* Handle device event */
|
|
270
|
+
} /* Handle device event */
|
|
191
271
|
else if (type == MessageType.DEVICE_EVENT) {
|
|
192
272
|
this._execDeviceEventHandlers(request.header.device, request.header.from_addr, request.event);
|
|
193
|
-
}
|
|
194
|
-
/* Handle device data */
|
|
273
|
+
} /* Handle device data */
|
|
195
274
|
else if (type == MessageType.DEVICE_DATA) {
|
|
196
275
|
this._execDeviceDataHandlers(request.header.from_addr, request.data);
|
|
197
276
|
}
|
|
198
277
|
}
|
|
278
|
+
// Handler execution methods iterating over dictionary values
|
|
199
279
|
_execDeviceDataHandlers(from_addr, data) {
|
|
200
|
-
for (let handler of this._deviceDataHandlers) {
|
|
280
|
+
for (let handler of Object.values(this._deviceDataHandlers)) {
|
|
201
281
|
handler(from_addr, data);
|
|
202
282
|
}
|
|
203
283
|
}
|
|
204
284
|
_execDeviceEventHandlers(device, from_addr, event) {
|
|
205
|
-
for (let handler of this._deviceEventHandlers) {
|
|
285
|
+
for (let handler of Object.values(this._deviceEventHandlers)) {
|
|
206
286
|
handler(device, from_addr, event);
|
|
207
287
|
}
|
|
208
288
|
}
|
|
209
289
|
_execChangeStateHandlers(from, state, update) {
|
|
210
|
-
for (let handler of this._changeStateHandlers) {
|
|
290
|
+
for (let handler of Object.values(this._changeStateHandlers)) {
|
|
211
291
|
handler(from, state, update);
|
|
212
292
|
}
|
|
213
293
|
}
|
|
214
294
|
_execChangeStageHandlers(from, stage) {
|
|
215
|
-
for (let handler of this._changeStageHandlers) {
|
|
295
|
+
for (let handler of Object.values(this._changeStageHandlers)) {
|
|
216
296
|
handler(from, stage);
|
|
217
297
|
}
|
|
218
298
|
}
|
|
219
299
|
_execDataExchangeHandlers(from, data) {
|
|
220
|
-
for (let handler of this._dataExchangeHandlers) {
|
|
300
|
+
for (let handler of Object.values(this._dataExchangeHandlers)) {
|
|
221
301
|
handler(from, data);
|
|
222
302
|
}
|
|
223
303
|
}
|
|
224
304
|
_execAnyRequestHandlers(request, params, from, address) {
|
|
225
|
-
for (let handler of this._anyRequestHandlers) {
|
|
305
|
+
for (let handler of Object.values(this._anyRequestHandlers)) {
|
|
226
306
|
handler(request, params, from, address);
|
|
227
307
|
}
|
|
228
308
|
}
|
|
309
|
+
/**
|
|
310
|
+
* Clears all registered event handlers.
|
|
311
|
+
*/
|
|
229
312
|
destroyEvents() {
|
|
230
|
-
|
|
231
|
-
this.
|
|
232
|
-
this.
|
|
233
|
-
|
|
313
|
+
// Reset dictionaries to empty objects
|
|
314
|
+
this._deviceEventHandlers = {};
|
|
315
|
+
this._deviceDataHandlers = {};
|
|
316
|
+
this._anyRequestHandlers = {};
|
|
317
|
+
logger.log("Destroyed event handlers");
|
|
234
318
|
}
|
|
235
319
|
}
|
|
@@ -89,7 +89,12 @@ export declare class Koppelia {
|
|
|
89
89
|
* Add a new resizable text element and define the callback that will be executed when receive and a resizable
|
|
90
90
|
* text update notification form koppelia application
|
|
91
91
|
*/
|
|
92
|
-
registerNewResizableText(id: string, defaultSize: number
|
|
92
|
+
registerNewResizableText(id: string, defaultSize: number): Promise<void>;
|
|
93
|
+
onResizableTextChanged(id: string, onTextResized: (newSize: number) => void): string;
|
|
94
|
+
unsubResizableText(callbackId: string): void;
|
|
95
|
+
getResizableTexts(): Promise<{
|
|
96
|
+
[key: string]: any;
|
|
97
|
+
}[]>;
|
|
93
98
|
writeGameConfig(config_id: string, config_value: {
|
|
94
99
|
[key: string]: any;
|
|
95
100
|
}, current_play?: boolean): Promise<void>;
|
package/dist/scripts/koppelia.js
CHANGED
|
@@ -282,7 +282,7 @@ export class Koppelia {
|
|
|
282
282
|
* Add a new resizable text element and define the callback that will be executed when receive and a resizable
|
|
283
283
|
* text update notification form koppelia application
|
|
284
284
|
*/
|
|
285
|
-
async registerNewResizableText(id, defaultSize
|
|
285
|
+
async registerNewResizableText(id, defaultSize) {
|
|
286
286
|
return new Promise((resolve, reject) => {
|
|
287
287
|
if (get(routeType) == "monitor") {
|
|
288
288
|
let addGrowableElRequest = new Message();
|
|
@@ -294,18 +294,33 @@ export class Koppelia {
|
|
|
294
294
|
this._console.sendMessage(addGrowableElRequest, (response) => {
|
|
295
295
|
});
|
|
296
296
|
}
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
297
|
+
resolve();
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
onResizableTextChanged(id, onTextResized) {
|
|
301
|
+
return this._console.onRequest((req, params) => {
|
|
302
|
+
if (req == "resizableTextNotification") {
|
|
303
|
+
if (params.id !== undefined && params.id == id &&
|
|
304
|
+
params.fontSize != undefined) {
|
|
305
|
+
let fontSize = params.fontSize;
|
|
306
|
+
onTextResized(fontSize);
|
|
306
307
|
}
|
|
308
|
+
}
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
unsubResizableText(callbackId) {
|
|
312
|
+
this._console.unsubscribeCallback(callbackId);
|
|
313
|
+
}
|
|
314
|
+
async getResizableTexts() {
|
|
315
|
+
return new Promise((resolve, reject) => {
|
|
316
|
+
let addGrowableElRequest = new Message();
|
|
317
|
+
addGrowableElRequest.setRequest("getResizableTexts");
|
|
318
|
+
addGrowableElRequest.setDestination(PeerType.MASTER, "");
|
|
319
|
+
// send the message to the console (only the controller sends the )
|
|
320
|
+
this._console.sendMessage(addGrowableElRequest, (response) => {
|
|
321
|
+
let resizables = response.getParam("resizableTexts", []);
|
|
322
|
+
resolve(resizables);
|
|
307
323
|
});
|
|
308
|
-
resolve();
|
|
309
324
|
});
|
|
310
325
|
}
|
|
311
326
|
async writeGameConfig(config_id, config_value, current_play = true) {
|
package/dist/scripts/play.js
CHANGED
|
@@ -26,6 +26,9 @@ export class Play {
|
|
|
26
26
|
if (playRawObj.file_name !== undefined) {
|
|
27
27
|
this._playFileName = playRawObj.file_name;
|
|
28
28
|
}
|
|
29
|
+
if (playRawObj.thumbnail !== undefined) {
|
|
30
|
+
this._playImagebase64 = playRawObj.thumbnail;
|
|
31
|
+
}
|
|
29
32
|
this._playContentLoaded = false;
|
|
30
33
|
}
|
|
31
34
|
getPlayMediaPath(mediaName) {
|