@series-inc/venus-sdk 2.4.1 → 2.6.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/README.md +264 -204
- package/dist/{AdsApi-Cz0XgLM8.d.mts → AdsApi-C_GcWmfO.d.mts} +178 -84
- package/dist/{AdsApi-Cz0XgLM8.d.ts → AdsApi-C_GcWmfO.d.ts} +178 -84
- package/dist/{chunk-MWUS3A7C.mjs → chunk-W7IPHM67.mjs} +22 -3
- package/dist/chunk-W7IPHM67.mjs.map +1 -0
- package/dist/{chunk-KQZIPQLJ.mjs → chunk-YDXFZ2A2.mjs} +363 -49
- package/dist/chunk-YDXFZ2A2.mjs.map +1 -0
- package/dist/core-R3FHW62G.mjs +3 -0
- package/dist/{core-RDMPQV6U.mjs.map → core-R3FHW62G.mjs.map} +1 -1
- package/dist/index.cjs +343 -45
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +110 -9
- package/dist/index.d.ts +110 -9
- package/dist/index.mjs +6 -2
- package/dist/index.mjs.map +1 -1
- package/dist/venus-api/index.cjs +579 -1366
- package/dist/venus-api/index.cjs.map +1 -1
- package/dist/venus-api/index.d.mts +2 -2
- package/dist/venus-api/index.d.ts +2 -2
- package/dist/venus-api/index.mjs +159 -1270
- package/dist/venus-api/index.mjs.map +1 -1
- package/package.json +2 -2
- package/dist/chunk-KQZIPQLJ.mjs.map +0 -1
- package/dist/chunk-MWUS3A7C.mjs.map +0 -1
- package/dist/core-RDMPQV6U.mjs +0 -3
package/dist/venus-api/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { SDK_VERSION, initializeStorage, initializeAds, initializePopups, initializeAnalytics, initializeIap, initializeLocalNotifications, initializeTime, initializeLifecycleApi, initializeHaptics, initializeCdn, initializeFeaturesApi, initializeLoggingApi, initializeProfile, initializeAvatar3d, initializeStackNavigation, initializeAi, initializeSimulation, MockAdsApi, MockLifecycleApi, MockAnalyticsApi, createMockStorageApi, MockAvatarApi, MockNavigationApi, MockNotificationsApi, MockPopupsApi, MockProfileApi, MockCdnApi, MockTimeApi, MockAiApi, MockHapticsApi, MockFeaturesApi, MockSimulationApi, MockLoggingApi, MockIapApi, MockSharedAssetsApi, RpcClient, RpcAdsApi, RpcAnalyticsApi, RpcStorageApi, RpcAvatarApi, RpcNavigationApi, RpcPopupsApi, HostProfileApi, HostCdnApi, HostTimeApi, RpcAiApi, RpcHapticsApi, RpcFeaturesApi, RpcLifecycleApi, RpcSimulationApi, RpcLoggingApi, RpcIapApi, RpcSharedAssetsApi } from '../chunk-
|
|
2
|
-
import { createProxiedObject, createProxiedMethod, __publicField, createMockDelay, MOCK_DELAYS } from '../chunk-
|
|
1
|
+
import { init_rooms, init_VenusRoom, SDK_VERSION, initializeStorage, initializeRoomsApi, initializeAds, initializePopups, initializeAnalytics, initializeIap, initializeLocalNotifications, initializePreloader, initializeTime, initializeLifecycleApi, initializeHaptics, initializeCdn, initializeFeaturesApi, initializeLoggingApi, initializeProfile, initializeAvatar3d, initializeStackNavigation, initializeAi, initializeSimulation, MockAdsApi, MockLifecycleApi, MockAnalyticsApi, createMockStorageApi, MockAvatarApi, MockNavigationApi, MockNotificationsApi, MockPopupsApi, MockProfileApi, MockCdnApi, MockTimeApi, MockAiApi, MockHapticsApi, MockFeaturesApi, MockSimulationApi, MockLoggingApi, MockIapApi, MockPreloaderApi, MockSharedAssetsApi, RpcClient, RpcAdsApi, RpcAnalyticsApi, RpcStorageApi, RpcAvatarApi, RpcNavigationApi, RpcNotificationsApi, RpcPopupsApi, HostProfileApi, HostCdnApi, HostTimeApi, RpcAiApi, RpcHapticsApi, RpcFeaturesApi, RpcLifecycleApi, RpcSimulationApi, RpcLoggingApi, RpcIapApi, RpcPreloaderApi, RpcSharedAssetsApi, rooms_exports, VenusRoom } from '../chunk-YDXFZ2A2.mjs';
|
|
2
|
+
import { createProxiedObject, createProxiedMethod, __publicField, createMockDelay, MOCK_DELAYS, __toCommonJS } from '../chunk-W7IPHM67.mjs';
|
|
3
3
|
|
|
4
4
|
// src/venus-api/systems/theme.js
|
|
5
5
|
var DEFAULT_TYPOGRAPHY = {
|
|
@@ -184,941 +184,6 @@ function initializeTheme(venusApiInstance) {
|
|
|
184
184
|
venusApiInstance.DEFAULT_TYPOGRAPHY = DEFAULT_TYPOGRAPHY;
|
|
185
185
|
}
|
|
186
186
|
|
|
187
|
-
// src/venus-api/systems/rooms.js
|
|
188
|
-
var mockRooms = /* @__PURE__ */ new Map();
|
|
189
|
-
var mockMessages = /* @__PURE__ */ new Map();
|
|
190
|
-
var mockRoomMoves = /* @__PURE__ */ new Map();
|
|
191
|
-
var mockSubscriptions = /* @__PURE__ */ new Map();
|
|
192
|
-
function generateRoomId() {
|
|
193
|
-
return "room_" + Date.now() + "_" + Math.random().toString(36).substr(2, 9);
|
|
194
|
-
}
|
|
195
|
-
function generateMessageId() {
|
|
196
|
-
return "msg_" + Date.now() + "_" + Math.random().toString(36).substr(2, 9);
|
|
197
|
-
}
|
|
198
|
-
function generateRoomCode() {
|
|
199
|
-
const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
|
200
|
-
let code = "";
|
|
201
|
-
for (let i = 0; i < 6; i++) {
|
|
202
|
-
code += characters.charAt(Math.floor(Math.random() * characters.length));
|
|
203
|
-
}
|
|
204
|
-
return code;
|
|
205
|
-
}
|
|
206
|
-
function broadcastEvent(roomId, eventType, eventData) {
|
|
207
|
-
console.log(`[Venus Mock Rooms] Broadcasting ${eventType} for room ${roomId}:`, eventData);
|
|
208
|
-
for (const [instanceId, subscriptions] of mockSubscriptions.entries()) {
|
|
209
|
-
const roomSubscriptions = subscriptions.get(roomId);
|
|
210
|
-
if (roomSubscriptions) {
|
|
211
|
-
setTimeout(() => {
|
|
212
|
-
if (roomSubscriptions.onRoomDataUpdated && eventType === "room_data_updated") {
|
|
213
|
-
roomSubscriptions.onRoomDataUpdated(eventData);
|
|
214
|
-
}
|
|
215
|
-
if (roomSubscriptions.onMessageReceived && eventType === "message_received") {
|
|
216
|
-
roomSubscriptions.onMessageReceived(eventData);
|
|
217
|
-
}
|
|
218
|
-
if (roomSubscriptions.onPlayerJoined && eventType === "player_joined") {
|
|
219
|
-
roomSubscriptions.onPlayerJoined(eventData);
|
|
220
|
-
}
|
|
221
|
-
if (roomSubscriptions.onPlayerLeft && eventType === "player_left") {
|
|
222
|
-
roomSubscriptions.onPlayerLeft(eventData);
|
|
223
|
-
}
|
|
224
|
-
if (roomSubscriptions.onGameStarted && eventType === "game_started") {
|
|
225
|
-
roomSubscriptions.onGameStarted(eventData);
|
|
226
|
-
}
|
|
227
|
-
if (roomSubscriptions.onTurnChanged && eventType === "turn_changed") {
|
|
228
|
-
roomSubscriptions.onTurnChanged(eventData);
|
|
229
|
-
}
|
|
230
|
-
if (roomSubscriptions.onOptimisticGameStateUpdated && eventType === "app:h5:optimisticGameStateUpdated") {
|
|
231
|
-
roomSubscriptions.onOptimisticGameStateUpdated(eventData);
|
|
232
|
-
}
|
|
233
|
-
if (roomSubscriptions.onProposedMoveValidationUpdated && eventType === "app:h5:proposedMoveValidationUpdated") {
|
|
234
|
-
roomSubscriptions.onProposedMoveValidationUpdated(eventData);
|
|
235
|
-
}
|
|
236
|
-
}, 50);
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
var MockVenusRoom = class {
|
|
241
|
-
constructor(roomData) {
|
|
242
|
-
this.id = roomData.id;
|
|
243
|
-
this.roomId = roomData.id;
|
|
244
|
-
this.name = roomData.name;
|
|
245
|
-
this.players = roomData.currentPlayers || [];
|
|
246
|
-
this.maxPlayers = roomData.maxPlayers;
|
|
247
|
-
this.gameType = roomData.gameType;
|
|
248
|
-
this._subscriptions = /* @__PURE__ */ new Map();
|
|
249
|
-
this.appId = roomData.appId;
|
|
250
|
-
this.type = roomData.type;
|
|
251
|
-
this.createdBy = roomData.createdBy;
|
|
252
|
-
this.createdAt = roomData.createdAt;
|
|
253
|
-
this.updatedAt = roomData.updatedAt;
|
|
254
|
-
this.isPrivate = roomData.isPrivate;
|
|
255
|
-
this.currentPlayers = roomData.currentPlayers || [];
|
|
256
|
-
this.status = roomData.status;
|
|
257
|
-
this.customMetadata = roomData.customMetadata || {};
|
|
258
|
-
this.admins = roomData.admins || [];
|
|
259
|
-
this.roomCode = roomData.roomCode;
|
|
260
|
-
this.description = roomData.description;
|
|
261
|
-
this.data = roomData.data || {};
|
|
262
|
-
this.version = roomData.version;
|
|
263
|
-
console.log(`[Venus Mock VenusRoom] Created room object for ${this.id}`, {
|
|
264
|
-
hasCustomMetadata: !!this.customMetadata,
|
|
265
|
-
hasGameState: !!this.customMetadata?.rules?.gameState,
|
|
266
|
-
gamePhase: this.customMetadata?.rules?.gameState?.phase,
|
|
267
|
-
currentPlayer: this.customMetadata?.rules?.gameState?.currentPlayer
|
|
268
|
-
});
|
|
269
|
-
}
|
|
270
|
-
// Update room data
|
|
271
|
-
async updateData(updates, merge = true) {
|
|
272
|
-
return roomsMock.updateRoomData(this.roomId, updates, merge);
|
|
273
|
-
}
|
|
274
|
-
// Get room data
|
|
275
|
-
async getData() {
|
|
276
|
-
return roomsMock.getRoomData(this.roomId);
|
|
277
|
-
}
|
|
278
|
-
// Send message
|
|
279
|
-
async sendMessage(messageData) {
|
|
280
|
-
return roomsMock.sendMessage(this.roomId, messageData);
|
|
281
|
-
}
|
|
282
|
-
// Subscribe to room data changes
|
|
283
|
-
subscribeToData(callback) {
|
|
284
|
-
return roomsMock.subscribeToRoom(this.roomId, {
|
|
285
|
-
onRoomDataUpdated: callback
|
|
286
|
-
});
|
|
287
|
-
}
|
|
288
|
-
// Subscribe to messages
|
|
289
|
-
subscribeToMessages(callback) {
|
|
290
|
-
return roomsMock.subscribeToRoom(this.roomId, {
|
|
291
|
-
onMessageReceived: callback
|
|
292
|
-
});
|
|
293
|
-
}
|
|
294
|
-
// Leave room
|
|
295
|
-
async leave() {
|
|
296
|
-
this._subscriptions.forEach((sub) => {
|
|
297
|
-
if (sub.unsubscribe) sub.unsubscribe();
|
|
298
|
-
});
|
|
299
|
-
this._subscriptions.clear();
|
|
300
|
-
return { success: true };
|
|
301
|
-
}
|
|
302
|
-
// Start game
|
|
303
|
-
async startGame(gameConfig = {}, turnOrder = null) {
|
|
304
|
-
return roomsMock.startGame(this.roomId, gameConfig);
|
|
305
|
-
}
|
|
306
|
-
// End game
|
|
307
|
-
async endGame(winner = null, reason = null, gameResults = {}) {
|
|
308
|
-
return roomsMock.endGame(this.roomId, winner, reason, gameResults);
|
|
309
|
-
}
|
|
310
|
-
// Propose move (for client-proposed state architecture)
|
|
311
|
-
async proposeMove(proposalPayload) {
|
|
312
|
-
return roomsMock.proposeMove(this.roomId, proposalPayload);
|
|
313
|
-
}
|
|
314
|
-
// Validate move
|
|
315
|
-
async validateMove(moveId, isValid, reason = null, validatorId = null) {
|
|
316
|
-
console.log(`[Venus Mock VenusRoom] Validating move ${moveId}: ${isValid}`);
|
|
317
|
-
return { success: true, moveId, isValid, reason };
|
|
318
|
-
}
|
|
319
|
-
// Subscribe to game events
|
|
320
|
-
subscribeToGameEvents(callback) {
|
|
321
|
-
return roomsMock.subscribeToRoom(this.roomId, {
|
|
322
|
-
onOptimisticGameStateUpdated: callback,
|
|
323
|
-
onProposedMoveValidationUpdated: callback
|
|
324
|
-
});
|
|
325
|
-
}
|
|
326
|
-
// Generic message handler for room-manager.js integration
|
|
327
|
-
onMessage(callback) {
|
|
328
|
-
return roomsMock.subscribeToRoom(this.roomId, {
|
|
329
|
-
onRoomDataUpdated: callback,
|
|
330
|
-
onMessageReceived: callback,
|
|
331
|
-
onGameStarted: callback,
|
|
332
|
-
onTurnChanged: callback,
|
|
333
|
-
onOptimisticGameStateUpdated: callback,
|
|
334
|
-
onProposedMoveValidationUpdated: callback
|
|
335
|
-
});
|
|
336
|
-
}
|
|
337
|
-
// Unified subscription helper
|
|
338
|
-
subscribe(options = {}) {
|
|
339
|
-
const unsubFns = [];
|
|
340
|
-
if (options.onData) {
|
|
341
|
-
const sub = this.subscribeToData(options.onData);
|
|
342
|
-
unsubFns.push(() => sub.unsubscribe());
|
|
343
|
-
}
|
|
344
|
-
if (options.onMessages) {
|
|
345
|
-
const sub = this.subscribeToMessages(options.onMessages);
|
|
346
|
-
unsubFns.push(() => sub.unsubscribe());
|
|
347
|
-
}
|
|
348
|
-
if (options.onMoves || options.onGameEvents) {
|
|
349
|
-
const handler = options.onMoves || options.onGameEvents;
|
|
350
|
-
const sub = this.subscribeToGameEvents(handler);
|
|
351
|
-
unsubFns.push(() => sub.unsubscribe());
|
|
352
|
-
}
|
|
353
|
-
let called = false;
|
|
354
|
-
return () => {
|
|
355
|
-
if (called) return;
|
|
356
|
-
called = true;
|
|
357
|
-
unsubFns.forEach((fn) => {
|
|
358
|
-
try {
|
|
359
|
-
fn();
|
|
360
|
-
} catch (e) {
|
|
361
|
-
console.error("Mock room subscribe teardown error", e);
|
|
362
|
-
}
|
|
363
|
-
});
|
|
364
|
-
};
|
|
365
|
-
}
|
|
366
|
-
};
|
|
367
|
-
var roomsMock = {
|
|
368
|
-
createRoom(options = {}) {
|
|
369
|
-
try {
|
|
370
|
-
console.log(`[Venus Mock Rooms] Creating room with options:`, options);
|
|
371
|
-
const roomId = generateRoomId();
|
|
372
|
-
const creatorId = options.userId || "mock-user-creator";
|
|
373
|
-
const creatorDisplayName = options.userDisplayName || `Creator ${creatorId.slice(-4)}`;
|
|
374
|
-
const initialGameState = {
|
|
375
|
-
phase: "waiting",
|
|
376
|
-
currentPlayer: creatorId,
|
|
377
|
-
// Creator might be the first player by default
|
|
378
|
-
turnOrder: [creatorId],
|
|
379
|
-
playerStates: {
|
|
380
|
-
[creatorId]: {
|
|
381
|
-
displayName: creatorDisplayName,
|
|
382
|
-
status: "active",
|
|
383
|
-
role: "admin",
|
|
384
|
-
// Creator is admin
|
|
385
|
-
joinedAt: /* @__PURE__ */ new Date()
|
|
386
|
-
}
|
|
387
|
-
},
|
|
388
|
-
gameStartedAt: null,
|
|
389
|
-
turnCount: 0
|
|
390
|
-
// other game-specific state can be added by the H5 app via customMetadata or startGame
|
|
391
|
-
};
|
|
392
|
-
const room = {
|
|
393
|
-
id: roomId,
|
|
394
|
-
appId: options.appId || "mock-app",
|
|
395
|
-
name: options.name || "Mock Room",
|
|
396
|
-
type: "shared",
|
|
397
|
-
createdBy: creatorId,
|
|
398
|
-
createdAt: /* @__PURE__ */ new Date(),
|
|
399
|
-
updatedAt: /* @__PURE__ */ new Date(),
|
|
400
|
-
isPrivate: options.isPrivate || false,
|
|
401
|
-
maxPlayers: options.maxPlayers || 4,
|
|
402
|
-
currentPlayers: [creatorId],
|
|
403
|
-
status: "active",
|
|
404
|
-
customMetadata: {
|
|
405
|
-
...options.customMetadata || {},
|
|
406
|
-
rules: {
|
|
407
|
-
...options.customMetadata?.rules || {},
|
|
408
|
-
// Default generic rules, can be overridden by H5 app's options
|
|
409
|
-
ruleEngine: options.customMetadata?.rules?.ruleEngine || "generic-v1",
|
|
410
|
-
turnBased: options.customMetadata?.rules?.turnBased ?? true,
|
|
411
|
-
minPlayers: options.customMetadata?.rules?.minPlayers || 1,
|
|
412
|
-
maxPlayers: options.maxPlayers || 4,
|
|
413
|
-
gameState: initialGameState
|
|
414
|
-
}
|
|
415
|
-
},
|
|
416
|
-
admins: [creatorId],
|
|
417
|
-
roomCode: options.roomCode || (options.isPrivate ? generateRoomCode() : null),
|
|
418
|
-
description: options.description,
|
|
419
|
-
gameType: options.gameType,
|
|
420
|
-
data: {},
|
|
421
|
-
// General purpose data, game state is in customMetadata.rules.gameState
|
|
422
|
-
version: 1
|
|
423
|
-
};
|
|
424
|
-
mockRooms.set(roomId, room);
|
|
425
|
-
mockMessages.set(roomId, []);
|
|
426
|
-
mockRoomMoves.set(roomId, []);
|
|
427
|
-
console.log(`[Venus Mock Rooms] Created room ${roomId} with initial state:`, room);
|
|
428
|
-
return Promise.resolve(new MockVenusRoom(room));
|
|
429
|
-
} catch (error) {
|
|
430
|
-
console.error(`[Venus Mock Rooms] Error creating room:`, error);
|
|
431
|
-
return Promise.reject({ success: false, error: error.message || "Failed to create room" });
|
|
432
|
-
}
|
|
433
|
-
},
|
|
434
|
-
joinRoom(roomId, playerMetadata = {}) {
|
|
435
|
-
try {
|
|
436
|
-
console.log(`[Venus Mock Rooms] Joining room ${roomId}`);
|
|
437
|
-
const room = mockRooms.get(roomId);
|
|
438
|
-
if (!room) {
|
|
439
|
-
return Promise.reject({ success: false, error: "Room not found" });
|
|
440
|
-
}
|
|
441
|
-
const joiningPlayerId = playerMetadata.userId || "mock-user-" + Math.random().toString(36).substr(2, 5);
|
|
442
|
-
const joiningPlayerDisplayName = playerMetadata.displayName || `Player ${joiningPlayerId.slice(-4)}`;
|
|
443
|
-
if (room.currentPlayers.includes(joiningPlayerId)) {
|
|
444
|
-
console.log(`[Venus Mock Rooms] Player ${joiningPlayerId} already in room ${roomId}. Updating display name if needed.`);
|
|
445
|
-
if (room.customMetadata.rules.gameState.playerStates[joiningPlayerId]) {
|
|
446
|
-
room.customMetadata.rules.gameState.playerStates[joiningPlayerId].displayName = joiningPlayerDisplayName;
|
|
447
|
-
room.customMetadata.rules.gameState.playerStates[joiningPlayerId].status = "active";
|
|
448
|
-
} else {
|
|
449
|
-
room.customMetadata.rules.gameState.playerStates[joiningPlayerId] = {
|
|
450
|
-
displayName: joiningPlayerDisplayName,
|
|
451
|
-
status: "active",
|
|
452
|
-
role: "player",
|
|
453
|
-
joinedAt: /* @__PURE__ */ new Date()
|
|
454
|
-
};
|
|
455
|
-
}
|
|
456
|
-
room.updatedAt = /* @__PURE__ */ new Date();
|
|
457
|
-
room.version++;
|
|
458
|
-
broadcastEvent(roomId, "room_data_updated", { roomId, roomData: room, timestamp: Date.now() });
|
|
459
|
-
return Promise.resolve(new MockVenusRoom(room));
|
|
460
|
-
}
|
|
461
|
-
if (room.currentPlayers.length >= room.maxPlayers) {
|
|
462
|
-
return Promise.reject({ success: false, error: "Room is full" });
|
|
463
|
-
}
|
|
464
|
-
room.currentPlayers.push(joiningPlayerId);
|
|
465
|
-
room.customMetadata.rules.gameState.playerStates[joiningPlayerId] = {
|
|
466
|
-
displayName: joiningPlayerDisplayName,
|
|
467
|
-
status: "active",
|
|
468
|
-
role: "player",
|
|
469
|
-
joinedAt: /* @__PURE__ */ new Date()
|
|
470
|
-
};
|
|
471
|
-
if (room.customMetadata.rules.gameState.phase === "waiting" && room.customMetadata.rules.gameState.turnOrder) {
|
|
472
|
-
if (!room.customMetadata.rules.gameState.turnOrder.includes(joiningPlayerId)) {
|
|
473
|
-
room.customMetadata.rules.gameState.turnOrder.push(joiningPlayerId);
|
|
474
|
-
}
|
|
475
|
-
}
|
|
476
|
-
room.updatedAt = /* @__PURE__ */ new Date();
|
|
477
|
-
room.version++;
|
|
478
|
-
broadcastEvent(roomId, "player_joined", { roomId, player: { id: joiningPlayerId, displayName: joiningPlayerDisplayName } });
|
|
479
|
-
broadcastEvent(roomId, "room_data_updated", { roomId, roomData: room, timestamp: Date.now() });
|
|
480
|
-
console.log(`[Venus Mock Rooms] Player ${joiningPlayerId} joined room ${roomId}. Current state:`, room);
|
|
481
|
-
return Promise.resolve(new MockVenusRoom(room));
|
|
482
|
-
} catch (error) {
|
|
483
|
-
console.error(`[Venus Mock Rooms] Error joining room:`, error);
|
|
484
|
-
return Promise.reject({ success: false, error: error.message || "Failed to join room" });
|
|
485
|
-
}
|
|
486
|
-
},
|
|
487
|
-
updateRoomData(roomId, updates, merge = true) {
|
|
488
|
-
try {
|
|
489
|
-
console.log(`[Venus Mock Rooms] Updating room ${roomId} data:`, updates);
|
|
490
|
-
const room = mockRooms.get(roomId);
|
|
491
|
-
if (!room) {
|
|
492
|
-
throw new Error("Room not found");
|
|
493
|
-
}
|
|
494
|
-
if (merge) {
|
|
495
|
-
room.data = { ...room.data, ...updates };
|
|
496
|
-
} else {
|
|
497
|
-
room.data = updates;
|
|
498
|
-
}
|
|
499
|
-
room.updatedAt = /* @__PURE__ */ new Date();
|
|
500
|
-
room.version++;
|
|
501
|
-
broadcastEvent(roomId, "room_data_updated", {
|
|
502
|
-
roomId,
|
|
503
|
-
roomData: room,
|
|
504
|
-
timestamp: Date.now()
|
|
505
|
-
});
|
|
506
|
-
return Promise.resolve({
|
|
507
|
-
success: true
|
|
508
|
-
});
|
|
509
|
-
} catch (error) {
|
|
510
|
-
console.error(`[Venus Mock Rooms] Error updating room data:`, error);
|
|
511
|
-
return Promise.reject(new Error(error.message || "Failed to update room data"));
|
|
512
|
-
}
|
|
513
|
-
},
|
|
514
|
-
getRoomData(roomId) {
|
|
515
|
-
try {
|
|
516
|
-
console.log(`[Venus Mock Rooms] Getting room ${roomId} data`);
|
|
517
|
-
const room = mockRooms.get(roomId);
|
|
518
|
-
if (!room) {
|
|
519
|
-
throw new Error("Room not found");
|
|
520
|
-
}
|
|
521
|
-
return Promise.resolve({
|
|
522
|
-
success: true,
|
|
523
|
-
data: room.data || {}
|
|
524
|
-
});
|
|
525
|
-
} catch (error) {
|
|
526
|
-
console.error(`[Venus Mock Rooms] Error getting room data:`, error);
|
|
527
|
-
return Promise.reject(new Error(error.message || "Failed to get room data"));
|
|
528
|
-
}
|
|
529
|
-
},
|
|
530
|
-
sendMessage(roomId, message) {
|
|
531
|
-
try {
|
|
532
|
-
const room = mockRooms.get(roomId);
|
|
533
|
-
if (!room) {
|
|
534
|
-
return Promise.reject({ success: false, error: "Room not found" });
|
|
535
|
-
}
|
|
536
|
-
if (message.type === "chat") {
|
|
537
|
-
console.log(`[Venus Mock Rooms] Sending CHAT message to room ${roomId}:`, message);
|
|
538
|
-
const messageId = generateMessageId();
|
|
539
|
-
const messageData = {
|
|
540
|
-
id: messageId,
|
|
541
|
-
roomId,
|
|
542
|
-
senderId: message.senderId || "mock-user-chatter",
|
|
543
|
-
// H5 app should provide senderId
|
|
544
|
-
content: message.content || "",
|
|
545
|
-
type: "chat",
|
|
546
|
-
metadata: message.metadata || {},
|
|
547
|
-
timestamp: /* @__PURE__ */ new Date()
|
|
548
|
-
};
|
|
549
|
-
const messages = mockMessages.get(roomId) || [];
|
|
550
|
-
messages.push(messageData);
|
|
551
|
-
mockMessages.set(roomId, messages);
|
|
552
|
-
broadcastEvent(roomId, "message_received", { roomId, message: messageData });
|
|
553
|
-
return Promise.resolve({ success: true, messageId });
|
|
554
|
-
} else {
|
|
555
|
-
console.log(`[Venus Mock Rooms] Sending GAME ACTION/MOVE to room ${roomId} via moves subcollection:`, message);
|
|
556
|
-
const playerId = message.playerId || message.metadata?.playerId || "mock-player-action";
|
|
557
|
-
if (!playerId) ;
|
|
558
|
-
const move = {
|
|
559
|
-
playerId,
|
|
560
|
-
moveData: message.moveData || message.content || message.metadata || { type: message.type },
|
|
561
|
-
// Ensure type is captured
|
|
562
|
-
clientValidationHash: message.clientValidationHash,
|
|
563
|
-
timestamp: /* @__PURE__ */ new Date(),
|
|
564
|
-
// client-side timestamp for the move proposal
|
|
565
|
-
status: "pending_mock_processing"
|
|
566
|
-
};
|
|
567
|
-
const roomMoves = mockRoomMoves.get(roomId) || [];
|
|
568
|
-
roomMoves.push(move);
|
|
569
|
-
mockRoomMoves.set(roomId, roomMoves);
|
|
570
|
-
this._processMockMove(roomId, move, room);
|
|
571
|
-
return Promise.resolve({ success: true, moveId: "mock-move-" + Date.now() });
|
|
572
|
-
}
|
|
573
|
-
} catch (error) {
|
|
574
|
-
console.error(`[Venus Mock Rooms] Error sending message/move:`, error);
|
|
575
|
-
return Promise.reject({ success: false, error: error.message || "Failed to send message/move" });
|
|
576
|
-
}
|
|
577
|
-
},
|
|
578
|
-
subscribeToRoom(roomId, options = {}) {
|
|
579
|
-
try {
|
|
580
|
-
console.log(`[Venus Mock Rooms] Subscribing to room ${roomId}:`, options);
|
|
581
|
-
const room = mockRooms.get(roomId);
|
|
582
|
-
if (!room) {
|
|
583
|
-
throw new Error("Room not found");
|
|
584
|
-
}
|
|
585
|
-
const instanceId = "mock-instance-" + Date.now();
|
|
586
|
-
if (!mockSubscriptions.has(instanceId)) {
|
|
587
|
-
mockSubscriptions.set(instanceId, /* @__PURE__ */ new Map());
|
|
588
|
-
}
|
|
589
|
-
const subscriptions = mockSubscriptions.get(instanceId);
|
|
590
|
-
subscriptions.set(roomId, {
|
|
591
|
-
onRoomDataUpdated: options.onRoomDataUpdated,
|
|
592
|
-
onMessageReceived: options.onMessageReceived,
|
|
593
|
-
onPlayerJoined: options.onPlayerJoined,
|
|
594
|
-
onPlayerLeft: options.onPlayerLeft,
|
|
595
|
-
onGameStarted: options.onGameStarted,
|
|
596
|
-
onTurnChanged: options.onTurnChanged
|
|
597
|
-
});
|
|
598
|
-
return Promise.resolve({
|
|
599
|
-
success: true,
|
|
600
|
-
unsubscribe: () => {
|
|
601
|
-
subscriptions.delete(roomId);
|
|
602
|
-
console.log(`[Venus Mock Rooms] Unsubscribed from room ${roomId}`);
|
|
603
|
-
}
|
|
604
|
-
});
|
|
605
|
-
} catch (error) {
|
|
606
|
-
console.error(`[Venus Mock Rooms] Error subscribing to room:`, error);
|
|
607
|
-
return Promise.reject(new Error(error.message || "Failed to subscribe to room"));
|
|
608
|
-
}
|
|
609
|
-
},
|
|
610
|
-
listPublicRooms(gameType, limit = 20) {
|
|
611
|
-
try {
|
|
612
|
-
console.log(`[Venus Mock Rooms] Listing public rooms:`, { gameType, limit });
|
|
613
|
-
let rooms = Array.from(mockRooms.values()).filter(
|
|
614
|
-
(room) => !room.isPrivate && room.status === "active" && (!gameType || room.gameType === gameType)
|
|
615
|
-
);
|
|
616
|
-
rooms = rooms.slice(0, limit);
|
|
617
|
-
return Promise.resolve({
|
|
618
|
-
success: true,
|
|
619
|
-
rooms
|
|
620
|
-
});
|
|
621
|
-
} catch (error) {
|
|
622
|
-
console.error(`[Venus Mock Rooms] Error listing public rooms:`, error);
|
|
623
|
-
return Promise.reject(new Error(error.message || "Failed to list public rooms"));
|
|
624
|
-
}
|
|
625
|
-
},
|
|
626
|
-
searchRooms(searchQuery, gameType, limit = 20) {
|
|
627
|
-
try {
|
|
628
|
-
console.log(`[Venus Mock Rooms] Searching rooms:`, { searchQuery, gameType, limit });
|
|
629
|
-
let rooms = Array.from(mockRooms.values()).filter(
|
|
630
|
-
(room) => !room.isPrivate && room.status === "active" && (!gameType || room.gameType === gameType) && (!searchQuery || room.name.toLowerCase().includes(searchQuery.toLowerCase()) || room.description?.toLowerCase().includes(searchQuery.toLowerCase()))
|
|
631
|
-
);
|
|
632
|
-
rooms = rooms.slice(0, limit);
|
|
633
|
-
return Promise.resolve({
|
|
634
|
-
success: true,
|
|
635
|
-
rooms
|
|
636
|
-
});
|
|
637
|
-
} catch (error) {
|
|
638
|
-
console.error(`[Venus Mock Rooms] Error searching rooms:`, error);
|
|
639
|
-
return Promise.reject({ success: false, error: error.message || "Failed to search rooms" });
|
|
640
|
-
}
|
|
641
|
-
},
|
|
642
|
-
// Smart matchmaking - join existing room or create new one
|
|
643
|
-
joinOrCreateRoom(options = {}) {
|
|
644
|
-
try {
|
|
645
|
-
console.log(`[Venus Mock Rooms] Smart matchmaking with options:`, options);
|
|
646
|
-
const { matchCriteria = {}, createOptions = {} } = options;
|
|
647
|
-
let matchingRoom = null;
|
|
648
|
-
for (const room of mockRooms.values()) {
|
|
649
|
-
const matchesGameType = !matchCriteria.gameType || room.gameType === matchCriteria.gameType;
|
|
650
|
-
const matchesPrivacy = !matchCriteria.hasOwnProperty("isPrivate") || room.isPrivate === matchCriteria.isPrivate;
|
|
651
|
-
const hasSpace = !matchCriteria.hasSpace || room.currentPlayers.length < room.maxPlayers;
|
|
652
|
-
const isActive = room.status === "active";
|
|
653
|
-
const isWaiting = room.customMetadata?.rules?.gameState?.phase === "waiting";
|
|
654
|
-
if (matchesGameType && matchesPrivacy && hasSpace && isActive && isWaiting) {
|
|
655
|
-
matchingRoom = room;
|
|
656
|
-
console.log(`[Venus Mock Rooms] Found matching room: ${room.id}`);
|
|
657
|
-
break;
|
|
658
|
-
}
|
|
659
|
-
}
|
|
660
|
-
if (matchingRoom) {
|
|
661
|
-
console.log(`[Venus Mock Rooms] Joining existing room: ${matchingRoom.id}`);
|
|
662
|
-
const joiningPlayerId = createOptions.userId || options.userId || "mock-user-joiner";
|
|
663
|
-
const joiningPlayerDisplayName = createOptions.userDisplayName || options.userDisplayName || `Player ${joiningPlayerId.slice(-4)}`;
|
|
664
|
-
if (matchingRoom.currentPlayers.includes(joiningPlayerId)) {
|
|
665
|
-
return Promise.resolve({
|
|
666
|
-
action: "joined",
|
|
667
|
-
room: new MockVenusRoom(matchingRoom),
|
|
668
|
-
playersJoined: 0
|
|
669
|
-
});
|
|
670
|
-
}
|
|
671
|
-
matchingRoom.currentPlayers.push(joiningPlayerId);
|
|
672
|
-
matchingRoom.customMetadata.rules.gameState.playerStates[joiningPlayerId] = {
|
|
673
|
-
displayName: joiningPlayerDisplayName,
|
|
674
|
-
status: "active",
|
|
675
|
-
role: "player",
|
|
676
|
-
joinedAt: /* @__PURE__ */ new Date()
|
|
677
|
-
};
|
|
678
|
-
if (matchingRoom.customMetadata.rules.gameState.phase === "waiting" && matchingRoom.customMetadata.rules.gameState.turnOrder) {
|
|
679
|
-
if (!matchingRoom.customMetadata.rules.gameState.turnOrder.includes(joiningPlayerId)) {
|
|
680
|
-
matchingRoom.customMetadata.rules.gameState.turnOrder.push(joiningPlayerId);
|
|
681
|
-
}
|
|
682
|
-
}
|
|
683
|
-
matchingRoom.updatedAt = /* @__PURE__ */ new Date();
|
|
684
|
-
matchingRoom.version++;
|
|
685
|
-
if (matchingRoom.currentPlayers.length >= matchingRoom.maxPlayers) {
|
|
686
|
-
console.log(`[Venus Mock Rooms] Room ${matchingRoom.id} is full, auto-starting game`);
|
|
687
|
-
const gameState = matchingRoom.customMetadata.rules.gameState;
|
|
688
|
-
gameState.phase = "playing";
|
|
689
|
-
gameState.gameStartedAt = /* @__PURE__ */ new Date();
|
|
690
|
-
let turnOrder = [...matchingRoom.currentPlayers];
|
|
691
|
-
if (matchingRoom.customMetadata.rules.randomizePlayerOrder) {
|
|
692
|
-
for (let i = turnOrder.length - 1; i > 0; i--) {
|
|
693
|
-
const j = Math.floor(Math.random() * (i + 1));
|
|
694
|
-
[turnOrder[i], turnOrder[j]] = [turnOrder[j], turnOrder[i]];
|
|
695
|
-
}
|
|
696
|
-
}
|
|
697
|
-
gameState.turnOrder = turnOrder;
|
|
698
|
-
gameState.currentPlayer = turnOrder[0] || null;
|
|
699
|
-
if (matchingRoom.gameType === "chess" && turnOrder.length >= 2) {
|
|
700
|
-
gameState.playerStates[turnOrder[0]].gameRole = "white";
|
|
701
|
-
gameState.playerStates[turnOrder[1]].gameRole = "black";
|
|
702
|
-
}
|
|
703
|
-
broadcastEvent(matchingRoom.id, "game_started", {
|
|
704
|
-
roomId: matchingRoom.id,
|
|
705
|
-
gameState,
|
|
706
|
-
turnOrder: gameState.turnOrder,
|
|
707
|
-
currentPlayer: gameState.currentPlayer
|
|
708
|
-
});
|
|
709
|
-
}
|
|
710
|
-
broadcastEvent(matchingRoom.id, "player_joined", {
|
|
711
|
-
roomId: matchingRoom.id,
|
|
712
|
-
player: { id: joiningPlayerId, displayName: joiningPlayerDisplayName }
|
|
713
|
-
});
|
|
714
|
-
broadcastEvent(matchingRoom.id, "room_data_updated", {
|
|
715
|
-
roomId: matchingRoom.id,
|
|
716
|
-
roomData: matchingRoom,
|
|
717
|
-
timestamp: Date.now()
|
|
718
|
-
});
|
|
719
|
-
return Promise.resolve({
|
|
720
|
-
action: "joined",
|
|
721
|
-
room: new MockVenusRoom(matchingRoom),
|
|
722
|
-
playersJoined: 1
|
|
723
|
-
});
|
|
724
|
-
} else {
|
|
725
|
-
console.log(`[Venus Mock Rooms] No matching room found, creating new room`);
|
|
726
|
-
const roomCreationOptions = {
|
|
727
|
-
...createOptions,
|
|
728
|
-
userId: createOptions.userId || options.userId || "mock-user-creator",
|
|
729
|
-
userDisplayName: createOptions.userDisplayName || options.userDisplayName || "Creator"
|
|
730
|
-
};
|
|
731
|
-
const createResult = this.createRoom(roomCreationOptions);
|
|
732
|
-
return createResult.then((room) => ({
|
|
733
|
-
action: "created",
|
|
734
|
-
room,
|
|
735
|
-
// createRoom already returns MockVenusRoom instance
|
|
736
|
-
playersJoined: 1
|
|
737
|
-
}));
|
|
738
|
-
}
|
|
739
|
-
} catch (error) {
|
|
740
|
-
console.error(`[Venus Mock Rooms] Error in joinOrCreateRoom:`, error);
|
|
741
|
-
return Promise.reject({ success: false, error: error.message || "Failed to join or create room" });
|
|
742
|
-
}
|
|
743
|
-
},
|
|
744
|
-
joinRoomByCode(roomCode, playerMetadata = {}) {
|
|
745
|
-
try {
|
|
746
|
-
console.log(`[Venus Mock Rooms] Joining room by code ${roomCode}`);
|
|
747
|
-
let foundRoom = null;
|
|
748
|
-
for (const [roomId, room] of mockRooms.entries()) {
|
|
749
|
-
if (room.roomCode === roomCode && room.status === "active") {
|
|
750
|
-
foundRoom = room;
|
|
751
|
-
break;
|
|
752
|
-
}
|
|
753
|
-
}
|
|
754
|
-
if (!foundRoom) {
|
|
755
|
-
return Promise.reject({ success: false, error: `Room not found with code: ${roomCode}` });
|
|
756
|
-
}
|
|
757
|
-
return this.joinRoom(foundRoom.id, playerMetadata);
|
|
758
|
-
} catch (error) {
|
|
759
|
-
console.error(`[Venus Mock Rooms] Error joining room by code:`, error);
|
|
760
|
-
return Promise.reject({ success: false, error: error.message || "Failed to join room by code" });
|
|
761
|
-
}
|
|
762
|
-
},
|
|
763
|
-
// Stage 2: Enhanced game features
|
|
764
|
-
startGame(roomId, gameConfig = {}, requestingUserId = "mock-admin-user") {
|
|
765
|
-
try {
|
|
766
|
-
console.log(`[Venus Mock Rooms] Starting game in room ${roomId} by ${requestingUserId}`);
|
|
767
|
-
const room = mockRooms.get(roomId);
|
|
768
|
-
if (!room) {
|
|
769
|
-
return Promise.reject({ success: false, error: "Room not found" });
|
|
770
|
-
}
|
|
771
|
-
if (!room.admins.includes(requestingUserId) && room.createdBy !== requestingUserId) {
|
|
772
|
-
return Promise.reject({ success: false, error: "Only admin or creator can start game" });
|
|
773
|
-
}
|
|
774
|
-
if (room.customMetadata.rules.gameState.phase === "playing") {
|
|
775
|
-
return Promise.reject({ success: false, error: "Game already in progress" });
|
|
776
|
-
}
|
|
777
|
-
const minPlayers = room.customMetadata.rules.minPlayers || 1;
|
|
778
|
-
if (room.currentPlayers.length < minPlayers) {
|
|
779
|
-
return Promise.reject({ success: false, error: `Not enough players. Needs ${minPlayers}` });
|
|
780
|
-
}
|
|
781
|
-
const gameState = room.customMetadata.rules.gameState;
|
|
782
|
-
gameState.phase = "playing";
|
|
783
|
-
gameState.gameStartedAt = /* @__PURE__ */ new Date();
|
|
784
|
-
let turnOrder = [...room.currentPlayers];
|
|
785
|
-
if (room.customMetadata.rules.randomizePlayerOrder) {
|
|
786
|
-
for (let i = turnOrder.length - 1; i > 0; i--) {
|
|
787
|
-
const j = Math.floor(Math.random() * (i + 1));
|
|
788
|
-
[turnOrder[i], turnOrder[j]] = [turnOrder[j], turnOrder[i]];
|
|
789
|
-
}
|
|
790
|
-
}
|
|
791
|
-
gameState.turnOrder = turnOrder;
|
|
792
|
-
gameState.currentPlayer = turnOrder[0] || null;
|
|
793
|
-
turnOrder.forEach((playerId) => {
|
|
794
|
-
if (!gameState.playerStates[playerId]) {
|
|
795
|
-
gameState.playerStates[playerId] = { displayName: `Player ${playerId.slice(-4)}`, status: "active", role: "player" };
|
|
796
|
-
} else {
|
|
797
|
-
gameState.playerStates[playerId].status = "active";
|
|
798
|
-
if (!gameState.playerStates[playerId].displayName) {
|
|
799
|
-
gameState.playerStates[playerId].displayName = `Player ${playerId.slice(-4)}`;
|
|
800
|
-
}
|
|
801
|
-
}
|
|
802
|
-
});
|
|
803
|
-
room.updatedAt = /* @__PURE__ */ new Date();
|
|
804
|
-
room.version++;
|
|
805
|
-
console.log(`[Venus Mock Rooms] Game started in room ${roomId}. New state:`, room);
|
|
806
|
-
broadcastEvent(roomId, "game_started", { roomId, gameState, turnOrder: gameState.turnOrder, currentPlayer: gameState.currentPlayer });
|
|
807
|
-
broadcastEvent(roomId, "room_data_updated", { roomId, roomData: room, timestamp: Date.now() });
|
|
808
|
-
return Promise.resolve({ success: true, ...room });
|
|
809
|
-
} catch (error) {
|
|
810
|
-
console.error(`[Venus Mock Rooms] Error starting game:`, error);
|
|
811
|
-
return Promise.reject({ success: false, error: error.message || "Failed to start game" });
|
|
812
|
-
}
|
|
813
|
-
},
|
|
814
|
-
endGame(roomId, winner = null, reason = null, gameResults = {}) {
|
|
815
|
-
try {
|
|
816
|
-
console.log(`[Venus Mock Rooms] Player requesting to end game in room ${roomId}`);
|
|
817
|
-
const room = mockRooms.get(roomId);
|
|
818
|
-
if (!room) return Promise.reject({ success: false, error: "Room not found" });
|
|
819
|
-
const playerId = gameResults.endedBy || "mock-player-ender";
|
|
820
|
-
const move = {
|
|
821
|
-
playerId,
|
|
822
|
-
moveData: {
|
|
823
|
-
type: "end_game",
|
|
824
|
-
winner,
|
|
825
|
-
reason,
|
|
826
|
-
gameResults
|
|
827
|
-
},
|
|
828
|
-
timestamp: /* @__PURE__ */ new Date(),
|
|
829
|
-
status: "pending_mock_processing"
|
|
830
|
-
};
|
|
831
|
-
const roomMoves = mockRoomMoves.get(roomId) || [];
|
|
832
|
-
roomMoves.push(move);
|
|
833
|
-
mockRoomMoves.set(roomId, roomMoves);
|
|
834
|
-
this._processMockMove(roomId, move, room);
|
|
835
|
-
return Promise.resolve({ success: true, moveId: "mock-move-" + Date.now() });
|
|
836
|
-
} catch (error) {
|
|
837
|
-
console.error(`[Venus Mock Rooms] Error ending game:`, error);
|
|
838
|
-
return Promise.reject({ success: false, error: error.message || "Failed to end game" });
|
|
839
|
-
}
|
|
840
|
-
},
|
|
841
|
-
// NEW: Propose move (client-proposed state architecture)
|
|
842
|
-
proposeMove(roomId, proposalPayload, proposerId = "mock-proposer") {
|
|
843
|
-
try {
|
|
844
|
-
console.log(`[Venus Mock Rooms] Player ${proposerId} proposing move in room ${roomId}:`, proposalPayload);
|
|
845
|
-
const room = mockRooms.get(roomId);
|
|
846
|
-
if (!room) return Promise.reject({ success: false, error: "Room not found" });
|
|
847
|
-
const proposedMoveId = `prop_move_${Date.now()}_${Math.random().toString(36).substr(2, 5)}`;
|
|
848
|
-
const proposedMove = {
|
|
849
|
-
id: proposedMoveId,
|
|
850
|
-
proposerProfileId: proposerId,
|
|
851
|
-
timestamp: /* @__PURE__ */ new Date(),
|
|
852
|
-
gameSpecificState: proposalPayload.gameSpecificState,
|
|
853
|
-
moveType: proposalPayload.moveType,
|
|
854
|
-
clientContext: proposalPayload.clientContext,
|
|
855
|
-
clientProposalId: proposalPayload.clientProposalId,
|
|
856
|
-
serverGenericValidationStatus: "pending",
|
|
857
|
-
serverCustomValidationStatus: "pending",
|
|
858
|
-
clientConsensusStatus: "pending",
|
|
859
|
-
...proposalPayload.resignedBy && { resignedBy: proposalPayload.resignedBy },
|
|
860
|
-
...proposalPayload.winner && { winner: proposalPayload.winner }
|
|
861
|
-
};
|
|
862
|
-
if (!mockRoomMoves.has(roomId + "_proposed")) {
|
|
863
|
-
mockRoomMoves.set(roomId + "_proposed", []);
|
|
864
|
-
}
|
|
865
|
-
mockRoomMoves.get(roomId + "_proposed").push(proposedMove);
|
|
866
|
-
if (proposalPayload.gameSpecificState) {
|
|
867
|
-
room.optimisticGameState = proposalPayload.gameSpecificState;
|
|
868
|
-
room.lastProposedMoveId = proposedMoveId;
|
|
869
|
-
room.lastProposedMoveBy = proposerId;
|
|
870
|
-
room.lastProposedMoveAt = /* @__PURE__ */ new Date();
|
|
871
|
-
room.updatedAt = /* @__PURE__ */ new Date();
|
|
872
|
-
room.version++;
|
|
873
|
-
}
|
|
874
|
-
setTimeout(() => {
|
|
875
|
-
this._processMockProposedMove(roomId, proposedMoveId, proposedMove, room);
|
|
876
|
-
}, 100);
|
|
877
|
-
broadcastEvent(roomId, "room_data_updated", {
|
|
878
|
-
roomId,
|
|
879
|
-
roomData: room,
|
|
880
|
-
timestamp: Date.now()
|
|
881
|
-
});
|
|
882
|
-
if (proposalPayload.gameSpecificState) {
|
|
883
|
-
broadcastEvent(roomId, "app:h5:optimisticGameStateUpdated", {
|
|
884
|
-
roomId,
|
|
885
|
-
optimisticGameState: proposalPayload.gameSpecificState
|
|
886
|
-
});
|
|
887
|
-
}
|
|
888
|
-
return Promise.resolve({
|
|
889
|
-
success: true,
|
|
890
|
-
proposedMoveId,
|
|
891
|
-
optimisticGameState: proposalPayload.gameSpecificState
|
|
892
|
-
});
|
|
893
|
-
} catch (error) {
|
|
894
|
-
console.error(`[Venus Mock Rooms] Error proposing move:`, error);
|
|
895
|
-
return Promise.reject({ success: false, error: error.message || "Failed to propose move" });
|
|
896
|
-
}
|
|
897
|
-
},
|
|
898
|
-
// NEW internal helper to simulate server-side move processing for mock API
|
|
899
|
-
_processMockMove(roomId, move, room) {
|
|
900
|
-
console.log("[Venus Mock Rooms] Simulating server processing for move:", move);
|
|
901
|
-
move.id = "processed-mock-move-" + Date.now();
|
|
902
|
-
setTimeout(() => {
|
|
903
|
-
const currentRoomState = mockRooms.get(roomId);
|
|
904
|
-
if (!currentRoomState) return;
|
|
905
|
-
const { rules, gameState } = currentRoomState.customMetadata;
|
|
906
|
-
const { playerId, moveData } = move;
|
|
907
|
-
let isValidMove = true;
|
|
908
|
-
let validationError = null;
|
|
909
|
-
if (rules.turnBased && gameState.currentPlayer !== playerId) {
|
|
910
|
-
isValidMove = false;
|
|
911
|
-
validationError = "Not current player's turn.";
|
|
912
|
-
console.warn(`[Venus Mock Rooms] Invalid move by ${playerId}: Not their turn. Current: ${gameState.currentPlayer}`);
|
|
913
|
-
}
|
|
914
|
-
const moveType = moveData?.type;
|
|
915
|
-
if (isValidMove && moveType && rules.allowedMessageTypes?.[gameState.phase]?.[moveType]) {
|
|
916
|
-
const ruleForMoveType = rules.allowedMessageTypes[gameState.phase][moveType];
|
|
917
|
-
if (ruleForMoveType.requiredFields) {
|
|
918
|
-
for (const field of ruleForMoveType.requiredFields) {
|
|
919
|
-
if (!(field in moveData)) {
|
|
920
|
-
isValidMove = false;
|
|
921
|
-
validationError = `Missing required field: ${field} for move type ${moveType}.`;
|
|
922
|
-
console.warn(`[Venus Mock Rooms] Invalid move by ${playerId}: ${validationError}`);
|
|
923
|
-
break;
|
|
924
|
-
}
|
|
925
|
-
}
|
|
926
|
-
}
|
|
927
|
-
} else if (isValidMove && moveType && !rules.allowedMessageTypes?.[gameState.phase]?.[moveType]) {
|
|
928
|
-
console.warn(`[Venus Mock Rooms] Move type "${moveType}" not defined in allowedMessageTypes for phase "${gameState.phase}". Processing by default.`);
|
|
929
|
-
}
|
|
930
|
-
if (isValidMove) {
|
|
931
|
-
console.log("[Venus Mock Rooms] Move considered valid by mock server. Updating game state.");
|
|
932
|
-
move.status = "mock_valid";
|
|
933
|
-
gameState.lastMoveBy = playerId;
|
|
934
|
-
gameState.lastMoveTimestamp = /* @__PURE__ */ new Date();
|
|
935
|
-
if (moveData.type === "end_game") {
|
|
936
|
-
gameState.phase = "ended";
|
|
937
|
-
gameState.endedAt = /* @__PURE__ */ new Date();
|
|
938
|
-
currentRoomState.status = "archived";
|
|
939
|
-
console.log("[Venus Mock Rooms] Mock: Game ended.");
|
|
940
|
-
} else if (moveData.type === "force_update_state") {
|
|
941
|
-
Object.assign(gameState, moveData.payload);
|
|
942
|
-
console.log("[Venus Mock Rooms] Mock: Game state forcibly updated with:", moveData.payload);
|
|
943
|
-
}
|
|
944
|
-
const nonTurnAdvancingMoves = ["end_game", "force_update_state"];
|
|
945
|
-
if (rules.turnBased && gameState.turnOrder && gameState.turnOrder.length > 0 && !nonTurnAdvancingMoves.includes(moveData.type)) {
|
|
946
|
-
const currentPlayerIndex = gameState.turnOrder.indexOf(gameState.currentPlayer || "");
|
|
947
|
-
if (currentPlayerIndex !== -1) {
|
|
948
|
-
const nextPlayerIndex = (currentPlayerIndex + 1) % gameState.turnOrder.length;
|
|
949
|
-
gameState.currentPlayer = gameState.turnOrder[nextPlayerIndex];
|
|
950
|
-
gameState.turnCount = (gameState.turnCount || 0) + 1;
|
|
951
|
-
console.log(`[Venus Mock Rooms] Mock: Turn advanced to ${gameState.currentPlayer}`);
|
|
952
|
-
broadcastEvent(roomId, "turn_changed", {
|
|
953
|
-
roomId,
|
|
954
|
-
currentPlayer: gameState.currentPlayer,
|
|
955
|
-
previousPlayer: playerId,
|
|
956
|
-
// The one who just moved
|
|
957
|
-
turnCount: gameState.turnCount
|
|
958
|
-
});
|
|
959
|
-
}
|
|
960
|
-
}
|
|
961
|
-
currentRoomState.updatedAt = /* @__PURE__ */ new Date();
|
|
962
|
-
currentRoomState.version++;
|
|
963
|
-
broadcastEvent(roomId, "room_data_updated", { roomId, roomData: currentRoomState, timestamp: Date.now() });
|
|
964
|
-
} else {
|
|
965
|
-
console.warn("[Venus Mock Rooms] Move considered invalid by mock server. No game state change.", { validationError });
|
|
966
|
-
move.status = "mock_invalid";
|
|
967
|
-
move.error = validationError;
|
|
968
|
-
}
|
|
969
|
-
console.log("[Venus Mock Rooms] Finished mock processing for move:", move);
|
|
970
|
-
}, 100);
|
|
971
|
-
},
|
|
972
|
-
// NEW: Process proposed move for mock API
|
|
973
|
-
_processMockProposedMove(roomId, proposedMoveId, proposedMove, room) {
|
|
974
|
-
console.log("[Venus Mock Rooms] Simulating server processing for proposed move:", proposedMoveId);
|
|
975
|
-
const { rules, gameState } = room.customMetadata;
|
|
976
|
-
const { proposerProfileId, gameSpecificState, moveType } = proposedMove;
|
|
977
|
-
let isGenericValid = true;
|
|
978
|
-
let genericValidationReason = "";
|
|
979
|
-
if (moveType === "resignation") {
|
|
980
|
-
const resignedBy = proposedMove.resignedBy || gameSpecificState?.resignedBy;
|
|
981
|
-
if (!resignedBy) {
|
|
982
|
-
isGenericValid = false;
|
|
983
|
-
genericValidationReason = "Security violation: Resignation move must specify who is resigning (resignedBy field required).";
|
|
984
|
-
} else if (resignedBy !== proposerProfileId) {
|
|
985
|
-
isGenericValid = false;
|
|
986
|
-
genericValidationReason = `Security violation: Player ${proposerProfileId} cannot resign on behalf of player ${resignedBy}. Players can only resign themselves.`;
|
|
987
|
-
} else if (!gameState.playerStates || !gameState.playerStates[proposerProfileId]) {
|
|
988
|
-
isGenericValid = false;
|
|
989
|
-
genericValidationReason = `Security violation: Player ${proposerProfileId} is not in this game and cannot resign.`;
|
|
990
|
-
} else {
|
|
991
|
-
console.log(`[Venus Mock Rooms] \u2705 Resignation move validated: ${proposerProfileId} is resigning themselves`);
|
|
992
|
-
}
|
|
993
|
-
} else {
|
|
994
|
-
if (rules.turnBased && gameState.currentPlayer !== proposerProfileId) {
|
|
995
|
-
isGenericValid = false;
|
|
996
|
-
genericValidationReason = `Not player's turn. Current: ${gameState.currentPlayer}`;
|
|
997
|
-
}
|
|
998
|
-
}
|
|
999
|
-
if (isGenericValid && moveType && rules.allowedMessageTypes?.[gameState.phase]?.[moveType]) {
|
|
1000
|
-
const ruleForMoveType = rules.allowedMessageTypes[gameState.phase][moveType];
|
|
1001
|
-
if (ruleForMoveType.requiredFields) {
|
|
1002
|
-
for (const field of ruleForMoveType.requiredFields) {
|
|
1003
|
-
const hasField = moveType === "resignation" ? proposedMove[field] !== void 0 || gameSpecificState[field] !== void 0 : gameSpecificState[field] !== void 0;
|
|
1004
|
-
if (!hasField) {
|
|
1005
|
-
isGenericValid = false;
|
|
1006
|
-
genericValidationReason = `Missing required field: ${field}`;
|
|
1007
|
-
break;
|
|
1008
|
-
}
|
|
1009
|
-
}
|
|
1010
|
-
}
|
|
1011
|
-
}
|
|
1012
|
-
proposedMove.serverGenericValidationStatus = isGenericValid ? "valid" : "invalid";
|
|
1013
|
-
proposedMove.serverGenericValidationReason = genericValidationReason;
|
|
1014
|
-
proposedMove.serverCustomValidationStatus = "not_applicable";
|
|
1015
|
-
proposedMove.clientConsensusStatus = "valid";
|
|
1016
|
-
if (isGenericValid) {
|
|
1017
|
-
Object.assign(gameState, gameSpecificState);
|
|
1018
|
-
if (gameSpecificState.isGameOver === true) {
|
|
1019
|
-
gameState.phase = "ended";
|
|
1020
|
-
gameState.winner = gameSpecificState.winner || null;
|
|
1021
|
-
gameState.endReason = gameSpecificState.gameStatus || "completed";
|
|
1022
|
-
gameState.endedAt = /* @__PURE__ */ new Date();
|
|
1023
|
-
gameState.currentPlayer = null;
|
|
1024
|
-
console.log(`[Venus Mock Rooms] \u{1F3C1} Game ended in room ${roomId}: ${gameState.endReason}, winner: ${gameState.winner || "draw"}`);
|
|
1025
|
-
} else {
|
|
1026
|
-
if (rules.turnBased && gameState.turnOrder && gameState.turnOrder.length > 0) {
|
|
1027
|
-
const currentPlayerIndex = gameState.turnOrder.indexOf(gameState.currentPlayer || "");
|
|
1028
|
-
if (currentPlayerIndex !== -1) {
|
|
1029
|
-
const nextPlayerIndex = (currentPlayerIndex + 1) % gameState.turnOrder.length;
|
|
1030
|
-
gameState.currentPlayer = gameState.turnOrder[nextPlayerIndex];
|
|
1031
|
-
gameState.turnCount = (gameState.turnCount || 0) + 1;
|
|
1032
|
-
}
|
|
1033
|
-
}
|
|
1034
|
-
}
|
|
1035
|
-
gameState.lastMoveBy = proposerProfileId;
|
|
1036
|
-
gameState.lastMoveTimestamp = /* @__PURE__ */ new Date();
|
|
1037
|
-
room.updatedAt = /* @__PURE__ */ new Date();
|
|
1038
|
-
room.version++;
|
|
1039
|
-
console.log(`[Venus Mock Rooms] Proposed move ${proposedMoveId} validated and applied`);
|
|
1040
|
-
} else {
|
|
1041
|
-
console.log(`[Venus Mock Rooms] Proposed move ${proposedMoveId} validation failed: ${genericValidationReason}`);
|
|
1042
|
-
}
|
|
1043
|
-
broadcastEvent(roomId, "app:h5:proposedMoveValidationUpdated", {
|
|
1044
|
-
roomId,
|
|
1045
|
-
proposedMoveId,
|
|
1046
|
-
proposedMoveData: proposedMove
|
|
1047
|
-
});
|
|
1048
|
-
if (isGenericValid) {
|
|
1049
|
-
broadcastEvent(roomId, "room_data_updated", {
|
|
1050
|
-
roomId,
|
|
1051
|
-
roomData: room,
|
|
1052
|
-
timestamp: Date.now()
|
|
1053
|
-
});
|
|
1054
|
-
}
|
|
1055
|
-
},
|
|
1056
|
-
getUserRooms(appId, includeArchived = false) {
|
|
1057
|
-
try {
|
|
1058
|
-
console.log(`[Venus Mock Rooms] Getting user rooms:`, { appId, includeArchived });
|
|
1059
|
-
const userId = "mock-user";
|
|
1060
|
-
let rooms = Array.from(mockRooms.values()).filter(
|
|
1061
|
-
(room) => room.currentPlayers.includes(userId) && (!appId || room.appId === appId) && (includeArchived || room.status === "active")
|
|
1062
|
-
);
|
|
1063
|
-
rooms.sort((a, b) => new Date(b.updatedAt) - new Date(a.updatedAt));
|
|
1064
|
-
return Promise.resolve({
|
|
1065
|
-
success: true,
|
|
1066
|
-
rooms
|
|
1067
|
-
});
|
|
1068
|
-
} catch (error) {
|
|
1069
|
-
console.error(`[Venus Mock Rooms] Error getting user rooms:`, error);
|
|
1070
|
-
return Promise.reject(new Error(error.message || "Failed to get user rooms"));
|
|
1071
|
-
}
|
|
1072
|
-
},
|
|
1073
|
-
getGameState(roomId) {
|
|
1074
|
-
try {
|
|
1075
|
-
console.log(`[Venus Mock Rooms] Getting game state for room ${roomId}`);
|
|
1076
|
-
const room = mockRooms.get(roomId);
|
|
1077
|
-
if (!room) {
|
|
1078
|
-
return Promise.reject({ success: false, error: "Room not found" });
|
|
1079
|
-
}
|
|
1080
|
-
const gameState = room.customMetadata?.rules?.gameState || {};
|
|
1081
|
-
return Promise.resolve({
|
|
1082
|
-
success: true,
|
|
1083
|
-
data: gameState
|
|
1084
|
-
// Return the authoritative game state from the mock room
|
|
1085
|
-
});
|
|
1086
|
-
} catch (error) {
|
|
1087
|
-
console.error(`[Venus Mock Rooms] Error getting game state:`, error);
|
|
1088
|
-
return Promise.reject({ success: false, error: error.message || "Failed to get game state" });
|
|
1089
|
-
}
|
|
1090
|
-
}
|
|
1091
|
-
};
|
|
1092
|
-
function initializeRooms(venusApiInstance, mockData = null) {
|
|
1093
|
-
if (mockData && Array.isArray(mockData.rooms)) {
|
|
1094
|
-
mockData.rooms.forEach((room) => {
|
|
1095
|
-
mockRooms.set(room.id, room);
|
|
1096
|
-
mockMessages.set(room.id, []);
|
|
1097
|
-
mockPlayers.set(room.id, room.currentPlayers.map((playerId) => ({
|
|
1098
|
-
id: playerId,
|
|
1099
|
-
roomId: room.id,
|
|
1100
|
-
joinedAt: /* @__PURE__ */ new Date(),
|
|
1101
|
-
lastActive: /* @__PURE__ */ new Date(),
|
|
1102
|
-
status: "active",
|
|
1103
|
-
customData: {},
|
|
1104
|
-
role: playerId === room.createdBy ? "owner" : "member"
|
|
1105
|
-
})));
|
|
1106
|
-
});
|
|
1107
|
-
}
|
|
1108
|
-
venusApiInstance.rooms = createProxiedObject.call(venusApiInstance, "rooms", roomsMock);
|
|
1109
|
-
venusApiInstance.getUserRooms = createProxiedMethod("getUserRooms", roomsMock.getUserRooms);
|
|
1110
|
-
venusApiInstance.createRoom = createProxiedMethod("createRoom", roomsMock.createRoom);
|
|
1111
|
-
venusApiInstance.joinRoom = createProxiedMethod("joinRoom", roomsMock.joinRoom);
|
|
1112
|
-
venusApiInstance.joinOrCreateRoom = createProxiedMethod("joinOrCreateRoom", roomsMock.joinOrCreateRoom);
|
|
1113
|
-
venusApiInstance.joinRoomByCode = createProxiedMethod("joinRoomByCode", roomsMock.joinRoomByCode);
|
|
1114
|
-
venusApiInstance.listPublicRooms = createProxiedMethod("listPublicRooms", roomsMock.listPublicRooms);
|
|
1115
|
-
venusApiInstance.searchRooms = createProxiedMethod("searchRooms", roomsMock.searchRooms);
|
|
1116
|
-
venusApiInstance.subscribeToRoom = createProxiedMethod("subscribeToRoom", roomsMock.subscribeToRoom);
|
|
1117
|
-
venusApiInstance.isRoomSystemEnabled = function() {
|
|
1118
|
-
return true;
|
|
1119
|
-
};
|
|
1120
|
-
}
|
|
1121
|
-
|
|
1122
187
|
// src/venus-api/systems/asset-loader.js
|
|
1123
188
|
var VenusAssetLoader = class {
|
|
1124
189
|
constructor() {
|
|
@@ -2869,7 +1934,7 @@ function createNumbersAPI() {
|
|
|
2869
1934
|
return numbersAPI;
|
|
2870
1935
|
}
|
|
2871
1936
|
async function initializeNumbers(venusApiInstance) {
|
|
2872
|
-
const { createProxiedObject: createProxiedObject2, createProxiedMethod: createProxiedMethod2 } = await import('../core-
|
|
1937
|
+
const { createProxiedObject: createProxiedObject2, createProxiedMethod: createProxiedMethod2 } = await import('../core-R3FHW62G.mjs');
|
|
2873
1938
|
const numbersAPI = createNumbersAPI();
|
|
2874
1939
|
venusApiInstance.numbers = createProxiedObject2.call(
|
|
2875
1940
|
venusApiInstance,
|
|
@@ -2995,43 +2060,50 @@ function initializePost(venusApi, host) {
|
|
|
2995
2060
|
};
|
|
2996
2061
|
}
|
|
2997
2062
|
|
|
2998
|
-
// src/rooms/MockRoomsApi.ts
|
|
2999
|
-
var MockRoomsApi = class {
|
|
3000
|
-
constructor() {
|
|
3001
|
-
// Mock room storage to simulate real-time rooms in development
|
|
3002
|
-
__publicField(this, "mockRooms", /* @__PURE__ */ new Map());
|
|
3003
|
-
__publicField(this, "mockMessages", /* @__PURE__ */ new Map());
|
|
3004
|
-
// roomId -> messages[]
|
|
3005
|
-
__publicField(this, "mockRoomMoves", /* @__PURE__ */ new Map());
|
|
3006
|
-
// roomId -> moves[]
|
|
3007
|
-
__publicField(this, "mockSubscriptions", /* @__PURE__ */ new Map());
|
|
3008
|
-
}
|
|
3009
|
-
join(roomId) {
|
|
3010
|
-
throw new Error("Method not implemented.");
|
|
3011
|
-
}
|
|
3012
|
-
// instanceId -> subscriptions
|
|
3013
|
-
createRoom(options) {
|
|
3014
|
-
return Promise.resolve(void 0);
|
|
3015
|
-
}
|
|
3016
|
-
generateRoomId() {
|
|
3017
|
-
return "room_" + Date.now() + "_" + Math.random().toString(36).substr(2, 9);
|
|
3018
|
-
}
|
|
3019
|
-
// Helper to generate message IDs
|
|
3020
|
-
generateMessageId() {
|
|
3021
|
-
return "msg_" + Date.now() + "_" + Math.random().toString(36).substr(2, 9);
|
|
3022
|
-
}
|
|
3023
|
-
// Helper to generate room codes
|
|
3024
|
-
generateRoomCode() {
|
|
3025
|
-
const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
|
3026
|
-
let code = "";
|
|
3027
|
-
for (let i = 0; i < 6; i++) {
|
|
3028
|
-
code += characters.charAt(Math.floor(Math.random() * characters.length));
|
|
3029
|
-
}
|
|
3030
|
-
return code;
|
|
3031
|
-
}
|
|
3032
|
-
};
|
|
3033
|
-
|
|
3034
2063
|
// src/MockHost.ts
|
|
2064
|
+
init_rooms();
|
|
2065
|
+
var ROOMS_UNAVAILABLE_MESSAGE = "[Venus SDK] Rooms API is only available when running inside the Venus host environment.";
|
|
2066
|
+
function createUnavailableRoomsApi() {
|
|
2067
|
+
const roomsUnavailableError = () => new Error(ROOMS_UNAVAILABLE_MESSAGE);
|
|
2068
|
+
return {
|
|
2069
|
+
async createRoom() {
|
|
2070
|
+
throw roomsUnavailableError();
|
|
2071
|
+
},
|
|
2072
|
+
async joinOrCreateRoom() {
|
|
2073
|
+
throw roomsUnavailableError();
|
|
2074
|
+
},
|
|
2075
|
+
async getUserRooms() {
|
|
2076
|
+
throw roomsUnavailableError();
|
|
2077
|
+
},
|
|
2078
|
+
async joinRoomByCode() {
|
|
2079
|
+
throw roomsUnavailableError();
|
|
2080
|
+
},
|
|
2081
|
+
subscribe() {
|
|
2082
|
+
throw roomsUnavailableError();
|
|
2083
|
+
},
|
|
2084
|
+
async updateData() {
|
|
2085
|
+
throw roomsUnavailableError();
|
|
2086
|
+
},
|
|
2087
|
+
async getData() {
|
|
2088
|
+
throw roomsUnavailableError();
|
|
2089
|
+
},
|
|
2090
|
+
async sendMessage() {
|
|
2091
|
+
throw roomsUnavailableError();
|
|
2092
|
+
},
|
|
2093
|
+
async leave() {
|
|
2094
|
+
throw roomsUnavailableError();
|
|
2095
|
+
},
|
|
2096
|
+
async startGame() {
|
|
2097
|
+
throw roomsUnavailableError();
|
|
2098
|
+
},
|
|
2099
|
+
async proposeMove() {
|
|
2100
|
+
throw roomsUnavailableError();
|
|
2101
|
+
},
|
|
2102
|
+
async validateMove() {
|
|
2103
|
+
throw roomsUnavailableError();
|
|
2104
|
+
}
|
|
2105
|
+
};
|
|
2106
|
+
}
|
|
3035
2107
|
var MockHost = class {
|
|
3036
2108
|
constructor(venusApi) {
|
|
3037
2109
|
__publicField(this, "ads");
|
|
@@ -3055,6 +2127,7 @@ var MockHost = class {
|
|
|
3055
2127
|
__publicField(this, "rooms");
|
|
3056
2128
|
__publicField(this, "logging");
|
|
3057
2129
|
__publicField(this, "iap");
|
|
2130
|
+
__publicField(this, "preloader");
|
|
3058
2131
|
__publicField(this, "state", 0 /* PLAYING */);
|
|
3059
2132
|
__publicField(this, "venusApi");
|
|
3060
2133
|
__publicField(this, "_isInitialized", false);
|
|
@@ -3084,18 +2157,19 @@ var MockHost = class {
|
|
|
3084
2157
|
this.features = new MockFeaturesApi();
|
|
3085
2158
|
this.lifecycle = this._mockLifecyclesApi;
|
|
3086
2159
|
this.simulation = new MockSimulationApi();
|
|
3087
|
-
this.rooms =
|
|
2160
|
+
this.rooms = createUnavailableRoomsApi();
|
|
3088
2161
|
this.logging = new MockLoggingApi();
|
|
3089
2162
|
this.iap = new MockIapApi();
|
|
2163
|
+
initializeRoomsApi(this.venusApi, this);
|
|
2164
|
+
this.preloader = new MockPreloaderApi();
|
|
3090
2165
|
venusApi.isMock = () => true;
|
|
3091
2166
|
this.venusApi.sharedAssets = new MockSharedAssetsApi(this.venusApi);
|
|
3092
2167
|
}
|
|
3093
2168
|
get isInitialized() {
|
|
3094
2169
|
return this._isInitialized;
|
|
3095
2170
|
}
|
|
3096
|
-
initialize() {
|
|
2171
|
+
async initialize(options = {}) {
|
|
3097
2172
|
this._isInitialized = true;
|
|
3098
|
-
return Promise.resolve();
|
|
3099
2173
|
}
|
|
3100
2174
|
updateUiControls() {
|
|
3101
2175
|
const controls = {
|
|
@@ -3720,177 +2794,49 @@ var VenusTransport = class {
|
|
|
3720
2794
|
}
|
|
3721
2795
|
};
|
|
3722
2796
|
|
|
3723
|
-
// src/
|
|
3724
|
-
|
|
2797
|
+
// src/RemoteHost.ts
|
|
2798
|
+
init_rooms();
|
|
2799
|
+
|
|
2800
|
+
// src/rooms/RpcRoomsApi.ts
|
|
2801
|
+
init_VenusRoom();
|
|
2802
|
+
var RpcRoomsApi = class {
|
|
3725
2803
|
constructor(rpcClient) {
|
|
3726
2804
|
__publicField(this, "rpcClient");
|
|
2805
|
+
__publicField(this, "subscriptions");
|
|
2806
|
+
__publicField(this, "transportSubscription", null);
|
|
3727
2807
|
this.rpcClient = rpcClient;
|
|
3728
|
-
|
|
3729
|
-
|
|
3730
|
-
|
|
3731
|
-
|
|
3732
|
-
|
|
3733
|
-
data: options?.payload,
|
|
3734
|
-
key: options?.groupId,
|
|
3735
|
-
priority: options?.priority || 1,
|
|
3736
|
-
trigger: options?.trigger ?? null
|
|
2808
|
+
this.subscriptions = {
|
|
2809
|
+
data: {},
|
|
2810
|
+
messages: {},
|
|
2811
|
+
gameEvents: {},
|
|
2812
|
+
allEvents: {}
|
|
3737
2813
|
};
|
|
3738
|
-
const response = await this.rpcClient.call(
|
|
3739
|
-
"H5_SCHEDULE_LOCAL_NOTIFICATION" /* SCHEDULE_LOCAL_NOTIFICATION */,
|
|
3740
|
-
request
|
|
3741
|
-
);
|
|
3742
|
-
if (response.scheduled) {
|
|
3743
|
-
return response.id;
|
|
3744
|
-
}
|
|
3745
|
-
return null;
|
|
3746
|
-
}
|
|
3747
|
-
async cancelLocalNotification(id) {
|
|
3748
|
-
const result = await this.rpcClient.call(
|
|
3749
|
-
"H5_CANCEL_LOCAL_NOTIFICATION" /* CANCEL_LOCAL_NOTIFICATION */,
|
|
3750
|
-
{
|
|
3751
|
-
id
|
|
3752
|
-
}
|
|
3753
|
-
);
|
|
3754
|
-
return result.canceled;
|
|
3755
|
-
}
|
|
3756
|
-
async getAllScheduledLocalNotifications() {
|
|
3757
|
-
const response = await this.rpcClient.call(
|
|
3758
|
-
"H5_GET_ALL_SCHEDULED_LOCAL_NOTIFICATIONS" /* GET_ALL_SCHEDULED_LOCAL_NOTIFICATIONS */,
|
|
3759
|
-
{}
|
|
3760
|
-
);
|
|
3761
|
-
const notifications = response.notifications.map((notif) => {
|
|
3762
|
-
return {
|
|
3763
|
-
id: notif.identifier,
|
|
3764
|
-
title: notif.content.title,
|
|
3765
|
-
body: notif.content.body,
|
|
3766
|
-
payload: notif.content.data,
|
|
3767
|
-
trigger: notif.trigger
|
|
3768
|
-
};
|
|
3769
|
-
});
|
|
3770
|
-
return notifications;
|
|
3771
2814
|
}
|
|
3772
|
-
|
|
3773
|
-
|
|
3774
|
-
|
|
3775
|
-
|
|
3776
|
-
|
|
3777
|
-
return response.enabled;
|
|
2815
|
+
/**
|
|
2816
|
+
* Get the subscription state for external access (used by setupRoomNotifications)
|
|
2817
|
+
*/
|
|
2818
|
+
getSubscriptions() {
|
|
2819
|
+
return this.subscriptions;
|
|
3778
2820
|
}
|
|
3779
|
-
|
|
3780
|
-
|
|
3781
|
-
|
|
3782
|
-
|
|
3783
|
-
|
|
3784
|
-
|
|
2821
|
+
/**
|
|
2822
|
+
* Set up room notification routing from the transport
|
|
2823
|
+
*/
|
|
2824
|
+
setupNotifications(transport) {
|
|
2825
|
+
const { setupRoomNotifications } = (init_rooms(), __toCommonJS(rooms_exports));
|
|
2826
|
+
this.transportSubscription = setupRoomNotifications(
|
|
2827
|
+
transport,
|
|
2828
|
+
() => this.getSubscriptions()
|
|
3785
2829
|
);
|
|
3786
|
-
return response.enabled;
|
|
3787
2830
|
}
|
|
3788
|
-
|
|
3789
|
-
|
|
3790
|
-
|
|
3791
|
-
|
|
3792
|
-
|
|
3793
|
-
|
|
3794
|
-
|
|
3795
|
-
|
|
3796
|
-
__publicField(this, "maxPlayers");
|
|
3797
|
-
__publicField(this, "gameType");
|
|
3798
|
-
__publicField(this, "appId");
|
|
3799
|
-
__publicField(this, "type");
|
|
3800
|
-
__publicField(this, "createdBy");
|
|
3801
|
-
__publicField(this, "createdAt");
|
|
3802
|
-
__publicField(this, "updatedAt");
|
|
3803
|
-
__publicField(this, "isPrivate");
|
|
3804
|
-
__publicField(this, "currentPlayers");
|
|
3805
|
-
__publicField(this, "status");
|
|
3806
|
-
__publicField(this, "customMetadata");
|
|
3807
|
-
__publicField(this, "admins");
|
|
3808
|
-
__publicField(this, "roomCode");
|
|
3809
|
-
__publicField(this, "description");
|
|
3810
|
-
__publicField(this, "data");
|
|
3811
|
-
__publicField(this, "version");
|
|
3812
|
-
__publicField(this, "_subscriptions", /* @__PURE__ */ new Map());
|
|
3813
|
-
this.id = roomData.id;
|
|
3814
|
-
this.name = roomData.name;
|
|
3815
|
-
this.players = roomData.currentPlayers || [];
|
|
3816
|
-
this.maxPlayers = roomData.maxPlayers;
|
|
3817
|
-
this.gameType = roomData.gameType;
|
|
3818
|
-
this.appId = roomData.appId;
|
|
3819
|
-
this.type = roomData.type;
|
|
3820
|
-
this.createdBy = roomData.createdBy;
|
|
3821
|
-
this.createdAt = roomData.createdAt;
|
|
3822
|
-
this.updatedAt = roomData.updatedAt;
|
|
3823
|
-
this.isPrivate = roomData.isPrivate;
|
|
3824
|
-
this.currentPlayers = roomData.currentPlayers || [];
|
|
3825
|
-
this.status = roomData.status;
|
|
3826
|
-
this.customMetadata = roomData.customMetadata || {};
|
|
3827
|
-
this.admins = roomData.admins || [];
|
|
3828
|
-
this.roomCode = roomData.roomCode;
|
|
3829
|
-
this.description = roomData.description;
|
|
3830
|
-
this.data = roomData.data || {};
|
|
3831
|
-
this.version = roomData.version;
|
|
3832
|
-
console.log(`VenusRoom: Created room object for ${this.id}`, {
|
|
3833
|
-
hasCustomMetadata: !!this.customMetadata,
|
|
3834
|
-
hasGameState: !!this.customMetadata?.rules?.gameState,
|
|
3835
|
-
gamePhase: this.customMetadata?.rules?.gameState?.phase,
|
|
3836
|
-
currentPlayer: this.customMetadata?.rules?.gameState?.currentPlayer
|
|
3837
|
-
});
|
|
3838
|
-
}
|
|
3839
|
-
updateFromRoomData(newRoomData) {
|
|
3840
|
-
if (newRoomData.id === this.id) {
|
|
3841
|
-
this.name = newRoomData.name || this.name;
|
|
3842
|
-
this.players = newRoomData.currentPlayers || this.players;
|
|
3843
|
-
this.maxPlayers = newRoomData.maxPlayers || this.maxPlayers;
|
|
3844
|
-
this.gameType = newRoomData.gameType || this.gameType;
|
|
3845
|
-
this.currentPlayers = newRoomData.currentPlayers || this.currentPlayers;
|
|
3846
|
-
this.customMetadata = newRoomData.customMetadata || this.customMetadata;
|
|
3847
|
-
this.data = newRoomData.data || this.data;
|
|
3848
|
-
this.status = newRoomData.status || this.status;
|
|
3849
|
-
this.updatedAt = newRoomData.updatedAt || this.updatedAt;
|
|
3850
|
-
console.log(`VenusRoom: Updated room object ${this.id} with fresh data`, {
|
|
3851
|
-
hasCustomMetadata: !!this.customMetadata,
|
|
3852
|
-
hasGameState: !!this.customMetadata?.rules?.gameState,
|
|
3853
|
-
gamePhase: this.customMetadata?.rules?.gameState?.phase,
|
|
3854
|
-
currentPlayer: this.customMetadata?.rules?.gameState?.currentPlayer
|
|
3855
|
-
});
|
|
3856
|
-
}
|
|
3857
|
-
}
|
|
3858
|
-
// NEW: Generic message handler for room-manager.js integration
|
|
3859
|
-
onMessage(callback) {
|
|
3860
|
-
const subscriptionId = "messages_" + Date.now() + "_" + Math.random().toString(36).substr(2, 9);
|
|
3861
|
-
if (!window.venus._roomSubscriptions.allEvents) {
|
|
3862
|
-
window.venus._roomSubscriptions.allEvents = {};
|
|
3863
|
-
}
|
|
3864
|
-
if (!window.venus._roomSubscriptions.allEvents[this.id]) {
|
|
3865
|
-
window.venus._roomSubscriptions.allEvents[this.id] = [];
|
|
2831
|
+
/**
|
|
2832
|
+
* Clean up subscriptions and resources
|
|
2833
|
+
*/
|
|
2834
|
+
dispose() {
|
|
2835
|
+
if (this.transportSubscription) {
|
|
2836
|
+
this.transportSubscription.unsubscribe();
|
|
2837
|
+
this.transportSubscription = null;
|
|
2838
|
+
console.log("[Venus Rooms] Cleaned up room notification subscription");
|
|
3866
2839
|
}
|
|
3867
|
-
window.venus._roomSubscriptions.allEvents[this.id].push(callback);
|
|
3868
|
-
this._subscriptions.set(subscriptionId, {
|
|
3869
|
-
type: "allEvents",
|
|
3870
|
-
callback
|
|
3871
|
-
});
|
|
3872
|
-
return {
|
|
3873
|
-
unsubscribe: () => {
|
|
3874
|
-
const callbacks = window.venus._roomSubscriptions.allEvents[this.id] || [];
|
|
3875
|
-
const index = callbacks.indexOf(callback);
|
|
3876
|
-
if (index > -1) callbacks.splice(index, 1);
|
|
3877
|
-
this._subscriptions.delete(subscriptionId);
|
|
3878
|
-
}
|
|
3879
|
-
};
|
|
3880
|
-
}
|
|
3881
|
-
};
|
|
3882
|
-
|
|
3883
|
-
// src/rooms/RpcRoomsApi.ts
|
|
3884
|
-
var RpcRoomsApi = class {
|
|
3885
|
-
constructor(rpcClient) {
|
|
3886
|
-
__publicField(this, "rpcClient");
|
|
3887
|
-
__publicField(this, "isRoomSystemEnabled", function() {
|
|
3888
|
-
return true;
|
|
3889
|
-
});
|
|
3890
|
-
this.rpcClient = rpcClient;
|
|
3891
|
-
}
|
|
3892
|
-
join(roomId) {
|
|
3893
|
-
throw new Error("Method not implemented.");
|
|
3894
2840
|
}
|
|
3895
2841
|
async createRoom(options) {
|
|
3896
2842
|
const response = await this.rpcClient.call(
|
|
@@ -3924,33 +2870,6 @@ var RpcRoomsApi = class {
|
|
|
3924
2870
|
playersJoined: data.playersJoined
|
|
3925
2871
|
};
|
|
3926
2872
|
}
|
|
3927
|
-
async listPublicRooms(gameType, limit = 20) {
|
|
3928
|
-
const response = await this.rpcClient.call(
|
|
3929
|
-
"H5_ROOM_LIST_PUBLIC" /* H5_ROOM_LIST_PUBLIC */,
|
|
3930
|
-
{
|
|
3931
|
-
gameType,
|
|
3932
|
-
limit
|
|
3933
|
-
}
|
|
3934
|
-
);
|
|
3935
|
-
if (!response.success) {
|
|
3936
|
-
throw new Error(response.error || "Failed to list public rooms");
|
|
3937
|
-
}
|
|
3938
|
-
return response.rooms || [];
|
|
3939
|
-
}
|
|
3940
|
-
async searchRooms(searchQuery, gameType, limit = 20) {
|
|
3941
|
-
const response = await this.rpcClient.call(
|
|
3942
|
-
"H5_ROOM_SEARCH" /* H5_ROOM_SEARCH */,
|
|
3943
|
-
{
|
|
3944
|
-
searchQuery,
|
|
3945
|
-
gameType,
|
|
3946
|
-
limit
|
|
3947
|
-
}
|
|
3948
|
-
);
|
|
3949
|
-
if (!response.success) {
|
|
3950
|
-
throw new Error(response.error || "Failed to search rooms");
|
|
3951
|
-
}
|
|
3952
|
-
return response.rooms || [];
|
|
3953
|
-
}
|
|
3954
2873
|
async joinRoomByCode(roomCode) {
|
|
3955
2874
|
const response = await this.rpcClient.call(
|
|
3956
2875
|
"H5_ROOM_JOIN_BY_CODE" /* H5_ROOM_JOIN_BY_CODE */,
|
|
@@ -3958,7 +2877,7 @@ var RpcRoomsApi = class {
|
|
|
3958
2877
|
roomCode
|
|
3959
2878
|
}
|
|
3960
2879
|
);
|
|
3961
|
-
if (
|
|
2880
|
+
if (response?.success === false) {
|
|
3962
2881
|
throw new Error(response.error || "Failed to join room by code");
|
|
3963
2882
|
}
|
|
3964
2883
|
const roomData = response.roomData || response;
|
|
@@ -3966,15 +2885,14 @@ var RpcRoomsApi = class {
|
|
|
3966
2885
|
return room;
|
|
3967
2886
|
}
|
|
3968
2887
|
// Get user's rooms with optional filtering
|
|
3969
|
-
async getUserRooms(
|
|
2888
|
+
async getUserRooms(includeArchived = false) {
|
|
3970
2889
|
const response = await this.rpcClient.call(
|
|
3971
2890
|
"H5_ROOM_GET_USER_ROOMS" /* H5_ROOM_GET_USER_ROOMS */,
|
|
3972
2891
|
{
|
|
3973
|
-
|
|
3974
|
-
includePersonal: includeArchived
|
|
2892
|
+
includeArchived
|
|
3975
2893
|
}
|
|
3976
2894
|
);
|
|
3977
|
-
if (
|
|
2895
|
+
if (response?.success === false) {
|
|
3978
2896
|
throw new Error(response.error || "Failed to get user rooms");
|
|
3979
2897
|
}
|
|
3980
2898
|
const rawRooms = response.rooms || [];
|
|
@@ -3997,62 +2915,6 @@ var RpcRoomsApi = class {
|
|
|
3997
2915
|
}
|
|
3998
2916
|
return venusRooms;
|
|
3999
2917
|
}
|
|
4000
|
-
// Convenience method for common use case
|
|
4001
|
-
quickMatch(gameType) {
|
|
4002
|
-
return this.joinOrCreateRoom({
|
|
4003
|
-
matchCriteria: {
|
|
4004
|
-
gameType,
|
|
4005
|
-
isPrivate: false,
|
|
4006
|
-
hasSpace: true
|
|
4007
|
-
},
|
|
4008
|
-
createOptions: {
|
|
4009
|
-
name: gameType + " Game",
|
|
4010
|
-
gameType,
|
|
4011
|
-
isPrivate: false,
|
|
4012
|
-
maxPlayers: 4
|
|
4013
|
-
// sensible default
|
|
4014
|
-
}
|
|
4015
|
-
});
|
|
4016
|
-
}
|
|
4017
|
-
// Enhanced room creation with game rules
|
|
4018
|
-
async createGameRoom(options) {
|
|
4019
|
-
const enhancedOptions = {
|
|
4020
|
-
...options,
|
|
4021
|
-
customMetadata: {
|
|
4022
|
-
...options.customMetadata,
|
|
4023
|
-
rules: {
|
|
4024
|
-
ruleEngine: options.ruleEngine || "basic",
|
|
4025
|
-
validateMessages: options.validateMessages || false,
|
|
4026
|
-
randomizePlayerOrder: options.randomizePlayerOrder || false,
|
|
4027
|
-
clientValidation: options.clientValidation || false,
|
|
4028
|
-
allowedMessageTypes: options.allowedMessageTypes || {},
|
|
4029
|
-
gameState: {
|
|
4030
|
-
phase: "waiting",
|
|
4031
|
-
currentPlayer: null,
|
|
4032
|
-
turnOrder: [],
|
|
4033
|
-
playerStates: {},
|
|
4034
|
-
...options.initialGameState
|
|
4035
|
-
},
|
|
4036
|
-
...options.rules
|
|
4037
|
-
}
|
|
4038
|
-
}
|
|
4039
|
-
};
|
|
4040
|
-
return this.createRoom(enhancedOptions);
|
|
4041
|
-
}
|
|
4042
|
-
// Convenience method for subscribing to all game events
|
|
4043
|
-
subscribeToGameEvents(roomId, callback) {
|
|
4044
|
-
if (!window.venus._roomSubscriptions.gameEvents[roomId]) {
|
|
4045
|
-
window.venus._roomSubscriptions.gameEvents[roomId] = [];
|
|
4046
|
-
}
|
|
4047
|
-
window.venus._roomSubscriptions.gameEvents[roomId].push(callback);
|
|
4048
|
-
return {
|
|
4049
|
-
unsubscribe: () => {
|
|
4050
|
-
const callbacks = window.venus._roomSubscriptions.gameEvents[roomId] || [];
|
|
4051
|
-
const index = callbacks.indexOf(callback);
|
|
4052
|
-
if (index > -1) callbacks.splice(index, 1);
|
|
4053
|
-
}
|
|
4054
|
-
};
|
|
4055
|
-
}
|
|
4056
2918
|
async updateData(room, updates, merge = true) {
|
|
4057
2919
|
const response = await this.rpcClient.call(
|
|
4058
2920
|
"H5_ROOM_UPDATE_DATA" /* H5_ROOM_UPDATE_DATA */,
|
|
@@ -4062,7 +2924,7 @@ var RpcRoomsApi = class {
|
|
|
4062
2924
|
merge
|
|
4063
2925
|
}
|
|
4064
2926
|
);
|
|
4065
|
-
if (
|
|
2927
|
+
if (response?.success === false) {
|
|
4066
2928
|
throw new Error(response.error || "Failed to update room data");
|
|
4067
2929
|
}
|
|
4068
2930
|
return response.data;
|
|
@@ -4074,7 +2936,7 @@ var RpcRoomsApi = class {
|
|
|
4074
2936
|
roomId: room.id
|
|
4075
2937
|
}
|
|
4076
2938
|
);
|
|
4077
|
-
if (
|
|
2939
|
+
if (response?.success === false) {
|
|
4078
2940
|
throw new Error(response.error || "Failed to get room data");
|
|
4079
2941
|
}
|
|
4080
2942
|
return response.data;
|
|
@@ -4087,7 +2949,7 @@ var RpcRoomsApi = class {
|
|
|
4087
2949
|
message: messageData
|
|
4088
2950
|
}
|
|
4089
2951
|
);
|
|
4090
|
-
if (
|
|
2952
|
+
if (response?.success === false) {
|
|
4091
2953
|
throw new Error(response.error || "Failed to send message");
|
|
4092
2954
|
}
|
|
4093
2955
|
return response.messageId;
|
|
@@ -4099,7 +2961,7 @@ var RpcRoomsApi = class {
|
|
|
4099
2961
|
roomId: room.id
|
|
4100
2962
|
}
|
|
4101
2963
|
);
|
|
4102
|
-
if (
|
|
2964
|
+
if (response?.success === false) {
|
|
4103
2965
|
throw new Error(response.error || "Failed to leave room");
|
|
4104
2966
|
}
|
|
4105
2967
|
return response;
|
|
@@ -4113,7 +2975,7 @@ var RpcRoomsApi = class {
|
|
|
4113
2975
|
turnOrder
|
|
4114
2976
|
}
|
|
4115
2977
|
);
|
|
4116
|
-
if (
|
|
2978
|
+
if (response?.success === false) {
|
|
4117
2979
|
throw new Error(response.error || "Failed to start game");
|
|
4118
2980
|
}
|
|
4119
2981
|
return response.data;
|
|
@@ -4129,7 +2991,7 @@ var RpcRoomsApi = class {
|
|
|
4129
2991
|
clientProposalId: proposalPayload.clientProposalId
|
|
4130
2992
|
}
|
|
4131
2993
|
);
|
|
4132
|
-
if (
|
|
2994
|
+
if (response?.success === false) {
|
|
4133
2995
|
throw new Error(response.error || "Failed to propose move");
|
|
4134
2996
|
}
|
|
4135
2997
|
return response.data;
|
|
@@ -4140,20 +3002,20 @@ var RpcRoomsApi = class {
|
|
|
4140
3002
|
}
|
|
4141
3003
|
async roomSubscribeToGameEvents(room, callback) {
|
|
4142
3004
|
"game_" + Date.now() + "_" + Math.random().toString(36).substr(2, 9);
|
|
4143
|
-
if (!
|
|
4144
|
-
|
|
3005
|
+
if (!this.subscriptions.gameEvents[room.id]) {
|
|
3006
|
+
this.subscriptions.gameEvents[room.id] = [];
|
|
4145
3007
|
}
|
|
4146
|
-
|
|
3008
|
+
this.subscriptions.gameEvents[room.id].push(callback);
|
|
4147
3009
|
}
|
|
4148
3010
|
subscribe(room, options = {}) {
|
|
4149
3011
|
const subscriptionIds = [];
|
|
4150
3012
|
const roomId = room.id;
|
|
4151
3013
|
if (options.onData) {
|
|
4152
3014
|
const dataSubId = "data_" + Date.now() + "_" + Math.random().toString(36).substr(2, 9);
|
|
4153
|
-
if (!
|
|
4154
|
-
|
|
3015
|
+
if (!this.subscriptions.data[roomId]) {
|
|
3016
|
+
this.subscriptions.data[roomId] = [];
|
|
4155
3017
|
}
|
|
4156
|
-
|
|
3018
|
+
this.subscriptions.data[roomId].push(options.onData);
|
|
4157
3019
|
subscriptionIds.push({
|
|
4158
3020
|
type: "data",
|
|
4159
3021
|
id: dataSubId,
|
|
@@ -4162,10 +3024,10 @@ var RpcRoomsApi = class {
|
|
|
4162
3024
|
}
|
|
4163
3025
|
if (options.onMessages) {
|
|
4164
3026
|
const msgSubId = "messages_" + Date.now() + "_" + Math.random().toString(36).substr(2, 9);
|
|
4165
|
-
if (!
|
|
4166
|
-
|
|
3027
|
+
if (!this.subscriptions.messages[roomId]) {
|
|
3028
|
+
this.subscriptions.messages[roomId] = [];
|
|
4167
3029
|
}
|
|
4168
|
-
|
|
3030
|
+
this.subscriptions.messages[roomId].push(options.onMessages);
|
|
4169
3031
|
subscriptionIds.push({
|
|
4170
3032
|
type: "messages",
|
|
4171
3033
|
id: msgSubId,
|
|
@@ -4174,18 +3036,20 @@ var RpcRoomsApi = class {
|
|
|
4174
3036
|
}
|
|
4175
3037
|
if (options.onMoves || options.onGameEvents) {
|
|
4176
3038
|
const handler = options.onMoves || options.onGameEvents;
|
|
4177
|
-
|
|
4178
|
-
|
|
4179
|
-
|
|
3039
|
+
if (handler) {
|
|
3040
|
+
const gameSubId = "game_" + Date.now() + "_" + Math.random().toString(36).substr(2, 9);
|
|
3041
|
+
if (!this.subscriptions.gameEvents[roomId]) {
|
|
3042
|
+
this.subscriptions.gameEvents[roomId] = [];
|
|
3043
|
+
}
|
|
3044
|
+
this.subscriptions.gameEvents[roomId].push(handler);
|
|
3045
|
+
subscriptionIds.push({
|
|
3046
|
+
type: "gameEvents",
|
|
3047
|
+
id: gameSubId,
|
|
3048
|
+
callback: handler
|
|
3049
|
+
});
|
|
4180
3050
|
}
|
|
4181
|
-
window.venus._roomSubscriptions.gameEvents[roomId].push(handler);
|
|
4182
|
-
subscriptionIds.push({
|
|
4183
|
-
type: "gameEvents",
|
|
4184
|
-
id: gameSubId,
|
|
4185
|
-
callback: handler
|
|
4186
|
-
});
|
|
4187
3051
|
}
|
|
4188
|
-
const needsSubscription = subscriptionIds.length > 0 && (
|
|
3052
|
+
const needsSubscription = subscriptionIds.length > 0 && (this.subscriptions.data[roomId]?.length ?? 0) <= 1 && (this.subscriptions.messages[roomId]?.length ?? 0) <= 1 && (this.subscriptions.gameEvents[roomId]?.length ?? 0) <= 1;
|
|
4189
3053
|
if (needsSubscription) {
|
|
4190
3054
|
this.rpcClient.call("H5_ROOM_SUBSCRIBE" /* H5_ROOM_SUBSCRIBE */, {
|
|
4191
3055
|
roomId,
|
|
@@ -4201,11 +3065,12 @@ var RpcRoomsApi = class {
|
|
|
4201
3065
|
if (called) return;
|
|
4202
3066
|
called = true;
|
|
4203
3067
|
subscriptionIds.forEach((sub) => {
|
|
4204
|
-
const
|
|
3068
|
+
const bucket = this.subscriptions[sub.type];
|
|
3069
|
+
const callbacks = bucket && bucket[roomId] || [];
|
|
4205
3070
|
const index = callbacks.indexOf(sub.callback);
|
|
4206
3071
|
if (index > -1) callbacks.splice(index, 1);
|
|
4207
3072
|
});
|
|
4208
|
-
const hasNoCallbacks = (
|
|
3073
|
+
const hasNoCallbacks = (this.subscriptions.data[roomId]?.length ?? 0) === 0 && (this.subscriptions.messages[roomId]?.length ?? 0) === 0 && (this.subscriptions.gameEvents[roomId]?.length ?? 0) === 0;
|
|
4209
3074
|
if (hasNoCallbacks) {
|
|
4210
3075
|
this.rpcClient.call("H5_ROOM_UNSUBSCRIBE" /* H5_ROOM_UNSUBSCRIBE */, {
|
|
4211
3076
|
roomId
|
|
@@ -4244,6 +3109,7 @@ var RemoteHost = class {
|
|
|
4244
3109
|
__publicField(this, "rooms");
|
|
4245
3110
|
__publicField(this, "logging");
|
|
4246
3111
|
__publicField(this, "iap");
|
|
3112
|
+
__publicField(this, "preloader");
|
|
4247
3113
|
__publicField(this, "venusApi");
|
|
4248
3114
|
__publicField(this, "rpcClient");
|
|
4249
3115
|
__publicField(this, "_isInitialized", false);
|
|
@@ -4298,18 +3164,22 @@ var RemoteHost = class {
|
|
|
4298
3164
|
this.rooms = new RpcRoomsApi(rpcClient);
|
|
4299
3165
|
this.logging = new RpcLoggingApi(this, rpcClient);
|
|
4300
3166
|
this.iap = new RpcIapApi(rpcClient);
|
|
3167
|
+
this.preloader = new RpcPreloaderApi(rpcClient);
|
|
4301
3168
|
venusApi.isMock = () => false;
|
|
4302
3169
|
this.venusApi.sharedAssets = new RpcSharedAssetsApi(rpcClient, venusApi);
|
|
3170
|
+
initializeRoomsApi(this.venusApi, this);
|
|
4303
3171
|
console.log("[Venus SDK] Remote host created");
|
|
4304
3172
|
}
|
|
4305
3173
|
get isInitialized() {
|
|
4306
3174
|
return this._isInitialized;
|
|
4307
3175
|
}
|
|
4308
|
-
async initialize() {
|
|
3176
|
+
async initialize(options = {}) {
|
|
4309
3177
|
this.log("Initializing Remote Host...");
|
|
4310
3178
|
const transport = new VenusTransport();
|
|
4311
3179
|
transport.start();
|
|
4312
3180
|
this.rpcClient.start(transport);
|
|
3181
|
+
const roomsApi = this.rooms;
|
|
3182
|
+
roomsApi.setupNotifications(transport);
|
|
4313
3183
|
try {
|
|
4314
3184
|
this.log("Trying to initialize using NEW method...");
|
|
4315
3185
|
transport.instanceId = await this.initNew();
|
|
@@ -4369,6 +3239,26 @@ var RemoteHost = class {
|
|
|
4369
3239
|
{},
|
|
4370
3240
|
1e3
|
|
4371
3241
|
);
|
|
3242
|
+
if (response.profile) {
|
|
3243
|
+
const profile = response.profile;
|
|
3244
|
+
const sanitizedProfile = {
|
|
3245
|
+
id: profile.id,
|
|
3246
|
+
username: profile.username,
|
|
3247
|
+
avatarUrl: profile.avatarUrl ?? null,
|
|
3248
|
+
isAnonymous: Boolean(profile.isAnonymous)
|
|
3249
|
+
};
|
|
3250
|
+
if (typeof window !== "undefined") {
|
|
3251
|
+
const globalWindow = window;
|
|
3252
|
+
const venus = globalWindow.venus || (globalWindow.venus = {});
|
|
3253
|
+
venus.profile = sanitizedProfile;
|
|
3254
|
+
if (venus._config) {
|
|
3255
|
+
venus._config.profile = sanitizedProfile;
|
|
3256
|
+
}
|
|
3257
|
+
if (venus.config) {
|
|
3258
|
+
venus.config.profile = sanitizedProfile;
|
|
3259
|
+
}
|
|
3260
|
+
}
|
|
3261
|
+
}
|
|
4372
3262
|
return response.instanceId;
|
|
4373
3263
|
}
|
|
4374
3264
|
async initOld(transport) {
|
|
@@ -4407,6 +3297,7 @@ function createHost(venusApi, isMock) {
|
|
|
4407
3297
|
}
|
|
4408
3298
|
|
|
4409
3299
|
// src/venus-api/index.js
|
|
3300
|
+
init_rooms();
|
|
4410
3301
|
var HapticStyle = {
|
|
4411
3302
|
LIGHT: "light",
|
|
4412
3303
|
MEDIUM: "medium",
|
|
@@ -4521,12 +3412,7 @@ var VenusAPI2 = class {
|
|
|
4521
3412
|
// Static locale data at top level
|
|
4522
3413
|
locale: "en-US",
|
|
4523
3414
|
languageCode: "en",
|
|
4524
|
-
//
|
|
4525
|
-
profile: {
|
|
4526
|
-
id: "mock-profile-123",
|
|
4527
|
-
username: "MockProfile",
|
|
4528
|
-
avatarUrl: "https://i.pravatar.cc/150?u=mock"
|
|
4529
|
-
},
|
|
3415
|
+
// Note: Profile is now separate from config and accessed via getCurrentProfile()
|
|
4530
3416
|
// Complete environment info (matching buildStaticConfig)
|
|
4531
3417
|
environment: {
|
|
4532
3418
|
isDevelopment: true,
|
|
@@ -4596,11 +3482,7 @@ var VenusAPI2 = class {
|
|
|
4596
3482
|
this.config = createProxiedObject.call(this, "config", {
|
|
4597
3483
|
locale: "en-US",
|
|
4598
3484
|
languageCode: "en",
|
|
4599
|
-
|
|
4600
|
-
id: "mock-user-123",
|
|
4601
|
-
username: "Test User",
|
|
4602
|
-
avatarUrl: null
|
|
4603
|
-
},
|
|
3485
|
+
// Note: Profile is no longer in config - use getCurrentProfile() instead
|
|
4604
3486
|
environment: {
|
|
4605
3487
|
isDevelopment: true,
|
|
4606
3488
|
platform: typeof navigator !== "undefined" ? navigator.platform : "unknown",
|
|
@@ -4714,12 +3596,14 @@ var VenusAPI2 = class {
|
|
|
4714
3596
|
const host = createHost(this, !isInsideHostedEnv);
|
|
4715
3597
|
this.host = host;
|
|
4716
3598
|
initializeStorage(this, host);
|
|
3599
|
+
initializeRoomsApi(this, host);
|
|
4717
3600
|
initializeAds(this, host);
|
|
4718
3601
|
initializeTheme(this);
|
|
4719
3602
|
initializePopups(this, host);
|
|
4720
3603
|
initializeAnalytics(this, host);
|
|
4721
3604
|
initializeIap(this, host);
|
|
4722
3605
|
initializeLocalNotifications(this, host);
|
|
3606
|
+
initializePreloader(this, host);
|
|
4723
3607
|
initializeTime(this, host);
|
|
4724
3608
|
initializeLifecycleApi(this, host);
|
|
4725
3609
|
initializeHaptics(this, host);
|
|
@@ -4734,7 +3618,6 @@ var VenusAPI2 = class {
|
|
|
4734
3618
|
initializeStackNavigation(this, host);
|
|
4735
3619
|
initializePost(this, host);
|
|
4736
3620
|
initializeAi(this, host);
|
|
4737
|
-
initializeRooms(this);
|
|
4738
3621
|
initializeSimulation(this, host);
|
|
4739
3622
|
initializeAssetLoader(this, createProxiedMethod);
|
|
4740
3623
|
}
|
|
@@ -4790,7 +3673,9 @@ var VenusAPI2 = class {
|
|
|
4790
3673
|
this.config.languageCode = this._mock.localeOverride.split("-")[0];
|
|
4791
3674
|
}
|
|
4792
3675
|
if (this._mock.roomsData) {
|
|
4793
|
-
|
|
3676
|
+
console.warn(
|
|
3677
|
+
"[Venus Mock] Rooms mock data is no longer supported. Rooms functionality requires the Venus host environment."
|
|
3678
|
+
);
|
|
4794
3679
|
}
|
|
4795
3680
|
}
|
|
4796
3681
|
//---------------------------------------
|
|
@@ -4810,7 +3695,8 @@ var VenusAPI2 = class {
|
|
|
4810
3695
|
"hardDisableMock",
|
|
4811
3696
|
"mock",
|
|
4812
3697
|
"helpText",
|
|
4813
|
-
"forceRemoteCdn"
|
|
3698
|
+
"forceRemoteCdn",
|
|
3699
|
+
"usePreloader"
|
|
4814
3700
|
];
|
|
4815
3701
|
const supportedMockParams = [
|
|
4816
3702
|
"initDelay",
|
|
@@ -4851,7 +3737,10 @@ var VenusAPI2 = class {
|
|
|
4851
3737
|
);
|
|
4852
3738
|
}
|
|
4853
3739
|
}
|
|
4854
|
-
await this.host.initialize();
|
|
3740
|
+
await this.host.initialize(options);
|
|
3741
|
+
if (!options.usePreloader) {
|
|
3742
|
+
await this.host.preloader.hideLoadScreen();
|
|
3743
|
+
}
|
|
4855
3744
|
if (this._bootstrap.isInsideHostedEnvironment) {
|
|
4856
3745
|
this._shared.initialized = true;
|
|
4857
3746
|
resolve(true);
|