@momo2555/koppeliajs 0.0.145 → 0.0.147
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/scripts/console.js +3 -2
- package/dist/scripts/koppelia.d.ts +1 -0
- package/dist/scripts/koppelia.js +8 -4
- package/dist/scripts/koppeliaWebsocket.js +7 -6
- package/dist/scripts/logger.d.ts +6 -0
- package/dist/scripts/logger.js +25 -0
- package/dist/scripts/state.js +2 -1
- package/dist/server/koppeliaServerApi.js +3 -2
- package/dist/stores/routeStore.js +4 -3
- package/dist/stores/stateStore.js +2 -1
- package/package.json +1 -1
package/dist/scripts/console.js
CHANGED
|
@@ -3,6 +3,7 @@ import { Message, PeerType, MessageType } from './message.js';
|
|
|
3
3
|
import { page } from '$app/stores';
|
|
4
4
|
import { get } from 'svelte/store';
|
|
5
5
|
import { routeType } from '../stores/routeStore.js';
|
|
6
|
+
import { logger } from './logger.js';
|
|
6
7
|
const PORT = 2225;
|
|
7
8
|
const API_PORT = 8000;
|
|
8
9
|
/**
|
|
@@ -160,7 +161,7 @@ export class Console {
|
|
|
160
161
|
});
|
|
161
162
|
}
|
|
162
163
|
_processReceivedData(request) {
|
|
163
|
-
|
|
164
|
+
logger.log("Receive new data from console", request);
|
|
164
165
|
if (request.header.type === undefined)
|
|
165
166
|
return;
|
|
166
167
|
let type = request.header.type;
|
|
@@ -227,6 +228,6 @@ export class Console {
|
|
|
227
228
|
this._deviceDataHandlers = [];
|
|
228
229
|
this._dataExchangeHandlers = [];
|
|
229
230
|
this._anyRequestHandlers = [];
|
|
230
|
-
|
|
231
|
+
logger.log("destroy events event handlers");
|
|
231
232
|
}
|
|
232
233
|
}
|
|
@@ -16,6 +16,7 @@ export declare class Koppelia {
|
|
|
16
16
|
updateState(stateUpdate: AnyState): void;
|
|
17
17
|
setState(newState: AnyState): void;
|
|
18
18
|
get ready(): boolean;
|
|
19
|
+
setDebugMode(enable: boolean): void;
|
|
19
20
|
/**
|
|
20
21
|
* Add a callback that will be called when the connection to the console is entirely ready
|
|
21
22
|
*
|
package/dist/scripts/koppelia.js
CHANGED
|
@@ -9,6 +9,7 @@ import { Play } from "./play.js";
|
|
|
9
9
|
import { PUBLIC_GAME_ID } from "$env/static/public";
|
|
10
10
|
import { Resident } from "./resident.js";
|
|
11
11
|
import { Option } from "./option.js";
|
|
12
|
+
import { logger, setDebugMode } from "./logger.js";
|
|
12
13
|
export class Koppelia {
|
|
13
14
|
_console;
|
|
14
15
|
_state;
|
|
@@ -20,15 +21,15 @@ export class Koppelia {
|
|
|
20
21
|
this._console.onReady(() => {
|
|
21
22
|
let type = get(routeType);
|
|
22
23
|
if (type == "controller") {
|
|
23
|
-
|
|
24
|
+
logger.log("identify controller");
|
|
24
25
|
this._console.identify(PeerType.CONTROLLER);
|
|
25
26
|
}
|
|
26
27
|
else if (type == "monitor") {
|
|
27
|
-
|
|
28
|
+
logger.log("identify monitor");
|
|
28
29
|
this._console.identify(PeerType.MONITOR);
|
|
29
30
|
}
|
|
30
31
|
else {
|
|
31
|
-
|
|
32
|
+
logger.log("Cannot identifiy type ", type);
|
|
32
33
|
}
|
|
33
34
|
});
|
|
34
35
|
this._state = new State(this._console, {
|
|
@@ -55,6 +56,9 @@ export class Koppelia {
|
|
|
55
56
|
get ready() {
|
|
56
57
|
return this._console.ready;
|
|
57
58
|
}
|
|
59
|
+
setDebugMode(enable) {
|
|
60
|
+
setDebugMode(enable);
|
|
61
|
+
}
|
|
58
62
|
/**
|
|
59
63
|
* Add a callback that will be called when the connection to the console is entirely ready
|
|
60
64
|
*
|
|
@@ -72,7 +76,7 @@ export class Koppelia {
|
|
|
72
76
|
init(defaultState, stages) {
|
|
73
77
|
this._console.onReady(() => {
|
|
74
78
|
let type = get(routeType);
|
|
75
|
-
if (type == "
|
|
79
|
+
if (type == "monitor") {
|
|
76
80
|
this._state.setState(defaultState, true); // set the state
|
|
77
81
|
this._stage.initStages(stages); // init the list of stages
|
|
78
82
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { logger } from "./logger.js";
|
|
1
2
|
import { Message } from "./message.js";
|
|
2
3
|
const DEFAULT_WS_TIMEOUT = 20000;
|
|
3
4
|
export class KoppeliaWebsocket {
|
|
@@ -16,11 +17,11 @@ export class KoppeliaWebsocket {
|
|
|
16
17
|
constructor(websocketUrl, timeout = DEFAULT_WS_TIMEOUT) {
|
|
17
18
|
if (!import.meta.env.SSR) {
|
|
18
19
|
this._connectWebsocket(websocketUrl);
|
|
19
|
-
|
|
20
|
+
logger.log("Open new Koppelia websocket connection successfully with url ", websocketUrl);
|
|
20
21
|
this._setupEvents();
|
|
21
22
|
}
|
|
22
23
|
else
|
|
23
|
-
|
|
24
|
+
logger.log("Koppelia websocket not accessible during server rendering");
|
|
24
25
|
this.onGoingRequests = [];
|
|
25
26
|
this.timeout = timeout;
|
|
26
27
|
this.receiveCallbacks = [];
|
|
@@ -34,7 +35,7 @@ export class KoppeliaWebsocket {
|
|
|
34
35
|
*/
|
|
35
36
|
send(data, callback) {
|
|
36
37
|
if (this.socket === undefined) {
|
|
37
|
-
|
|
38
|
+
logger.log("KoppeliaWebsocket::send(): Koppelia websocket client was not instancieated");
|
|
38
39
|
return;
|
|
39
40
|
}
|
|
40
41
|
// Create a request id
|
|
@@ -42,7 +43,7 @@ export class KoppeliaWebsocket {
|
|
|
42
43
|
this._addNewRequest(data.getRequestId(), callback);
|
|
43
44
|
// Send the request
|
|
44
45
|
const serializedMessage = JSON.stringify(data.toObject());
|
|
45
|
-
|
|
46
|
+
logger.log("sending message", serializedMessage);
|
|
46
47
|
this.socket.send(serializedMessage);
|
|
47
48
|
// set a timeout
|
|
48
49
|
window.setTimeout(() => this._deleteRequest(data.getRequestId()), this.timeout);
|
|
@@ -100,7 +101,7 @@ export class KoppeliaWebsocket {
|
|
|
100
101
|
*/
|
|
101
102
|
_setupEvents() {
|
|
102
103
|
if (this.socket === undefined) {
|
|
103
|
-
|
|
104
|
+
logger.log("KoppeliaWebsocket::_setupEvents(): Koppelia websocket client was not instancieated");
|
|
104
105
|
return;
|
|
105
106
|
}
|
|
106
107
|
// handle web socker opening
|
|
@@ -115,7 +116,7 @@ export class KoppeliaWebsocket {
|
|
|
115
116
|
});
|
|
116
117
|
// handle connection close (if an error occure)
|
|
117
118
|
this.socket.onclose = (event) => {
|
|
118
|
-
|
|
119
|
+
logger.log(`Connection closed ${event.reason}, code=${event.code}, retry onnection ...`);
|
|
119
120
|
setTimeout(() => { this._connectWebsocket(this.websocketUrl); this._setupEvents(); }, 1000);
|
|
120
121
|
};
|
|
121
122
|
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
let isDebugMode = false;
|
|
2
|
+
// 2. Fonction de configuration (à exporter pour l'utilisateur de la lib)
|
|
3
|
+
export function setDebugMode(enable) {
|
|
4
|
+
isDebugMode = enable;
|
|
5
|
+
}
|
|
6
|
+
// 3. Le logger lui-même
|
|
7
|
+
// On ajoute un préfixe pour que l'utilisateur sache que ça vient de votre lib
|
|
8
|
+
const prefix = '[MaSuperLib]';
|
|
9
|
+
export const logger = {
|
|
10
|
+
log: (...args) => {
|
|
11
|
+
if (!isDebugMode)
|
|
12
|
+
return;
|
|
13
|
+
console.log(prefix, ...args);
|
|
14
|
+
},
|
|
15
|
+
warn: (...args) => {
|
|
16
|
+
if (!isDebugMode)
|
|
17
|
+
return;
|
|
18
|
+
console.warn(prefix, ...args);
|
|
19
|
+
},
|
|
20
|
+
error: (...args) => {
|
|
21
|
+
// Note : Souvent, on veut voir les erreurs même si le debug est off.
|
|
22
|
+
// Mais si vous voulez TOUT couper, gardez la condition.
|
|
23
|
+
console.error(prefix, ...args);
|
|
24
|
+
}
|
|
25
|
+
};
|
package/dist/scripts/state.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Console } from "./console.js";
|
|
2
|
+
import { logger } from "./logger.js";
|
|
2
3
|
import { Message } from "./message.js";
|
|
3
4
|
import { get, writable } from "svelte/store";
|
|
4
5
|
export class State {
|
|
@@ -79,7 +80,7 @@ export class State {
|
|
|
79
80
|
update[entry] = newState[entry];
|
|
80
81
|
}
|
|
81
82
|
}
|
|
82
|
-
|
|
83
|
+
logger.log("change state NewState=", newState, "; update=", update, " currentState=", this._previousStateValue);
|
|
83
84
|
this._previousStateValue = structuredClone(newState);
|
|
84
85
|
this._console.onReady(() => {
|
|
85
86
|
let req = new Message();
|
|
@@ -2,6 +2,7 @@ import fs from 'node:fs';
|
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import express from 'express';
|
|
4
4
|
import bodyParser from 'body-parser';
|
|
5
|
+
import { logger } from '../scripts/logger.js';
|
|
5
6
|
const app = express();
|
|
6
7
|
app.use(bodyParser.urlencoded({ extended: true }));
|
|
7
8
|
app.use(bodyParser.json());
|
|
@@ -17,7 +18,7 @@ export class KoppeliaServerApi {
|
|
|
17
18
|
getContentType(file) {
|
|
18
19
|
let contentType = "";
|
|
19
20
|
let ext = path.extname(file).substring(1);
|
|
20
|
-
|
|
21
|
+
logger.log(ext);
|
|
21
22
|
switch (ext) {
|
|
22
23
|
case 'html':
|
|
23
24
|
contentType = "text/html";
|
|
@@ -49,7 +50,7 @@ export class KoppeliaServerApi {
|
|
|
49
50
|
case "json":
|
|
50
51
|
contentType = "application/" + ext;
|
|
51
52
|
}
|
|
52
|
-
|
|
53
|
+
logger.log(file + "; " + contentType);
|
|
53
54
|
return contentType;
|
|
54
55
|
}
|
|
55
56
|
serveApi() {
|
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
// src/lib/routeStore.js (dans la librairie)
|
|
2
2
|
import { writable, get } from 'svelte/store';
|
|
3
3
|
import { page } from '$app/stores';
|
|
4
|
+
import { logger } from '../scripts/logger.js';
|
|
4
5
|
// Crée un store pour la route active
|
|
5
6
|
export const routeType = writable('');
|
|
6
7
|
// Cette fonction met à jour le store en fonction de la route
|
|
7
8
|
export function updateRoute() {
|
|
8
9
|
const path = get(page).url.pathname;
|
|
9
|
-
|
|
10
|
+
logger.log("updateRoue with path = ", path);
|
|
10
11
|
if (path.includes('controller')) {
|
|
11
12
|
routeType.set('controller');
|
|
12
|
-
|
|
13
|
+
logger.log(path, "CONTROLLER");
|
|
13
14
|
}
|
|
14
15
|
else if (path.includes('monitor')) {
|
|
15
16
|
routeType.set('monitor');
|
|
16
|
-
|
|
17
|
+
logger.log(path, "MONITOR");
|
|
17
18
|
}
|
|
18
19
|
else {
|
|
19
20
|
routeType.set('');
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { writable } from 'svelte/store';
|
|
2
|
+
import { logger } from '../scripts/logger.js';
|
|
2
3
|
// Create an empty game state
|
|
3
4
|
export const gameState = writable({});
|
|
4
5
|
gameState.subscribe((newValue) => {
|
|
5
6
|
// change the sate of the game
|
|
6
|
-
|
|
7
|
+
logger.log("Game state changed");
|
|
7
8
|
});
|