@zaisma/game-server 1.46.0 → 1.48.0

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.
@@ -2,7 +2,7 @@
2
2
  // (bench/glass.ts) and one frame, the player's page, which is zaisma.com's game page with its own scripts. These never reach into it.
3
3
 
4
4
  /** What the dev page's frame lets the player's page pass on to the game: the game page's own list (apps/site/src/pages.ts; test/node/local-play-parity.test.ts holds the two together). */
5
- export const FRAME_ALLOW = "fullscreen; gamepad; autoplay; web-share; clipboard-write; cross-origin-isolated; compute-pressure";
5
+ export const FRAME_ALLOW = "fullscreen; gamepad; autoplay; web-share; clipboard-write; cross-origin-isolated; compute-pressure; microphone";
6
6
 
7
7
  /** The dev page's script: it keeps the player's place, reloads the game when a file changes, runs the dev bar's menus and the Players panel. */
8
8
  export const devScriptSource = () => `(${devScript.toString()})();\n`;
package/bin/local-play.js CHANGED
@@ -129,7 +129,7 @@ export function localGameHeaders(contentType, benchOrigin, connectOrigins) {
129
129
  "object-src 'none'",
130
130
  `frame-ancestors ${benchOrigin}`,
131
131
  ].join("; "),
132
- "Permissions-Policy": "camera=(), microphone=(), geolocation=(), payment=(), usb=(), serial=(), bluetooth=(), hid=(), display-capture=(), fullscreen=(self), gamepad=(self), autoplay=(self)",
132
+ "Permissions-Policy": "camera=(), microphone=(self), geolocation=(), payment=(), usb=(), serial=(), bluetooth=(), hid=(), display-capture=(), fullscreen=(self), gamepad=(self), autoplay=(self)",
133
133
  "X-Content-Type-Options": "nosniff",
134
134
  "Referrer-Policy": "no-referrer",
135
135
  "Cross-Origin-Opener-Policy": "same-origin",
@@ -379,7 +379,7 @@ export async function startLocalPlay(givenOptions) {
379
379
  const claims = account
380
380
  ? {
381
381
  sub: account.playerId, aud: gameSlug, iss: issuerUrl, pass_version_number: PASS_VERSION_NUMBER, kind: "account",
382
- who_can_chat: chat.whoReadsMyChat === "friends" ? "friends" : "anyone", who_reads_my_chat: chat.whoReadsMyChat, chat_reading_enabled: true,
382
+ who_can_chat: chat.whoReadsMyChat === "friends" ? "friends" : "anyone", who_reads_my_chat: chat.whoReadsMyChat, chat_reading_enabled: true, who_hears_my_voice: chat.whoReadsMyChat, voice_hearing_enabled: true,
383
383
  chat_group_id: `chat_group_${createHash("sha256").update(`local:${gameSlug}:${chat.bandGroup}`).digest("hex").slice(0, 24)}`,
384
384
  player_tag_id: account.playerTagId, friend_player_tag_ids: tagsOf(friendIdsOf(account.id)), block_player_tag_ids: tagsOf(blockIdsOf(account.id)),
385
385
  owned_item_names: ownedNamesOf(account.id), iat: nowSec, exp: nowSec + PASS_DURATION_SEC,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zaisma/game-server",
3
- "version": "1.46.0",
3
+ "version": "1.48.0",
4
4
  "description": "Run your Zaisma game server: the same rooms on Zaisma or on your own server.",
5
5
  "license": "MIT",
6
6
  "homepage": "https://zaisma.com",
package/sdk/zaisma.d.ts CHANGED
@@ -1127,6 +1127,24 @@ declare namespace Zaisma {
1127
1127
  * nobody, playing (not watching). False for guests: hide your chat box, and offer preset phrases or emotes.
1128
1128
  */
1129
1129
  readonly canChat: boolean;
1130
+ /**
1131
+ * Whether this player can talk in voice ({@link Room.voice}): a Zaisma account whose voice setting reaches someone,
1132
+ * playing (not watching). A player who can't talk can still join voice to listen.
1133
+ */
1134
+ readonly canTalk: boolean;
1135
+ /**
1136
+ * Voice in this room: your game holds the microphone, and Zaisma's room decides whose voices reach this player, by
1137
+ * chat's rules (who each player lets hear them, blocks, mutes, and anyone under 18 only where two independent
1138
+ * players hear them too), plus your server's teams and ranges (room.setVoiceGroup, setHeardSpeakers). It goes
1139
+ * through Cloudflare's media server, so nobody sees anyone's address, and it's on your game's meter as voice.
1140
+ * Each player hears up to 16 voices at once (your server can set 1 to 32), the loudest past that.
1141
+ * @example
1142
+ * await room.voice.join();
1143
+ * room.on("speaking", ({ playerId, isSpeaking }) => showMicIcon(playerId, isSpeaking));
1144
+ * // Proximity voice: fade and place each voice by distance.
1145
+ * for (const other of room.players) room.voice.setSpeakerVolume(other.id, volumeByDistance(other));
1146
+ */
1147
+ readonly voice: RoomVoice;
1130
1148
  /**
1131
1149
  * When Zaisma will end this match, an ISO time, or null: set once the game's hosting pauses for the
1132
1150
  * month, an hour after the pause (the "ending" event); null again if Zaisma calls the end off (the
@@ -1420,6 +1438,67 @@ declare namespace Zaisma {
1420
1438
  * them if your game doesn't. (Optional here only so games written for v1's events still fit.)
1421
1439
  */
1422
1440
  chat?: (chatMessage: ChatMessage) => void;
1441
+ /** A voice started or stopped speaking, this player's own included, from its level on this device ({@link Room.voice}). */
1442
+ speaking?: (speaking: Speaking) => void;
1443
+ /** The voices this player hears changed: who's in {@link RoomVoice.speakerPlayerIds} now. */
1444
+ voiceSpeakers?: (voiceSpeakers: { playerIds: string[] }) => void;
1445
+ }
1446
+
1447
+ /** The "speaking" event's answer. */
1448
+ interface Speaking {
1449
+ playerId: string;
1450
+ isSpeaking: boolean;
1451
+ }
1452
+
1453
+ /** What {@link RoomVoice.join} takes. */
1454
+ interface VoiceOptions {
1455
+ /** Join with the microphone muted (push-to-talk starts here). */
1456
+ isMuted?: boolean;
1457
+ /**
1458
+ * For a room on your own server: a voice ticket your server signed (voiceTicket in @zaisma/game-server, with the
1459
+ * game's ticket secret from create_ticket_secret), naming the voice channel and this player's team and range. Rooms
1460
+ * on Zaisma need none.
1461
+ */
1462
+ ticket?: string;
1463
+ }
1464
+
1465
+ /** A room's voice: {@link Room.voice}. */
1466
+ interface RoomVoice {
1467
+ /**
1468
+ * Join the room's voice: asks for the microphone when the player can talk ({@link Room.canTalk}), else joins to
1469
+ * listen. Resolves once connected; rejects with microphone_refused (the player or browser said no), voice_not_allowed
1470
+ * (a guest or a spectator), voice_unavailable or hosting_paused. Call it from a tap or key press: browsers play
1471
+ * sound only after one.
1472
+ */
1473
+ join(voiceOptions?: VoiceOptions): Promise<void>;
1474
+ /** Leave voice: the microphone stops and nobody's voice comes. Leaving the room does it too. */
1475
+ leave(): void;
1476
+ /** On your own server: new rules for this player (a team switch, a range), as a new ticket from your server for the same channel. */
1477
+ updateTicket(ticket: string): void;
1478
+ /** Mute or unmute this player's microphone, for push-to-talk or a mute button. Muted, it sends almost nothing. */
1479
+ setMicrophoneMuted(isMuted: boolean): void;
1480
+ /** A voice's volume here, 0 to 100 (100 unless you set it), for proximity voice or a volume slider. At 0 it isn't sent at all. */
1481
+ setSpeakerVolume(playerId: string, volumePct: number): void;
1482
+ /** Where a voice sits left to right, -100 (left) to 100 (right), 0 unless you set it. */
1483
+ setSpeakerPan(playerId: string, panPct: number): void;
1484
+ /**
1485
+ * A voice's sound after its volume, for your own effects (a radio's crackle, a muffled wall): disconnect it and
1486
+ * connect it through your own nodes to {@link RoomVoice.outputNode}. Null while that voice isn't heard.
1487
+ */
1488
+ audioNodeOf(playerId: string): AudioNode | null;
1489
+ /** The Web Audio context voices play through, or null before joining. */
1490
+ readonly audioContext: AudioContext | null;
1491
+ /**
1492
+ * Where voices go to the speakers, in {@link RoomVoice.audioContext}, or null before joining. Echo cancellation
1493
+ * hears what plays through it, so the microphone doesn't send it back: connect your effects here, not to the
1494
+ * context's destination, and your game's own sound too, made in this context, while players talk on speakers.
1495
+ */
1496
+ readonly outputNode: AudioNode | null;
1497
+ /** The players whose voices reach this player now (the "voiceSpeakers" event says when it changes). */
1498
+ readonly speakerPlayerIds: readonly string[];
1499
+ readonly isJoined: boolean;
1500
+ /** Whether this player can talk, as {@link Room.canTalk}. */
1501
+ readonly canTalk: boolean;
1423
1502
  }
1424
1503
 
1425
1504
  /** What {@link Room.chat} takes. */
@@ -1704,6 +1783,7 @@ declare namespace Zaisma {
1704
1783
  * - spectator_cannot_send: a spectator tried to send to the room ({@link Room.send}, {@link Room.sendBytes}).
1705
1784
  * - send_queue_full: the SDK's own: more than 60 reliable sends waited while the room wasn't reachable, so the oldest were dropped. Send less while connectionStatus isn't open, or use latest_only for updates that replace each other.
1706
1785
  * - chat_not_allowed, chat_empty, chat_too_long, chat_too_fast: {@link Room.chat} refused (they reject its promise, not the "error" event); chat_not_here: the room's server doesn't take chat.
1786
+ * - microphone_refused, voice_not_allowed, voice_unavailable: {@link RoomVoice.join} refused (they reject its promise); after joining, the "error" event says when voice stopped. voice_not_here: the room's server doesn't take voice. voice_ticket_required, voice_ticket_refused: on your own server, join needs a ticket your server signed, for this player and game, not expired.
1707
1787
  *
1708
1788
  * More codes may come within v1: handle one you don't know like an error you can show (its message).
1709
1789
  *
@@ -1740,7 +1820,13 @@ declare namespace Zaisma {
1740
1820
  | "chat_not_allowed"
1741
1821
  | "chat_empty"
1742
1822
  | "chat_too_long"
1743
- | "chat_too_fast";
1823
+ | "chat_too_fast"
1824
+ | "voice_not_here"
1825
+ | "microphone_refused"
1826
+ | "voice_not_allowed"
1827
+ | "voice_unavailable"
1828
+ | "voice_ticket_required"
1829
+ | "voice_ticket_refused";
1744
1830
 
1745
1831
  /**
1746
1832
  * The codes a request's errors have ({@link Server.request}), from Zaisma or the Node runner alike: