@unitn-asa/deliveroo-js-sdk 1.3.4 → 1.3.10

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unitn-asa/deliveroo-js-sdk",
3
- "version": "1.3.4",
3
+ "version": "1.3.10",
4
4
  "description": "Software development kit for Deliveroo.js",
5
5
  "author": "Marco Robol <marco.robol@unitn.it>",
6
6
  "type": "module",
@@ -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/IOInfo.js").IOInfo} IOInfo
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( IOInfo ) : void } callback
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-expect-error
267
+ // @ts-ignore
268
268
  delete descriptors.constructor;
269
269
 
270
270
  Object.defineProperties(target, descriptors);
@@ -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( { clientTimestamp: performance.now() } );
39
+ callback();
40
40
  } catch (error) {
41
41
  console.warn("Error handling ping event");
42
42
  }
@@ -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
@@ -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/IOInfo.js").IOInfo} IOInfo
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, info, ...message) {
74
- this.emit('log', src, info, ...message);
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/IOInfo.js").IOInfo} IOInfo
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 { IOInfo } info
100
+ * @param { IOMetrics } metrics
99
101
  */
100
- emitInfo ( info ) {
101
- super.emit( 'info', info );
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 ( selected, acknowledgementCallback )
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 ( myId, myName, src, info, ...message ) {
227
- super.broadcast.emit( 'log', src, info, ...message );
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', {id:string, x:number, y:number, reward:number} ) : void } callback
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 );
@@ -253,6 +254,14 @@ export class DjsServerSocket extends Socket {
253
254
  super.on( 'restart', callback );
254
255
  }
255
256
 
257
+ /**
258
+ * Process request for rewarding an agent with a certain amount of points
259
+ * @param { function ( {agentId: string, points: number} ) : void } callback
260
+ */
261
+ onReward ( callback ) {
262
+ super.on( 'reward', callback );
263
+ }
264
+
256
265
 
257
266
 
258
267
  /**
@@ -265,11 +274,13 @@ export class DjsServerSocket extends Socket {
265
274
  /**
266
275
  * Mixin function to copy methods from a class prototype to an object
267
276
  */
277
+ // @ts-ignore
268
278
  function applyMixin(target, MixinClass) {
269
279
 
270
280
  let proto = MixinClass.prototype;
271
281
 
272
282
  const descriptors = Object.getOwnPropertyDescriptors(proto);
283
+ // @ts-ignore
273
284
  delete descriptors.constructor;
274
285
 
275
286
  Object.defineProperties(target, descriptors);
@@ -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
@@ -1,6 +1,6 @@
1
1
 
2
2
  /**
3
- * @typedef { 'frame' | '1s' | '2s' | '5s' | '10s' | 'infinite' } IOClockEvent
3
+ * @typedef { 'frame' | '1s' | '2s' | '5s' | '10s' | '1m' | '1h' | 'infinite' } IOClockEvent
4
4
  */
5
5
 
6
6
 
@@ -10,7 +10,7 @@
10
10
  * @returns { IOClockEvent }
11
11
  */
12
12
  function parseClockEvent ( event ) {
13
- if ( event == 'frame' || event == '1s' || event == '2s' || event == '5s' || event == '10s' || event == 'infinite' )
13
+ if ( event == 'frame' || event == '1s' || event == '2s' || event == '5s' || event == '10s' || event == '1m' || event == '1h' || event == 'infinite' )
14
14
  return event;
15
15
  else
16
16
  console.warn( `IOClockEvent: invalid event '${event}', defaulting to '1s'` );
@@ -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.
@@ -36,6 +20,7 @@
36
20
  * 'crate': function ( 'create' | 'dispose', { x:number, y:number } ) : void,
37
21
  * 'restart': function () : void,
38
22
  * 'tile': function ( IOTile ) : void,
23
+ * 'reward': function ( { agentId: string, points: number } ) : void,
39
24
  * 'log': function ( ...any ) : void
40
25
  * }} IOClientEvents
41
26
  */
@@ -52,8 +37,7 @@
52
37
  * 'controller': function ( 'connected' | 'disconnected', {id:string, name:string, teamId:string, teamName:string, score:number} ) : void,
53
38
  * 'you': function ( IOAgent ) : void,
54
39
  * 'sensing': function ( IOSensing ) : void,
55
- * 'info': function ( IOInfo ) : void,
56
- * 'ping': function ( { timestamp: number }, function ( { clientTimestamp: number } ) : void ) : void,
40
+ * 'ping': function ( { frame: number, roundTrip: number }, function () : void ) : void,
57
41
  * 'metrics': function ( IOMetrics ) : void,
58
42
  * 'msg': function ( string, string, Object, function ( Object ) : void = ) : Object,
59
43
  * 'log': function ( 'server' | { socket:string, id:string, name:string }, ...any ) : void
@@ -1,11 +0,0 @@
1
-
2
- /**
3
- * @typedef IOInfo
4
- * @property {number} ms
5
- * @property {number} frame
6
- * @property {number} fps
7
- * @property {number} heapUsed
8
- * @property {number} heapTotal
9
- */
10
-
11
- export { };