@series-inc/venus-sdk 2.4.1 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +345 -249
- package/dist/AdsApi-3DEYUUuj.d.mts +1414 -0
- package/dist/AdsApi-3DEYUUuj.d.ts +1414 -0
- package/dist/{chunk-KQZIPQLJ.mjs → chunk-6DYG4RFQ.mjs} +2066 -133
- package/dist/chunk-6DYG4RFQ.mjs.map +1 -0
- package/dist/{chunk-MWUS3A7C.mjs → chunk-W7IPHM67.mjs} +22 -3
- package/dist/chunk-W7IPHM67.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 +2084 -129
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +253 -303
- package/dist/index.d.ts +253 -303
- package/dist/index.mjs +6 -2
- package/dist/index.mjs.map +1 -1
- package/dist/venus-api/index.cjs +1072 -1654
- 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 +31 -2552
- package/dist/venus-api/index.mjs.map +1 -1
- package/package.json +2 -2
- package/dist/AdsApi-Cz0XgLM8.d.mts +0 -851
- package/dist/AdsApi-Cz0XgLM8.d.ts +0 -851
- 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,
|
|
2
|
-
import { createProxiedObject, createProxiedMethod
|
|
1
|
+
import { init_rooms, SDK_VERSION, createHost, initializeStorage, initializeRoomsApi, initializeAds, initializePopups, initializeAnalytics, initializeIap, initializeLeaderboard, initializeLocalNotifications, initializePreloader, initializeTime, initializeLifecycleApi, initializeHaptics, initializeCdn, initializeFeaturesApi, initializeLoggingApi, initializeProfile, initializeAvatar3d, initializeStackNavigation, initializePost, initializeAi, initializeSimulation, initializeSocial } from '../chunk-6DYG4RFQ.mjs';
|
|
2
|
+
import { createProxiedObject, createProxiedMethod } 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,
|
|
@@ -2890,1532 +1955,17 @@ async function initializeNumbers(venusApiInstance) {
|
|
|
2890
1955
|
);
|
|
2891
1956
|
}
|
|
2892
1957
|
|
|
2893
|
-
// src/
|
|
2894
|
-
|
|
2895
|
-
|
|
2896
|
-
|
|
2897
|
-
|
|
2898
|
-
|
|
2899
|
-
|
|
2900
|
-
|
|
2901
|
-
|
|
2902
|
-
return venusApi._mock.currentPostInteractions;
|
|
2903
|
-
}
|
|
2904
|
-
async openCommentsAsync() {
|
|
2905
|
-
await createMockDelay(MOCK_DELAYS.short);
|
|
2906
|
-
return {
|
|
2907
|
-
opened: true,
|
|
2908
|
-
commentsCount: 0
|
|
2909
|
-
};
|
|
2910
|
-
}
|
|
2911
|
-
async sharePostAsync(context) {
|
|
2912
|
-
console.log("[Venus Mock] Sharing post with additionalInfo:", context);
|
|
2913
|
-
await createMockDelay(MOCK_DELAYS.short);
|
|
2914
|
-
return {
|
|
2915
|
-
shared: true,
|
|
2916
|
-
platform: "mock"
|
|
2917
|
-
};
|
|
2918
|
-
}
|
|
2919
|
-
async toggleFollowAsync() {
|
|
2920
|
-
const venusApi = this.venusApi;
|
|
2921
|
-
console.log("[Venus Mock] *Toggling follow status");
|
|
2922
|
-
await createMockDelay(MOCK_DELAYS.short);
|
|
2923
|
-
venusApi._mock.currentPostInteractions.isFollowing = !venusApi._mock.currentPostInteractions.isFollowing;
|
|
2924
|
-
const isFollowing = venusApi._mock.currentPostInteractions.isFollowing;
|
|
2925
|
-
return {
|
|
2926
|
-
isFollowing,
|
|
2927
|
-
action: isFollowing ? "followed" : "unfollowed"
|
|
2928
|
-
};
|
|
2929
|
-
}
|
|
2930
|
-
async toggleLikeAsync() {
|
|
2931
|
-
const venusApi = this.venusApi;
|
|
2932
|
-
await createMockDelay(MOCK_DELAYS.short);
|
|
2933
|
-
venusApi._mock.currentPostInteractions.isLiked = !venusApi._mock.currentPostInteractions.isLiked;
|
|
2934
|
-
const isLiked = venusApi._mock.currentPostInteractions.isLiked;
|
|
2935
|
-
if (isLiked) {
|
|
2936
|
-
venusApi._mock.currentPostInteractions.likesCount++;
|
|
2937
|
-
} else {
|
|
2938
|
-
venusApi._mock.currentPostInteractions.likesCount = Math.max(
|
|
2939
|
-
0,
|
|
2940
|
-
venusApi._mock.currentPostInteractions.likesCount - 1
|
|
2941
|
-
);
|
|
2942
|
-
}
|
|
2943
|
-
return {
|
|
2944
|
-
isLiked,
|
|
2945
|
-
likesCount: venusApi._mock.currentPostInteractions.likesCount,
|
|
2946
|
-
action: isLiked ? "liked" : "unliked"
|
|
2947
|
-
};
|
|
2948
|
-
}
|
|
2949
|
-
};
|
|
2950
|
-
|
|
2951
|
-
// src/post/RpcPostApi.ts
|
|
2952
|
-
var RpcPostApi = class {
|
|
2953
|
-
constructor(rpcClient) {
|
|
2954
|
-
__publicField(this, "rpcClient");
|
|
2955
|
-
this.rpcClient = rpcClient;
|
|
2956
|
-
}
|
|
2957
|
-
getPostInfo() {
|
|
2958
|
-
return this.rpcClient.call("H5_GET_POST_INTERACTIONS" /* GET_POST_INTERACTIONS */, {});
|
|
2959
|
-
}
|
|
2960
|
-
openCommentsAsync() {
|
|
2961
|
-
return this.rpcClient.call("H5_OPEN_COMMENTS" /* OPEN_COMMENTS */, {});
|
|
2962
|
-
}
|
|
2963
|
-
sharePostAsync(context) {
|
|
2964
|
-
return this.rpcClient.call("H5_SHARE_POST" /* SHARE_POST */, {
|
|
2965
|
-
shareContext: context
|
|
2966
|
-
});
|
|
2967
|
-
}
|
|
2968
|
-
toggleFollowAsync() {
|
|
2969
|
-
return this.rpcClient.call(
|
|
2970
|
-
"H5_TOGGLE_FOLLOW" /* TOGGLE_FOLLOW */,
|
|
2971
|
-
{}
|
|
2972
|
-
);
|
|
2973
|
-
}
|
|
2974
|
-
toggleLikeAsync() {
|
|
2975
|
-
return this.rpcClient.call("H5_TOGGLE_LIKE" /* TOGGLE_LIKE */, {});
|
|
2976
|
-
}
|
|
1958
|
+
// src/venus-api/index.js
|
|
1959
|
+
init_rooms();
|
|
1960
|
+
var HapticStyle = {
|
|
1961
|
+
LIGHT: "light",
|
|
1962
|
+
MEDIUM: "medium",
|
|
1963
|
+
HEAVY: "heavy",
|
|
1964
|
+
SUCCESS: "success",
|
|
1965
|
+
WARNING: "warning",
|
|
1966
|
+
ERROR: "error"
|
|
2977
1967
|
};
|
|
2978
|
-
|
|
2979
|
-
// src/post/index.ts
|
|
2980
|
-
function initializePost(venusApi, host) {
|
|
2981
|
-
venusApi.getPostInteractionsAsync = () => {
|
|
2982
|
-
return host.post.getPostInfo();
|
|
2983
|
-
};
|
|
2984
|
-
venusApi.toggleFollowAsync = () => {
|
|
2985
|
-
return host.post.toggleFollowAsync();
|
|
2986
|
-
};
|
|
2987
|
-
venusApi.toggleLikeAsync = () => {
|
|
2988
|
-
return host.post.toggleLikeAsync();
|
|
2989
|
-
};
|
|
2990
|
-
venusApi.sharePostAsync = async (options) => {
|
|
2991
|
-
await host.post.sharePostAsync(options);
|
|
2992
|
-
};
|
|
2993
|
-
venusApi.openCommentsAsync = async () => {
|
|
2994
|
-
await host.post.openCommentsAsync();
|
|
2995
|
-
};
|
|
2996
|
-
}
|
|
2997
|
-
|
|
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
|
-
// src/MockHost.ts
|
|
3035
|
-
var MockHost = class {
|
|
3036
|
-
constructor(venusApi) {
|
|
3037
|
-
__publicField(this, "ads");
|
|
3038
|
-
__publicField(this, "analytics");
|
|
3039
|
-
__publicField(this, "deviceCache");
|
|
3040
|
-
__publicField(this, "appStorage");
|
|
3041
|
-
__publicField(this, "globalStorage");
|
|
3042
|
-
__publicField(this, "avatar3d");
|
|
3043
|
-
__publicField(this, "navigation");
|
|
3044
|
-
__publicField(this, "notifications");
|
|
3045
|
-
__publicField(this, "popups");
|
|
3046
|
-
__publicField(this, "profile");
|
|
3047
|
-
__publicField(this, "cdn");
|
|
3048
|
-
__publicField(this, "time");
|
|
3049
|
-
__publicField(this, "post");
|
|
3050
|
-
__publicField(this, "ai");
|
|
3051
|
-
__publicField(this, "haptics");
|
|
3052
|
-
__publicField(this, "features");
|
|
3053
|
-
__publicField(this, "lifecycle");
|
|
3054
|
-
__publicField(this, "simulation");
|
|
3055
|
-
__publicField(this, "rooms");
|
|
3056
|
-
__publicField(this, "logging");
|
|
3057
|
-
__publicField(this, "iap");
|
|
3058
|
-
__publicField(this, "state", 0 /* PLAYING */);
|
|
3059
|
-
__publicField(this, "venusApi");
|
|
3060
|
-
__publicField(this, "_isInitialized", false);
|
|
3061
|
-
__publicField(this, "_overlay");
|
|
3062
|
-
__publicField(this, "_mockLifecyclesApi");
|
|
3063
|
-
__publicField(this, "_mockAdsApi");
|
|
3064
|
-
this.venusApi = venusApi;
|
|
3065
|
-
this._overlay = this.createOverlay();
|
|
3066
|
-
this._mockAdsApi = new MockAdsApi(this._overlay);
|
|
3067
|
-
this._mockLifecyclesApi = new MockLifecycleApi();
|
|
3068
|
-
this.ads = this._mockAdsApi;
|
|
3069
|
-
this.analytics = new MockAnalyticsApi();
|
|
3070
|
-
const appUrl = typeof window !== "undefined" ? window.location.href : "";
|
|
3071
|
-
this.deviceCache = createMockStorageApi("deviceCache", appUrl);
|
|
3072
|
-
this.appStorage = createMockStorageApi("appStorage", appUrl);
|
|
3073
|
-
this.globalStorage = createMockStorageApi("globalStorage");
|
|
3074
|
-
this.avatar3d = new MockAvatarApi(venusApi);
|
|
3075
|
-
this.navigation = new MockNavigationApi(venusApi);
|
|
3076
|
-
this.notifications = new MockNotificationsApi(venusApi);
|
|
3077
|
-
this.popups = new MockPopupsApi(this._overlay);
|
|
3078
|
-
this.profile = new MockProfileApi();
|
|
3079
|
-
this.cdn = new MockCdnApi();
|
|
3080
|
-
this.time = new MockTimeApi(venusApi);
|
|
3081
|
-
this.post = new MockPostApi(venusApi);
|
|
3082
|
-
this.ai = new MockAiApi();
|
|
3083
|
-
this.haptics = new MockHapticsApi(venusApi);
|
|
3084
|
-
this.features = new MockFeaturesApi();
|
|
3085
|
-
this.lifecycle = this._mockLifecyclesApi;
|
|
3086
|
-
this.simulation = new MockSimulationApi();
|
|
3087
|
-
this.rooms = new MockRoomsApi();
|
|
3088
|
-
this.logging = new MockLoggingApi();
|
|
3089
|
-
this.iap = new MockIapApi();
|
|
3090
|
-
venusApi.isMock = () => true;
|
|
3091
|
-
this.venusApi.sharedAssets = new MockSharedAssetsApi(this.venusApi);
|
|
3092
|
-
}
|
|
3093
|
-
get isInitialized() {
|
|
3094
|
-
return this._isInitialized;
|
|
3095
|
-
}
|
|
3096
|
-
initialize() {
|
|
3097
|
-
this._isInitialized = true;
|
|
3098
|
-
return Promise.resolve();
|
|
3099
|
-
}
|
|
3100
|
-
updateUiControls() {
|
|
3101
|
-
const controls = {
|
|
3102
|
-
closeButton: { x: 16, y: 16, width: 32, height: 32 },
|
|
3103
|
-
menuButton: {
|
|
3104
|
-
x: window.innerWidth - 48,
|
|
3105
|
-
y: 16,
|
|
3106
|
-
width: 32,
|
|
3107
|
-
height: 32
|
|
3108
|
-
},
|
|
3109
|
-
feedHeader: { x: 0, y: 0, width: window.innerWidth, height: 56 },
|
|
3110
|
-
playButton: {
|
|
3111
|
-
x: 0,
|
|
3112
|
-
y: window.innerHeight - 60,
|
|
3113
|
-
width: window.innerWidth,
|
|
3114
|
-
height: 60
|
|
3115
|
-
}
|
|
3116
|
-
};
|
|
3117
|
-
return controls;
|
|
3118
|
-
}
|
|
3119
|
-
createOverlay() {
|
|
3120
|
-
const venusApi = this.venusApi;
|
|
3121
|
-
venusApi.config.ui.controls = this.updateUiControls();
|
|
3122
|
-
const uiControls = venusApi.config.ui.controls;
|
|
3123
|
-
const overlayContainer = document.createElement("div");
|
|
3124
|
-
overlayContainer.id = "venus-mock-overlay";
|
|
3125
|
-
overlayContainer.style.cssText = `
|
|
3126
|
-
position: fixed;
|
|
3127
|
-
top: 0;
|
|
3128
|
-
left: 0;
|
|
3129
|
-
width: 100%;
|
|
3130
|
-
height: 100%;
|
|
3131
|
-
pointer-events: none;
|
|
3132
|
-
z-index: 10000;
|
|
3133
|
-
`;
|
|
3134
|
-
document.body.appendChild(overlayContainer);
|
|
3135
|
-
const menuButton = this.createOverlayButton(
|
|
3136
|
-
"close",
|
|
3137
|
-
"Menu",
|
|
3138
|
-
uiControls.menuButton,
|
|
3139
|
-
() => {
|
|
3140
|
-
this.handleMenuButtonClicked();
|
|
3141
|
-
},
|
|
3142
|
-
"rgba(59, 130, 246, 0.7)",
|
|
3143
|
-
// Blue background instead of black
|
|
3144
|
-
"#FFFFFF"
|
|
3145
|
-
);
|
|
3146
|
-
overlayContainer.appendChild(menuButton);
|
|
3147
|
-
const adOverlay = this.setupAdOverlay();
|
|
3148
|
-
const actionSheet = this.setupActionSheetOverlay();
|
|
3149
|
-
window.addEventListener("resize", () => {
|
|
3150
|
-
this.updateOverlayLayout();
|
|
3151
|
-
});
|
|
3152
|
-
return {
|
|
3153
|
-
container: overlayContainer,
|
|
3154
|
-
elements: {
|
|
3155
|
-
menuButton
|
|
3156
|
-
},
|
|
3157
|
-
appVisibilityState: "visible",
|
|
3158
|
-
actionSheetOverlay: actionSheet,
|
|
3159
|
-
adOverlay,
|
|
3160
|
-
showAdOverlay: () => {
|
|
3161
|
-
return this.showAdOverlay("REWARDED VIDEO AD");
|
|
3162
|
-
},
|
|
3163
|
-
showActionSheet: (items, options) => {
|
|
3164
|
-
return this.showActionSheetOverlay(items, options);
|
|
3165
|
-
}
|
|
3166
|
-
};
|
|
3167
|
-
}
|
|
3168
|
-
async handleMenuButtonClicked() {
|
|
3169
|
-
this.triggerLifecycleEvent("PAUSE" /* PAUSE */);
|
|
3170
|
-
const sleepAwakeToggleAction = {
|
|
3171
|
-
label: "\u23F0 Awake",
|
|
3172
|
-
id: "sleepAwakeToggle"
|
|
3173
|
-
};
|
|
3174
|
-
if (this.state === 1 /* PAUSED */) {
|
|
3175
|
-
sleepAwakeToggleAction.label = "\u{1F4A4} Sleep";
|
|
3176
|
-
}
|
|
3177
|
-
const action = await this.showActionSheetOverlay([sleepAwakeToggleAction]);
|
|
3178
|
-
if (action === sleepAwakeToggleAction.id) {
|
|
3179
|
-
if (this.state === 1 /* PAUSED */) {
|
|
3180
|
-
this.state = 2 /* SLEEPING */;
|
|
3181
|
-
this.triggerLifecycleEvent("HIDDEN" /* HIDDEN */);
|
|
3182
|
-
} else {
|
|
3183
|
-
this.state = 1 /* PAUSED */;
|
|
3184
|
-
this.triggerLifecycleEvent("SHOWN" /* SHOWN */);
|
|
3185
|
-
}
|
|
3186
|
-
} else {
|
|
3187
|
-
if (this.state === 1 /* PAUSED */) {
|
|
3188
|
-
this.triggerLifecycleEvent("RESUME" /* RESUME */);
|
|
3189
|
-
}
|
|
3190
|
-
}
|
|
3191
|
-
}
|
|
3192
|
-
async showAdOverlay(type) {
|
|
3193
|
-
return new Promise((resolve, reject) => {
|
|
3194
|
-
const overlay = this._overlay;
|
|
3195
|
-
const adOverlay = overlay.adOverlay;
|
|
3196
|
-
overlay.adOverlay.innerHTML = "";
|
|
3197
|
-
const heading = document.createElement("h1");
|
|
3198
|
-
heading.style.cssText = `
|
|
3199
|
-
font-size: 24px;
|
|
3200
|
-
margin-bottom: 20px;
|
|
3201
|
-
text-align: center;
|
|
3202
|
-
`;
|
|
3203
|
-
heading.innerText = type === "interstitial" ? "INTERSTITIAL AD" : "REWARDED VIDEO AD";
|
|
3204
|
-
overlay.adOverlay.appendChild(heading);
|
|
3205
|
-
const content = document.createElement("div");
|
|
3206
|
-
content.style.cssText = `
|
|
3207
|
-
width: 300px;
|
|
3208
|
-
height: 250px;
|
|
3209
|
-
background-color: #1e40af;
|
|
3210
|
-
display: flex;
|
|
3211
|
-
align-items: center;
|
|
3212
|
-
justify-content: center;
|
|
3213
|
-
margin-bottom: 20px;
|
|
3214
|
-
border-radius: 8px;
|
|
3215
|
-
`;
|
|
3216
|
-
content.innerText = "Mock Ad Content";
|
|
3217
|
-
adOverlay.appendChild(content);
|
|
3218
|
-
const timer = document.createElement("p");
|
|
3219
|
-
timer.style.cssText = `
|
|
3220
|
-
margin-bottom: 20px;
|
|
3221
|
-
font-size: 16px;
|
|
3222
|
-
`;
|
|
3223
|
-
timer.innerText = "Normally ads would have a timer...";
|
|
3224
|
-
adOverlay.appendChild(timer);
|
|
3225
|
-
const okButton = document.createElement("button");
|
|
3226
|
-
okButton.style.cssText = `
|
|
3227
|
-
padding: 10px 40px;
|
|
3228
|
-
background-color: #2563eb;
|
|
3229
|
-
color: white;
|
|
3230
|
-
border: none;
|
|
3231
|
-
border-radius: 4px;
|
|
3232
|
-
font-size: 16px;
|
|
3233
|
-
cursor: pointer;
|
|
3234
|
-
`;
|
|
3235
|
-
okButton.innerText = "Close Ad";
|
|
3236
|
-
adOverlay.appendChild(okButton);
|
|
3237
|
-
adOverlay.style.display = "flex";
|
|
3238
|
-
okButton.onclick = () => {
|
|
3239
|
-
this.hideAdOverlay();
|
|
3240
|
-
resolve(true);
|
|
3241
|
-
};
|
|
3242
|
-
});
|
|
3243
|
-
}
|
|
3244
|
-
hideAdOverlay() {
|
|
3245
|
-
const overlay = this._overlay;
|
|
3246
|
-
if (overlay.adOverlay) {
|
|
3247
|
-
overlay.adOverlay.style.display = "none";
|
|
3248
|
-
}
|
|
3249
|
-
}
|
|
3250
|
-
setupActionSheetOverlay() {
|
|
3251
|
-
const actionSheetOverlay = document.createElement("div");
|
|
3252
|
-
actionSheetOverlay.id = "venus-action-sheet-overlay";
|
|
3253
|
-
actionSheetOverlay.style.cssText = `
|
|
3254
|
-
position: fixed;
|
|
3255
|
-
top: 0;
|
|
3256
|
-
left: 0;
|
|
3257
|
-
width: 100%;
|
|
3258
|
-
height: 100%;
|
|
3259
|
-
background-color: rgba(0, 0, 0, 0.5);
|
|
3260
|
-
display: flex;
|
|
3261
|
-
align-items: center;
|
|
3262
|
-
justify-content: center;
|
|
3263
|
-
z-index: 10600;
|
|
3264
|
-
font-family: sans-serif;
|
|
3265
|
-
display: none;
|
|
3266
|
-
`;
|
|
3267
|
-
document.body.appendChild(actionSheetOverlay);
|
|
3268
|
-
return actionSheetOverlay;
|
|
3269
|
-
}
|
|
3270
|
-
createOverlayButton(id, text, position, onClick, background, color) {
|
|
3271
|
-
const button = document.createElement("button");
|
|
3272
|
-
button.id = `venus-mock-${id}-button`;
|
|
3273
|
-
button.innerText = text;
|
|
3274
|
-
button.style.cssText = `
|
|
3275
|
-
position: absolute;
|
|
3276
|
-
left: ${position.x}px;
|
|
3277
|
-
top: ${position.y}px;
|
|
3278
|
-
width: ${position.width}px;
|
|
3279
|
-
min-width: ${position.width}px;
|
|
3280
|
-
height: ${position.height}px;
|
|
3281
|
-
background: ${background};
|
|
3282
|
-
color: ${color};
|
|
3283
|
-
border: none;
|
|
3284
|
-
border-radius: 8px;
|
|
3285
|
-
font-family: sans-serif;
|
|
3286
|
-
font-weight: bold;
|
|
3287
|
-
font-size: ${Math.min(position.width, position.height) / 3}px;
|
|
3288
|
-
cursor: pointer;
|
|
3289
|
-
pointer-events: auto;
|
|
3290
|
-
display: flex;
|
|
3291
|
-
align-items: center;
|
|
3292
|
-
justify-content: center;
|
|
3293
|
-
opacity: 0.9;
|
|
3294
|
-
transition: opacity 0.2s;
|
|
3295
|
-
`;
|
|
3296
|
-
button.addEventListener("click", onClick);
|
|
3297
|
-
button.addEventListener("mouseover", () => {
|
|
3298
|
-
button.style.opacity = "1";
|
|
3299
|
-
});
|
|
3300
|
-
button.addEventListener("mouseout", () => {
|
|
3301
|
-
button.style.opacity = "0.9";
|
|
3302
|
-
});
|
|
3303
|
-
return button;
|
|
3304
|
-
}
|
|
3305
|
-
updateOverlayLayout() {
|
|
3306
|
-
const venusApi = this.venusApi;
|
|
3307
|
-
const overlay = this._overlay;
|
|
3308
|
-
venusApi.config.ui.controls = this.updateUiControls();
|
|
3309
|
-
const uiControls = venusApi.config.ui.controls;
|
|
3310
|
-
const menuBtn = overlay.elements.menuButton;
|
|
3311
|
-
const menuPos = uiControls.menuButton;
|
|
3312
|
-
menuBtn.style.left = `${menuPos.x}px`;
|
|
3313
|
-
menuBtn.style.top = `${menuPos.y}px`;
|
|
3314
|
-
menuBtn.style.width = `${menuPos.width}px`;
|
|
3315
|
-
menuBtn.style.minWidth = `${menuPos.width}px`;
|
|
3316
|
-
menuBtn.style.height = `${menuPos.height}px`;
|
|
3317
|
-
}
|
|
3318
|
-
triggerLifecycleEvent(name) {
|
|
3319
|
-
console.log("Trigger Lifecycle Event: ", name);
|
|
3320
|
-
if (name == "PLAY" /* PLAY */) {
|
|
3321
|
-
this._mockLifecyclesApi.triggerOnPlayCallbacks({
|
|
3322
|
-
hudInsets: { top: 60, right: 0, bottom: 0, left: 0 },
|
|
3323
|
-
// shareData: {
|
|
3324
|
-
// title: 'Mock Share Title',
|
|
3325
|
-
// description: 'Mock share description for testing',
|
|
3326
|
-
// },
|
|
3327
|
-
format: "post"
|
|
3328
|
-
// stackData: null,
|
|
3329
|
-
});
|
|
3330
|
-
} else if (name == "PAUSE" /* PAUSE */) {
|
|
3331
|
-
this._mockLifecyclesApi.triggerOnPauseCallbacks();
|
|
3332
|
-
} else if (name == "RESUME" /* RESUME */) {
|
|
3333
|
-
this._mockLifecyclesApi.triggerOnResumeCallbacks();
|
|
3334
|
-
} else if (name == "QUIT" /* QUIT */) {
|
|
3335
|
-
this._mockLifecyclesApi.triggerOnQuitCallbacks();
|
|
3336
|
-
} else if (name == "SHOWN" /* SHOWN */) {
|
|
3337
|
-
this._mockLifecyclesApi.triggerOnShowCallbacks({
|
|
3338
|
-
hudInsets: { top: 60, bottom: 120, left: 0, right: 0 }
|
|
3339
|
-
});
|
|
3340
|
-
} else if (name == "HIDDEN" /* HIDDEN */) {
|
|
3341
|
-
this._mockLifecyclesApi.triggerOnHideCallbacks();
|
|
3342
|
-
}
|
|
3343
|
-
}
|
|
3344
|
-
setOverlayElementVisibility(element, visible) {
|
|
3345
|
-
const overlay = this._overlay;
|
|
3346
|
-
const elements = overlay.elements;
|
|
3347
|
-
if (elements[element]) {
|
|
3348
|
-
elements[element].style.display = visible ? "flex" : "none";
|
|
3349
|
-
}
|
|
3350
|
-
}
|
|
3351
|
-
setupAdOverlay() {
|
|
3352
|
-
const adOverlay = document.createElement("div");
|
|
3353
|
-
adOverlay.id = "venus-ad-overlay";
|
|
3354
|
-
adOverlay.style.cssText = `
|
|
3355
|
-
position: fixed;
|
|
3356
|
-
top: 0;
|
|
3357
|
-
left: 0;
|
|
3358
|
-
width: 100%;
|
|
3359
|
-
height: 100%;
|
|
3360
|
-
background-color: rgba(37, 99, 235, 0.9);
|
|
3361
|
-
color: white;
|
|
3362
|
-
display: flex;
|
|
3363
|
-
flex-direction: column;
|
|
3364
|
-
align-items: center;
|
|
3365
|
-
justify-content: center;
|
|
3366
|
-
z-index: 10500;
|
|
3367
|
-
font-family: sans-serif;
|
|
3368
|
-
display: none;
|
|
3369
|
-
`;
|
|
3370
|
-
document.body.appendChild(adOverlay);
|
|
3371
|
-
return adOverlay;
|
|
3372
|
-
}
|
|
3373
|
-
log(msg, ...args) {
|
|
3374
|
-
console.log(`[Venus Mock] ${msg}`, ...args);
|
|
3375
|
-
}
|
|
3376
|
-
showActionSheetOverlay(items, options) {
|
|
3377
|
-
this.log("Showing ActionSheetOverlay...");
|
|
3378
|
-
return new Promise((resolve, reject) => {
|
|
3379
|
-
const overlay = this._overlay;
|
|
3380
|
-
overlay.actionSheetOverlay.innerHTML = "";
|
|
3381
|
-
overlay.actionSheetOverlay.style.display = "flex";
|
|
3382
|
-
const actionSheet = document.createElement("div");
|
|
3383
|
-
actionSheet.className = "venus-action-sheet";
|
|
3384
|
-
actionSheet.style.cssText = `
|
|
3385
|
-
background-color: white;
|
|
3386
|
-
border-radius: 8px;
|
|
3387
|
-
width: 80%;
|
|
3388
|
-
max-width: 400px;
|
|
3389
|
-
max-height: 80%;
|
|
3390
|
-
display: flex;
|
|
3391
|
-
flex-direction: column;
|
|
3392
|
-
overflow: hidden;
|
|
3393
|
-
color: black;
|
|
3394
|
-
`;
|
|
3395
|
-
if (options?.title) {
|
|
3396
|
-
const titleContainer = document.createElement("div");
|
|
3397
|
-
titleContainer.style.cssText = `
|
|
3398
|
-
padding: 16px;
|
|
3399
|
-
border-bottom: 1px solid #eaeaea;
|
|
3400
|
-
font-weight: bold;
|
|
3401
|
-
font-size: 18px;
|
|
3402
|
-
text-align: center;
|
|
3403
|
-
color: black;
|
|
3404
|
-
`;
|
|
3405
|
-
titleContainer.innerText = options.title;
|
|
3406
|
-
actionSheet.appendChild(titleContainer);
|
|
3407
|
-
}
|
|
3408
|
-
if (options?.message) {
|
|
3409
|
-
const messageContainer = document.createElement("div");
|
|
3410
|
-
messageContainer.style.cssText = `
|
|
3411
|
-
padding: 8px 16px;
|
|
3412
|
-
color: #666;
|
|
3413
|
-
font-size: 14px;
|
|
3414
|
-
text-align: center;
|
|
3415
|
-
`;
|
|
3416
|
-
messageContainer.innerText = options.message;
|
|
3417
|
-
actionSheet.appendChild(messageContainer);
|
|
3418
|
-
}
|
|
3419
|
-
const optionsContainer = document.createElement("div");
|
|
3420
|
-
optionsContainer.style.cssText = `
|
|
3421
|
-
overflow-y: auto;
|
|
3422
|
-
max-height: 300px;
|
|
3423
|
-
`;
|
|
3424
|
-
items.forEach((item, index) => {
|
|
3425
|
-
const optionItem = document.createElement("div");
|
|
3426
|
-
optionItem.style.cssText = `
|
|
3427
|
-
padding: 12px 16px;
|
|
3428
|
-
border-bottom: 1px solid #eaeaea;
|
|
3429
|
-
cursor: pointer;
|
|
3430
|
-
display: flex;
|
|
3431
|
-
align-items: center;
|
|
3432
|
-
transition: background-color 0.2s;
|
|
3433
|
-
color: black;
|
|
3434
|
-
`;
|
|
3435
|
-
optionItem.addEventListener("mouseover", () => {
|
|
3436
|
-
optionItem.style.backgroundColor = "#f5f5f5";
|
|
3437
|
-
});
|
|
3438
|
-
optionItem.addEventListener("mouseout", () => {
|
|
3439
|
-
optionItem.style.backgroundColor = "white";
|
|
3440
|
-
});
|
|
3441
|
-
if (item.icon) {
|
|
3442
|
-
const iconSpan = document.createElement("span");
|
|
3443
|
-
iconSpan.style.cssText = `
|
|
3444
|
-
margin-right: 12px;
|
|
3445
|
-
font-size: 16px;
|
|
3446
|
-
`;
|
|
3447
|
-
iconSpan.innerText = item.icon;
|
|
3448
|
-
optionItem.appendChild(iconSpan);
|
|
3449
|
-
}
|
|
3450
|
-
const labelSpan = document.createElement("span");
|
|
3451
|
-
labelSpan.style.cssText = `
|
|
3452
|
-
color: black;
|
|
3453
|
-
`;
|
|
3454
|
-
labelSpan.innerText = item.label;
|
|
3455
|
-
optionItem.appendChild(labelSpan);
|
|
3456
|
-
optionItem.addEventListener("click", () => {
|
|
3457
|
-
this.hideActionSheetOverlay();
|
|
3458
|
-
const optionId = item.id !== void 0 ? item.id : index;
|
|
3459
|
-
resolve(optionId);
|
|
3460
|
-
});
|
|
3461
|
-
optionsContainer.appendChild(optionItem);
|
|
3462
|
-
});
|
|
3463
|
-
actionSheet.appendChild(optionsContainer);
|
|
3464
|
-
if (!options?.disableCancel) {
|
|
3465
|
-
const cancelButton = document.createElement("div");
|
|
3466
|
-
cancelButton.style.cssText = `
|
|
3467
|
-
padding: 14px 16px;
|
|
3468
|
-
text-align: center;
|
|
3469
|
-
font-weight: bold;
|
|
3470
|
-
cursor: pointer;
|
|
3471
|
-
color: #3b82f6;
|
|
3472
|
-
border-top: 1px solid #eaeaea;
|
|
3473
|
-
`;
|
|
3474
|
-
cancelButton.innerText = options?.cancelButtonText || "Cancel";
|
|
3475
|
-
cancelButton.addEventListener("click", () => {
|
|
3476
|
-
this.hideActionSheetOverlay();
|
|
3477
|
-
resolve(null);
|
|
3478
|
-
});
|
|
3479
|
-
actionSheet.appendChild(cancelButton);
|
|
3480
|
-
}
|
|
3481
|
-
if (!options?.disableCancel) {
|
|
3482
|
-
const closeButton = document.createElement("div");
|
|
3483
|
-
closeButton.style.cssText = `
|
|
3484
|
-
position: absolute;
|
|
3485
|
-
top: 8px;
|
|
3486
|
-
right: 8px;
|
|
3487
|
-
width: 24px;
|
|
3488
|
-
height: 24px;
|
|
3489
|
-
border-radius: 12px;
|
|
3490
|
-
background-color: rgba(0,0,0,0.1);
|
|
3491
|
-
color: #666;
|
|
3492
|
-
display: flex;
|
|
3493
|
-
align-items: center;
|
|
3494
|
-
justify-content: center;
|
|
3495
|
-
cursor: pointer;
|
|
3496
|
-
font-size: 14px;
|
|
3497
|
-
`;
|
|
3498
|
-
closeButton.innerText = "\u2715";
|
|
3499
|
-
closeButton.addEventListener("click", () => {
|
|
3500
|
-
this.hideActionSheetOverlay();
|
|
3501
|
-
resolve(null);
|
|
3502
|
-
});
|
|
3503
|
-
actionSheet.appendChild(closeButton);
|
|
3504
|
-
overlay.actionSheetOverlay.appendChild(actionSheet);
|
|
3505
|
-
}
|
|
3506
|
-
});
|
|
3507
|
-
}
|
|
3508
|
-
hideActionSheetOverlay() {
|
|
3509
|
-
const overlay = this._overlay;
|
|
3510
|
-
if (overlay.actionSheetOverlay) {
|
|
3511
|
-
overlay.actionSheetOverlay.style.display = "none";
|
|
3512
|
-
}
|
|
3513
|
-
}
|
|
3514
|
-
};
|
|
3515
|
-
|
|
3516
|
-
// src/VenusTransport.ts
|
|
3517
|
-
var VenusTransport = class {
|
|
3518
|
-
constructor() {
|
|
3519
|
-
__publicField(this, "messageHandler");
|
|
3520
|
-
__publicField(this, "onNotificationCallbacks", []);
|
|
3521
|
-
__publicField(this, "onNotificationCallbacksToRemove", []);
|
|
3522
|
-
__publicField(this, "onVenusMessageCallbacks", []);
|
|
3523
|
-
__publicField(this, "onResponseCallbacks", []);
|
|
3524
|
-
__publicField(this, "onResponseCallbacksToRemove", []);
|
|
3525
|
-
__publicField(this, "_instanceId", null);
|
|
3526
|
-
__publicField(this, "isStarted", false);
|
|
3527
|
-
__publicField(this, "isProcessingMessage", false);
|
|
3528
|
-
this.messageHandler = async (event) => {
|
|
3529
|
-
this.isProcessingMessage = true;
|
|
3530
|
-
let message;
|
|
3531
|
-
if (typeof event.data === "string") {
|
|
3532
|
-
message = JSON.parse(event.data);
|
|
3533
|
-
} else {
|
|
3534
|
-
message = event.data;
|
|
3535
|
-
}
|
|
3536
|
-
if (!message) {
|
|
3537
|
-
this.logInfo("No message found. Ignoring message...");
|
|
3538
|
-
return;
|
|
3539
|
-
}
|
|
3540
|
-
this.notifyVenusMessageReceived(message);
|
|
3541
|
-
if (message.type === "PLAY" /* PLAY */ || message.type === "PAUSE" /* PAUSE */ || message.type === "RESUME" /* RESUME */ || message.type === "SHOWN" /* SHOWN */ || message.type === "HIDDEN" /* HIDDEN */ || message.type === "CLEANUP" /* CLEANUP */ || message.type === "QUIT" /* QUIT */) {
|
|
3542
|
-
const notification = {
|
|
3543
|
-
type: "rpc-notification",
|
|
3544
|
-
id: message.type,
|
|
3545
|
-
payload: message.data
|
|
3546
|
-
};
|
|
3547
|
-
this.handleNotification(notification);
|
|
3548
|
-
this.isProcessingMessage = false;
|
|
3549
|
-
return;
|
|
3550
|
-
}
|
|
3551
|
-
const messageData = message.data;
|
|
3552
|
-
if (!messageData) {
|
|
3553
|
-
this.logWarn("No data found. Ignoring message...");
|
|
3554
|
-
this.isProcessingMessage = false;
|
|
3555
|
-
return;
|
|
3556
|
-
}
|
|
3557
|
-
const requestId = messageData.requestId;
|
|
3558
|
-
if (!requestId) {
|
|
3559
|
-
this.logWarn("No requestId. Ignoring message...");
|
|
3560
|
-
this.isProcessingMessage = false;
|
|
3561
|
-
return;
|
|
3562
|
-
}
|
|
3563
|
-
if (message.type !== "H5_RESPONSE" /* H5_RESPONSE */) {
|
|
3564
|
-
this.logWarn(`Ignoring unknown message type: ${message.type}`);
|
|
3565
|
-
this.isProcessingMessage = false;
|
|
3566
|
-
return;
|
|
3567
|
-
}
|
|
3568
|
-
const success = messageData.success;
|
|
3569
|
-
let error = void 0;
|
|
3570
|
-
if (!success) {
|
|
3571
|
-
error = {
|
|
3572
|
-
message: messageData.error || "Unknown error"
|
|
3573
|
-
};
|
|
3574
|
-
}
|
|
3575
|
-
let result = messageData.value;
|
|
3576
|
-
if (result === void 0) {
|
|
3577
|
-
result = messageData.data;
|
|
3578
|
-
}
|
|
3579
|
-
const response = {
|
|
3580
|
-
type: "rpc-response",
|
|
3581
|
-
id: requestId,
|
|
3582
|
-
result,
|
|
3583
|
-
method: message.type,
|
|
3584
|
-
error
|
|
3585
|
-
};
|
|
3586
|
-
await this.handleResponse(response);
|
|
3587
|
-
this.isProcessingMessage = false;
|
|
3588
|
-
};
|
|
3589
|
-
}
|
|
3590
|
-
onNotification(callback) {
|
|
3591
|
-
this.onNotificationCallbacks.push(callback);
|
|
3592
|
-
return {
|
|
3593
|
-
unsubscribe: () => {
|
|
3594
|
-
if (this.isProcessingMessage) {
|
|
3595
|
-
this.onNotificationCallbacks.push(callback);
|
|
3596
|
-
} else {
|
|
3597
|
-
this.removeOnNotificationCallback(callback);
|
|
3598
|
-
}
|
|
3599
|
-
}
|
|
3600
|
-
};
|
|
3601
|
-
}
|
|
3602
|
-
onRequest(callback) {
|
|
3603
|
-
throw new Error("Method not implemented.");
|
|
3604
|
-
}
|
|
3605
|
-
onResponse(callback) {
|
|
3606
|
-
this.onResponseCallbacks.push(callback);
|
|
3607
|
-
return {
|
|
3608
|
-
unsubscribe: () => {
|
|
3609
|
-
if (this.isProcessingMessage) {
|
|
3610
|
-
this.onResponseCallbacksToRemove.push(callback);
|
|
3611
|
-
} else {
|
|
3612
|
-
this.removeOnResponseCallback(callback);
|
|
3613
|
-
}
|
|
3614
|
-
}
|
|
3615
|
-
};
|
|
3616
|
-
}
|
|
3617
|
-
get instanceId() {
|
|
3618
|
-
return this._instanceId;
|
|
3619
|
-
}
|
|
3620
|
-
set instanceId(instanceId) {
|
|
3621
|
-
this._instanceId = instanceId;
|
|
3622
|
-
}
|
|
3623
|
-
sendRequest(request) {
|
|
3624
|
-
const instanceId = this.instanceId || "unknown";
|
|
3625
|
-
const method = request.method;
|
|
3626
|
-
const message = {
|
|
3627
|
-
type: method,
|
|
3628
|
-
direction: "H5_TO_APP",
|
|
3629
|
-
data: {
|
|
3630
|
-
...request.args,
|
|
3631
|
-
requestId: request.id
|
|
3632
|
-
},
|
|
3633
|
-
instanceId,
|
|
3634
|
-
timestamp: Date.now()
|
|
3635
|
-
};
|
|
3636
|
-
this.sendVenusMessage(message);
|
|
3637
|
-
}
|
|
3638
|
-
sendVenusMessage(message) {
|
|
3639
|
-
const messageAsString = JSON.stringify(message, null, 2);
|
|
3640
|
-
const reactNativeWebView = window.ReactNativeWebView;
|
|
3641
|
-
if (reactNativeWebView) {
|
|
3642
|
-
reactNativeWebView.postMessage(messageAsString);
|
|
3643
|
-
} else {
|
|
3644
|
-
window.parent.postMessage(messageAsString, "*");
|
|
3645
|
-
}
|
|
3646
|
-
}
|
|
3647
|
-
sendResponse(response) {
|
|
3648
|
-
throw new Error("Method not implemented.");
|
|
3649
|
-
}
|
|
3650
|
-
start() {
|
|
3651
|
-
if (this.isStarted) {
|
|
3652
|
-
return;
|
|
3653
|
-
}
|
|
3654
|
-
this.isStarted = true;
|
|
3655
|
-
window.addEventListener("message", this.messageHandler, true);
|
|
3656
|
-
this.logInfo(`Started`);
|
|
3657
|
-
}
|
|
3658
|
-
stop() {
|
|
3659
|
-
if (!this.isStarted) {
|
|
3660
|
-
return;
|
|
3661
|
-
}
|
|
3662
|
-
this.isStarted = false;
|
|
3663
|
-
window.removeEventListener("message", this.messageHandler);
|
|
3664
|
-
this.logInfo(`Stopped`);
|
|
3665
|
-
}
|
|
3666
|
-
handleNotification(notification) {
|
|
3667
|
-
for (const callback of this.onNotificationCallbacks) {
|
|
3668
|
-
callback(notification);
|
|
3669
|
-
}
|
|
3670
|
-
for (const callback of this.onNotificationCallbacksToRemove) {
|
|
3671
|
-
this.removeOnNotificationCallback(callback);
|
|
3672
|
-
}
|
|
3673
|
-
this.onNotificationCallbacksToRemove.length = 0;
|
|
3674
|
-
}
|
|
3675
|
-
async handleResponse(response) {
|
|
3676
|
-
for (const callback of this.onResponseCallbacks) {
|
|
3677
|
-
const consumed = await callback(response);
|
|
3678
|
-
if (consumed) {
|
|
3679
|
-
break;
|
|
3680
|
-
}
|
|
3681
|
-
}
|
|
3682
|
-
for (const callback of this.onResponseCallbacksToRemove) {
|
|
3683
|
-
this.removeOnResponseCallback(callback);
|
|
3684
|
-
}
|
|
3685
|
-
this.onResponseCallbacksToRemove.length = 0;
|
|
3686
|
-
}
|
|
3687
|
-
removeOnResponseCallback(callback) {
|
|
3688
|
-
this.onResponseCallbacks.splice(
|
|
3689
|
-
this.onResponseCallbacks.indexOf(callback),
|
|
3690
|
-
1
|
|
3691
|
-
);
|
|
3692
|
-
}
|
|
3693
|
-
removeOnNotificationCallback(callback) {
|
|
3694
|
-
this.onNotificationCallbacks.splice(
|
|
3695
|
-
this.onNotificationCallbacks.indexOf(callback),
|
|
3696
|
-
1
|
|
3697
|
-
);
|
|
3698
|
-
}
|
|
3699
|
-
logInfo(message, ...params) {
|
|
3700
|
-
console.log(`[Venus Transport] ${message}`, ...params);
|
|
3701
|
-
}
|
|
3702
|
-
logWarn(message, ...params) {
|
|
3703
|
-
console.warn(`[Venus Transport] ${message}`, ...params);
|
|
3704
|
-
}
|
|
3705
|
-
onVenusMessage(callback) {
|
|
3706
|
-
this.onVenusMessageCallbacks.push(callback);
|
|
3707
|
-
return {
|
|
3708
|
-
unsubscribe: () => {
|
|
3709
|
-
this.onVenusMessageCallbacks.splice(
|
|
3710
|
-
this.onVenusMessageCallbacks.indexOf(callback),
|
|
3711
|
-
1
|
|
3712
|
-
);
|
|
3713
|
-
}
|
|
3714
|
-
};
|
|
3715
|
-
}
|
|
3716
|
-
notifyVenusMessageReceived(message) {
|
|
3717
|
-
for (const callback of this.onVenusMessageCallbacks) {
|
|
3718
|
-
callback(message);
|
|
3719
|
-
}
|
|
3720
|
-
}
|
|
3721
|
-
};
|
|
3722
|
-
|
|
3723
|
-
// src/notifications/RpcNotificationsApi.ts
|
|
3724
|
-
var RpcNotificationsApi = class {
|
|
3725
|
-
constructor(rpcClient) {
|
|
3726
|
-
__publicField(this, "rpcClient");
|
|
3727
|
-
this.rpcClient = rpcClient;
|
|
3728
|
-
}
|
|
3729
|
-
async scheduleLocalNotification(title, body, options) {
|
|
3730
|
-
const request = {
|
|
3731
|
-
title,
|
|
3732
|
-
body,
|
|
3733
|
-
data: options?.payload,
|
|
3734
|
-
key: options?.groupId,
|
|
3735
|
-
priority: options?.priority || 1,
|
|
3736
|
-
trigger: options?.trigger ?? null
|
|
3737
|
-
};
|
|
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
|
-
}
|
|
3772
|
-
async isLocalNotificationsEnabled() {
|
|
3773
|
-
const response = await this.rpcClient.call(
|
|
3774
|
-
"H5_IS_LOCAL_NOTIFICATIONS_ENABLED" /* IS_LOCAL_NOTIFICATIONS_ENABLED */,
|
|
3775
|
-
{}
|
|
3776
|
-
);
|
|
3777
|
-
return response.enabled;
|
|
3778
|
-
}
|
|
3779
|
-
async setLocalNotificationsEnabled(enabled) {
|
|
3780
|
-
const response = await this.rpcClient.call(
|
|
3781
|
-
"H5_SET_LOCAL_NOTIFICATIONS_ENABLED" /* SET_LOCAL_NOTIFICATIONS_ENABLED */,
|
|
3782
|
-
{
|
|
3783
|
-
enabled
|
|
3784
|
-
}
|
|
3785
|
-
);
|
|
3786
|
-
return response.enabled;
|
|
3787
|
-
}
|
|
3788
|
-
};
|
|
3789
|
-
|
|
3790
|
-
// src/rooms/VenusRoom.ts
|
|
3791
|
-
var VenusRoom = class {
|
|
3792
|
-
constructor(roomData) {
|
|
3793
|
-
__publicField(this, "id");
|
|
3794
|
-
__publicField(this, "name");
|
|
3795
|
-
__publicField(this, "players");
|
|
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] = [];
|
|
3866
|
-
}
|
|
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
|
-
}
|
|
3895
|
-
async createRoom(options) {
|
|
3896
|
-
const response = await this.rpcClient.call(
|
|
3897
|
-
"H5_ROOM_CREATE" /* H5_ROOM_CREATE */,
|
|
3898
|
-
{
|
|
3899
|
-
options
|
|
3900
|
-
}
|
|
3901
|
-
);
|
|
3902
|
-
if (response.success === false) {
|
|
3903
|
-
throw new Error(response.error || "Failed to create room");
|
|
3904
|
-
}
|
|
3905
|
-
const roomData = response.roomData || response;
|
|
3906
|
-
const room = new VenusRoom(roomData);
|
|
3907
|
-
return room;
|
|
3908
|
-
}
|
|
3909
|
-
async joinOrCreateRoom(options) {
|
|
3910
|
-
const response = await this.rpcClient.call(
|
|
3911
|
-
"H5_ROOM_JOIN_OR_CREATE" /* H5_ROOM_JOIN_OR_CREATE */,
|
|
3912
|
-
{
|
|
3913
|
-
options
|
|
3914
|
-
}
|
|
3915
|
-
);
|
|
3916
|
-
if (response.success === false) {
|
|
3917
|
-
throw new Error(response.error || "Failed to join or create room");
|
|
3918
|
-
}
|
|
3919
|
-
const data = response.value || response;
|
|
3920
|
-
const room = new VenusRoom(data.roomData);
|
|
3921
|
-
return {
|
|
3922
|
-
action: data.action,
|
|
3923
|
-
room,
|
|
3924
|
-
playersJoined: data.playersJoined
|
|
3925
|
-
};
|
|
3926
|
-
}
|
|
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
|
-
async joinRoomByCode(roomCode) {
|
|
3955
|
-
const response = await this.rpcClient.call(
|
|
3956
|
-
"H5_ROOM_JOIN_BY_CODE" /* H5_ROOM_JOIN_BY_CODE */,
|
|
3957
|
-
{
|
|
3958
|
-
roomCode
|
|
3959
|
-
}
|
|
3960
|
-
);
|
|
3961
|
-
if (!response.success) {
|
|
3962
|
-
throw new Error(response.error || "Failed to join room by code");
|
|
3963
|
-
}
|
|
3964
|
-
const roomData = response.roomData || response;
|
|
3965
|
-
const room = new VenusRoom(roomData);
|
|
3966
|
-
return room;
|
|
3967
|
-
}
|
|
3968
|
-
// Get user's rooms with optional filtering
|
|
3969
|
-
async getUserRooms(appId, includeArchived = false) {
|
|
3970
|
-
const response = await this.rpcClient.call(
|
|
3971
|
-
"H5_ROOM_GET_USER_ROOMS" /* H5_ROOM_GET_USER_ROOMS */,
|
|
3972
|
-
{
|
|
3973
|
-
appId,
|
|
3974
|
-
includePersonal: includeArchived
|
|
3975
|
-
}
|
|
3976
|
-
);
|
|
3977
|
-
if (!response.success) {
|
|
3978
|
-
throw new Error(response.error || "Failed to get user rooms");
|
|
3979
|
-
}
|
|
3980
|
-
const rawRooms = response.rooms || [];
|
|
3981
|
-
const venusRooms = [];
|
|
3982
|
-
for (const roomData of rawRooms) {
|
|
3983
|
-
if (!roomData.id) {
|
|
3984
|
-
console.warn("getUserRooms: Skipping room with missing ID:", roomData);
|
|
3985
|
-
continue;
|
|
3986
|
-
}
|
|
3987
|
-
try {
|
|
3988
|
-
const venusRoom = new VenusRoom(roomData);
|
|
3989
|
-
venusRooms.push(venusRoom);
|
|
3990
|
-
} catch (error) {
|
|
3991
|
-
console.warn(
|
|
3992
|
-
"getUserRooms: Failed to create VenusRoom object:",
|
|
3993
|
-
error,
|
|
3994
|
-
roomData
|
|
3995
|
-
);
|
|
3996
|
-
}
|
|
3997
|
-
}
|
|
3998
|
-
return venusRooms;
|
|
3999
|
-
}
|
|
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
|
-
async updateData(room, updates, merge = true) {
|
|
4057
|
-
const response = await this.rpcClient.call(
|
|
4058
|
-
"H5_ROOM_UPDATE_DATA" /* H5_ROOM_UPDATE_DATA */,
|
|
4059
|
-
{
|
|
4060
|
-
roomId: room.id,
|
|
4061
|
-
updates,
|
|
4062
|
-
merge
|
|
4063
|
-
}
|
|
4064
|
-
);
|
|
4065
|
-
if (!response.success) {
|
|
4066
|
-
throw new Error(response.error || "Failed to update room data");
|
|
4067
|
-
}
|
|
4068
|
-
return response.data;
|
|
4069
|
-
}
|
|
4070
|
-
async getData(room) {
|
|
4071
|
-
const response = await this.rpcClient.call(
|
|
4072
|
-
"H5_ROOM_GET_DATA" /* H5_ROOM_GET_DATA */,
|
|
4073
|
-
{
|
|
4074
|
-
roomId: room.id
|
|
4075
|
-
}
|
|
4076
|
-
);
|
|
4077
|
-
if (!response.success) {
|
|
4078
|
-
throw new Error(response.error || "Failed to get room data");
|
|
4079
|
-
}
|
|
4080
|
-
return response.data;
|
|
4081
|
-
}
|
|
4082
|
-
async sendMessage(venusRoom, messageData) {
|
|
4083
|
-
const response = await this.rpcClient.call(
|
|
4084
|
-
"H5_ROOM_SEND_MESSAGE" /* H5_ROOM_SEND_MESSAGE */,
|
|
4085
|
-
{
|
|
4086
|
-
roomId: venusRoom.id,
|
|
4087
|
-
message: messageData
|
|
4088
|
-
}
|
|
4089
|
-
);
|
|
4090
|
-
if (!response.success) {
|
|
4091
|
-
throw new Error(response.error || "Failed to send message");
|
|
4092
|
-
}
|
|
4093
|
-
return response.messageId;
|
|
4094
|
-
}
|
|
4095
|
-
async leave(room) {
|
|
4096
|
-
const response = await this.rpcClient.call(
|
|
4097
|
-
"H5_ROOM_LEAVE" /* H5_ROOM_LEAVE */,
|
|
4098
|
-
{
|
|
4099
|
-
roomId: room.id
|
|
4100
|
-
}
|
|
4101
|
-
);
|
|
4102
|
-
if (!response.success) {
|
|
4103
|
-
throw new Error(response.error || "Failed to leave room");
|
|
4104
|
-
}
|
|
4105
|
-
return response;
|
|
4106
|
-
}
|
|
4107
|
-
async startGame(room, gameConfig = {}, turnOrder = null) {
|
|
4108
|
-
const response = await this.rpcClient.call(
|
|
4109
|
-
"H5_ROOM_START_GAME" /* H5_ROOM_START_GAME */,
|
|
4110
|
-
{
|
|
4111
|
-
roomId: room.id,
|
|
4112
|
-
gameConfig,
|
|
4113
|
-
turnOrder
|
|
4114
|
-
}
|
|
4115
|
-
);
|
|
4116
|
-
if (!response.success) {
|
|
4117
|
-
throw new Error(response.error || "Failed to start game");
|
|
4118
|
-
}
|
|
4119
|
-
return response.data;
|
|
4120
|
-
}
|
|
4121
|
-
async proposeMove(room, proposalPayload) {
|
|
4122
|
-
const response = await this.rpcClient.call(
|
|
4123
|
-
"h5:room:proposeMove" /* H5_ROOM_PROPOSE_MOVE */,
|
|
4124
|
-
{
|
|
4125
|
-
roomId: room.id,
|
|
4126
|
-
gameSpecificState: proposalPayload.gameSpecificState,
|
|
4127
|
-
moveType: proposalPayload.moveType,
|
|
4128
|
-
clientContext: proposalPayload.clientContext,
|
|
4129
|
-
clientProposalId: proposalPayload.clientProposalId
|
|
4130
|
-
}
|
|
4131
|
-
);
|
|
4132
|
-
if (!response.success) {
|
|
4133
|
-
throw new Error(response.error || "Failed to propose move");
|
|
4134
|
-
}
|
|
4135
|
-
return response.data;
|
|
4136
|
-
}
|
|
4137
|
-
async validateMove(room, moveId, isValid, reason = null, validatorId = null) {
|
|
4138
|
-
console.log(`[Venus Rooms] Validating move ${moveId}: ${isValid}`);
|
|
4139
|
-
return { success: true, moveId, isValid, reason };
|
|
4140
|
-
}
|
|
4141
|
-
async roomSubscribeToGameEvents(room, callback) {
|
|
4142
|
-
"game_" + Date.now() + "_" + Math.random().toString(36).substr(2, 9);
|
|
4143
|
-
if (!window.venus._roomSubscriptions.gameEvents[room.id]) {
|
|
4144
|
-
window.venus._roomSubscriptions.gameEvents[room.id] = [];
|
|
4145
|
-
}
|
|
4146
|
-
window.venus._roomSubscriptions.gameEvents[room.id].push(callback);
|
|
4147
|
-
}
|
|
4148
|
-
subscribe(room, options = {}) {
|
|
4149
|
-
const subscriptionIds = [];
|
|
4150
|
-
const roomId = room.id;
|
|
4151
|
-
if (options.onData) {
|
|
4152
|
-
const dataSubId = "data_" + Date.now() + "_" + Math.random().toString(36).substr(2, 9);
|
|
4153
|
-
if (!window.venus._roomSubscriptions.data[roomId]) {
|
|
4154
|
-
window.venus._roomSubscriptions.data[roomId] = [];
|
|
4155
|
-
}
|
|
4156
|
-
window.venus._roomSubscriptions.data[roomId].push(options.onData);
|
|
4157
|
-
subscriptionIds.push({
|
|
4158
|
-
type: "data",
|
|
4159
|
-
id: dataSubId,
|
|
4160
|
-
callback: options.onData
|
|
4161
|
-
});
|
|
4162
|
-
}
|
|
4163
|
-
if (options.onMessages) {
|
|
4164
|
-
const msgSubId = "messages_" + Date.now() + "_" + Math.random().toString(36).substr(2, 9);
|
|
4165
|
-
if (!window.venus._roomSubscriptions.messages[roomId]) {
|
|
4166
|
-
window.venus._roomSubscriptions.messages[roomId] = [];
|
|
4167
|
-
}
|
|
4168
|
-
window.venus._roomSubscriptions.messages[roomId].push(options.onMessages);
|
|
4169
|
-
subscriptionIds.push({
|
|
4170
|
-
type: "messages",
|
|
4171
|
-
id: msgSubId,
|
|
4172
|
-
callback: options.onMessages
|
|
4173
|
-
});
|
|
4174
|
-
}
|
|
4175
|
-
if (options.onMoves || options.onGameEvents) {
|
|
4176
|
-
const handler = options.onMoves || options.onGameEvents;
|
|
4177
|
-
const gameSubId = "game_" + Date.now() + "_" + Math.random().toString(36).substr(2, 9);
|
|
4178
|
-
if (!window.venus._roomSubscriptions.gameEvents[roomId]) {
|
|
4179
|
-
window.venus._roomSubscriptions.gameEvents[roomId] = [];
|
|
4180
|
-
}
|
|
4181
|
-
window.venus._roomSubscriptions.gameEvents[roomId].push(handler);
|
|
4182
|
-
subscriptionIds.push({
|
|
4183
|
-
type: "gameEvents",
|
|
4184
|
-
id: gameSubId,
|
|
4185
|
-
callback: handler
|
|
4186
|
-
});
|
|
4187
|
-
}
|
|
4188
|
-
const needsSubscription = subscriptionIds.length > 0 && (!window.venus._roomSubscriptions.data[roomId] || window.venus._roomSubscriptions.data[roomId].length <= 1) && (!window.venus._roomSubscriptions.messages[roomId] || window.venus._roomSubscriptions.messages[roomId].length <= 1) && (!window.venus._roomSubscriptions.gameEvents[roomId] || window.venus._roomSubscriptions.gameEvents[roomId].length <= 1);
|
|
4189
|
-
if (needsSubscription) {
|
|
4190
|
-
this.rpcClient.call("H5_ROOM_SUBSCRIBE" /* H5_ROOM_SUBSCRIBE */, {
|
|
4191
|
-
roomId,
|
|
4192
|
-
subscribeToData: !!options.onData,
|
|
4193
|
-
subscribeToMessages: !!options.onMessages,
|
|
4194
|
-
subscribeToProposedMoves: !!(options.onMoves || options.onGameEvents)
|
|
4195
|
-
}).catch((error) => {
|
|
4196
|
-
console.error("Failed to set up room subscription:", error);
|
|
4197
|
-
});
|
|
4198
|
-
}
|
|
4199
|
-
let called = false;
|
|
4200
|
-
return () => {
|
|
4201
|
-
if (called) return;
|
|
4202
|
-
called = true;
|
|
4203
|
-
subscriptionIds.forEach((sub) => {
|
|
4204
|
-
const callbacks = window.venus._roomSubscriptions[sub.type][roomId] || [];
|
|
4205
|
-
const index = callbacks.indexOf(sub.callback);
|
|
4206
|
-
if (index > -1) callbacks.splice(index, 1);
|
|
4207
|
-
});
|
|
4208
|
-
const hasNoCallbacks = (!window.venus._roomSubscriptions.data[roomId] || window.venus._roomSubscriptions.data[roomId].length === 0) && (!window.venus._roomSubscriptions.messages[roomId] || window.venus._roomSubscriptions.messages[roomId].length === 0) && (!window.venus._roomSubscriptions.gameEvents[roomId] || window.venus._roomSubscriptions.gameEvents[roomId].length === 0);
|
|
4209
|
-
if (hasNoCallbacks) {
|
|
4210
|
-
this.rpcClient.call("H5_ROOM_UNSUBSCRIBE" /* H5_ROOM_UNSUBSCRIBE */, {
|
|
4211
|
-
roomId
|
|
4212
|
-
}).catch((error) => {
|
|
4213
|
-
console.error("Failed to clean up room subscription:", error);
|
|
4214
|
-
});
|
|
4215
|
-
}
|
|
4216
|
-
};
|
|
4217
|
-
}
|
|
4218
|
-
};
|
|
4219
|
-
|
|
4220
|
-
// src/RemoteHost.ts
|
|
4221
|
-
var getCdnBaseUrl = () => {
|
|
4222
|
-
return "https://venus-static-01293ak.web.app/";
|
|
4223
|
-
};
|
|
4224
|
-
var RemoteHost = class {
|
|
4225
|
-
constructor(venusApi) {
|
|
4226
|
-
__publicField(this, "ads");
|
|
4227
|
-
__publicField(this, "analytics");
|
|
4228
|
-
__publicField(this, "deviceCache");
|
|
4229
|
-
__publicField(this, "appStorage");
|
|
4230
|
-
__publicField(this, "globalStorage");
|
|
4231
|
-
__publicField(this, "avatar3d");
|
|
4232
|
-
__publicField(this, "navigation");
|
|
4233
|
-
__publicField(this, "notifications");
|
|
4234
|
-
__publicField(this, "popups");
|
|
4235
|
-
__publicField(this, "profile");
|
|
4236
|
-
__publicField(this, "cdn");
|
|
4237
|
-
__publicField(this, "time");
|
|
4238
|
-
__publicField(this, "post");
|
|
4239
|
-
__publicField(this, "ai");
|
|
4240
|
-
__publicField(this, "haptics");
|
|
4241
|
-
__publicField(this, "features");
|
|
4242
|
-
__publicField(this, "lifecycle");
|
|
4243
|
-
__publicField(this, "simulation");
|
|
4244
|
-
__publicField(this, "rooms");
|
|
4245
|
-
__publicField(this, "logging");
|
|
4246
|
-
__publicField(this, "iap");
|
|
4247
|
-
__publicField(this, "venusApi");
|
|
4248
|
-
__publicField(this, "rpcClient");
|
|
4249
|
-
__publicField(this, "_isInitialized", false);
|
|
4250
|
-
this.venusApi = venusApi;
|
|
4251
|
-
const rpcClient = new RpcClient();
|
|
4252
|
-
this.rpcClient = rpcClient;
|
|
4253
|
-
this.ads = new RpcAdsApi(rpcClient);
|
|
4254
|
-
this.analytics = new RpcAnalyticsApi(rpcClient);
|
|
4255
|
-
this.deviceCache = new RpcStorageApi(rpcClient, {
|
|
4256
|
-
clear: "H5_DEVICE_CACHE_CLEAR" /* DEVICE_CACHE_CLEAR */,
|
|
4257
|
-
getItem: "H5_DEVICE_CACHE_GET_ITEM" /* DEVICE_CACHE_GET_ITEM */,
|
|
4258
|
-
getKey: "H5_DEVICE_CACHE_KEY" /* DEVICE_CACHE_KEY */,
|
|
4259
|
-
length: "H5_DEVICE_CACHE_LENGTH" /* DEVICE_CACHE_LENGTH */,
|
|
4260
|
-
removeItem: "H5_DEVICE_CACHE_REMOVE_ITEM" /* DEVICE_CACHE_REMOVE_ITEM */,
|
|
4261
|
-
setItem: "H5_DEVICE_CACHE_SET_ITEM" /* DEVICE_CACHE_SET_ITEM */
|
|
4262
|
-
});
|
|
4263
|
-
this.appStorage = new RpcStorageApi(rpcClient, {
|
|
4264
|
-
clear: "H5_APP_STORAGE_CLEAR" /* APP_STORAGE_CLEAR */,
|
|
4265
|
-
getItem: "H5_APP_STORAGE_GET_ITEM" /* APP_STORAGE_GET_ITEM */,
|
|
4266
|
-
getKey: "H5_APP_STORAGE_KEY" /* APP_STORAGE_KEY */,
|
|
4267
|
-
length: "H5_APP_STORAGE_LENGTH" /* APP_STORAGE_LENGTH */,
|
|
4268
|
-
removeItem: "H5_APP_STORAGE_REMOVE_ITEM" /* APP_STORAGE_REMOVE_ITEM */,
|
|
4269
|
-
setItem: "H5_APP_STORAGE_SET_ITEM" /* APP_STORAGE_SET_ITEM */,
|
|
4270
|
-
getAllItems: "H5_APP_STORAGE_GET_ALL_ITEMS" /* APP_STORAGE_GET_ALL_ITEMS */,
|
|
4271
|
-
setMultipleItems: "H5_APP_STORAGE_SET_ITEM" /* APP_STORAGE_SET_ITEM */,
|
|
4272
|
-
removeMultipleItems: "H5_APP_STORAGE_REMOVE_ITEM" /* APP_STORAGE_REMOVE_ITEM */
|
|
4273
|
-
});
|
|
4274
|
-
this.globalStorage = new RpcStorageApi(rpcClient, {
|
|
4275
|
-
clear: "H5_GLOBAL_STORAGE_CLEAR" /* GLOBAL_STORAGE_CLEAR */,
|
|
4276
|
-
getItem: "H5_GLOBAL_STORAGE_GET_ITEM" /* GLOBAL_STORAGE_GET_ITEM */,
|
|
4277
|
-
getKey: "H5_GLOBAL_STORAGE_KEY" /* GLOBAL_STORAGE_KEY */,
|
|
4278
|
-
length: "H5_GLOBAL_STORAGE_LENGTH" /* GLOBAL_STORAGE_LENGTH */,
|
|
4279
|
-
removeItem: "H5_GLOBAL_STORAGE_REMOVE_ITEM" /* GLOBAL_STORAGE_REMOVE_ITEM */,
|
|
4280
|
-
setItem: "H5_GLOBAL_STORAGE_SET_ITEM" /* GLOBAL_STORAGE_SET_ITEM */,
|
|
4281
|
-
getAllItems: "H5_GLOBAL_STORAGE_GET_ALL_ITEMS" /* GLOBAL_STORAGE_GET_ALL_ITEMS */,
|
|
4282
|
-
setMultipleItems: "H5_GLOBAL_STORAGE_SET_MULTIPLE_ITEMS" /* GLOBAL_STORAGE_SET_MULTIPLE_ITEMS */,
|
|
4283
|
-
removeMultipleItems: "H5_GLOBAL_STORAGE_REMOVE_MULTIPLE_ITEMS" /* GLOBAL_STORAGE_REMOVE_MULTIPLE_ITEMS */
|
|
4284
|
-
});
|
|
4285
|
-
this.avatar3d = new RpcAvatarApi(rpcClient, venusApi);
|
|
4286
|
-
this.navigation = new RpcNavigationApi(rpcClient, venusApi);
|
|
4287
|
-
this.notifications = new RpcNotificationsApi(rpcClient);
|
|
4288
|
-
this.popups = new RpcPopupsApi(rpcClient);
|
|
4289
|
-
this.profile = new HostProfileApi();
|
|
4290
|
-
this.cdn = new HostCdnApi(getCdnBaseUrl());
|
|
4291
|
-
this.time = new HostTimeApi(rpcClient);
|
|
4292
|
-
this.post = new RpcPostApi(rpcClient);
|
|
4293
|
-
this.ai = new RpcAiApi(rpcClient);
|
|
4294
|
-
this.haptics = new RpcHapticsApi(rpcClient);
|
|
4295
|
-
this.features = new RpcFeaturesApi(rpcClient);
|
|
4296
|
-
this.lifecycle = new RpcLifecycleApi(rpcClient);
|
|
4297
|
-
this.simulation = new RpcSimulationApi(rpcClient);
|
|
4298
|
-
this.rooms = new RpcRoomsApi(rpcClient);
|
|
4299
|
-
this.logging = new RpcLoggingApi(this, rpcClient);
|
|
4300
|
-
this.iap = new RpcIapApi(rpcClient);
|
|
4301
|
-
venusApi.isMock = () => false;
|
|
4302
|
-
this.venusApi.sharedAssets = new RpcSharedAssetsApi(rpcClient, venusApi);
|
|
4303
|
-
console.log("[Venus SDK] Remote host created");
|
|
4304
|
-
}
|
|
4305
|
-
get isInitialized() {
|
|
4306
|
-
return this._isInitialized;
|
|
4307
|
-
}
|
|
4308
|
-
async initialize() {
|
|
4309
|
-
this.log("Initializing Remote Host...");
|
|
4310
|
-
const transport = new VenusTransport();
|
|
4311
|
-
transport.start();
|
|
4312
|
-
this.rpcClient.start(transport);
|
|
4313
|
-
try {
|
|
4314
|
-
this.log("Trying to initialize using NEW method...");
|
|
4315
|
-
transport.instanceId = await this.initNew();
|
|
4316
|
-
} catch (error) {
|
|
4317
|
-
this.log(`Failed to initialize using NEW method: ${error}`);
|
|
4318
|
-
this.log(`Trying to initialize using OLD method...`);
|
|
4319
|
-
transport.instanceId = await this.initOld(transport);
|
|
4320
|
-
}
|
|
4321
|
-
this.log(`Remote Host Initialized with id: ${transport.instanceId}`);
|
|
4322
|
-
this._isInitialized = true;
|
|
4323
|
-
this.venusApi._bootstrap.apiInjected = true;
|
|
4324
|
-
this.venusApi._bootstrap.venus = window.venus;
|
|
4325
|
-
await this.rpcClient.call("READY" /* READY */, {});
|
|
4326
|
-
}
|
|
4327
|
-
registerIFrame(transport) {
|
|
4328
|
-
return new Promise((resolve, reject) => {
|
|
4329
|
-
this.log("Registering IFrame...");
|
|
4330
|
-
const location = window.location;
|
|
4331
|
-
const pathName = location.pathname;
|
|
4332
|
-
const tokens = pathName.split("/");
|
|
4333
|
-
const appId = tokens[2];
|
|
4334
|
-
console.log("[Venus SDK] App ID ", appId);
|
|
4335
|
-
const registrationMessage = {
|
|
4336
|
-
type: "H5_IFRAME_REGISTER",
|
|
4337
|
-
instanceId: appId,
|
|
4338
|
-
direction: "H5_TO_APP",
|
|
4339
|
-
timestamp: Date.now()
|
|
4340
|
-
};
|
|
4341
|
-
const subscription = transport.onVenusMessage((message) => {
|
|
4342
|
-
if (message.type == "INJECT_VENUS_API_SCRIPT") {
|
|
4343
|
-
const scriptContent = message.data?.script;
|
|
4344
|
-
if (!scriptContent) {
|
|
4345
|
-
throw new Error("Failed to inject venus api, no script found.");
|
|
4346
|
-
}
|
|
4347
|
-
const script = document.createElement("script");
|
|
4348
|
-
script.type = "text/javascript";
|
|
4349
|
-
script.textContent = scriptContent;
|
|
4350
|
-
document.head.appendChild(script);
|
|
4351
|
-
setTimeout(() => {
|
|
4352
|
-
if (window.venus) {
|
|
4353
|
-
subscription.unsubscribe();
|
|
4354
|
-
resolve(window.venus?._config?.instanceId);
|
|
4355
|
-
}
|
|
4356
|
-
}, 100);
|
|
4357
|
-
}
|
|
4358
|
-
});
|
|
4359
|
-
transport.sendVenusMessage(registrationMessage);
|
|
4360
|
-
setTimeout(() => {
|
|
4361
|
-
subscription.unsubscribe();
|
|
4362
|
-
reject();
|
|
4363
|
-
}, 1e3);
|
|
4364
|
-
});
|
|
4365
|
-
}
|
|
4366
|
-
async initNew() {
|
|
4367
|
-
const response = await this.rpcClient.call(
|
|
4368
|
-
"INITIALIZE_SDK" /* INIT_SDK */,
|
|
4369
|
-
{},
|
|
4370
|
-
1e3
|
|
4371
|
-
);
|
|
4372
|
-
return response.instanceId;
|
|
4373
|
-
}
|
|
4374
|
-
async initOld(transport) {
|
|
4375
|
-
const isInIframe = window.self !== window.top;
|
|
4376
|
-
const hasReactNativeWebView = typeof window.ReactNativeWebView !== "undefined";
|
|
4377
|
-
if (hasReactNativeWebView) {
|
|
4378
|
-
return this.useInjectedId();
|
|
4379
|
-
} else if (isInIframe) {
|
|
4380
|
-
return await this.registerIFrame(transport);
|
|
4381
|
-
} else {
|
|
4382
|
-
throw new Error("Failed to initialize. Unknown Error");
|
|
4383
|
-
}
|
|
4384
|
-
}
|
|
4385
|
-
useInjectedId() {
|
|
4386
|
-
const instanceId = window.venus?._config?.instanceId || window._venusInitState?.poolId;
|
|
4387
|
-
this.log(`On mobile, using injected instanceId: ${instanceId}`);
|
|
4388
|
-
if (!instanceId) {
|
|
4389
|
-
throw new Error("Expected injected instanceId on mobile");
|
|
4390
|
-
}
|
|
4391
|
-
return instanceId;
|
|
4392
|
-
}
|
|
4393
|
-
log(message) {
|
|
4394
|
-
console.log(`[Venus SDK] [Remote Host] ${message}`);
|
|
4395
|
-
}
|
|
4396
|
-
};
|
|
4397
|
-
|
|
4398
|
-
// src/Host.ts
|
|
4399
|
-
function createHost(venusApi, isMock) {
|
|
4400
|
-
if (isMock) {
|
|
4401
|
-
console.log("[Venus SDK] Creating Local Host");
|
|
4402
|
-
return new MockHost(venusApi);
|
|
4403
|
-
} else {
|
|
4404
|
-
console.log("[Venus SDK] Creating Remote Host");
|
|
4405
|
-
return new RemoteHost(venusApi);
|
|
4406
|
-
}
|
|
4407
|
-
}
|
|
4408
|
-
|
|
4409
|
-
// src/venus-api/index.js
|
|
4410
|
-
var HapticStyle = {
|
|
4411
|
-
LIGHT: "light",
|
|
4412
|
-
MEDIUM: "medium",
|
|
4413
|
-
HEAVY: "heavy",
|
|
4414
|
-
SUCCESS: "success",
|
|
4415
|
-
WARNING: "warning",
|
|
4416
|
-
ERROR: "error"
|
|
4417
|
-
};
|
|
4418
|
-
var VenusAPI2 = class {
|
|
1968
|
+
var VenusAPI2 = class {
|
|
4419
1969
|
constructor() {
|
|
4420
1970
|
console.log(`[Venus SDK] SDK Version: ${SDK_VERSION}`);
|
|
4421
1971
|
this._shared = {
|
|
@@ -4521,12 +2071,7 @@ var VenusAPI2 = class {
|
|
|
4521
2071
|
// Static locale data at top level
|
|
4522
2072
|
locale: "en-US",
|
|
4523
2073
|
languageCode: "en",
|
|
4524
|
-
//
|
|
4525
|
-
profile: {
|
|
4526
|
-
id: "mock-profile-123",
|
|
4527
|
-
username: "MockProfile",
|
|
4528
|
-
avatarUrl: "https://i.pravatar.cc/150?u=mock"
|
|
4529
|
-
},
|
|
2074
|
+
// Note: Profile is now separate from config and accessed via getCurrentProfile()
|
|
4530
2075
|
// Complete environment info (matching buildStaticConfig)
|
|
4531
2076
|
environment: {
|
|
4532
2077
|
isDevelopment: true,
|
|
@@ -4593,14 +2138,11 @@ var VenusAPI2 = class {
|
|
|
4593
2138
|
}
|
|
4594
2139
|
};
|
|
4595
2140
|
this._detectHostedEnvironment();
|
|
2141
|
+
this.launchParams = {};
|
|
4596
2142
|
this.config = createProxiedObject.call(this, "config", {
|
|
4597
2143
|
locale: "en-US",
|
|
4598
2144
|
languageCode: "en",
|
|
4599
|
-
|
|
4600
|
-
id: "mock-user-123",
|
|
4601
|
-
username: "Test User",
|
|
4602
|
-
avatarUrl: null
|
|
4603
|
-
},
|
|
2145
|
+
// Note: Profile is no longer in config - use getCurrentProfile() instead
|
|
4604
2146
|
environment: {
|
|
4605
2147
|
isDevelopment: true,
|
|
4606
2148
|
platform: typeof navigator !== "undefined" ? navigator.platform : "unknown",
|
|
@@ -4714,12 +2256,15 @@ var VenusAPI2 = class {
|
|
|
4714
2256
|
const host = createHost(this, !isInsideHostedEnv);
|
|
4715
2257
|
this.host = host;
|
|
4716
2258
|
initializeStorage(this, host);
|
|
2259
|
+
initializeRoomsApi(this, host);
|
|
4717
2260
|
initializeAds(this, host);
|
|
4718
2261
|
initializeTheme(this);
|
|
4719
2262
|
initializePopups(this, host);
|
|
4720
2263
|
initializeAnalytics(this, host);
|
|
4721
2264
|
initializeIap(this, host);
|
|
2265
|
+
initializeLeaderboard(this, host);
|
|
4722
2266
|
initializeLocalNotifications(this, host);
|
|
2267
|
+
initializePreloader(this, host);
|
|
4723
2268
|
initializeTime(this, host);
|
|
4724
2269
|
initializeLifecycleApi(this, host);
|
|
4725
2270
|
initializeHaptics(this, host);
|
|
@@ -4734,8 +2279,8 @@ var VenusAPI2 = class {
|
|
|
4734
2279
|
initializeStackNavigation(this, host);
|
|
4735
2280
|
initializePost(this, host);
|
|
4736
2281
|
initializeAi(this, host);
|
|
4737
|
-
initializeRooms(this);
|
|
4738
2282
|
initializeSimulation(this, host);
|
|
2283
|
+
initializeSocial(this, host);
|
|
4739
2284
|
initializeAssetLoader(this, createProxiedMethod);
|
|
4740
2285
|
}
|
|
4741
2286
|
// Generate deterministic instance ID based on current page URL
|
|
@@ -4790,97 +2335,31 @@ var VenusAPI2 = class {
|
|
|
4790
2335
|
this.config.languageCode = this._mock.localeOverride.split("-")[0];
|
|
4791
2336
|
}
|
|
4792
2337
|
if (this._mock.roomsData) {
|
|
4793
|
-
|
|
2338
|
+
console.warn(
|
|
2339
|
+
"[Venus Mock] Rooms mock data is no longer supported. Rooms functionality requires the Venus host environment."
|
|
2340
|
+
);
|
|
4794
2341
|
}
|
|
4795
2342
|
}
|
|
4796
2343
|
//---------------------------------------
|
|
4797
2344
|
// PUBLIC API METHODS
|
|
4798
2345
|
//---------------------------------------
|
|
4799
|
-
async initializeAsync(options
|
|
2346
|
+
async initializeAsync(options) {
|
|
4800
2347
|
if (this._shared.initialized) {
|
|
4801
2348
|
return Promise.resolve(true);
|
|
4802
2349
|
}
|
|
4803
2350
|
if (this._shared.initPromise) {
|
|
4804
2351
|
return this._shared.initPromise;
|
|
4805
2352
|
}
|
|
4806
|
-
this._shared.initPromise = new Promise(async (resolve) => {
|
|
2353
|
+
this._shared.initPromise = new Promise(async (resolve, reject) => {
|
|
4807
2354
|
try {
|
|
4808
|
-
|
|
4809
|
-
|
|
4810
|
-
|
|
4811
|
-
|
|
4812
|
-
"helpText",
|
|
4813
|
-
"forceRemoteCdn"
|
|
4814
|
-
];
|
|
4815
|
-
const supportedMockParams = [
|
|
4816
|
-
"initDelay",
|
|
4817
|
-
"isMobile",
|
|
4818
|
-
"isWeb",
|
|
4819
|
-
"locale",
|
|
4820
|
-
"rooms",
|
|
4821
|
-
"craftingConfig",
|
|
4822
|
-
"onShowContext",
|
|
4823
|
-
"onHideContext"
|
|
4824
|
-
];
|
|
4825
|
-
Object.keys(options).forEach((param) => {
|
|
4826
|
-
if (!supportedRootParams.includes(param)) {
|
|
4827
|
-
this.log(`Unsupported parameter: ${param}`);
|
|
4828
|
-
}
|
|
4829
|
-
});
|
|
4830
|
-
if (options.mockData && typeof options.mockData === "object") {
|
|
4831
|
-
console.warn(
|
|
4832
|
-
"[Venus Mock] mockData is deprecated, use options.mock instead"
|
|
4833
|
-
);
|
|
4834
|
-
options.mock = { ...options.mock, ...options.mockData };
|
|
4835
|
-
}
|
|
4836
|
-
if (options.mock && typeof options.mock === "object") {
|
|
4837
|
-
Object.keys(options.mock).forEach((param) => {
|
|
4838
|
-
if (!supportedMockParams.includes(param)) {
|
|
4839
|
-
this.log(`Unsupported mock parameter: ${param}`);
|
|
4840
|
-
}
|
|
4841
|
-
});
|
|
4842
|
-
}
|
|
4843
|
-
if (options.helpText && typeof options.helpText === "string") {
|
|
4844
|
-
this._mock.helpText = options.helpText;
|
|
4845
|
-
}
|
|
4846
|
-
if (typeof options.forceRemoteCdn === "boolean") {
|
|
4847
|
-
this._mock.forceRemoteCdn = options.forceRemoteCdn;
|
|
4848
|
-
console.log(
|
|
4849
|
-
"[Venus Mock] Force remote CDN mode:",
|
|
4850
|
-
options.forceRemoteCdn
|
|
4851
|
-
);
|
|
4852
|
-
}
|
|
4853
|
-
}
|
|
4854
|
-
await this.host.initialize();
|
|
4855
|
-
if (this._bootstrap.isInsideHostedEnvironment) {
|
|
4856
|
-
this._shared.initialized = true;
|
|
4857
|
-
resolve(true);
|
|
4858
|
-
return;
|
|
2355
|
+
const result = await this.host.initialize(options);
|
|
2356
|
+
this._shared.initialized = true;
|
|
2357
|
+
if (!options.usePreloader) {
|
|
2358
|
+
this.host.preloader.hideLoadScreen();
|
|
4859
2359
|
}
|
|
4860
|
-
|
|
4861
|
-
this.log(`Using mock initialization delay: ${mockDelay}ms`);
|
|
4862
|
-
setTimeout(async () => {
|
|
4863
|
-
this._shared.initialized = true;
|
|
4864
|
-
this._initializeMockMode();
|
|
4865
|
-
resolve(true);
|
|
4866
|
-
}, mockDelay);
|
|
2360
|
+
resolve(result);
|
|
4867
2361
|
} catch (err) {
|
|
4868
|
-
|
|
4869
|
-
"[Venus Bootstrap] Initialization error, falling back to mock mode",
|
|
4870
|
-
err
|
|
4871
|
-
);
|
|
4872
|
-
if (options.hardDisableMock) {
|
|
4873
|
-
console.warn(
|
|
4874
|
-
"[Venus Bootstrap] hardDisableMock is true, not using mock."
|
|
4875
|
-
);
|
|
4876
|
-
resolve(false);
|
|
4877
|
-
return;
|
|
4878
|
-
}
|
|
4879
|
-
this._initializeMockMode();
|
|
4880
|
-
setTimeout(async () => {
|
|
4881
|
-
this._shared.initialized = true;
|
|
4882
|
-
resolve(true);
|
|
4883
|
-
}, 100);
|
|
2362
|
+
reject(err);
|
|
4884
2363
|
}
|
|
4885
2364
|
});
|
|
4886
2365
|
return this._shared.initPromise;
|