arcadible 1.0.17 → 1.0.19

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
@@ -65,5 +65,5 @@
65
65
  "scripts": {
66
66
  "test": "node --test \"test/**/*.test.js\""
67
67
  },
68
- "version": "1.0.17"
68
+ "version": "1.0.19"
69
69
  }
package/src/account.js CHANGED
@@ -153,20 +153,21 @@ const getSaved = function (onRefresh) {
153
153
 
154
154
  // [function]
155
155
 
156
- // the account an ARC_TOKEN stands for. The API doesn't describe a token's
157
- // user yet, so this is a placeholder with a real user's shape, to be replaced
158
- // by the API's answer without changing it.
156
+ // the account an ARCADIBLE_TOKEN stands for. The API doesn't describe a
157
+ // token's user yet, so this is a placeholder with a real user's shape, to be
158
+ // replaced by the API's answer without changing it.
159
159
  const fromToken = function (token) {
160
160
  return { session: { access_token: token }, token: true, user: TOKEN_USER }; // eslint-disable-line camelcase
161
161
  };
162
162
 
163
163
  // [function]
164
164
 
165
- // the account commands use: ARC_TOKEN when it's set, which takes precedence
166
- // over the saved session, or else the saved session, refreshed if needed.
165
+ // the account commands use: ARCADIBLE_TOKEN when it's set, which takes
166
+ // precedence over the saved session, or else the saved session, refreshed if
167
+ // needed.
167
168
  const get = function (onRefresh) {
168
- if (process.env.ARC_TOKEN) {
169
- return Promise.resolve(fromToken(process.env.ARC_TOKEN));
169
+ if (process.env.ARCADIBLE_TOKEN) {
170
+ return Promise.resolve(fromToken(process.env.ARCADIBLE_TOKEN));
170
171
  }
171
172
  return getSaved(onRefresh);
172
173
  };
@@ -179,8 +180,8 @@ const get = function (onRefresh) {
179
180
  // this one's. A refresh tells them apart: refused, the session is over, so
180
181
  // it's removed and the error says to log in (session_expired); renewed, the
181
182
  // session is kept, and the request's own error stands, so running the
182
- // command again works. An ARC_TOKEN's refusal stays as it is, since logging
183
- // in doesn't change the token.
183
+ // command again works. An ARCADIBLE_TOKEN's refusal stays as it is, since
184
+ // logging in doesn't change the token.
184
185
  const ended = function (current) {
185
186
  return (ex) => {
186
187
  if (
@@ -229,8 +230,8 @@ const revoke = function (session) {
229
230
  // working, then removed. Never an error: a refused refresh means the session
230
231
  // was already over, and a failure to reach the API (offline, an outage)
231
232
  // leaves it to expire after 90 idle days, while the file is removed either
232
- // way. It ends only the saved session: never an ARC_TOKEN, nor any other
233
- // session.
233
+ // way. It ends only the saved session: never an ARCADIBLE_TOKEN, nor any
234
+ // other session.
234
235
  const end = function () {
235
236
  return readSaved()
236
237
  .then((current) => {
@@ -105,6 +105,18 @@ const storeIcon = function (root) {
105
105
 
106
106
  // [function]
107
107
 
108
+ // the loading screen's art: the project's splash, else its banner, else its
109
+ // cover, as the play page picks it, or null; each time it's asked for.
110
+ const storeArt = function (root) {
111
+ return async () => {
112
+ const { game } = await media(root);
113
+ const file = game.splash ?? game.banner ?? game.cover;
114
+ return file ? readFile(join(root, file)) : null;
115
+ };
116
+ };
117
+
118
+ // [function]
119
+
108
120
  // listens, turning a port in use into its code.
109
121
  const listen = async function (options) {
110
122
  try {
@@ -138,6 +150,7 @@ const main = async function (conf) {
138
150
  const project = await given(conf);
139
151
  const game = project.game;
140
152
  const options = {
153
+ art: storeArt(root),
141
154
  icon: storeIcon(root),
142
155
  info: {
143
156
  channel: CHANNEL,
@@ -148,8 +161,8 @@ const main = async function (conf) {
148
161
  onRemote: handler.onRemote,
149
162
  port,
150
163
  remote: remoteFiles({
151
- asset: cfguri.ARCADIBLE_ASSET,
152
164
  dir: join(configDir(), cfgproduct.tool, "sdk"),
165
+ host: cfguri.HOST_HTTP_PLAY,
153
166
  sdk: cfguri.ARCADIBLE_SDK,
154
167
  }),
155
168
  };
package/src/config/uri.js CHANGED
@@ -12,10 +12,9 @@ const PROTOCOL = cfgproduct.protocol;
12
12
  // [export]
13
13
 
14
14
  module.exports = {
15
- // where arc serve fetches Arcadible's own files (src/serve/remote.js): the
16
- // asset site, which has the play page's host, and a build origin, any of
17
- // which serves the SDK's hosted script at /arcadible/sdk/.
18
- ARCADIBLE_ASSET: "https://asset.offst.net",
15
+ // a build origin, where arc serve fetches the SDK's hosted script
16
+ // (src/serve/remote.js): any of them serves it at /arcadible/sdk/. The play
17
+ // page's host comes from the play site, HOST_HTTP_PLAY.
19
18
  ARCADIBLE_SDK: `https://sdk.${cfgproduct.handle}.io`,
20
19
  HOST_APP_PLAY: `${PROTOCOL}://play`,
21
20
  HOST_APP_STORE: `${PROTOCOL}://store`,
package/src/phrase.js CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  // [import]
4
4
 
5
+ const cfgfile = require("./config/file");
5
6
  const cfgproduct = require("./config/product");
6
7
 
7
8
  // [declare]
@@ -9,6 +10,14 @@ const cfgproduct = require("./config/product");
9
10
  const HANDLE = cfgproduct.handle;
10
11
  const TITLE = cfgproduct.title;
11
12
  const TOOL = cfgproduct.tool;
13
+
14
+ // [declare]
15
+
16
+ const MANIFEST = cfgfile.MANIFEST;
17
+ const MEDIA = cfgfile.MEDIA;
18
+
19
+ // [declare]
20
+
12
21
  const TAIL_LINES = 20;
13
22
 
14
23
  // [function]
@@ -276,7 +285,7 @@ const errorCode = function (code) {
276
285
  const gameHandleTaken = function (handle) {
277
286
  return blocks(
278
287
  `Handle taken: ${handle}`,
279
- "Choose another handle in arcadible.toml.",
288
+ `Choose another handle in ${MANIFEST}.`,
280
289
  );
281
290
  };
282
291
 
@@ -286,7 +295,7 @@ const gameHandleTaken = function (handle) {
286
295
  // deploy does.
287
296
  const gameHandleChanged = function (handle, current) {
288
297
  return blocks(
289
- `The handle in arcadible.toml (${handle ?? "none"}) isn't the game's on ${TITLE} (${current ?? "none"}).`,
298
+ `The handle in ${MANIFEST} (${handle ?? "none"}) isn't the game's on ${TITLE} (${current ?? "none"}).`,
290
299
  `Only ${cmdDeploy()} changes a handle: deploy with it, or set the handle back.`,
291
300
  );
292
301
  };
@@ -399,9 +408,7 @@ const portInUse = function (port) {
399
408
  // what one of Arcadible's files is, for arc serve's warnings: `host`, the play
400
409
  // page's, or a path under /arcadible/, such as sdk/v1.js.
401
410
  const remoteName = function (name) {
402
- return name === "host"
403
- ? "the play page's host"
404
- : `/${cfgproduct.handle}/${name}`;
411
+ return name === "host" ? "the play page's host" : `/${HANDLE}/${name}`;
405
412
  };
406
413
 
407
414
  // [function]
@@ -823,7 +830,7 @@ const packagePathReserved = function (name) {
823
830
  const packageTooLarge = function (size) {
824
831
  return blocks(
825
832
  `Package is larger than ${size} MB.`,
826
- ".arcadible/ doesn't count toward it.",
833
+ `${MEDIA}/ doesn't count toward it.`,
827
834
  );
828
835
  };
829
836
 
package/src/serve/page.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  // the local play page: it frames the game as the play page does
3
- // (site/src/javascripts/arcadible/play/app/page.coffee), with the same
3
+ // (ui2/src/play), with the same
4
4
  // sandbox and permissions, and runs the play page's own host for the SDK,
5
5
  // so saves are kept by the page, across builds. It reloads the
6
6
  // game, and only the game, when told to. Its tab shows the game's store
@@ -32,6 +32,14 @@ const SANDBOX =
32
32
  const HOST = "/_arcadible/host.js";
33
33
  const RELOAD = "/_arcadible/reload";
34
34
  const ICON = "/_arcadible/icon";
35
+ // the loading screen's art and icon, PNGs, or 404 without.
36
+ const ART = "/_arcadible/art.png";
37
+ const ICON_PNG = "/_arcadible/icon.png";
38
+ // the loading screen's timing, as the play page's (ui2/src/play/loading.ts): up at
39
+ // least the minimum, then a fade; a game that began and stops reporting
40
+ // comes down after `STUCK` without a call; the SDK's word at load is
41
+ // waited for `SAFETY` at most.
42
+ const LOADING = { FADE: 300, MINIMUM: 1500, SAFETY: 2000, STUCK: 30000 };
35
43
  // the play page's own favicon.ico (app/src/web/arcadible-play/content), for a
36
44
  // game without a store icon, and for /favicon.ico, which browsers ask for.
37
45
  const FAVICON = join(__dirname, "favicon.ico");
@@ -83,13 +91,25 @@ const escapeHtml = function (text) {
83
91
 
84
92
  // [function]
85
93
 
94
+ // the loading screen, as the play page's (ui2/src/play/play.css;
95
+ // ui2/ARCHITECTURE.md, The play page's loading screen): without
96
+ // the developer's name, which isn't known here, or the rotate prompt, since
97
+ // arc serve listens on this machine only.
98
+ const LOADING_CSS =
99
+ ".loading{position:fixed;inset:0;z-index:2;overflow:hidden;pointer-events:none;background:#000;color:#fff;font-family:system-ui,-apple-system,'Segoe UI',sans-serif;transition:opacity 300ms ease}.loading-fading{opacity:0}.loading-gone{display:none}.loading-art{position:absolute;inset:0;inline-size:100%;block-size:100%;object-fit:cover;opacity:0;transition:opacity 400ms ease}.loading-scrim{position:absolute;inset:0;opacity:0;background:linear-gradient(to top,rgba(0,0,0,.8) 0%,rgba(0,0,0,.36) 32%,rgba(0,0,0,0) 58%);transition:opacity 400ms ease}.loading-info{position:absolute;inset-inline:28px;inset-block-end:30px;display:flex;align-items:center;column-gap:14px;opacity:0;transition:opacity 400ms ease}.loading-arrived .loading-art,.loading-arrived .loading-scrim,.loading-arrived .loading-info,.loading-bare .loading-scrim,.loading-bare .loading-info{opacity:1}.loading-bare{background:#141618}.loading-icon{inline-size:64px;block-size:64px;border-radius:22%;flex:none}.loading-title{margin:0;font-size:24px;font-weight:600;letter-spacing:-.02em;line-height:1.15;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.loading-bar{position:absolute;inset-inline:0;inset-block-end:0;block-size:4px;overflow:hidden;background:rgba(255,255,255,.18)}.loading-fill{inline-size:25%;block-size:100%;background:rgba(255,255,255,.85);animation:loading-sweep 1.6s cubic-bezier(.45,0,.55,1) infinite}.loading-counting .loading-fill{animation:none;background:#fff;transition:inline-size 400ms ease-out}@media (max-height:359px){.loading-info{inset-inline:18px;inset-block-end:20px;column-gap:12px}.loading-icon{inline-size:44px;block-size:44px}.loading-title{font-size:18px}.loading-bar{block-size:3px}}@media (min-width:1024px) and (min-height:600px){.loading-info{inset-inline:48px;inset-block-end:44px;column-gap:20px}.loading-icon{inline-size:88px;block-size:88px}.loading-title{font-size:32px}}@media (prefers-reduced-motion:reduce){.loading-fill{animation:none;inline-size:100%;opacity:.45}.loading-counting .loading-fill{opacity:1}}@keyframes loading-sweep{0%{transform:translateX(-100%)}100%{transform:translateX(400%)}}";
100
+
101
+ // [function]
102
+
86
103
  // the page for `game`: `{ id, channel, version, title, src }`, where `src` is
87
104
  // the game's URL, on its own origin.
88
105
  const html = function (game) {
89
106
  const config = {
90
107
  allow: ALLOW,
108
+ art: ART,
91
109
  channel: game.channel,
92
110
  game: game.id,
111
+ icon: ICON_PNG,
112
+ loading: LOADING,
93
113
  sandbox: SANDBOX,
94
114
  src: game.src,
95
115
  version: game.version,
@@ -101,18 +121,73 @@ const html = function (game) {
101
121
  <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no,viewport-fit=cover">
102
122
  <title>${escapeHtml(game.title)}</title>
103
123
  <link href="${ICON}" rel="icon">
104
- <style>html,body{margin:0;height:100%;overflow:hidden;background:#000}iframe{display:block;width:100%;height:100%;border:0;visibility:hidden}</style>
124
+ <style>html,body{margin:0;height:100%;overflow:hidden;background:#000}iframe{display:block;width:100%;height:100%;border:0}${LOADING_CSS}</style>
105
125
  </head>
106
126
  <body>
127
+ <div class="loading" id="loading">
128
+ <img alt="" class="loading-art" id="loading-art">
129
+ <div class="loading-scrim"></div>
130
+ <div class="loading-info">
131
+ <img alt="" class="loading-icon" id="loading-icon">
132
+ <p class="loading-title">${escapeHtml(game.title)}</p>
133
+ </div>
134
+ <div aria-label="Loading ${escapeHtml(game.title)}" aria-valuemax="100" aria-valuemin="0" class="loading-bar" id="loading-bar" role="progressbar"><div class="loading-fill" id="loading-fill"></div></div>
135
+ </div>
107
136
  <script src="${HOST}"></script>
108
137
  <script>
109
138
  const config = ${scriptJson(config)};
110
139
  const frame = document.createElement("iframe");
111
140
  frame.allow = config.allow;
112
141
  frame.sandbox = config.sandbox;
142
+ // the loading screen, as the play page runs it (ui2/src/play/loading.ts): decided
143
+ // once, at the first load, from whether the game's SDK can report and
144
+ // began; down after LOADING.MINIMUM, faded. Reloads after a save don't
145
+ // show it again, so iterating stays instant.
146
+ const cover = document.getElementById("loading");
147
+ const loading = { begun: false, decided: false, down: false, leaving: false, reports: false, safety: 0, stuck: 0, visible: [] };
148
+ const gone = () => {
149
+ if (loading.down) return;
150
+ loading.down = true;
151
+ cover.classList.add("loading-gone");
152
+ for (const resolve of loading.visible) resolve();
153
+ loading.visible = [];
154
+ };
155
+ const takeDown = () => {
156
+ if (loading.down || loading.leaving) return;
157
+ loading.leaving = loading.decided = true;
158
+ clearTimeout(loading.stuck);
159
+ clearTimeout(loading.safety);
160
+ setTimeout(() => {
161
+ cover.classList.add("loading-fading");
162
+ setTimeout(gone, config.loading.FADE);
163
+ }, Math.max(0, config.loading.MINIMUM - performance.now()));
164
+ };
165
+ const armStuck = () => {
166
+ clearTimeout(loading.stuck);
167
+ if (!loading.down && !loading.leaving) loading.stuck = setTimeout(takeDown, config.loading.STUCK);
168
+ };
169
+ const decide = (keep) => {
170
+ if (loading.decided) return;
171
+ loading.decided = true;
172
+ if (keep) armStuck();
173
+ else takeDown();
174
+ };
175
+ // a frame that never loads mustn't keep it up.
176
+ setTimeout(() => decide(false), config.loading.STUCK);
177
+ const art = document.getElementById("loading-art");
178
+ // shown once decoded, so the title never shows before the art.
179
+ const arrive = () => cover.classList.add("loading-arrived");
180
+ art.addEventListener("load", () => art.decode().then(arrive, arrive));
181
+ art.addEventListener("error", () => cover.classList.add("loading-bare"));
182
+ art.src = config.art;
183
+ const icon = document.getElementById("loading-icon");
184
+ icon.addEventListener("error", () => icon.remove());
185
+ icon.src = config.icon;
113
186
  frame.addEventListener("load", () => {
114
- frame.style.visibility = "visible";
115
187
  frame.focus();
188
+ if (loading.decided) return;
189
+ if (loading.reports) loading.safety = setTimeout(() => decide(loading.begun), config.loading.SAFETY);
190
+ else decide(false);
116
191
  });
117
192
  // the host answers the game's hello, so it's created before the frame
118
193
  // exists. Without it, the game stands alone, as off Arcadible.
@@ -124,19 +199,45 @@ const html = function (game) {
124
199
  channel: config.channel,
125
200
  frame,
126
201
  game: config.game,
202
+ lifecycle: {
203
+ begin: () => {
204
+ loading.begun = true;
205
+ },
206
+ end: () => new Promise((resolve) => {
207
+ if (loading.down) {
208
+ resolve();
209
+ return;
210
+ }
211
+ loading.visible.push(resolve);
212
+ takeDown();
213
+ }),
214
+ loaded: (begun) => {
215
+ clearTimeout(loading.safety);
216
+ decide(begun);
217
+ },
218
+ progress: (fraction) => {
219
+ if (loading.down || loading.leaving) return;
220
+ cover.classList.add("loading-counting");
221
+ document.getElementById("loading-fill").style.inlineSize = fraction * 100 + "%";
222
+ document.getElementById("loading-bar").setAttribute("aria-valuenow", String(Math.round(fraction * 100)));
223
+ if (loading.decided) armStuck();
224
+ },
225
+ },
226
+ onHello: (hello) => {
227
+ loading.reports = Boolean(lib.reportsInit && lib.reportsInit(hello.client));
228
+ },
127
229
  origin: new URL(config.src).origin,
128
230
  version: config.version,
129
231
  });
130
232
  } catch (err) {
131
- console.error("Arcadible SDK: the play page couldn't host the game, so it stands alone.", err);
233
+ console.error("Arcadible: the play page couldn't host the game, so it stands alone.", err);
132
234
  }
133
235
  } else {
134
- console.error("Arcadible SDK: the play page's host didn't load, so the game stands alone.");
236
+ console.error("Arcadible: the play page's host didn't load, so the game stands alone.");
135
237
  }
136
238
  frame.src = config.src;
137
239
  document.body.prepend(frame);
138
240
  new EventSource(${scriptJson(RELOAD)}).addEventListener("reload", () => {
139
- frame.style.visibility = "hidden";
140
241
  frame.src = config.src;
141
242
  });
142
243
  </script>
@@ -149,8 +250,9 @@ const html = function (game) {
149
250
 
150
251
  // the request handler for the page's origin. `reloads` keeps the pages
151
252
  // listening for a reload; `remote` has the host; `icon()` resolves with the
152
- // game's store icon, or null.
253
+ // game's store icon, and `art()` with its loading screen's art, or null.
153
254
  const pageHandler = function ({
255
+ art = () => Promise.resolve(null),
154
256
  game,
155
257
  icon = () => Promise.resolve(null),
156
258
  onRemote = () => null,
@@ -185,6 +287,20 @@ const pageHandler = function ({
185
287
  endWith(req, res, body);
186
288
  });
187
289
  }
290
+ if (pathname === ART || pathname === ICON_PNG) {
291
+ // read for each request, so art added while serving shows on the next
292
+ // load.
293
+ return (pathname === ART ? art() : icon())
294
+ .catch(() => null)
295
+ .then((png) => {
296
+ if (!png) {
297
+ res.writeHead(404, HEADERS).end();
298
+ return;
299
+ }
300
+ res.writeHead(200, { ...HEADERS, "content-type": "image/png" });
301
+ endWith(req, res, png);
302
+ });
303
+ }
188
304
  if (pathname === "/favicon.ico") {
189
305
  return readFavicon().then((body) => {
190
306
  res.writeHead(200, { ...HEADERS, "content-type": "image/x-icon" });
@@ -19,10 +19,12 @@ const writeFile = fs.promises.writeFile;
19
19
 
20
20
  // [declare]
21
21
 
22
- // the play page's host, published with each web deploy beside the asset
23
- // site's other vendored files. Any number in /static/<n>/ is served, and each
24
- // is cached at Google's edge for a year, so a new one gets the current copy.
25
- const HOST_PATH = "/asset/arcadible/vnd/arcadible-sdk/host.min.js";
22
+ // the play page's host, as the play page runs it, published with each web
23
+ // deploy on the play site (ui2's play build). Any number in /static/<n>/ is
24
+ // served, and each is cached at Google's edge for a year, so a new one gets
25
+ // the current copy. `v1` is the shape of the `arcadibleHost` global, which
26
+ // this CLI calls: a breaking change to it is v2, beside v1.
27
+ const HOST_PATH = "/asset/host.v1.min.js";
26
28
  // the files under /arcadible/ that Arcadible serves: the SDK's, such as
27
29
  // sdk/v1.js. Anything else there isn't found, as on Arcadible.
28
30
  const SDK_PATH = /^sdk\/[\w.-]+$/u;
@@ -59,17 +61,17 @@ const keep = async function (dir, name, { body, ...meta }) {
59
61
 
60
62
  // [function]
61
63
 
62
- // the files from Arcadible. `asset` is the asset site's origin, `sdk` an
64
+ // the files from Arcadible. `host` is the play site's origin, `sdk` an
63
65
  // origin that serves /arcadible/sdk/, and `dir` where copies are kept.
64
66
  // `get(name)` resolves with `{ body, type, fetchedAt, kept }`, where `kept`
65
67
  // says the copy is from disk because Arcadible couldn't be reached, or null
66
68
  // when Arcadible has no such file; it rejects when Arcadible can't be reached
67
69
  // and there's no copy. `name` is `host`, or a path under /arcadible/.
68
- const remoteFiles = function ({ asset, dir, request = fetch, sdk }) {
70
+ const remoteFiles = function ({ dir, host, request = fetch, sdk }) {
69
71
  const session = {};
70
72
  const url = function (name) {
71
73
  if (name === "host") {
72
- return `${asset}/static/${Date.now()}${HOST_PATH}`;
74
+ return `${host}/static/${Date.now()}${HOST_PATH}`;
73
75
  }
74
76
  return SDK_PATH.test(name) ? `${sdk}/arcadible/${name}` : null;
75
77
  };
@@ -45,12 +45,14 @@ const listen = function (handler, port, address) {
45
45
  // [function]
46
46
 
47
47
  // starts serving `files` for `info`, `{ id, channel, version, title }`, on
48
- // `port`, with Arcadible's own files from `remote`, and the tab's icon from
49
- // `icon()`, which resolves with a PNG or null. With `src`, another
48
+ // `port`, with Arcadible's own files from `remote`, the tab's icon from
49
+ // `icon()`, and the loading screen's art from `art()`, which each resolve
50
+ // with a PNG or null. With `src`, another
50
51
  // server's page, it frames that instead, and serves no files. Resolves with
51
52
  // `{ page, game, reload(), close() }`: the page's origin, the game's URL,
52
53
  // and the controls.
53
54
  const serve = async function ({
55
+ art,
54
56
  files,
55
57
  icon,
56
58
  info,
@@ -69,6 +71,7 @@ const serve = async function ({
69
71
  ? gameHandler({ files, onRemote, page: origins.page, remote })
70
72
  : null;
71
73
  const forPage = pageHandler({
74
+ art,
72
75
  game: { ...info, src: framed },
73
76
  icon,
74
77
  onRemote,