@unitn-asa/deliveroo-js-sdk 1.3.4 → 1.3.5
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/package.json +1 -1
- package/src/client/DjsClientSocket.js +4 -4
- package/src/client/DjsConnect.js +1 -1
- package/src/client/index.js +1 -1
- package/src/server/DjsServer.js +4 -4
- package/src/server/DjsServerSocket.js +18 -15
- package/src/server/index.js +1 -1
- package/src/types/IOMetrics.js +17 -0
- package/src/types/IOSocketEvents.js +2 -19
- package/src/types/IOInfo.js +0 -11
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@ import { Socket } from 'socket.io-client';
|
|
|
5
5
|
* @typedef {import("../types/IOParcel.js").IOParcel} IOParcel
|
|
6
6
|
* @typedef {import("../types/IOTile.js").IOTile} IOTile
|
|
7
7
|
* @typedef {import("../types/IOConfig.js").IOConfig} IOConfig
|
|
8
|
-
* @typedef {import("../types/
|
|
8
|
+
* @typedef {import("../types/IOMetrics.js").IOMetrics} IOMetrics
|
|
9
9
|
*
|
|
10
10
|
* @typedef {import("../types/IOSocketEvents.js").IOSensing} IOSensing
|
|
11
11
|
* @typedef {import("../types/IOSocketEvents.js").IOClientEvents} IOClientEvents
|
|
@@ -118,10 +118,10 @@ export class DjsClientSocket extends Socket {
|
|
|
118
118
|
|
|
119
119
|
/**
|
|
120
120
|
* Listen to 'info' events
|
|
121
|
-
* @param { function(
|
|
121
|
+
* @param { function( ) : void } callback
|
|
122
|
+
* @deprecated 'info' events are deprecated, use 'metrics' instead (only for admin)
|
|
122
123
|
*/
|
|
123
124
|
onInfo ( callback ) {
|
|
124
|
-
this.on( "info", callback )
|
|
125
125
|
}
|
|
126
126
|
|
|
127
127
|
/**
|
|
@@ -264,7 +264,7 @@ export class DjsClientSocket extends Socket {
|
|
|
264
264
|
let proto = MixinClass.prototype;
|
|
265
265
|
|
|
266
266
|
const descriptors = Object.getOwnPropertyDescriptors(proto);
|
|
267
|
-
// @ts-
|
|
267
|
+
// @ts-ignore
|
|
268
268
|
delete descriptors.constructor;
|
|
269
269
|
|
|
270
270
|
Object.defineProperties(target, descriptors);
|
package/src/client/DjsConnect.js
CHANGED
|
@@ -36,7 +36,7 @@ export function DjsConnect ( host = process.env.HOST || 'http://localhost:8080',
|
|
|
36
36
|
try {
|
|
37
37
|
enhancedClientSocket.on( "ping", ( pingData, callback ) => {
|
|
38
38
|
try {
|
|
39
|
-
callback(
|
|
39
|
+
callback();
|
|
40
40
|
} catch (error) {
|
|
41
41
|
console.warn("Error handling ping event");
|
|
42
42
|
}
|
package/src/client/index.js
CHANGED
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
* @typedef {import("../types/IOTile.js").IOTile} IOTile
|
|
11
11
|
*
|
|
12
12
|
* @typedef {import("../types/IOIdentity.js").IOIdentity} IOIdentity
|
|
13
|
-
* @typedef {import("../types/IOInfo.js").IOInfo} IOInfo
|
|
14
13
|
* @typedef {import("../types/IOSensing.js").IOSensing} IOSensing
|
|
14
|
+
* @typedef {import("../types/IOMetrics.js").IOMetrics} IOMetrics
|
|
15
15
|
*
|
|
16
16
|
* @typedef {import("../types/IOSocketEvents.js").IOClientEvents} IOClientEvents
|
|
17
17
|
* @typedef {import("../types/IOSocketEvents.js").IOServerEvents} IOServerEvents
|
package/src/server/DjsServer.js
CHANGED
|
@@ -6,7 +6,7 @@ import { DjsServerSocket } from './DjsServerSocket.js';
|
|
|
6
6
|
* @typedef {import("../types/IOParcel.js").IOParcel} IOParcel
|
|
7
7
|
* @typedef {import("../types/IOTile.js").IOTile} IOTile
|
|
8
8
|
* @typedef {import("../types/IOConfig.js").IOConfig} IOConfig
|
|
9
|
-
* @typedef {import("../types/
|
|
9
|
+
* @typedef {import("../types/IOMetrics.js").IOMetrics} IOMetrics
|
|
10
10
|
*
|
|
11
11
|
* @typedef {import("../types/IOSocketEvents.js").IOSensing} IOSensing
|
|
12
12
|
* @typedef {import("../types/IOSocketEvents.js").IOClientEvents} IOClientEvents on the client side these are to be emitted with .emit
|
|
@@ -67,11 +67,10 @@ export class DjsServer extends Server {
|
|
|
67
67
|
/**
|
|
68
68
|
* Broadcast a log message to all connected clients
|
|
69
69
|
* @param { 'server' | { socket:string, id:string, name:string } } src - 'server' or client
|
|
70
|
-
* @param { IOInfo } info
|
|
71
70
|
* @param { ...any } message
|
|
72
71
|
*/
|
|
73
|
-
broadcastLog(src,
|
|
74
|
-
this.emit('log', src,
|
|
72
|
+
broadcastLog(src, ...message) {
|
|
73
|
+
this.emit('log', src, ...message);
|
|
75
74
|
}
|
|
76
75
|
|
|
77
76
|
// /**
|
|
@@ -117,6 +116,7 @@ export class DjsServer extends Server {
|
|
|
117
116
|
let proto = MixinClass.prototype;
|
|
118
117
|
|
|
119
118
|
const descriptors = Object.getOwnPropertyDescriptors(proto);
|
|
119
|
+
// @ts-ignore
|
|
120
120
|
delete descriptors.constructor;
|
|
121
121
|
|
|
122
122
|
Object.defineProperties(target, descriptors);
|
|
@@ -5,7 +5,7 @@ import { Socket } from 'socket.io';
|
|
|
5
5
|
* @typedef {import("../types/IOParcel.js").IOParcel} IOParcel
|
|
6
6
|
* @typedef {import("../types/IOTile.js").IOTile} IOTile
|
|
7
7
|
* @typedef {import("../types/IOConfig.js").IOConfig} IOConfig
|
|
8
|
-
* @typedef {import("../types/
|
|
8
|
+
* @typedef {import("../types/IOMetrics.js").IOMetrics} IOMetrics
|
|
9
9
|
*
|
|
10
10
|
* @typedef {import("../types/IOSocketEvents.js").IOSensing} IOSensing
|
|
11
11
|
* @typedef {import("../types/IOSocketEvents.js").IOClientEvents} IOClientEvents on the client side these are to be emitted with .emit
|
|
@@ -28,7 +28,9 @@ export class DjsServerSocket extends Socket {
|
|
|
28
28
|
// * @param {IOClientEvents[K]} listener
|
|
29
29
|
// * @returns {void}
|
|
30
30
|
// */
|
|
31
|
+
// @ts-ignore
|
|
31
32
|
on ( event, listener ) {
|
|
33
|
+
// @ts-ignore
|
|
32
34
|
return super.on( event, (...args) => {
|
|
33
35
|
try {
|
|
34
36
|
return listener.apply( this, args );
|
|
@@ -95,10 +97,10 @@ export class DjsServerSocket extends Socket {
|
|
|
95
97
|
}
|
|
96
98
|
|
|
97
99
|
/**
|
|
98
|
-
* @param {
|
|
100
|
+
* @param { IOMetrics } metrics
|
|
99
101
|
*/
|
|
100
|
-
|
|
101
|
-
super.emit( '
|
|
102
|
+
emitMetrics ( metrics ) {
|
|
103
|
+
super.emit( 'metrics', metrics );
|
|
102
104
|
}
|
|
103
105
|
|
|
104
106
|
|
|
@@ -106,7 +108,7 @@ export class DjsServerSocket extends Socket {
|
|
|
106
108
|
/**
|
|
107
109
|
* @callback onMoveCallback
|
|
108
110
|
* @param { 'up' | 'right' | 'left' | 'down' } direction
|
|
109
|
-
* @param { function( { x:number, y:number } | false ) : void } replyAcknowledgmentCallback ( reply )
|
|
111
|
+
* @param { function( { x:number, y:number } | false ) : void = } replyAcknowledgmentCallback ( reply )
|
|
110
112
|
*/
|
|
111
113
|
/**
|
|
112
114
|
* @param { onMoveCallback } callback ( direction, acknowledgementCallback )
|
|
@@ -117,7 +119,7 @@ export class DjsServerSocket extends Socket {
|
|
|
117
119
|
|
|
118
120
|
/**
|
|
119
121
|
* @callback onPickupCallback
|
|
120
|
-
* @param { function( { id:string } [] ) : void } acknowledgementCallback
|
|
122
|
+
* @param { function( { id:string } [] ) : void = } acknowledgementCallback
|
|
121
123
|
*/
|
|
122
124
|
/**
|
|
123
125
|
* @param { onPickupCallback } callback ( acknowledgementCallback )
|
|
@@ -128,11 +130,11 @@ export class DjsServerSocket extends Socket {
|
|
|
128
130
|
|
|
129
131
|
/**
|
|
130
132
|
* @callback onPutdownCallback
|
|
131
|
-
* @param { string [] } selected ids of parcels to drop
|
|
132
|
-
* @param { function( { id:string } [] ) : void } acknowledgementCallback
|
|
133
|
+
* @param { string [] = } selected ids of parcels to drop
|
|
134
|
+
* @param { function( { id:string } [] ) : void = } acknowledgementCallback
|
|
133
135
|
*/
|
|
134
136
|
/**
|
|
135
|
-
* @param { onPutdownCallback } callback
|
|
137
|
+
* @param { onPutdownCallback } callback
|
|
136
138
|
*/
|
|
137
139
|
onPutdown ( callback ) {
|
|
138
140
|
super.on( 'putdown', callback );
|
|
@@ -184,6 +186,7 @@ export class DjsServerSocket extends Socket {
|
|
|
184
186
|
const sockets = await super.to( "agent:" + toId ).fetchSockets();
|
|
185
187
|
const emissionPromises = sockets.map( socket => {
|
|
186
188
|
return new Promise( (res) => {
|
|
189
|
+
// @ts-ignore
|
|
187
190
|
socket.timeout(1000).emit( 'msg', me.id, me.name, msg, (err, response) => {
|
|
188
191
|
if (err)
|
|
189
192
|
res('timeout');
|
|
@@ -202,6 +205,7 @@ export class DjsServerSocket extends Socket {
|
|
|
202
205
|
}
|
|
203
206
|
|
|
204
207
|
/**
|
|
208
|
+
* @param { IOAgent } me
|
|
205
209
|
* @param { any } msg
|
|
206
210
|
* @returns { void } reply
|
|
207
211
|
*/
|
|
@@ -217,21 +221,18 @@ export class DjsServerSocket extends Socket {
|
|
|
217
221
|
}
|
|
218
222
|
|
|
219
223
|
/**
|
|
220
|
-
* @param { string } myId
|
|
221
|
-
* @param { string } myName
|
|
222
224
|
* @param { 'server' | { socket:string, id:string, name:string } } src - 'server' or client
|
|
223
|
-
* @param { IOInfo } info
|
|
224
225
|
* @param { ...any } message
|
|
225
226
|
*/
|
|
226
|
-
broadcastLog (
|
|
227
|
-
super.broadcast.emit( 'log', src,
|
|
227
|
+
broadcastLog ( src, ...message ) {
|
|
228
|
+
super.broadcast.emit( 'log', src, ...message );
|
|
228
229
|
}
|
|
229
230
|
|
|
230
231
|
|
|
231
232
|
|
|
232
233
|
/**
|
|
233
234
|
* Process request for creating a parcel on x, y or disposing or setting its reward given the id
|
|
234
|
-
* @param { function ( 'create' | 'dispose' | 'set', {
|
|
235
|
+
* @param { function ( 'create' | 'dispose' | 'set', { x:number, y:number } | { id:string, reward?:number } ) : void } callback
|
|
235
236
|
*/
|
|
236
237
|
onParcel ( callback ) {
|
|
237
238
|
super.on( 'parcel', callback );
|
|
@@ -265,11 +266,13 @@ export class DjsServerSocket extends Socket {
|
|
|
265
266
|
/**
|
|
266
267
|
* Mixin function to copy methods from a class prototype to an object
|
|
267
268
|
*/
|
|
269
|
+
// @ts-ignore
|
|
268
270
|
function applyMixin(target, MixinClass) {
|
|
269
271
|
|
|
270
272
|
let proto = MixinClass.prototype;
|
|
271
273
|
|
|
272
274
|
const descriptors = Object.getOwnPropertyDescriptors(proto);
|
|
275
|
+
// @ts-ignore
|
|
273
276
|
delete descriptors.constructor;
|
|
274
277
|
|
|
275
278
|
Object.defineProperties(target, descriptors);
|
package/src/server/index.js
CHANGED
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
* @typedef {import("../types/IOTile.js").IOTile} IOTile
|
|
11
11
|
*
|
|
12
12
|
* @typedef {import("../types/IOIdentity.js").IOIdentity} IOIdentity
|
|
13
|
-
* @typedef {import("../types/IOInfo.js").IOInfo} IOInfo
|
|
14
13
|
* @typedef {import("../types/IOSensing.js").IOSensing} IOSensing
|
|
14
|
+
* @typedef {import("../types/IOMetrics.js").IOMetrics} IOMetrics
|
|
15
15
|
*
|
|
16
16
|
* @typedef {import("../types/IOSocketEvents.js").IOClientEvents} IOClientEvents
|
|
17
17
|
* @typedef {import("../types/IOSocketEvents.js").IOServerEvents} IOServerEvents
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* @typedef {Object} IOMetrics
|
|
4
|
+
* @property { {ms: number, frame: number, fps: number, uptime: number} } timing
|
|
5
|
+
* @property { {heapUsed: number, heapTotal: number, rss: number, external: number} } memory
|
|
6
|
+
* @property { {current: number} } cpu
|
|
7
|
+
* @property { {currentLag: number, maxLag: number, avgLag: number} } eventLoop
|
|
8
|
+
* @property { {avg: number, min: number, max: number, byAgent: Object.<string, {
|
|
9
|
+
* id: string,
|
|
10
|
+
* name: string,
|
|
11
|
+
* teamId: string,
|
|
12
|
+
* teamName: string,
|
|
13
|
+
* sockets: ( { socketId: string, frame: number, avg: number, min: number, max: number } ) []
|
|
14
|
+
* }> } } latency
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
export { };
|
|
@@ -1,26 +1,10 @@
|
|
|
1
1
|
|
|
2
2
|
/** @typedef {import('./IOAgent.js').IOAgent} IOAgent */
|
|
3
3
|
/** @typedef {import('./IOTile.js').IOTile} IOTile */
|
|
4
|
-
/** @typedef {import('./IOInfo.js').IOInfo} IOInfo */
|
|
5
4
|
/** @typedef {import('./IOSensing.js').IOSensing} IOSensing */
|
|
5
|
+
/** @typedef {import('./IOMetrics.js').IOMetrics} IOMetrics */
|
|
6
6
|
|
|
7
|
-
/**
|
|
8
|
-
* @typedef {Object} IOLatency
|
|
9
|
-
* @property {number} roundTrip - Total round trip time in milliseconds
|
|
10
|
-
* @property {number} clientProcessing - Time spent processing on the client side in milliseconds
|
|
11
|
-
* @property {number} serverProcessing - Time spent processing on the server side in milliseconds
|
|
12
|
-
* @property {number} networkLag - Estimated network latency in milliseconds
|
|
13
|
-
* @property {number} timestamp - Timestamp when the latency was measured (in milliseconds since epoch)
|
|
14
|
-
*/
|
|
15
7
|
|
|
16
|
-
/**
|
|
17
|
-
* @typedef {Object} IOMetrics
|
|
18
|
-
* @property { {ms: number, frame: number, fps: number, uptime: number} } timing
|
|
19
|
-
* @property { {heapUsed: number, heapTotal: number, rss: number, external: number} } memory
|
|
20
|
-
* @property { {current: number, samples: number[]} } cpu
|
|
21
|
-
* @property { {currentLag: number, maxLag: number, avgLag: number} } eventLoop
|
|
22
|
-
* @property { {count: number, avg: number, min: number, max: number, samples: IOLatency[], byAgent: Object.<string, {id: string, name: string, teamId: string, teamName: string, sockets: []}>} } latency
|
|
23
|
-
*/
|
|
24
8
|
|
|
25
9
|
/**
|
|
26
10
|
* Client -> Server events. Emitted by the client and listened by the server.
|
|
@@ -52,8 +36,7 @@
|
|
|
52
36
|
* 'controller': function ( 'connected' | 'disconnected', {id:string, name:string, teamId:string, teamName:string, score:number} ) : void,
|
|
53
37
|
* 'you': function ( IOAgent ) : void,
|
|
54
38
|
* 'sensing': function ( IOSensing ) : void,
|
|
55
|
-
* '
|
|
56
|
-
* 'ping': function ( { timestamp: number }, function ( { clientTimestamp: number } ) : void ) : void,
|
|
39
|
+
* 'ping': function ( { frame: number, roundTrip: number }, function () : void ) : void,
|
|
57
40
|
* 'metrics': function ( IOMetrics ) : void,
|
|
58
41
|
* 'msg': function ( string, string, Object, function ( Object ) : void = ) : Object,
|
|
59
42
|
* 'log': function ( 'server' | { socket:string, id:string, name:string }, ...any ) : void
|