dewdrop-sdk 0.5.1 → 0.5.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dewdrop-sdk",
3
- "version": "0.5.1",
3
+ "version": "0.5.2",
4
4
  "description": "Build a three.js game for Dewdrop: the Vite plugin, model calls, multiplayer, saves and voice.",
5
5
  "license": "MIT",
6
6
  "type": "module",
package/src/index.js CHANGED
@@ -5,7 +5,8 @@
5
5
  // runs, `clients`, in that backend, over its port back, and `saves` into
6
6
  // the browser's own storage, which the plugin's script empties as each
7
7
  // page loads; `session` says when a session ends ahead of time, which here
8
- // none does; and `voice` reads the microphone through the browser's own
8
+ // none does, and lets a game end its player's session, which here ends
9
+ // nothing; and `voice` reads the microphone through the browser's own
9
10
  // audio worklet, into the chunks a game gets on Dewdrop.
10
11
  export { llm } from './llm.js';
11
12
  export { backend } from './backend.js';
package/src/session.js CHANGED
@@ -1,17 +1,31 @@
1
1
  // `session` on a developer's machine. On Dewdrop a session can end ahead of
2
- // time — for maintenance, a newer version of its game published, or its
3
- // player idle for fifteen minutes — and hears of it first, up to fifteen
4
- // minutes before, a minute for an idle player: `session.ending` is
5
- // `{at, reason}`, `at` in milliseconds since the epoch as `Date.now()` counts
6
- // and `reason` `'restart'`, `'update'` or `'idle'`, and an `ending` event
7
- // fires each time it changes, its withdrawal to null included, so a game can
8
- // save and say so. `npm run dev` ends no session ahead of time, so here `ending`
9
- // stays null and the event never fires; a game tries its handler by calling
10
- // it.
11
- import { defineHandlers } from './net.js';
2
+ // time — for maintenance, a newer version of its game published, its player
3
+ // idle for fifteen minutes, its player away for ten — the page hidden, or
4
+ // another game of theirs showing — or its player choosing to play in
5
+ // another tab — and hears of it first, up to fifteen minutes before, a
6
+ // minute for an idle or an away player, and as it ends for a player playing
7
+ // elsewhere: `session.ending` is `{at, reason}`, `at` in milliseconds since
8
+ // the epoch as `Date.now()` counts and `reason` `'restart'`, `'update'`,
9
+ // `'idle'`, `'away'`, `'elsewhere'` or `'exit'`, and an `ending` event fires
10
+ // each time it changes, its withdrawal to null included, so a game can save
11
+ // and say so. A game ends its player's session itself with
12
+ // `session.exit()`, which on Dewdrop takes the player back to Dewdrop's
13
+ // home page while the room's other players play on, the game hearing
14
+ // `'exit'` as it goes; a backend has no player to send anywhere, so there it
15
+ // throws NotSupportedError. `npm run dev` ends no session, so here `ending`
16
+ // stays null and the event never fires, a game trying its handler by
17
+ // calling it, and `exit()` ends nothing: the console says so, once.
18
+ import { defineHandlers, side } from './net.js';
12
19
 
20
+ let told = false;
13
21
  class Session extends EventTarget {
14
22
  get ending() { return null; }
23
+ exit() {
24
+ if (side.backend) throw new DOMException('session.exit is unavailable in a backend', 'NotSupportedError');
25
+ if (told) return;
26
+ told = true;
27
+ console.info('[dewdrop] session.exit(): on Dewdrop this ends the session and takes the player back to Dewdrop’s home page; npm run dev keeps the game running');
28
+ }
15
29
  }
16
30
  defineHandlers(Session.prototype, ['ending']);
17
31