@air-jam/sdk 0.1.1 → 0.1.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/dist/{chunk-7M5D3Y3L.js → chunk-B5DURUWT.js} +11 -3
- package/dist/chunk-B5DURUWT.js.map +1 -0
- package/dist/index.cjs +226 -127
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +19 -27
- package/dist/index.d.ts +19 -27
- package/dist/index.js +218 -129
- package/dist/index.js.map +1 -1
- package/dist/protocol.cjs +10 -0
- package/dist/protocol.cjs.map +1 -1
- package/dist/protocol.d.cts +19 -1
- package/dist/protocol.d.ts +19 -1
- package/dist/protocol.js +1 -1
- package/package.json +4 -1
- package/src/AirJamClient.ts +1 -552
- package/src/audio/audio-manager.ts +12 -1
- package/src/audio/volume-store.ts +47 -0
- package/src/components/air-jam-overlay.tsx +1 -1
- package/src/components/controller-shell.tsx +170 -171
- package/src/components/qr-scanner-dialog.tsx +2 -2
- package/src/constants.ts +3 -2
- package/src/context/air-jam-context.tsx +3 -14
- package/src/hooks/use-air-jam-controller.ts +1 -1
- package/src/hooks/use-air-jam-host.ts +94 -49
- package/src/hooks/use-air-jam-shell.ts +36 -0
- package/src/internal/input-manager.ts +28 -14
- package/src/protocol.ts +28 -0
- package/src/store/create-air-jam-store.ts +69 -7
- package/src/utils/url-builder.ts +3 -3
- package/dist/chunk-7M5D3Y3L.js.map +0 -1
package/src/AirJamClient.ts
CHANGED
|
@@ -30,7 +30,6 @@ export class AirJamClient {
|
|
|
30
30
|
public readonly role: ConnectionRole;
|
|
31
31
|
private readonly _inputBuffer: Map<string, ControllerInputPayload> =
|
|
32
32
|
new Map();
|
|
33
|
-
private _listenerRegisteredAt?: number;
|
|
34
33
|
public readonly _clientInstanceId: string;
|
|
35
34
|
|
|
36
35
|
constructor(options: AirJamClientOptions) {
|
|
@@ -64,106 +63,12 @@ export class AirJamClient {
|
|
|
64
63
|
this.socket.off("server:controllerLeft");
|
|
65
64
|
this.socket.off("server:input");
|
|
66
65
|
|
|
67
|
-
// #region agent log
|
|
68
|
-
fetch("http://127.0.0.1:7245/ingest/77275639-c0f5-41c0-a729-c2568f3ab68e", {
|
|
69
|
-
method: "POST",
|
|
70
|
-
headers: { "Content-Type": "application/json" },
|
|
71
|
-
body: JSON.stringify({
|
|
72
|
-
location: "AirJamClient.ts:56",
|
|
73
|
-
message: "setupHostListeners called - re-registering host listeners",
|
|
74
|
-
data: {
|
|
75
|
-
role: this.role,
|
|
76
|
-
socketId: this.socket.id,
|
|
77
|
-
socketConnected: this.socket.connected,
|
|
78
|
-
clientInstanceId: this._clientInstanceId,
|
|
79
|
-
},
|
|
80
|
-
timestamp: Date.now(),
|
|
81
|
-
sessionId: "debug-session",
|
|
82
|
-
runId: "run1",
|
|
83
|
-
hypothesisId: "HOST_LISTENERS_SETUP",
|
|
84
|
-
}),
|
|
85
|
-
}).catch(() => {});
|
|
86
|
-
// #endregion
|
|
87
|
-
|
|
88
66
|
this.socket.on(
|
|
89
67
|
"server:controllerJoined",
|
|
90
68
|
(payload: ControllerJoinedNotice) => {
|
|
91
|
-
// #region agent log
|
|
92
|
-
const logData = {
|
|
93
|
-
location: "AirJamClient.ts:62",
|
|
94
|
-
message: "CLIENT: server:controllerJoined event received",
|
|
95
|
-
data: {
|
|
96
|
-
role: this.role,
|
|
97
|
-
socketId: this.socket.id,
|
|
98
|
-
socketConnected: this.socket.connected,
|
|
99
|
-
payload: JSON.stringify(payload),
|
|
100
|
-
hasPlayer: !!payload.player,
|
|
101
|
-
clientInstanceId: this._clientInstanceId,
|
|
102
|
-
},
|
|
103
|
-
timestamp: Date.now(),
|
|
104
|
-
sessionId: "debug-session",
|
|
105
|
-
runId: "run1",
|
|
106
|
-
hypothesisId: "CLIENT_CONTROLLER_JOINED",
|
|
107
|
-
};
|
|
108
|
-
console.log(`[DEBUG] ${logData.message}`, logData.data);
|
|
109
|
-
fetch(
|
|
110
|
-
"http://127.0.0.1:7245/ingest/77275639-c0f5-41c0-a729-c2568f3ab68e",
|
|
111
|
-
{
|
|
112
|
-
method: "POST",
|
|
113
|
-
headers: { "Content-Type": "application/json" },
|
|
114
|
-
body: JSON.stringify(logData),
|
|
115
|
-
},
|
|
116
|
-
).catch(() => {});
|
|
117
|
-
// #endregion
|
|
118
69
|
console.log(`[AirJamClient] server:controllerJoined`, payload);
|
|
119
70
|
if (payload.player) {
|
|
120
|
-
// #region agent log
|
|
121
|
-
fetch(
|
|
122
|
-
"http://127.0.0.1:7245/ingest/77275639-c0f5-41c0-a729-c2568f3ab68e",
|
|
123
|
-
{
|
|
124
|
-
method: "POST",
|
|
125
|
-
headers: { "Content-Type": "application/json" },
|
|
126
|
-
body: JSON.stringify({
|
|
127
|
-
location: "AirJamClient.ts:70",
|
|
128
|
-
message: "CLIENT: calling store.upsertPlayer",
|
|
129
|
-
data: {
|
|
130
|
-
playerId: payload.player.id,
|
|
131
|
-
playerLabel: payload.player.label,
|
|
132
|
-
currentPlayersCount: this.store.getState().players.length,
|
|
133
|
-
clientInstanceId: this._clientInstanceId,
|
|
134
|
-
},
|
|
135
|
-
timestamp: Date.now(),
|
|
136
|
-
sessionId: "debug-session",
|
|
137
|
-
runId: "run1",
|
|
138
|
-
hypothesisId: "CLIENT_CONTROLLER_JOINED",
|
|
139
|
-
}),
|
|
140
|
-
},
|
|
141
|
-
).catch(() => {});
|
|
142
|
-
// #endregion
|
|
143
71
|
this.store.getState().upsertPlayer(payload.player);
|
|
144
|
-
// #region agent log
|
|
145
|
-
const newPlayersCount = this.store.getState().players.length;
|
|
146
|
-
fetch(
|
|
147
|
-
"http://127.0.0.1:7245/ingest/77275639-c0f5-41c0-a729-c2568f3ab68e",
|
|
148
|
-
{
|
|
149
|
-
method: "POST",
|
|
150
|
-
headers: { "Content-Type": "application/json" },
|
|
151
|
-
body: JSON.stringify({
|
|
152
|
-
location: "AirJamClient.ts:75",
|
|
153
|
-
message: "CLIENT: store.upsertPlayer completed",
|
|
154
|
-
data: {
|
|
155
|
-
playerId: payload.player.id,
|
|
156
|
-
newPlayersCount,
|
|
157
|
-
clientInstanceId: this._clientInstanceId,
|
|
158
|
-
},
|
|
159
|
-
timestamp: Date.now(),
|
|
160
|
-
sessionId: "debug-session",
|
|
161
|
-
runId: "run1",
|
|
162
|
-
hypothesisId: "CLIENT_CONTROLLER_JOINED",
|
|
163
|
-
}),
|
|
164
|
-
},
|
|
165
|
-
).catch(() => {});
|
|
166
|
-
// #endregion
|
|
167
72
|
}
|
|
168
73
|
},
|
|
169
74
|
);
|
|
@@ -182,310 +87,35 @@ export class AirJamClient {
|
|
|
182
87
|
// Remove existing listener to avoid duplicates
|
|
183
88
|
this.socket.off("server:state");
|
|
184
89
|
|
|
185
|
-
// #region agent log
|
|
186
|
-
fetch("http://127.0.0.1:7245/ingest/77275639-c0f5-41c0-a729-c2568f3ab68e", {
|
|
187
|
-
method: "POST",
|
|
188
|
-
headers: { "Content-Type": "application/json" },
|
|
189
|
-
body: JSON.stringify({
|
|
190
|
-
location: "AirJamClient.ts:59",
|
|
191
|
-
message: "setupServerStateListener called",
|
|
192
|
-
data: {
|
|
193
|
-
role: this.role,
|
|
194
|
-
socketId: this.socket.id,
|
|
195
|
-
socketConnected: this.socket.connected,
|
|
196
|
-
clientInstanceId: this._clientInstanceId,
|
|
197
|
-
},
|
|
198
|
-
timestamp: Date.now(),
|
|
199
|
-
sessionId: "debug-session",
|
|
200
|
-
runId: "run1",
|
|
201
|
-
hypothesisId: "I",
|
|
202
|
-
}),
|
|
203
|
-
}).catch(() => {});
|
|
204
|
-
// #endregion
|
|
205
|
-
|
|
206
90
|
const serverStateHandler = (payload: {
|
|
207
91
|
state: { gameState?: GameState; message?: string };
|
|
208
92
|
}) => {
|
|
209
|
-
// #region agent log
|
|
210
|
-
fetch(
|
|
211
|
-
"http://127.0.0.1:7245/ingest/77275639-c0f5-41c0-a729-c2568f3ab68e",
|
|
212
|
-
{
|
|
213
|
-
method: "POST",
|
|
214
|
-
headers: { "Content-Type": "application/json" },
|
|
215
|
-
body: JSON.stringify({
|
|
216
|
-
location: "AirJamClient.ts:64",
|
|
217
|
-
message: "CLIENT: server:state event received in handler",
|
|
218
|
-
data: {
|
|
219
|
-
role: this.role,
|
|
220
|
-
gameState: payload.state.gameState,
|
|
221
|
-
message: payload.state.message,
|
|
222
|
-
fullPayload: JSON.stringify(payload),
|
|
223
|
-
socketId: this.socket.id,
|
|
224
|
-
socketConnected: this.socket.connected,
|
|
225
|
-
listenerRegisteredAt: this._listenerRegisteredAt,
|
|
226
|
-
clientInstanceId: this._clientInstanceId,
|
|
227
|
-
},
|
|
228
|
-
timestamp: Date.now(),
|
|
229
|
-
sessionId: "debug-session",
|
|
230
|
-
runId: "run1",
|
|
231
|
-
hypothesisId: "CLIENT_RECEIVE",
|
|
232
|
-
}),
|
|
233
|
-
},
|
|
234
|
-
).catch(() => {});
|
|
235
|
-
// #endregion
|
|
236
93
|
const store = this.store.getState();
|
|
237
|
-
// #region agent log
|
|
238
|
-
fetch(
|
|
239
|
-
"http://127.0.0.1:7245/ingest/77275639-c0f5-41c0-a729-c2568f3ab68e",
|
|
240
|
-
{
|
|
241
|
-
method: "POST",
|
|
242
|
-
headers: { "Content-Type": "application/json" },
|
|
243
|
-
body: JSON.stringify({
|
|
244
|
-
location: "AirJamClient.ts:75",
|
|
245
|
-
message: "checking gameState in payload",
|
|
246
|
-
data: {
|
|
247
|
-
hasGameState: !!payload.state.gameState,
|
|
248
|
-
gameStateValue: payload.state.gameState,
|
|
249
|
-
currentStoreState: store.gameState,
|
|
250
|
-
},
|
|
251
|
-
timestamp: Date.now(),
|
|
252
|
-
sessionId: "debug-session",
|
|
253
|
-
runId: "run1",
|
|
254
|
-
hypothesisId: "B",
|
|
255
|
-
}),
|
|
256
|
-
},
|
|
257
|
-
).catch(() => {});
|
|
258
|
-
// #endregion
|
|
259
94
|
if (payload.state.gameState) {
|
|
260
|
-
// #region agent log
|
|
261
|
-
fetch(
|
|
262
|
-
"http://127.0.0.1:7245/ingest/77275639-c0f5-41c0-a729-c2568f3ab68e",
|
|
263
|
-
{
|
|
264
|
-
method: "POST",
|
|
265
|
-
headers: { "Content-Type": "application/json" },
|
|
266
|
-
body: JSON.stringify({
|
|
267
|
-
location: "AirJamClient.ts:77",
|
|
268
|
-
message: "calling store.setGameState",
|
|
269
|
-
data: {
|
|
270
|
-
newGameState: payload.state.gameState,
|
|
271
|
-
currentGameState: store.gameState,
|
|
272
|
-
},
|
|
273
|
-
timestamp: Date.now(),
|
|
274
|
-
sessionId: "debug-session",
|
|
275
|
-
runId: "run1",
|
|
276
|
-
hypothesisId: "B",
|
|
277
|
-
}),
|
|
278
|
-
},
|
|
279
|
-
).catch(() => {});
|
|
280
|
-
// #endregion
|
|
281
95
|
store.setGameState(payload.state.gameState);
|
|
282
96
|
}
|
|
283
97
|
if (payload.state.message !== undefined) {
|
|
284
98
|
store.setStateMessage(payload.state.message);
|
|
285
99
|
}
|
|
286
100
|
};
|
|
287
|
-
// #region agent log
|
|
288
|
-
this._listenerRegisteredAt = Date.now();
|
|
289
|
-
fetch("http://127.0.0.1:7245/ingest/77275639-c0f5-41c0-a729-c2568f3ab68e", {
|
|
290
|
-
method: "POST",
|
|
291
|
-
headers: { "Content-Type": "application/json" },
|
|
292
|
-
body: JSON.stringify({
|
|
293
|
-
location: "AirJamClient.ts:91",
|
|
294
|
-
message: "registering server:state listener",
|
|
295
|
-
data: {
|
|
296
|
-
role: this.role,
|
|
297
|
-
socketId: this.socket.id,
|
|
298
|
-
socketConnected: this.socket.connected,
|
|
299
|
-
clientInstanceId: this._clientInstanceId,
|
|
300
|
-
listenerRegisteredAt: this._listenerRegisteredAt,
|
|
301
|
-
},
|
|
302
|
-
timestamp: Date.now(),
|
|
303
|
-
sessionId: "debug-session",
|
|
304
|
-
runId: "run1",
|
|
305
|
-
hypothesisId: "H",
|
|
306
|
-
}),
|
|
307
|
-
}).catch(() => {});
|
|
308
|
-
// #endregion
|
|
309
|
-
// Wrap the handler to log when it's actually attached
|
|
310
|
-
const wrappedHandler = (payload: {
|
|
311
|
-
state: { gameState?: GameState; message?: string };
|
|
312
|
-
}) => {
|
|
313
|
-
// #region agent log
|
|
314
|
-
fetch(
|
|
315
|
-
"http://127.0.0.1:7245/ingest/77275639-c0f5-41c0-a729-c2568f3ab68e",
|
|
316
|
-
{
|
|
317
|
-
method: "POST",
|
|
318
|
-
headers: { "Content-Type": "application/json" },
|
|
319
|
-
body: JSON.stringify({
|
|
320
|
-
location: "AirJamClient.ts:86",
|
|
321
|
-
message: "WRAPPED_HANDLER: server:state handler invoked",
|
|
322
|
-
data: {
|
|
323
|
-
role: this.role,
|
|
324
|
-
socketId: this.socket.id,
|
|
325
|
-
socketConnected: this.socket.connected,
|
|
326
|
-
clientInstanceId: this._clientInstanceId,
|
|
327
|
-
payload: JSON.stringify(payload),
|
|
328
|
-
},
|
|
329
|
-
timestamp: Date.now(),
|
|
330
|
-
sessionId: "debug-session",
|
|
331
|
-
runId: "run1",
|
|
332
|
-
hypothesisId: "WRAPPED",
|
|
333
|
-
}),
|
|
334
|
-
},
|
|
335
|
-
).catch(() => {});
|
|
336
|
-
// #endregion
|
|
337
|
-
serverStateHandler(payload);
|
|
338
|
-
};
|
|
339
101
|
|
|
340
|
-
this.socket.on("server:state",
|
|
341
|
-
// #region agent log
|
|
342
|
-
const listenerCount = this.socket.listeners("server:state").length;
|
|
343
|
-
fetch("http://127.0.0.1:7245/ingest/77275639-c0f5-41c0-a729-c2568f3ab68e", {
|
|
344
|
-
method: "POST",
|
|
345
|
-
headers: { "Content-Type": "application/json" },
|
|
346
|
-
body: JSON.stringify({
|
|
347
|
-
location: "AirJamClient.ts:95",
|
|
348
|
-
message: "server:state listener registered - checking socket listeners",
|
|
349
|
-
data: {
|
|
350
|
-
role: this.role,
|
|
351
|
-
socketId: this.socket.id,
|
|
352
|
-
socketConnected: this.socket.connected,
|
|
353
|
-
clientInstanceId: this._clientInstanceId,
|
|
354
|
-
hasListeners: listenerCount > 0,
|
|
355
|
-
listenerCount,
|
|
356
|
-
},
|
|
357
|
-
timestamp: Date.now(),
|
|
358
|
-
sessionId: "debug-session",
|
|
359
|
-
runId: "run1",
|
|
360
|
-
hypothesisId: "H",
|
|
361
|
-
}),
|
|
362
|
-
}).catch(() => {});
|
|
363
|
-
// #endregion
|
|
102
|
+
this.socket.on("server:state", serverStateHandler);
|
|
364
103
|
}
|
|
365
104
|
|
|
366
105
|
private setupListeners() {
|
|
367
|
-
// #region agent log
|
|
368
|
-
fetch("http://127.0.0.1:7245/ingest/77275639-c0f5-41c0-a729-c2568f3ab68e", {
|
|
369
|
-
method: "POST",
|
|
370
|
-
headers: { "Content-Type": "application/json" },
|
|
371
|
-
body: JSON.stringify({
|
|
372
|
-
location: "AirJamClient.ts:89",
|
|
373
|
-
message: "setupListeners called",
|
|
374
|
-
data: {
|
|
375
|
-
role: this.role,
|
|
376
|
-
socketId: this.socket.id,
|
|
377
|
-
socketConnected: this.socket.connected,
|
|
378
|
-
clientInstanceId: this._clientInstanceId,
|
|
379
|
-
},
|
|
380
|
-
timestamp: Date.now(),
|
|
381
|
-
sessionId: "debug-session",
|
|
382
|
-
runId: "run1",
|
|
383
|
-
hypothesisId: "SETUP",
|
|
384
|
-
}),
|
|
385
|
-
}).catch(() => {});
|
|
386
|
-
// #endregion
|
|
387
106
|
// Handle connect event
|
|
388
107
|
const onConnect = () => {
|
|
389
|
-
// #region agent log
|
|
390
|
-
fetch(
|
|
391
|
-
"http://127.0.0.1:7245/ingest/77275639-c0f5-41c0-a729-c2568f3ab68e",
|
|
392
|
-
{
|
|
393
|
-
method: "POST",
|
|
394
|
-
headers: { "Content-Type": "application/json" },
|
|
395
|
-
body: JSON.stringify({
|
|
396
|
-
location: "AirJamClient.ts:92",
|
|
397
|
-
message: "socket connected - onConnect handler fired",
|
|
398
|
-
data: {
|
|
399
|
-
role: this.role,
|
|
400
|
-
socketId: this.socket.id,
|
|
401
|
-
clientInstanceId: this._clientInstanceId,
|
|
402
|
-
listenerRegisteredAt: this._listenerRegisteredAt,
|
|
403
|
-
},
|
|
404
|
-
timestamp: Date.now(),
|
|
405
|
-
sessionId: "debug-session",
|
|
406
|
-
runId: "run1",
|
|
407
|
-
hypothesisId: "G",
|
|
408
|
-
}),
|
|
409
|
-
},
|
|
410
|
-
).catch(() => {});
|
|
411
|
-
// #endregion
|
|
412
108
|
this.store.getState().setStatus("connected");
|
|
413
109
|
this.store.getState().setError(undefined);
|
|
414
110
|
// Re-register all listeners after connection to ensure they're active
|
|
415
111
|
// This fixes the issue where listeners registered before socket connects don't work
|
|
416
|
-
// #region agent log
|
|
417
|
-
fetch(
|
|
418
|
-
"http://127.0.0.1:7245/ingest/77275639-c0f5-41c0-a729-c2568f3ab68e",
|
|
419
|
-
{
|
|
420
|
-
method: "POST",
|
|
421
|
-
headers: { "Content-Type": "application/json" },
|
|
422
|
-
body: JSON.stringify({
|
|
423
|
-
location: "AirJamClient.ts:98",
|
|
424
|
-
message: "about to re-register all listeners in onConnect",
|
|
425
|
-
data: {
|
|
426
|
-
role: this.role,
|
|
427
|
-
socketId: this.socket.id,
|
|
428
|
-
socketConnected: this.socket.connected,
|
|
429
|
-
clientInstanceId: this._clientInstanceId,
|
|
430
|
-
},
|
|
431
|
-
timestamp: Date.now(),
|
|
432
|
-
sessionId: "debug-session",
|
|
433
|
-
runId: "run1",
|
|
434
|
-
hypothesisId: "G",
|
|
435
|
-
}),
|
|
436
|
-
},
|
|
437
|
-
).catch(() => {});
|
|
438
|
-
// #endregion
|
|
439
112
|
this.setupServerStateListener();
|
|
440
113
|
this.setupHostListeners();
|
|
441
114
|
};
|
|
442
|
-
// #region agent log
|
|
443
|
-
fetch("http://127.0.0.1:7245/ingest/77275639-c0f5-41c0-a729-c2568f3ab68e", {
|
|
444
|
-
method: "POST",
|
|
445
|
-
headers: { "Content-Type": "application/json" },
|
|
446
|
-
body: JSON.stringify({
|
|
447
|
-
location: "AirJamClient.ts:100",
|
|
448
|
-
message: "registering connect event listener",
|
|
449
|
-
data: {
|
|
450
|
-
role: this.role,
|
|
451
|
-
socketId: this.socket.id,
|
|
452
|
-
socketConnected: this.socket.connected,
|
|
453
|
-
clientInstanceId: this._clientInstanceId,
|
|
454
|
-
},
|
|
455
|
-
timestamp: Date.now(),
|
|
456
|
-
sessionId: "debug-session",
|
|
457
|
-
runId: "run1",
|
|
458
|
-
hypothesisId: "SETUP",
|
|
459
|
-
}),
|
|
460
|
-
}).catch(() => {});
|
|
461
|
-
// #endregion
|
|
462
115
|
this.socket.on("connect", onConnect);
|
|
463
116
|
|
|
464
117
|
// If socket is already connected, call handler immediately
|
|
465
118
|
if (this.socket.connected) {
|
|
466
|
-
// #region agent log
|
|
467
|
-
fetch(
|
|
468
|
-
"http://127.0.0.1:7245/ingest/77275639-c0f5-41c0-a729-c2568f3ab68e",
|
|
469
|
-
{
|
|
470
|
-
method: "POST",
|
|
471
|
-
headers: { "Content-Type": "application/json" },
|
|
472
|
-
body: JSON.stringify({
|
|
473
|
-
location: "AirJamClient.ts:103",
|
|
474
|
-
message:
|
|
475
|
-
"socket already connected when listener registered - calling onConnect immediately",
|
|
476
|
-
data: {
|
|
477
|
-
role: this.role,
|
|
478
|
-
socketId: this.socket.id,
|
|
479
|
-
clientInstanceId: this._clientInstanceId,
|
|
480
|
-
},
|
|
481
|
-
timestamp: Date.now(),
|
|
482
|
-
sessionId: "debug-session",
|
|
483
|
-
runId: "run1",
|
|
484
|
-
hypothesisId: "J",
|
|
485
|
-
}),
|
|
486
|
-
},
|
|
487
|
-
).catch(() => {});
|
|
488
|
-
// #endregion
|
|
489
119
|
onConnect();
|
|
490
120
|
}
|
|
491
121
|
|
|
@@ -527,159 +157,23 @@ export class AirJamClient {
|
|
|
527
157
|
* Connect to the Air Jam server.
|
|
528
158
|
*/
|
|
529
159
|
public connect() {
|
|
530
|
-
// #region agent log
|
|
531
|
-
fetch("http://127.0.0.1:7245/ingest/77275639-c0f5-41c0-a729-c2568f3ab68e", {
|
|
532
|
-
method: "POST",
|
|
533
|
-
headers: { "Content-Type": "application/json" },
|
|
534
|
-
body: JSON.stringify({
|
|
535
|
-
location: "AirJamClient.ts:177",
|
|
536
|
-
message: "connect() method called",
|
|
537
|
-
data: {
|
|
538
|
-
role: this.role,
|
|
539
|
-
socketId: this.socket.id,
|
|
540
|
-
socketConnected: this.socket.connected,
|
|
541
|
-
clientInstanceId: this._clientInstanceId,
|
|
542
|
-
},
|
|
543
|
-
timestamp: Date.now(),
|
|
544
|
-
sessionId: "debug-session",
|
|
545
|
-
runId: "run1",
|
|
546
|
-
hypothesisId: "CONNECT_METHOD",
|
|
547
|
-
}),
|
|
548
|
-
}).catch(() => {});
|
|
549
|
-
// #endregion
|
|
550
|
-
|
|
551
160
|
// CRITICAL FIX: Check if listeners were removed by destroy() and re-register them
|
|
552
161
|
// This handles React Strict Mode which calls destroy() then connect() on the same client
|
|
553
162
|
const hasConnectListener = this.socket.listeners("connect").length > 0;
|
|
554
163
|
if (!hasConnectListener) {
|
|
555
|
-
// #region agent log
|
|
556
|
-
fetch(
|
|
557
|
-
"http://127.0.0.1:7245/ingest/77275639-c0f5-41c0-a729-c2568f3ab68e",
|
|
558
|
-
{
|
|
559
|
-
method: "POST",
|
|
560
|
-
headers: { "Content-Type": "application/json" },
|
|
561
|
-
body: JSON.stringify({
|
|
562
|
-
location: "AirJamClient.ts:182",
|
|
563
|
-
message:
|
|
564
|
-
"connect() detected listeners removed by destroy() - re-registering all listeners",
|
|
565
|
-
data: {
|
|
566
|
-
role: this.role,
|
|
567
|
-
socketId: this.socket.id,
|
|
568
|
-
clientInstanceId: this._clientInstanceId,
|
|
569
|
-
},
|
|
570
|
-
timestamp: Date.now(),
|
|
571
|
-
sessionId: "debug-session",
|
|
572
|
-
runId: "run1",
|
|
573
|
-
hypothesisId: "CONNECT_REREGISTER",
|
|
574
|
-
}),
|
|
575
|
-
},
|
|
576
|
-
).catch(() => {});
|
|
577
|
-
// #endregion
|
|
578
164
|
this.setupListeners();
|
|
579
165
|
}
|
|
580
166
|
|
|
581
167
|
if (!this.socket.connected) {
|
|
582
168
|
this.store.getState().setStatus("connecting");
|
|
583
|
-
// #region agent log
|
|
584
|
-
fetch(
|
|
585
|
-
"http://127.0.0.1:7245/ingest/77275639-c0f5-41c0-a729-c2568f3ab68e",
|
|
586
|
-
{
|
|
587
|
-
method: "POST",
|
|
588
|
-
headers: { "Content-Type": "application/json" },
|
|
589
|
-
body: JSON.stringify({
|
|
590
|
-
location: "AirJamClient.ts:190",
|
|
591
|
-
message: "calling socket.connect()",
|
|
592
|
-
data: {
|
|
593
|
-
role: this.role,
|
|
594
|
-
socketId: this.socket.id,
|
|
595
|
-
clientInstanceId: this._clientInstanceId,
|
|
596
|
-
},
|
|
597
|
-
timestamp: Date.now(),
|
|
598
|
-
sessionId: "debug-session",
|
|
599
|
-
runId: "run1",
|
|
600
|
-
hypothesisId: "CONNECT_METHOD",
|
|
601
|
-
}),
|
|
602
|
-
},
|
|
603
|
-
).catch(() => {});
|
|
604
|
-
// #endregion
|
|
605
169
|
this.socket.connect();
|
|
606
|
-
// #region agent log
|
|
607
|
-
fetch(
|
|
608
|
-
"http://127.0.0.1:7245/ingest/77275639-c0f5-41c0-a729-c2568f3ab68e",
|
|
609
|
-
{
|
|
610
|
-
method: "POST",
|
|
611
|
-
headers: { "Content-Type": "application/json" },
|
|
612
|
-
body: JSON.stringify({
|
|
613
|
-
location: "AirJamClient.ts:192",
|
|
614
|
-
message: "socket.connect() called - checking state",
|
|
615
|
-
data: {
|
|
616
|
-
role: this.role,
|
|
617
|
-
socketId: this.socket.id,
|
|
618
|
-
socketConnected: this.socket.connected,
|
|
619
|
-
clientInstanceId: this._clientInstanceId,
|
|
620
|
-
},
|
|
621
|
-
timestamp: Date.now(),
|
|
622
|
-
sessionId: "debug-session",
|
|
623
|
-
runId: "run1",
|
|
624
|
-
hypothesisId: "CONNECT_METHOD",
|
|
625
|
-
}),
|
|
626
|
-
},
|
|
627
|
-
).catch(() => {});
|
|
628
|
-
// #endregion
|
|
629
170
|
// CRITICAL FIX: Register listener immediately if socket connects synchronously
|
|
630
171
|
// Socket.io may connect before the 'connect' event fires, so we check immediately
|
|
631
172
|
// and also use a timeout as fallback
|
|
632
173
|
const checkAndRegister = () => {
|
|
633
174
|
if (this.socket.connected) {
|
|
634
175
|
const hasListener = this.socket.listeners("server:state").length > 0;
|
|
635
|
-
// #region agent log
|
|
636
|
-
fetch(
|
|
637
|
-
"http://127.0.0.1:7245/ingest/77275639-c0f5-41c0-a729-c2568f3ab68e",
|
|
638
|
-
{
|
|
639
|
-
method: "POST",
|
|
640
|
-
headers: { "Content-Type": "application/json" },
|
|
641
|
-
body: JSON.stringify({
|
|
642
|
-
location: "AirJamClient.ts:200",
|
|
643
|
-
message:
|
|
644
|
-
"checkAndRegister: socket connected, checking listener",
|
|
645
|
-
data: {
|
|
646
|
-
role: this.role,
|
|
647
|
-
socketId: this.socket.id,
|
|
648
|
-
hasListener,
|
|
649
|
-
clientInstanceId: this._clientInstanceId,
|
|
650
|
-
},
|
|
651
|
-
timestamp: Date.now(),
|
|
652
|
-
sessionId: "debug-session",
|
|
653
|
-
runId: "run1",
|
|
654
|
-
hypothesisId: "CONNECT_METHOD",
|
|
655
|
-
}),
|
|
656
|
-
},
|
|
657
|
-
).catch(() => {});
|
|
658
|
-
// #endregion
|
|
659
176
|
if (!hasListener) {
|
|
660
|
-
// #region agent log
|
|
661
|
-
fetch(
|
|
662
|
-
"http://127.0.0.1:7245/ingest/77275639-c0f5-41c0-a729-c2568f3ab68e",
|
|
663
|
-
{
|
|
664
|
-
method: "POST",
|
|
665
|
-
headers: { "Content-Type": "application/json" },
|
|
666
|
-
body: JSON.stringify({
|
|
667
|
-
location: "AirJamClient.ts:204",
|
|
668
|
-
message:
|
|
669
|
-
"socket connected but listener missing - registering now",
|
|
670
|
-
data: {
|
|
671
|
-
role: this.role,
|
|
672
|
-
socketId: this.socket.id,
|
|
673
|
-
clientInstanceId: this._clientInstanceId,
|
|
674
|
-
},
|
|
675
|
-
timestamp: Date.now(),
|
|
676
|
-
sessionId: "debug-session",
|
|
677
|
-
runId: "run1",
|
|
678
|
-
hypothesisId: "CONNECT_METHOD",
|
|
679
|
-
}),
|
|
680
|
-
},
|
|
681
|
-
).catch(() => {});
|
|
682
|
-
// #endregion
|
|
683
177
|
this.store.getState().setStatus("connected");
|
|
684
178
|
this.store.getState().setError(undefined);
|
|
685
179
|
this.setupServerStateListener();
|
|
@@ -694,53 +188,8 @@ export class AirJamClient {
|
|
|
694
188
|
setTimeout(checkAndRegister, 200);
|
|
695
189
|
setTimeout(checkAndRegister, 500);
|
|
696
190
|
} else {
|
|
697
|
-
// #region agent log
|
|
698
|
-
fetch(
|
|
699
|
-
"http://127.0.0.1:7245/ingest/77275639-c0f5-41c0-a729-c2568f3ab68e",
|
|
700
|
-
{
|
|
701
|
-
method: "POST",
|
|
702
|
-
headers: { "Content-Type": "application/json" },
|
|
703
|
-
body: JSON.stringify({
|
|
704
|
-
location: "AirJamClient.ts:218",
|
|
705
|
-
message: "connect() called but socket already connected",
|
|
706
|
-
data: {
|
|
707
|
-
role: this.role,
|
|
708
|
-
socketId: this.socket.id,
|
|
709
|
-
clientInstanceId: this._clientInstanceId,
|
|
710
|
-
},
|
|
711
|
-
timestamp: Date.now(),
|
|
712
|
-
sessionId: "debug-session",
|
|
713
|
-
runId: "run1",
|
|
714
|
-
hypothesisId: "CONNECT_METHOD",
|
|
715
|
-
}),
|
|
716
|
-
},
|
|
717
|
-
).catch(() => {});
|
|
718
|
-
// #endregion
|
|
719
191
|
// Ensure listeners are registered if socket is already connected
|
|
720
192
|
if (!this.socket.listeners("server:state").length) {
|
|
721
|
-
// #region agent log
|
|
722
|
-
fetch(
|
|
723
|
-
"http://127.0.0.1:7245/ingest/77275639-c0f5-41c0-a729-c2568f3ab68e",
|
|
724
|
-
{
|
|
725
|
-
method: "POST",
|
|
726
|
-
headers: { "Content-Type": "application/json" },
|
|
727
|
-
body: JSON.stringify({
|
|
728
|
-
location: "AirJamClient.ts:222",
|
|
729
|
-
message:
|
|
730
|
-
"socket already connected but listener missing - registering now",
|
|
731
|
-
data: {
|
|
732
|
-
role: this.role,
|
|
733
|
-
socketId: this.socket.id,
|
|
734
|
-
clientInstanceId: this._clientInstanceId,
|
|
735
|
-
},
|
|
736
|
-
timestamp: Date.now(),
|
|
737
|
-
sessionId: "debug-session",
|
|
738
|
-
runId: "run1",
|
|
739
|
-
hypothesisId: "CONNECT_METHOD",
|
|
740
|
-
}),
|
|
741
|
-
},
|
|
742
|
-
).catch(() => {});
|
|
743
|
-
// #endregion
|
|
744
193
|
this.store.getState().setStatus("connected");
|
|
745
194
|
this.store.getState().setError(undefined);
|
|
746
195
|
this.setupServerStateListener();
|
|
@@ -130,7 +130,12 @@ export class AudioManager<T extends string = string> {
|
|
|
130
130
|
}
|
|
131
131
|
|
|
132
132
|
/**
|
|
133
|
-
*
|
|
133
|
+
* Resume audio context if suspended. This is automatically called by play(),
|
|
134
|
+
* so you typically don't need to call this manually.
|
|
135
|
+
*
|
|
136
|
+
* Note: Due to browser autoplay policies, audio context starts suspended
|
|
137
|
+
* and can only be resumed in response to a user gesture. The useAudio hook
|
|
138
|
+
* handles this automatically, and play() also calls init() internally.
|
|
134
139
|
*/
|
|
135
140
|
public init() {
|
|
136
141
|
if (Howler.ctx && Howler.ctx.state === "suspended") {
|
|
@@ -186,6 +191,9 @@ export class AudioManager<T extends string = string> {
|
|
|
186
191
|
pitch,
|
|
187
192
|
} = options || {};
|
|
188
193
|
|
|
194
|
+
// Auto-init audio context on play (handles browser autoplay policy)
|
|
195
|
+
this.init();
|
|
196
|
+
|
|
189
197
|
if (remote) {
|
|
190
198
|
this.playRemote(id, target, volume, loop);
|
|
191
199
|
return null; // Remote play doesn't return a local sound ID
|
|
@@ -296,6 +304,9 @@ export class AudioManager<T extends string = string> {
|
|
|
296
304
|
pos: { x: number; y: number; z: number },
|
|
297
305
|
sprite?: string,
|
|
298
306
|
): number | null {
|
|
307
|
+
// Auto-init audio context on play
|
|
308
|
+
this.init();
|
|
309
|
+
|
|
299
310
|
const soundId = this.playLocal(id, undefined, undefined, sprite);
|
|
300
311
|
if (soundId !== null) {
|
|
301
312
|
const sound = this.sounds.get(id);
|