@arcadible/sdk 0.3.0 → 0.3.1
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/bus/client.js +3 -3
- package/dist/bus/protocol.d.ts +2 -0
- package/dist/bus/protocol.js +16 -4
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/dist/bus/client.js
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
// alone when no page answers, running the page's end itself, in its own
|
|
3
3
|
// page, so the rules are the same.
|
|
4
4
|
// [import]
|
|
5
|
-
import { ArcadibleError, BUS_VERSION, Codes, HANDSHAKE_TIMEOUT,
|
|
5
|
+
import { ArcadibleError, BUS_VERSION, Codes, HANDSHAKE_TIMEOUT, isHostOrigin, isMessage, isWelcome, REQUEST_TIMEOUT, } from "./protocol.js";
|
|
6
6
|
// [function]
|
|
7
7
|
export function openBus(options) {
|
|
8
8
|
const win = options.window ?? (typeof window === "undefined" ? undefined : window);
|
|
9
|
-
const origins = options.origins
|
|
9
|
+
const origins = options.origins;
|
|
10
10
|
const requestTimeout = options.requestTimeout ?? REQUEST_TIMEOUT;
|
|
11
11
|
let state = "waiting";
|
|
12
12
|
let port = null;
|
|
@@ -79,7 +79,7 @@ export function openBus(options) {
|
|
|
79
79
|
if (state !== "waiting" ||
|
|
80
80
|
!win ||
|
|
81
81
|
event.source !== win.parent ||
|
|
82
|
-
!
|
|
82
|
+
!isHostOrigin(event.origin, origins) ||
|
|
83
83
|
!isWelcome(event.data) ||
|
|
84
84
|
!event.ports[0]) {
|
|
85
85
|
return;
|
package/dist/bus/protocol.d.ts
CHANGED
|
@@ -2,6 +2,8 @@ export declare const BUS_VERSION = 1;
|
|
|
2
2
|
export declare const HANDSHAKE_TIMEOUT = 1000;
|
|
3
3
|
export declare const REQUEST_TIMEOUT = 10000;
|
|
4
4
|
export declare const HOST_ORIGINS: readonly string[];
|
|
5
|
+
export declare const LOCAL_ORIGIN: RegExp;
|
|
6
|
+
export declare function isHostOrigin(origin: string, origins: readonly string[] | undefined): boolean;
|
|
5
7
|
export declare const MAX_IN_FLIGHT = 64;
|
|
6
8
|
export declare const MAX_MESSAGE: number;
|
|
7
9
|
export declare const Codes: {
|
package/dist/bus/protocol.js
CHANGED
|
@@ -9,11 +9,23 @@ export const BUS_VERSION = 1;
|
|
|
9
9
|
export const HANDSHAKE_TIMEOUT = 1000;
|
|
10
10
|
// How long a request waits for its response.
|
|
11
11
|
export const REQUEST_TIMEOUT = 10_000;
|
|
12
|
-
// The play pages a game accepts a welcome from: production's
|
|
13
|
-
// development page (play.arcadible.test
|
|
14
|
-
// `createClient({ origins })`, never trusted by what games
|
|
15
|
-
// hostile network could pose as an http one.
|
|
12
|
+
// The play pages a game accepts a welcome from: production's, and `arc
|
|
13
|
+
// serve`'s on this machine. Another development page (play.arcadible.test)
|
|
14
|
+
// is passed with `createClient({ origins })`, never trusted by what games
|
|
15
|
+
// ship, since a hostile network could pose as an http one.
|
|
16
16
|
export const HOST_ORIGINS = ["https://play.arcadible.com"];
|
|
17
|
+
// `arc serve`'s play page, on any port. The network can't pose as loopback,
|
|
18
|
+
// and on Arcadible a build's `frame-ancestors` lets only the play page frame
|
|
19
|
+
// it, so no local page can reach a player's saves there.
|
|
20
|
+
export const LOCAL_ORIGIN = /^http:\/\/localhost:\d+$/u;
|
|
21
|
+
// [function]
|
|
22
|
+
// Whether a game accepts a welcome from `origin`: one of `origins` when it
|
|
23
|
+
// was given, or else production's or `arc serve`'s.
|
|
24
|
+
export function isHostOrigin(origin, origins) {
|
|
25
|
+
return origins
|
|
26
|
+
? origins.includes(origin)
|
|
27
|
+
: HOST_ORIGINS.includes(origin) || LOCAL_ORIGIN.test(origin);
|
|
28
|
+
}
|
|
17
29
|
// The most requests one game can have waiting on the page; past it, a
|
|
18
30
|
// request fails with `busy`.
|
|
19
31
|
export const MAX_IN_FLIGHT = 64;
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "0.3.
|
|
1
|
+
export declare const VERSION = "0.3.1";
|
package/dist/version.js
CHANGED
package/package.json
CHANGED