@usions/sdk 2.24.0 → 2.24.2
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/README.md +1 -1
- package/package.json +13 -8
- package/src/browser.js +156 -85
- package/src/modules/core.js +13 -2
- package/src/modules/game-ack.js +32 -0
- package/src/modules/game-methods.js +107 -78
- package/src/modules/game-proxy.js +2 -0
- package/src/modules/game-socket.js +3 -1
- package/src/modules/leaderboard.js +4 -4
- package/types/index.d.ts +3 -1
package/README.md
CHANGED
|
@@ -258,7 +258,7 @@ Enable on the service (`leaderboard: { enabled: true, order: 'desc' }`), then:
|
|
|
258
258
|
|
|
259
259
|
```javascript
|
|
260
260
|
await Usion.leaderboard.submit(1500, { level: 3 }); // best score is kept
|
|
261
|
-
const friends = await Usion.leaderboard.friends(); //
|
|
261
|
+
const friends = await Usion.leaderboard.friends(); // your accepted friends + you
|
|
262
262
|
const top = await Usion.leaderboard.top({ limit: 20 });// global top
|
|
263
263
|
const me = await Usion.leaderboard.me(); // { score, rank, total }
|
|
264
264
|
// entry: { user_id, name, avatar, score, rank, is_me, metadata }
|
package/package.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@usions/sdk",
|
|
3
|
-
"version": "2.24.
|
|
3
|
+
"version": "2.24.2",
|
|
4
4
|
"description": "Usion Mini App SDK for iframe games and services",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"main": "src/
|
|
6
|
+
"main": "src/index.js",
|
|
7
7
|
"browser": "src/browser.js",
|
|
8
8
|
"types": "types/index.d.ts",
|
|
9
9
|
"exports": {
|
|
10
10
|
".": {
|
|
11
11
|
"types": "./types/index.d.ts",
|
|
12
|
-
"import": "./src/
|
|
12
|
+
"import": "./src/index.js",
|
|
13
13
|
"browser": "./src/browser.js",
|
|
14
|
-
"default": "./src/
|
|
14
|
+
"default": "./src/index.js"
|
|
15
15
|
},
|
|
16
16
|
"./browser": {
|
|
17
17
|
"types": "./types/browser.d.ts",
|
|
@@ -23,13 +23,18 @@
|
|
|
23
23
|
"types/"
|
|
24
24
|
],
|
|
25
25
|
"scripts": {
|
|
26
|
-
"build": "rollup -c",
|
|
27
|
-
"build:copy": "npm run build &&
|
|
26
|
+
"build": "node scripts/sync-version.mjs && rollup -c",
|
|
27
|
+
"build:copy": "npm run build && node scripts/sync-assets.mjs",
|
|
28
28
|
"watch": "rollup -c --watch",
|
|
29
|
-
"test": "npm run build && vitest run && npm run test:types && npm run check:src && npm run check:size",
|
|
30
|
-
"prepublishOnly": "npm run build && vitest run && npm run test:types && npm run check:src && npm run check:size",
|
|
29
|
+
"test": "npm run build && vitest run && npm run test:types && npm run check:src && npm run check:version && npm run check:assets && npm run check:cache && npm run check:size && npm run test:package",
|
|
30
|
+
"prepublishOnly": "npm run build && vitest run && npm run test:types && npm run check:src && npm run check:version && npm run check:size && npm run test:package",
|
|
31
31
|
"test:types": "tsc -p test/tsconfig.json",
|
|
32
|
+
"test:package": "node scripts/test-package.mjs",
|
|
33
|
+
"check:assets": "node scripts/sync-assets.mjs --check",
|
|
34
|
+
"check:cache": "node scripts/check-cache-headers.mjs",
|
|
35
|
+
"check:consumers": "node scripts/check-v2-consumers.mjs",
|
|
32
36
|
"check:size": "node scripts/check-size.mjs",
|
|
37
|
+
"check:version": "node scripts/sync-version.mjs --check",
|
|
33
38
|
"docs:api": "typedoc --plugin typedoc-plugin-markdown --entryPoints types/index.d.ts --out ../../docs/sdk-api --readme none --tsconfig test/tsconfig.json",
|
|
34
39
|
"check:src": "tsc -p tsconfig.src.json"
|
|
35
40
|
},
|
package/src/browser.js
CHANGED
|
@@ -191,7 +191,7 @@ var Usion = (function () {
|
|
|
191
191
|
* Core Usion object with init, _post, _request
|
|
192
192
|
*/
|
|
193
193
|
const core = {
|
|
194
|
-
version: '2.24.
|
|
194
|
+
version: '2.24.2', // synced from package.json by scripts/sync-version.mjs
|
|
195
195
|
config: {},
|
|
196
196
|
_initialized: false,
|
|
197
197
|
_initCallback: null,
|
|
@@ -271,8 +271,19 @@ var Usion = (function () {
|
|
|
271
271
|
|
|
272
272
|
// Handle INIT message
|
|
273
273
|
if (data.type === 'INIT' && data.config) {
|
|
274
|
-
//
|
|
274
|
+
// Re-INIT = credential/state refresh, not a re-boot. Hosts re-mint the
|
|
275
|
+
// scoped iframe token and re-INIT before it expires (and retry failed
|
|
276
|
+
// mints with backoff) — dropping these left long-lived iframes 401ing
|
|
277
|
+
// forever once their first token raced the mint or hit the 60-min TTL.
|
|
278
|
+
// Merge the refreshed fields; never re-fire the init callback.
|
|
275
279
|
if (self._initialized) {
|
|
280
|
+
if (data.config.authToken) {
|
|
281
|
+
self.config.authToken = data.config.authToken;
|
|
282
|
+
if (self.user) self.user._token = data.config.authToken;
|
|
283
|
+
}
|
|
284
|
+
if (data.config.balance !== undefined && self.wallet) {
|
|
285
|
+
self.wallet._balance = data.config.balance;
|
|
286
|
+
}
|
|
276
287
|
return;
|
|
277
288
|
}
|
|
278
289
|
|
|
@@ -2031,12 +2042,14 @@ var Usion = (function () {
|
|
|
2031
2042
|
// membership and sync are restored — otherwise a stale move could
|
|
2032
2043
|
// go out before the client has caught up.
|
|
2033
2044
|
if (self.roomId) {
|
|
2045
|
+
// Join reports the server head, so capture our replay cursor first.
|
|
2046
|
+
var resumeSequence = self._lastSequence || 0;
|
|
2034
2047
|
self._joined = false;
|
|
2035
2048
|
self._joinPromise = null;
|
|
2036
2049
|
self._rejoinPromise = self.join(self.roomId)
|
|
2037
2050
|
.then(function() {
|
|
2038
2051
|
Usion.log('Reconnected - joined room ' + self.roomId);
|
|
2039
|
-
self.requestSync(
|
|
2052
|
+
self.requestSync(resumeSequence);
|
|
2040
2053
|
})
|
|
2041
2054
|
.catch(function(err) {
|
|
2042
2055
|
Usion.log('Rejoin failed: ' + (err && err.message ? err.message : String(err)));
|
|
@@ -2276,6 +2289,7 @@ var Usion = (function () {
|
|
|
2276
2289
|
self._proxyJoinResolve(data);
|
|
2277
2290
|
self._proxyJoinResolve = null;
|
|
2278
2291
|
}
|
|
2292
|
+
self._proxyJoinReject = null;
|
|
2279
2293
|
self._dispatch('joined', data);
|
|
2280
2294
|
break;
|
|
2281
2295
|
|
|
@@ -2285,6 +2299,7 @@ var Usion = (function () {
|
|
|
2285
2299
|
self._proxyJoinReject(toUsionError(data.message || 'Join failed'));
|
|
2286
2300
|
self._proxyJoinReject = null;
|
|
2287
2301
|
}
|
|
2302
|
+
self._proxyJoinResolve = null;
|
|
2288
2303
|
break;
|
|
2289
2304
|
|
|
2290
2305
|
case 'GAME_PLAYER_JOINED':
|
|
@@ -2348,11 +2363,51 @@ var Usion = (function () {
|
|
|
2348
2363
|
};
|
|
2349
2364
|
}
|
|
2350
2365
|
|
|
2366
|
+
const GAME_ACK_TIMEOUT_MS = 10000;
|
|
2367
|
+
const GAME_JOIN_TIMEOUT_MS = 15000;
|
|
2368
|
+
|
|
2369
|
+
function emitGameWithAck(socket, event, payload, timeoutMs, timeoutCode) {
|
|
2370
|
+
timeoutMs = timeoutMs || GAME_ACK_TIMEOUT_MS;
|
|
2371
|
+
timeoutCode = timeoutCode || ERROR_CODES.REQUEST_TIMEOUT;
|
|
2372
|
+
return new Promise(function(resolve, reject) {
|
|
2373
|
+
let settled = false;
|
|
2374
|
+
const timer = setTimeout(function() {
|
|
2375
|
+
if (settled) return;
|
|
2376
|
+
settled = true;
|
|
2377
|
+
reject(new UsionError(timeoutCode,
|
|
2378
|
+
timeoutCode === ERROR_CODES.JOIN_TIMEOUT ? 'Join timeout' : 'Game request timeout'));
|
|
2379
|
+
}, timeoutMs);
|
|
2380
|
+
|
|
2381
|
+
try {
|
|
2382
|
+
socket.emit(event, payload, function(response) {
|
|
2383
|
+
if (settled) return;
|
|
2384
|
+
settled = true;
|
|
2385
|
+
clearTimeout(timer);
|
|
2386
|
+
resolve(response || {});
|
|
2387
|
+
});
|
|
2388
|
+
} catch (err) {
|
|
2389
|
+
if (settled) return;
|
|
2390
|
+
settled = true;
|
|
2391
|
+
clearTimeout(timer);
|
|
2392
|
+
reject(err);
|
|
2393
|
+
}
|
|
2394
|
+
});
|
|
2395
|
+
}
|
|
2396
|
+
|
|
2351
2397
|
/**
|
|
2352
2398
|
* Usion SDK Game Methods — join, leave, action, realtime, sync, etc.
|
|
2353
2399
|
*/
|
|
2354
2400
|
|
|
2355
2401
|
|
|
2402
|
+
function trackJoinPromise(game, promise) {
|
|
2403
|
+
game._joinPromise = promise;
|
|
2404
|
+
promise.catch(function() {
|
|
2405
|
+
game._joined = false;
|
|
2406
|
+
if (game._joinPromise === promise) game._joinPromise = null;
|
|
2407
|
+
});
|
|
2408
|
+
return promise;
|
|
2409
|
+
}
|
|
2410
|
+
|
|
2356
2411
|
/**
|
|
2357
2412
|
* Add game action methods to game module
|
|
2358
2413
|
* @param {object} game - The game module object
|
|
@@ -2368,8 +2423,8 @@ var Usion = (function () {
|
|
|
2368
2423
|
const self = this;
|
|
2369
2424
|
roomId = roomId || Usion.config.roomId;
|
|
2370
2425
|
|
|
2371
|
-
//
|
|
2372
|
-
if (self.
|
|
2426
|
+
// Coalesce in-flight/successful joins; rejected joins are cleared below.
|
|
2427
|
+
if (self.roomId === roomId && self._joinPromise) {
|
|
2373
2428
|
return self._joinPromise;
|
|
2374
2429
|
}
|
|
2375
2430
|
|
|
@@ -2387,35 +2442,35 @@ var Usion = (function () {
|
|
|
2387
2442
|
|
|
2388
2443
|
// Proxy mode: send join request to parent
|
|
2389
2444
|
if (self._useProxy) {
|
|
2390
|
-
|
|
2445
|
+
const joinPromise = new Promise(function(resolve, reject) {
|
|
2446
|
+
const rejectJoin = function(err) { reject(err); };
|
|
2391
2447
|
self._proxyJoinResolve = resolve;
|
|
2392
|
-
self._proxyJoinReject =
|
|
2448
|
+
self._proxyJoinReject = rejectJoin;
|
|
2393
2449
|
Usion._post({ type: 'GAME_JOIN', room_id: roomId });
|
|
2394
2450
|
setTimeout(function() {
|
|
2395
|
-
if (
|
|
2451
|
+
if (self._proxyJoinReject === rejectJoin) {
|
|
2452
|
+
self._proxyJoinResolve = null;
|
|
2396
2453
|
self._proxyJoinReject = null;
|
|
2397
2454
|
reject(new UsionError(ERROR_CODES.JOIN_TIMEOUT, 'Join timeout'));
|
|
2398
2455
|
}
|
|
2399
|
-
},
|
|
2456
|
+
}, GAME_JOIN_TIMEOUT_MS);
|
|
2400
2457
|
});
|
|
2401
|
-
return self
|
|
2458
|
+
return trackJoinPromise(self, joinPromise);
|
|
2402
2459
|
}
|
|
2403
2460
|
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
|
|
2414
|
-
|
|
2415
|
-
self.socket.emit('game:join', { room_id: roomId }, function(response) {
|
|
2461
|
+
let joinPromise;
|
|
2462
|
+
if (!self.socket || !self.connected) {
|
|
2463
|
+
joinPromise = Promise.reject(new UsionError(ERROR_CODES.NOT_CONNECTED, 'Not connected'));
|
|
2464
|
+
} else if (!roomId) {
|
|
2465
|
+
joinPromise = Promise.reject(new UsionError(ERROR_CODES.NO_ROOM, 'No room ID provided'));
|
|
2466
|
+
} else {
|
|
2467
|
+
joinPromise = emitGameWithAck(
|
|
2468
|
+
self.socket, 'game:join', { room_id: roomId },
|
|
2469
|
+
GAME_JOIN_TIMEOUT_MS, ERROR_CODES.JOIN_TIMEOUT
|
|
2470
|
+
).then(function(response) {
|
|
2416
2471
|
if (response.error) {
|
|
2417
2472
|
self._joined = false;
|
|
2418
|
-
|
|
2473
|
+
throw toUsionError(response);
|
|
2419
2474
|
} else {
|
|
2420
2475
|
self._joined = true;
|
|
2421
2476
|
if (response.sequence !== undefined) {
|
|
@@ -2429,12 +2484,12 @@ var Usion = (function () {
|
|
|
2429
2484
|
// the socket transport now does too, so onJoined / recovery
|
|
2430
2485
|
// logic behaves the same everywhere.
|
|
2431
2486
|
self._dispatch('joined', response);
|
|
2432
|
-
|
|
2487
|
+
return response;
|
|
2433
2488
|
}
|
|
2434
2489
|
});
|
|
2435
|
-
}
|
|
2490
|
+
}
|
|
2436
2491
|
|
|
2437
|
-
return self
|
|
2492
|
+
return trackJoinPromise(self, joinPromise);
|
|
2438
2493
|
};
|
|
2439
2494
|
|
|
2440
2495
|
/**
|
|
@@ -2532,10 +2587,14 @@ var Usion = (function () {
|
|
|
2532
2587
|
}
|
|
2533
2588
|
|
|
2534
2589
|
if (self._useProxy) {
|
|
2590
|
+
if (!self.connected) {
|
|
2591
|
+
return Promise.reject(new UsionError(ERROR_CODES.NOT_CONNECTED, 'Not connected'));
|
|
2592
|
+
}
|
|
2535
2593
|
const proxyMsg = { type: 'GAME_ACTION', room_id: self.roomId, action_type: actionType, action_data: actionData };
|
|
2536
2594
|
if (nextTurn) proxyMsg.next_turn = nextTurn;
|
|
2537
2595
|
Usion._post(proxyMsg);
|
|
2538
|
-
|
|
2596
|
+
// v2 hosts only confirm handoff; completion arrives via onAction.
|
|
2597
|
+
return Promise.resolve({ success: true, acknowledged: false });
|
|
2539
2598
|
}
|
|
2540
2599
|
|
|
2541
2600
|
// Gate sends while a post-reconnect rejoin is in flight, so a stale
|
|
@@ -2566,29 +2625,22 @@ var Usion = (function () {
|
|
|
2566
2625
|
*/
|
|
2567
2626
|
game._emitAction = function(payload, retryOnNotInRoom) {
|
|
2568
2627
|
const self = this;
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
if (response && response.error) {
|
|
2628
|
+
if (!self.socket || !self.connected) {
|
|
2629
|
+
return Promise.reject(new UsionError(ERROR_CODES.NOT_CONNECTED, 'Not connected'));
|
|
2630
|
+
}
|
|
2631
|
+
return emitGameWithAck(self.socket, 'game:action', payload)
|
|
2632
|
+
.then(function(response) {
|
|
2633
|
+
if (response.error) {
|
|
2576
2634
|
const ue = toUsionError(response);
|
|
2577
2635
|
if (retryOnNotInRoom && ue.code === ERROR_CODES.NOT_IN_ROOM) {
|
|
2578
|
-
self._autoRejoin()
|
|
2579
|
-
.then(function() { return self._emitAction(payload, false); })
|
|
2580
|
-
.then(resolve, reject);
|
|
2581
|
-
return;
|
|
2636
|
+
return self._autoRejoin()
|
|
2637
|
+
.then(function() { return self._emitAction(payload, false); });
|
|
2582
2638
|
}
|
|
2583
|
-
|
|
2584
|
-
} else {
|
|
2585
|
-
if (response && response.sequence !== undefined) {
|
|
2586
|
-
self._lastSequence = response.sequence;
|
|
2587
|
-
}
|
|
2588
|
-
resolve(response);
|
|
2639
|
+
throw ue;
|
|
2589
2640
|
}
|
|
2641
|
+
if (response.sequence !== undefined) self._lastSequence = response.sequence;
|
|
2642
|
+
return response;
|
|
2590
2643
|
});
|
|
2591
|
-
});
|
|
2592
2644
|
};
|
|
2593
2645
|
|
|
2594
2646
|
/**
|
|
@@ -2601,11 +2653,12 @@ var Usion = (function () {
|
|
|
2601
2653
|
if (self._rejoinPromise) return self._rejoinPromise;
|
|
2602
2654
|
if (!self.roomId || !self.socket || !self.connected) return Promise.resolve();
|
|
2603
2655
|
Usion.log('Server reports socket not in room - auto-rejoining ' + self.roomId);
|
|
2656
|
+
const resumeSequence = self._lastSequence || 0;
|
|
2604
2657
|
self._joined = false;
|
|
2605
2658
|
self._joinPromise = null;
|
|
2606
2659
|
self._rejoinPromise = self.join(self.roomId)
|
|
2607
2660
|
.then(function() {
|
|
2608
|
-
self.requestSync(
|
|
2661
|
+
self.requestSync(resumeSequence);
|
|
2609
2662
|
})
|
|
2610
2663
|
.catch(function(err) {
|
|
2611
2664
|
Usion.log('Auto-rejoin failed: ' + (err && err.message ? err.message : String(err)));
|
|
@@ -2654,18 +2707,43 @@ var Usion = (function () {
|
|
|
2654
2707
|
game._flushOfflineQueue = function() {
|
|
2655
2708
|
const self = this;
|
|
2656
2709
|
const queue = self._offlineQueue;
|
|
2657
|
-
if (!queue || !queue.length) return;
|
|
2658
|
-
self.
|
|
2710
|
+
if (!queue || !queue.length) return Promise.resolve();
|
|
2711
|
+
if (self._offlineFlushPromise) return self._offlineFlushPromise;
|
|
2712
|
+
if (!self.connected || (!self._useProxy && !self.directMode && !self._joined)) {
|
|
2713
|
+
return Promise.resolve();
|
|
2714
|
+
}
|
|
2659
2715
|
Usion.log('Flushing ' + queue.length + ' queued action(s) after reconnect');
|
|
2660
|
-
|
|
2661
|
-
|
|
2662
|
-
|
|
2663
|
-
|
|
2664
|
-
|
|
2665
|
-
|
|
2666
|
-
|
|
2716
|
+
|
|
2717
|
+
function sendNext() {
|
|
2718
|
+
if (!queue.length) return Promise.resolve();
|
|
2719
|
+
if (!self.connected || (!self._useProxy && !self.directMode && !self._joined)) {
|
|
2720
|
+
return Promise.resolve();
|
|
2721
|
+
}
|
|
2722
|
+
|
|
2723
|
+
const item = queue[0];
|
|
2724
|
+
return self.action(item.actionType, item.actionData, item.opts).then(function(result) {
|
|
2725
|
+
if (queue[0] === item) queue.shift();
|
|
2726
|
+
item.resolve(result);
|
|
2727
|
+
return sendNext();
|
|
2728
|
+
}, function(err) {
|
|
2729
|
+
const ue = toUsionError(err);
|
|
2730
|
+
// Preserve only commands known not to have reached a live room.
|
|
2731
|
+
if (ue.code === ERROR_CODES.NOT_CONNECTED || ue.code === ERROR_CODES.NOT_IN_ROOM) {
|
|
2732
|
+
return;
|
|
2733
|
+
}
|
|
2734
|
+
if (queue[0] === item) queue.shift();
|
|
2735
|
+
item.reject(err);
|
|
2736
|
+
return sendNext();
|
|
2667
2737
|
});
|
|
2668
|
-
}
|
|
2738
|
+
}
|
|
2739
|
+
|
|
2740
|
+
const flushPromise = Promise.resolve().then(sendNext);
|
|
2741
|
+
self._offlineFlushPromise = flushPromise;
|
|
2742
|
+
function clearFlush() {
|
|
2743
|
+
if (self._offlineFlushPromise === flushPromise) self._offlineFlushPromise = null;
|
|
2744
|
+
}
|
|
2745
|
+
flushPromise.then(clearFlush, clearFlush);
|
|
2746
|
+
return flushPromise;
|
|
2669
2747
|
};
|
|
2670
2748
|
|
|
2671
2749
|
/**
|
|
@@ -2711,24 +2789,20 @@ var Usion = (function () {
|
|
|
2711
2789
|
});
|
|
2712
2790
|
}
|
|
2713
2791
|
|
|
2714
|
-
|
|
2715
|
-
|
|
2716
|
-
|
|
2717
|
-
|
|
2718
|
-
}
|
|
2719
|
-
self.socket.emit('game:set_state', {
|
|
2792
|
+
if (!self.socket || !self.connected) {
|
|
2793
|
+
return Promise.reject(new UsionError(ERROR_CODES.NOT_CONNECTED, 'Not connected'));
|
|
2794
|
+
}
|
|
2795
|
+
return emitGameWithAck(self.socket, 'game:set_state', {
|
|
2720
2796
|
room_id: self.roomId,
|
|
2721
2797
|
state: state || {},
|
|
2722
2798
|
sequence: checkpointSeq
|
|
2723
|
-
}
|
|
2724
|
-
if (response
|
|
2799
|
+
}).then(function(response) {
|
|
2800
|
+
if (response.error) {
|
|
2725
2801
|
const ue = toUsionError(response);
|
|
2726
|
-
|
|
2727
|
-
} else {
|
|
2728
|
-
resolve(response || { success: true });
|
|
2802
|
+
return { success: false, error: ue.message, code: ue.code };
|
|
2729
2803
|
}
|
|
2804
|
+
return Object.keys(response).length ? response : { success: true };
|
|
2730
2805
|
});
|
|
2731
|
-
});
|
|
2732
2806
|
};
|
|
2733
2807
|
|
|
2734
2808
|
/**
|
|
@@ -2835,20 +2909,16 @@ var Usion = (function () {
|
|
|
2835
2909
|
return Promise.resolve({ success: true });
|
|
2836
2910
|
}
|
|
2837
2911
|
|
|
2838
|
-
|
|
2839
|
-
|
|
2840
|
-
|
|
2841
|
-
|
|
2842
|
-
|
|
2843
|
-
|
|
2844
|
-
self.socket.emit('game:forfeit', { room_id: self.roomId }, function(response) {
|
|
2912
|
+
if (!self.socket || !self.connected) {
|
|
2913
|
+
return Promise.reject(new UsionError(ERROR_CODES.NOT_CONNECTED, 'Not connected'));
|
|
2914
|
+
}
|
|
2915
|
+
return emitGameWithAck(self.socket, 'game:forfeit', { room_id: self.roomId })
|
|
2916
|
+
.then(function(response) {
|
|
2845
2917
|
if (response.error) {
|
|
2846
|
-
|
|
2847
|
-
} else {
|
|
2848
|
-
resolve(response);
|
|
2918
|
+
throw toUsionError(response);
|
|
2849
2919
|
}
|
|
2920
|
+
return response;
|
|
2850
2921
|
});
|
|
2851
|
-
});
|
|
2852
2922
|
};
|
|
2853
2923
|
|
|
2854
2924
|
/**
|
|
@@ -3095,9 +3165,10 @@ var Usion = (function () {
|
|
|
3095
3165
|
*/
|
|
3096
3166
|
game.isConnected = function() {
|
|
3097
3167
|
if (this.directMode) {
|
|
3098
|
-
return this.connected && this.directSocket && this.directSocket.readyState === WebSocket.OPEN;
|
|
3168
|
+
return !!(this.connected && this.directSocket && this.directSocket.readyState === WebSocket.OPEN);
|
|
3099
3169
|
}
|
|
3100
|
-
|
|
3170
|
+
if (this._useProxy) return !!this.connected;
|
|
3171
|
+
return !!(this.connected && this.socket && this.socket.connected);
|
|
3101
3172
|
};
|
|
3102
3173
|
}
|
|
3103
3174
|
|
|
@@ -5977,12 +6048,12 @@ var Usion = (function () {
|
|
|
5977
6048
|
* unified backend channel, so it works in standalone AND embedded games.
|
|
5978
6049
|
*
|
|
5979
6050
|
* await Usion.leaderboard.submit(1500); // your score
|
|
5980
|
-
* const friends = await Usion.leaderboard.friends(); //
|
|
6051
|
+
* const friends = await Usion.leaderboard.friends(); // your accepted friends + you
|
|
5981
6052
|
* const top = await Usion.leaderboard.top(); // global top N
|
|
5982
6053
|
* const me = await Usion.leaderboard.me(); // { score, rank, total }
|
|
5983
6054
|
*
|
|
5984
|
-
* The **friends** board is scoped to
|
|
5985
|
-
* plus yourself —
|
|
6055
|
+
* The **friends** board is scoped to your accepted friends (the mutual-consent
|
|
6056
|
+
* friend system) plus yourself — "see my friends' record scores".
|
|
5986
6057
|
* Entries: { user_id, name, avatar, score, rank, is_me, metadata }.
|
|
5987
6058
|
*/
|
|
5988
6059
|
function createLeaderboardModule(Usion) {
|
|
@@ -5996,7 +6067,7 @@ var Usion = (function () {
|
|
|
5996
6067
|
return Usion._backendEmit('lb:submit', { service_id: serviceId(opts), score: score, metadata: metadata != null ? metadata : null });
|
|
5997
6068
|
},
|
|
5998
6069
|
|
|
5999
|
-
/** Leaderboard of
|
|
6070
|
+
/** Leaderboard of your accepted friends (plus you). Returns entries[]. */
|
|
6000
6071
|
friends: function (opts) {
|
|
6001
6072
|
opts = opts || {};
|
|
6002
6073
|
return Usion._backendEmit('lb:friends', { service_id: serviceId(opts), limit: opts.limit || 50 })
|
package/src/modules/core.js
CHANGED
|
@@ -68,7 +68,7 @@ export function isTrustedMessageSource(event) {
|
|
|
68
68
|
* Core Usion object with init, _post, _request
|
|
69
69
|
*/
|
|
70
70
|
export const core = {
|
|
71
|
-
version: '
|
|
71
|
+
version: '2.24.2', // synced from package.json by scripts/sync-version.mjs
|
|
72
72
|
config: {},
|
|
73
73
|
_initialized: false,
|
|
74
74
|
_initCallback: null,
|
|
@@ -148,8 +148,19 @@ export const core = {
|
|
|
148
148
|
|
|
149
149
|
// Handle INIT message
|
|
150
150
|
if (data.type === 'INIT' && data.config) {
|
|
151
|
-
//
|
|
151
|
+
// Re-INIT = credential/state refresh, not a re-boot. Hosts re-mint the
|
|
152
|
+
// scoped iframe token and re-INIT before it expires (and retry failed
|
|
153
|
+
// mints with backoff) — dropping these left long-lived iframes 401ing
|
|
154
|
+
// forever once their first token raced the mint or hit the 60-min TTL.
|
|
155
|
+
// Merge the refreshed fields; never re-fire the init callback.
|
|
152
156
|
if (self._initialized) {
|
|
157
|
+
if (data.config.authToken) {
|
|
158
|
+
self.config.authToken = data.config.authToken;
|
|
159
|
+
if (self.user) self.user._token = data.config.authToken;
|
|
160
|
+
}
|
|
161
|
+
if (data.config.balance !== undefined && self.wallet) {
|
|
162
|
+
self.wallet._balance = data.config.balance;
|
|
163
|
+
}
|
|
153
164
|
return;
|
|
154
165
|
}
|
|
155
166
|
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { UsionError, ERROR_CODES } from './errors.js';
|
|
2
|
+
|
|
3
|
+
export const GAME_ACK_TIMEOUT_MS = 10000;
|
|
4
|
+
export const GAME_JOIN_TIMEOUT_MS = 15000;
|
|
5
|
+
|
|
6
|
+
export function emitGameWithAck(socket, event, payload, timeoutMs, timeoutCode) {
|
|
7
|
+
timeoutMs = timeoutMs || GAME_ACK_TIMEOUT_MS;
|
|
8
|
+
timeoutCode = timeoutCode || ERROR_CODES.REQUEST_TIMEOUT;
|
|
9
|
+
return new Promise(function(resolve, reject) {
|
|
10
|
+
let settled = false;
|
|
11
|
+
const timer = setTimeout(function() {
|
|
12
|
+
if (settled) return;
|
|
13
|
+
settled = true;
|
|
14
|
+
reject(new UsionError(timeoutCode,
|
|
15
|
+
timeoutCode === ERROR_CODES.JOIN_TIMEOUT ? 'Join timeout' : 'Game request timeout'));
|
|
16
|
+
}, timeoutMs);
|
|
17
|
+
|
|
18
|
+
try {
|
|
19
|
+
socket.emit(event, payload, function(response) {
|
|
20
|
+
if (settled) return;
|
|
21
|
+
settled = true;
|
|
22
|
+
clearTimeout(timer);
|
|
23
|
+
resolve(response || {});
|
|
24
|
+
});
|
|
25
|
+
} catch (err) {
|
|
26
|
+
if (settled) return;
|
|
27
|
+
settled = true;
|
|
28
|
+
clearTimeout(timer);
|
|
29
|
+
reject(err);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
@@ -3,6 +3,19 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import { UsionError, toUsionError, ERROR_CODES } from './errors.js';
|
|
6
|
+
import {
|
|
7
|
+
emitGameWithAck,
|
|
8
|
+
GAME_JOIN_TIMEOUT_MS,
|
|
9
|
+
} from './game-ack.js';
|
|
10
|
+
|
|
11
|
+
function trackJoinPromise(game, promise) {
|
|
12
|
+
game._joinPromise = promise;
|
|
13
|
+
promise.catch(function() {
|
|
14
|
+
game._joined = false;
|
|
15
|
+
if (game._joinPromise === promise) game._joinPromise = null;
|
|
16
|
+
});
|
|
17
|
+
return promise;
|
|
18
|
+
}
|
|
6
19
|
|
|
7
20
|
/**
|
|
8
21
|
* Add game action methods to game module
|
|
@@ -19,8 +32,8 @@ export function applyGameMethods(game, Usion) {
|
|
|
19
32
|
const self = this;
|
|
20
33
|
roomId = roomId || Usion.config.roomId;
|
|
21
34
|
|
|
22
|
-
//
|
|
23
|
-
if (self.
|
|
35
|
+
// Coalesce in-flight/successful joins; rejected joins are cleared below.
|
|
36
|
+
if (self.roomId === roomId && self._joinPromise) {
|
|
24
37
|
return self._joinPromise;
|
|
25
38
|
}
|
|
26
39
|
|
|
@@ -38,35 +51,35 @@ export function applyGameMethods(game, Usion) {
|
|
|
38
51
|
|
|
39
52
|
// Proxy mode: send join request to parent
|
|
40
53
|
if (self._useProxy) {
|
|
41
|
-
|
|
54
|
+
const joinPromise = new Promise(function(resolve, reject) {
|
|
55
|
+
const rejectJoin = function(err) { reject(err); };
|
|
42
56
|
self._proxyJoinResolve = resolve;
|
|
43
|
-
self._proxyJoinReject =
|
|
57
|
+
self._proxyJoinReject = rejectJoin;
|
|
44
58
|
Usion._post({ type: 'GAME_JOIN', room_id: roomId });
|
|
45
59
|
setTimeout(function() {
|
|
46
|
-
if (
|
|
60
|
+
if (self._proxyJoinReject === rejectJoin) {
|
|
61
|
+
self._proxyJoinResolve = null;
|
|
47
62
|
self._proxyJoinReject = null;
|
|
48
63
|
reject(new UsionError(ERROR_CODES.JOIN_TIMEOUT, 'Join timeout'));
|
|
49
64
|
}
|
|
50
|
-
},
|
|
65
|
+
}, GAME_JOIN_TIMEOUT_MS);
|
|
51
66
|
});
|
|
52
|
-
return self
|
|
67
|
+
return trackJoinPromise(self, joinPromise);
|
|
53
68
|
}
|
|
54
69
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
self.socket.emit('game:join', { room_id: roomId }, function(response) {
|
|
70
|
+
let joinPromise;
|
|
71
|
+
if (!self.socket || !self.connected) {
|
|
72
|
+
joinPromise = Promise.reject(new UsionError(ERROR_CODES.NOT_CONNECTED, 'Not connected'));
|
|
73
|
+
} else if (!roomId) {
|
|
74
|
+
joinPromise = Promise.reject(new UsionError(ERROR_CODES.NO_ROOM, 'No room ID provided'));
|
|
75
|
+
} else {
|
|
76
|
+
joinPromise = emitGameWithAck(
|
|
77
|
+
self.socket, 'game:join', { room_id: roomId },
|
|
78
|
+
GAME_JOIN_TIMEOUT_MS, ERROR_CODES.JOIN_TIMEOUT
|
|
79
|
+
).then(function(response) {
|
|
67
80
|
if (response.error) {
|
|
68
81
|
self._joined = false;
|
|
69
|
-
|
|
82
|
+
throw toUsionError(response);
|
|
70
83
|
} else {
|
|
71
84
|
self._joined = true;
|
|
72
85
|
if (response.sequence !== undefined) {
|
|
@@ -80,12 +93,12 @@ export function applyGameMethods(game, Usion) {
|
|
|
80
93
|
// the socket transport now does too, so onJoined / recovery
|
|
81
94
|
// logic behaves the same everywhere.
|
|
82
95
|
self._dispatch('joined', response);
|
|
83
|
-
|
|
96
|
+
return response;
|
|
84
97
|
}
|
|
85
98
|
});
|
|
86
|
-
}
|
|
99
|
+
}
|
|
87
100
|
|
|
88
|
-
return self
|
|
101
|
+
return trackJoinPromise(self, joinPromise);
|
|
89
102
|
};
|
|
90
103
|
|
|
91
104
|
/**
|
|
@@ -183,10 +196,14 @@ export function applyGameMethods(game, Usion) {
|
|
|
183
196
|
}
|
|
184
197
|
|
|
185
198
|
if (self._useProxy) {
|
|
199
|
+
if (!self.connected) {
|
|
200
|
+
return Promise.reject(new UsionError(ERROR_CODES.NOT_CONNECTED, 'Not connected'));
|
|
201
|
+
}
|
|
186
202
|
const proxyMsg = { type: 'GAME_ACTION', room_id: self.roomId, action_type: actionType, action_data: actionData };
|
|
187
203
|
if (nextTurn) proxyMsg.next_turn = nextTurn;
|
|
188
204
|
Usion._post(proxyMsg);
|
|
189
|
-
|
|
205
|
+
// v2 hosts only confirm handoff; completion arrives via onAction.
|
|
206
|
+
return Promise.resolve({ success: true, acknowledged: false });
|
|
190
207
|
}
|
|
191
208
|
|
|
192
209
|
// Gate sends while a post-reconnect rejoin is in flight, so a stale
|
|
@@ -217,29 +234,22 @@ export function applyGameMethods(game, Usion) {
|
|
|
217
234
|
*/
|
|
218
235
|
game._emitAction = function(payload, retryOnNotInRoom) {
|
|
219
236
|
const self = this;
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
if (response && response.error) {
|
|
237
|
+
if (!self.socket || !self.connected) {
|
|
238
|
+
return Promise.reject(new UsionError(ERROR_CODES.NOT_CONNECTED, 'Not connected'));
|
|
239
|
+
}
|
|
240
|
+
return emitGameWithAck(self.socket, 'game:action', payload)
|
|
241
|
+
.then(function(response) {
|
|
242
|
+
if (response.error) {
|
|
227
243
|
const ue = toUsionError(response);
|
|
228
244
|
if (retryOnNotInRoom && ue.code === ERROR_CODES.NOT_IN_ROOM) {
|
|
229
|
-
self._autoRejoin()
|
|
230
|
-
.then(function() { return self._emitAction(payload, false); })
|
|
231
|
-
.then(resolve, reject);
|
|
232
|
-
return;
|
|
245
|
+
return self._autoRejoin()
|
|
246
|
+
.then(function() { return self._emitAction(payload, false); });
|
|
233
247
|
}
|
|
234
|
-
|
|
235
|
-
} else {
|
|
236
|
-
if (response && response.sequence !== undefined) {
|
|
237
|
-
self._lastSequence = response.sequence;
|
|
238
|
-
}
|
|
239
|
-
resolve(response);
|
|
248
|
+
throw ue;
|
|
240
249
|
}
|
|
250
|
+
if (response.sequence !== undefined) self._lastSequence = response.sequence;
|
|
251
|
+
return response;
|
|
241
252
|
});
|
|
242
|
-
});
|
|
243
253
|
};
|
|
244
254
|
|
|
245
255
|
/**
|
|
@@ -252,11 +262,12 @@ export function applyGameMethods(game, Usion) {
|
|
|
252
262
|
if (self._rejoinPromise) return self._rejoinPromise;
|
|
253
263
|
if (!self.roomId || !self.socket || !self.connected) return Promise.resolve();
|
|
254
264
|
Usion.log('Server reports socket not in room - auto-rejoining ' + self.roomId);
|
|
265
|
+
const resumeSequence = self._lastSequence || 0;
|
|
255
266
|
self._joined = false;
|
|
256
267
|
self._joinPromise = null;
|
|
257
268
|
self._rejoinPromise = self.join(self.roomId)
|
|
258
269
|
.then(function() {
|
|
259
|
-
self.requestSync(
|
|
270
|
+
self.requestSync(resumeSequence);
|
|
260
271
|
})
|
|
261
272
|
.catch(function(err) {
|
|
262
273
|
Usion.log('Auto-rejoin failed: ' + (err && err.message ? err.message : String(err)));
|
|
@@ -305,18 +316,43 @@ export function applyGameMethods(game, Usion) {
|
|
|
305
316
|
game._flushOfflineQueue = function() {
|
|
306
317
|
const self = this;
|
|
307
318
|
const queue = self._offlineQueue;
|
|
308
|
-
if (!queue || !queue.length) return;
|
|
309
|
-
self.
|
|
319
|
+
if (!queue || !queue.length) return Promise.resolve();
|
|
320
|
+
if (self._offlineFlushPromise) return self._offlineFlushPromise;
|
|
321
|
+
if (!self.connected || (!self._useProxy && !self.directMode && !self._joined)) {
|
|
322
|
+
return Promise.resolve();
|
|
323
|
+
}
|
|
310
324
|
Usion.log('Flushing ' + queue.length + ' queued action(s) after reconnect');
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
325
|
+
|
|
326
|
+
function sendNext() {
|
|
327
|
+
if (!queue.length) return Promise.resolve();
|
|
328
|
+
if (!self.connected || (!self._useProxy && !self.directMode && !self._joined)) {
|
|
329
|
+
return Promise.resolve();
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
const item = queue[0];
|
|
333
|
+
return self.action(item.actionType, item.actionData, item.opts).then(function(result) {
|
|
334
|
+
if (queue[0] === item) queue.shift();
|
|
335
|
+
item.resolve(result);
|
|
336
|
+
return sendNext();
|
|
337
|
+
}, function(err) {
|
|
338
|
+
const ue = toUsionError(err);
|
|
339
|
+
// Preserve only commands known not to have reached a live room.
|
|
340
|
+
if (ue.code === ERROR_CODES.NOT_CONNECTED || ue.code === ERROR_CODES.NOT_IN_ROOM) {
|
|
341
|
+
return;
|
|
342
|
+
}
|
|
343
|
+
if (queue[0] === item) queue.shift();
|
|
344
|
+
item.reject(err);
|
|
345
|
+
return sendNext();
|
|
318
346
|
});
|
|
319
|
-
}
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
const flushPromise = Promise.resolve().then(sendNext);
|
|
350
|
+
self._offlineFlushPromise = flushPromise;
|
|
351
|
+
function clearFlush() {
|
|
352
|
+
if (self._offlineFlushPromise === flushPromise) self._offlineFlushPromise = null;
|
|
353
|
+
}
|
|
354
|
+
flushPromise.then(clearFlush, clearFlush);
|
|
355
|
+
return flushPromise;
|
|
320
356
|
};
|
|
321
357
|
|
|
322
358
|
/**
|
|
@@ -362,24 +398,20 @@ export function applyGameMethods(game, Usion) {
|
|
|
362
398
|
});
|
|
363
399
|
}
|
|
364
400
|
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
}
|
|
370
|
-
self.socket.emit('game:set_state', {
|
|
401
|
+
if (!self.socket || !self.connected) {
|
|
402
|
+
return Promise.reject(new UsionError(ERROR_CODES.NOT_CONNECTED, 'Not connected'));
|
|
403
|
+
}
|
|
404
|
+
return emitGameWithAck(self.socket, 'game:set_state', {
|
|
371
405
|
room_id: self.roomId,
|
|
372
406
|
state: state || {},
|
|
373
407
|
sequence: checkpointSeq
|
|
374
|
-
}
|
|
375
|
-
if (response
|
|
408
|
+
}).then(function(response) {
|
|
409
|
+
if (response.error) {
|
|
376
410
|
const ue = toUsionError(response);
|
|
377
|
-
|
|
378
|
-
} else {
|
|
379
|
-
resolve(response || { success: true });
|
|
411
|
+
return { success: false, error: ue.message, code: ue.code };
|
|
380
412
|
}
|
|
413
|
+
return Object.keys(response).length ? response : { success: true };
|
|
381
414
|
});
|
|
382
|
-
});
|
|
383
415
|
};
|
|
384
416
|
|
|
385
417
|
/**
|
|
@@ -486,20 +518,16 @@ export function applyGameMethods(game, Usion) {
|
|
|
486
518
|
return Promise.resolve({ success: true });
|
|
487
519
|
}
|
|
488
520
|
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
self.socket.emit('game:forfeit', { room_id: self.roomId }, function(response) {
|
|
521
|
+
if (!self.socket || !self.connected) {
|
|
522
|
+
return Promise.reject(new UsionError(ERROR_CODES.NOT_CONNECTED, 'Not connected'));
|
|
523
|
+
}
|
|
524
|
+
return emitGameWithAck(self.socket, 'game:forfeit', { room_id: self.roomId })
|
|
525
|
+
.then(function(response) {
|
|
496
526
|
if (response.error) {
|
|
497
|
-
|
|
498
|
-
} else {
|
|
499
|
-
resolve(response);
|
|
527
|
+
throw toUsionError(response);
|
|
500
528
|
}
|
|
529
|
+
return response;
|
|
501
530
|
});
|
|
502
|
-
});
|
|
503
531
|
};
|
|
504
532
|
|
|
505
533
|
/**
|
|
@@ -746,8 +774,9 @@ export function applyGameMethods(game, Usion) {
|
|
|
746
774
|
*/
|
|
747
775
|
game.isConnected = function() {
|
|
748
776
|
if (this.directMode) {
|
|
749
|
-
return this.connected && this.directSocket && this.directSocket.readyState === WebSocket.OPEN;
|
|
777
|
+
return !!(this.connected && this.directSocket && this.directSocket.readyState === WebSocket.OPEN);
|
|
750
778
|
}
|
|
751
|
-
|
|
779
|
+
if (this._useProxy) return !!this.connected;
|
|
780
|
+
return !!(this.connected && this.socket && this.socket.connected);
|
|
752
781
|
};
|
|
753
782
|
}
|
|
@@ -109,6 +109,7 @@ export function applyGameProxy(game, Usion) {
|
|
|
109
109
|
self._proxyJoinResolve(data);
|
|
110
110
|
self._proxyJoinResolve = null;
|
|
111
111
|
}
|
|
112
|
+
self._proxyJoinReject = null;
|
|
112
113
|
self._dispatch('joined', data);
|
|
113
114
|
break;
|
|
114
115
|
|
|
@@ -118,6 +119,7 @@ export function applyGameProxy(game, Usion) {
|
|
|
118
119
|
self._proxyJoinReject(toUsionError(data.message || 'Join failed'));
|
|
119
120
|
self._proxyJoinReject = null;
|
|
120
121
|
}
|
|
122
|
+
self._proxyJoinResolve = null;
|
|
121
123
|
break;
|
|
122
124
|
|
|
123
125
|
case 'GAME_PLAYER_JOINED':
|
|
@@ -75,12 +75,14 @@ export function applyGameSocket(game, Usion) {
|
|
|
75
75
|
// membership and sync are restored — otherwise a stale move could
|
|
76
76
|
// go out before the client has caught up.
|
|
77
77
|
if (self.roomId) {
|
|
78
|
+
// Join reports the server head, so capture our replay cursor first.
|
|
79
|
+
var resumeSequence = self._lastSequence || 0;
|
|
78
80
|
self._joined = false;
|
|
79
81
|
self._joinPromise = null;
|
|
80
82
|
self._rejoinPromise = self.join(self.roomId)
|
|
81
83
|
.then(function() {
|
|
82
84
|
Usion.log('Reconnected - joined room ' + self.roomId);
|
|
83
|
-
self.requestSync(
|
|
85
|
+
self.requestSync(resumeSequence);
|
|
84
86
|
})
|
|
85
87
|
.catch(function(err) {
|
|
86
88
|
Usion.log('Rejoin failed: ' + (err && err.message ? err.message : String(err)));
|
|
@@ -5,12 +5,12 @@
|
|
|
5
5
|
* unified backend channel, so it works in standalone AND embedded games.
|
|
6
6
|
*
|
|
7
7
|
* await Usion.leaderboard.submit(1500); // your score
|
|
8
|
-
* const friends = await Usion.leaderboard.friends(); //
|
|
8
|
+
* const friends = await Usion.leaderboard.friends(); // your accepted friends + you
|
|
9
9
|
* const top = await Usion.leaderboard.top(); // global top N
|
|
10
10
|
* const me = await Usion.leaderboard.me(); // { score, rank, total }
|
|
11
11
|
*
|
|
12
|
-
* The **friends** board is scoped to
|
|
13
|
-
* plus yourself —
|
|
12
|
+
* The **friends** board is scoped to your accepted friends (the mutual-consent
|
|
13
|
+
* friend system) plus yourself — "see my friends' record scores".
|
|
14
14
|
* Entries: { user_id, name, avatar, score, rank, is_me, metadata }.
|
|
15
15
|
*/
|
|
16
16
|
export function createLeaderboardModule(Usion) {
|
|
@@ -24,7 +24,7 @@ export function createLeaderboardModule(Usion) {
|
|
|
24
24
|
return Usion._backendEmit('lb:submit', { service_id: serviceId(opts), score: score, metadata: metadata != null ? metadata : null });
|
|
25
25
|
},
|
|
26
26
|
|
|
27
|
-
/** Leaderboard of
|
|
27
|
+
/** Leaderboard of your accepted friends (plus you). Returns entries[]. */
|
|
28
28
|
friends: function (opts) {
|
|
29
29
|
opts = opts || {};
|
|
30
30
|
return Usion._backendEmit('lb:friends', { service_id: serviceId(opts), limit: opts.limit || 50 })
|
package/types/index.d.ts
CHANGED
|
@@ -162,6 +162,8 @@ export interface GameJoinResult {
|
|
|
162
162
|
|
|
163
163
|
export interface ActionResult {
|
|
164
164
|
success: boolean;
|
|
165
|
+
/** False when a v2 proxy host accepted the command but cannot acknowledge it. */
|
|
166
|
+
acknowledged?: boolean;
|
|
165
167
|
sequence?: number;
|
|
166
168
|
error?: string;
|
|
167
169
|
message?: string;
|
|
@@ -1227,7 +1229,7 @@ export interface LeaderboardEntry {
|
|
|
1227
1229
|
export interface LeaderboardModule {
|
|
1228
1230
|
/** Submit a score (best is kept per the service's order config). Opt-in per game. */
|
|
1229
1231
|
submit(score: number, metadata?: any, opts?: { serviceId?: string }): Promise<{ success: boolean; score: number; best: number; rank: number; updated: boolean }>;
|
|
1230
|
-
/** Leaderboard of
|
|
1232
|
+
/** Leaderboard of your accepted friends (plus you). */
|
|
1231
1233
|
friends(opts?: { serviceId?: string; limit?: number }): Promise<LeaderboardEntry[]>;
|
|
1232
1234
|
/** Global top N. */
|
|
1233
1235
|
top(opts?: { serviceId?: string; limit?: number }): Promise<LeaderboardEntry[]>;
|