@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.
@@ -1,7 +1,9 @@
1
1
  'use strict';
2
2
 
3
3
  var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
7
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
8
  var __esm = (fn, res) => function __init() {
7
9
  return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
@@ -10,6 +12,15 @@ var __export = (target, all) => {
10
12
  for (var name in all)
11
13
  __defProp(target, name, { get: all[name], enumerable: true });
12
14
  };
15
+ var __copyProps = (to, from, except, desc) => {
16
+ if (from && typeof from === "object" || typeof from === "function") {
17
+ for (let key of __getOwnPropNames(from))
18
+ if (!__hasOwnProp.call(to, key) && key !== except)
19
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
20
+ }
21
+ return to;
22
+ };
23
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
13
24
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
14
25
 
15
26
  // src/venus-api/systems/core.js
@@ -100,6 +111,221 @@ var init_core = __esm({
100
111
  }
101
112
  });
102
113
 
114
+ // src/rooms/RoomsApi.ts
115
+ var init_RoomsApi = __esm({
116
+ "src/rooms/RoomsApi.ts"() {
117
+ }
118
+ });
119
+
120
+ // src/rooms/VenusRoom.ts
121
+ var VenusRoom;
122
+ var init_VenusRoom = __esm({
123
+ "src/rooms/VenusRoom.ts"() {
124
+ VenusRoom = class {
125
+ constructor(roomData) {
126
+ __publicField(this, "id");
127
+ __publicField(this, "name");
128
+ __publicField(this, "players");
129
+ __publicField(this, "maxPlayers");
130
+ __publicField(this, "gameType");
131
+ __publicField(this, "appId");
132
+ __publicField(this, "type");
133
+ __publicField(this, "createdBy");
134
+ __publicField(this, "createdAt");
135
+ __publicField(this, "updatedAt");
136
+ __publicField(this, "isPrivate");
137
+ __publicField(this, "currentPlayers");
138
+ __publicField(this, "status");
139
+ __publicField(this, "customMetadata");
140
+ __publicField(this, "admins");
141
+ __publicField(this, "roomCode");
142
+ __publicField(this, "description");
143
+ __publicField(this, "data");
144
+ __publicField(this, "version");
145
+ __publicField(this, "_subscriptions", /* @__PURE__ */ new Map());
146
+ this.id = roomData.id;
147
+ this.name = roomData.name;
148
+ this.players = roomData.currentPlayers || [];
149
+ this.maxPlayers = roomData.maxPlayers;
150
+ this.gameType = roomData.gameType;
151
+ this.appId = roomData.appId;
152
+ this.type = roomData.type;
153
+ this.createdBy = roomData.createdBy;
154
+ this.createdAt = roomData.createdAt;
155
+ this.updatedAt = roomData.updatedAt;
156
+ this.isPrivate = roomData.isPrivate;
157
+ this.currentPlayers = roomData.currentPlayers || [];
158
+ this.status = roomData.status;
159
+ this.customMetadata = roomData.customMetadata || {};
160
+ this.admins = roomData.admins || [];
161
+ this.roomCode = roomData.roomCode;
162
+ this.description = roomData.description;
163
+ this.data = roomData.data || {};
164
+ this.version = roomData.version;
165
+ console.log(`VenusRoom: Created room object for ${this.id}`, {
166
+ hasCustomMetadata: !!this.customMetadata,
167
+ hasGameState: !!this.customMetadata?.rules?.gameState,
168
+ gamePhase: this.customMetadata?.rules?.gameState?.phase,
169
+ currentPlayer: this.customMetadata?.rules?.gameState?.currentPlayer
170
+ });
171
+ }
172
+ updateFromRoomData(newRoomData) {
173
+ if (newRoomData.id === this.id) {
174
+ this.name = newRoomData.name || this.name;
175
+ this.players = newRoomData.currentPlayers || this.players;
176
+ this.maxPlayers = newRoomData.maxPlayers || this.maxPlayers;
177
+ this.gameType = newRoomData.gameType || this.gameType;
178
+ this.currentPlayers = newRoomData.currentPlayers || this.currentPlayers;
179
+ this.customMetadata = newRoomData.customMetadata || this.customMetadata;
180
+ this.data = newRoomData.data || this.data;
181
+ this.status = newRoomData.status || this.status;
182
+ this.updatedAt = newRoomData.updatedAt || this.updatedAt;
183
+ console.log(`VenusRoom: Updated room object ${this.id} with fresh data`, {
184
+ hasCustomMetadata: !!this.customMetadata,
185
+ hasGameState: !!this.customMetadata?.rules?.gameState,
186
+ gamePhase: this.customMetadata?.rules?.gameState?.phase,
187
+ currentPlayer: this.customMetadata?.rules?.gameState?.currentPlayer
188
+ });
189
+ }
190
+ }
191
+ };
192
+ }
193
+ });
194
+
195
+ // src/rooms/index.ts
196
+ var rooms_exports = {};
197
+ __export(rooms_exports, {
198
+ VenusRoom: () => VenusRoom,
199
+ initializeRoomsApi: () => initializeRoomsApi,
200
+ setupRoomNotifications: () => setupRoomNotifications
201
+ });
202
+ function bindMethod(target, targetKey, source, sourceKey) {
203
+ const key = sourceKey ?? targetKey;
204
+ const fn = source?.[key];
205
+ if (typeof fn === "function") {
206
+ target[targetKey] = fn.bind(source);
207
+ return true;
208
+ }
209
+ return false;
210
+ }
211
+ function setupRoomNotifications(transport, getSubscriptions) {
212
+ console.log("[Venus Rooms] Setting up room notification listeners");
213
+ return transport.onVenusMessage((message) => {
214
+ const subscriptions = getSubscriptions();
215
+ if (!subscriptions) {
216
+ return;
217
+ }
218
+ if (message.type === "H5_ROOM_DATA_UPDATED") {
219
+ const messageData = message.data;
220
+ const { roomId, roomData } = messageData;
221
+ if (!roomId) return;
222
+ const callbacks = subscriptions.data?.[roomId] || [];
223
+ const allEventsCallbacks = subscriptions.allEvents?.[roomId] || [];
224
+ console.log(`[Venus Rooms] \u{1F514} Room data updated for ${roomId}, notifying ${callbacks.length} callbacks`, roomData);
225
+ callbacks.forEach((callback) => {
226
+ try {
227
+ callback(roomData);
228
+ } catch (error) {
229
+ console.error("[Venus Rooms] Error in room data callback:", error);
230
+ throw error;
231
+ }
232
+ });
233
+ allEventsCallbacks.forEach((callback) => {
234
+ try {
235
+ callback({ type: message.type, ...messageData });
236
+ } catch (error) {
237
+ console.error("[Venus Rooms] Error in allEvents callback:", error);
238
+ throw error;
239
+ }
240
+ });
241
+ }
242
+ if (message.type === "H5_ROOM_MESSAGE_RECEIVED" || message.type === "H5_ROOM_MESSAGE_UPDATED" || message.type === "H5_ROOM_MESSAGE_DELETED") {
243
+ const messageData = message.data;
244
+ const { roomId } = messageData;
245
+ if (!roomId) return;
246
+ const callbacks = subscriptions.messages?.[roomId] || [];
247
+ const allEventsCallbacks = subscriptions.allEvents?.[roomId] || [];
248
+ console.log(`[Venus Rooms] \u{1F514} Room message event for ${roomId}, notifying ${callbacks.length} callbacks`);
249
+ callbacks.forEach((callback) => {
250
+ try {
251
+ callback(messageData);
252
+ } catch (error) {
253
+ console.error("[Venus Rooms] Error in room message callback:", error);
254
+ throw error;
255
+ }
256
+ });
257
+ allEventsCallbacks.forEach((callback) => {
258
+ try {
259
+ callback({ type: message.type, ...messageData });
260
+ } catch (error) {
261
+ console.error("[Venus Rooms] Error in allEvents callback:", error);
262
+ throw error;
263
+ }
264
+ });
265
+ }
266
+ if (message.type === "app:h5:proposedMoveValidationUpdated") {
267
+ const messageData = message.data;
268
+ const { roomId } = messageData;
269
+ if (!roomId) return;
270
+ const callbacks = subscriptions.gameEvents?.[roomId] || [];
271
+ const allEventsCallbacks = subscriptions.allEvents?.[roomId] || [];
272
+ console.log(`[Venus Rooms] \u{1F514} Proposed move validation updated for ${roomId}, notifying ${callbacks.length} callbacks`);
273
+ callbacks.forEach((callback) => {
274
+ try {
275
+ callback(messageData);
276
+ } catch (error) {
277
+ console.error("[Venus Rooms] Error in game event callback:", error);
278
+ throw error;
279
+ }
280
+ });
281
+ allEventsCallbacks.forEach((callback) => {
282
+ try {
283
+ callback({ type: message.type, ...messageData });
284
+ } catch (error) {
285
+ console.error("[Venus Rooms] Error in allEvents callback:", error);
286
+ throw error;
287
+ }
288
+ });
289
+ }
290
+ });
291
+ }
292
+ function initializeRoomsApi(venusApi, host) {
293
+ const roomsApi = host?.rooms;
294
+ if (!roomsApi) {
295
+ console.warn(
296
+ "[Venus SDK] Host did not provide a rooms implementation. Rooms API will be unavailable."
297
+ );
298
+ return;
299
+ }
300
+ const venus = venusApi;
301
+ const existingNamespace = venus.rooms || {};
302
+ const roomsNamespace = Object.assign({}, existingNamespace);
303
+ const namespaceBindings = [
304
+ ["create", "createRoom"],
305
+ ["joinOrCreate", "joinOrCreateRoom"],
306
+ ["joinByCode", "joinRoomByCode"],
307
+ ["list", "getUserRooms"],
308
+ ["subscribeToRoom", "subscribe"],
309
+ ["updateRoomData", "updateData"],
310
+ ["getRoomData", "getData"],
311
+ ["sendRoomMessage", "sendMessage"],
312
+ ["leaveRoom", "leave"],
313
+ ["startRoomGame", "startGame"],
314
+ ["proposeMove"],
315
+ ["validateMove"]
316
+ ];
317
+ namespaceBindings.forEach(([targetKey, sourceKey]) => {
318
+ bindMethod(roomsNamespace, targetKey, roomsApi, sourceKey);
319
+ });
320
+ venus.rooms = roomsNamespace;
321
+ }
322
+ var init_rooms = __esm({
323
+ "src/rooms/index.ts"() {
324
+ init_RoomsApi();
325
+ init_VenusRoom();
326
+ }
327
+ });
328
+
103
329
  // src/storage/MockStorageApi.ts
104
330
  function createMockStorageApi(storageType, appUrl) {
105
331
  const appIdentifier = appUrl ? generateAppIdentifier(appUrl) : null;
@@ -339,23 +565,27 @@ var RpcAdsApi = class {
339
565
  __publicField(this, "rpcClient");
340
566
  this.rpcClient = rpcClient;
341
567
  }
342
- async showInterstitialAd() {
568
+ async showInterstitialAd(options) {
343
569
  console.log(`[Venus SDK] [RpcAdsApi] showInterstitialAd`);
344
570
  const response = await this.rpcClient.call(
345
571
  "H5_SHOW_INTERSTITIAL_AD" /* SHOW_INTERSTITIAL_AD */,
346
- {},
572
+ options || {},
347
573
  -1
348
574
  );
349
575
  return response.shown;
350
576
  }
351
577
  async isRewardedAdReadyAsync() {
352
- return true;
578
+ console.log(`[Venus SDK] [RpcAdsApi] isRewardedAdReadyAsync`);
579
+ const response = await this.rpcClient.call(
580
+ "H5_IS_REWARDED_AD_READY" /* IS_REWARDED_AD_READY */
581
+ );
582
+ return response.ready;
353
583
  }
354
- async showRewardedAdAsync() {
584
+ async showRewardedAdAsync(options) {
355
585
  console.log("[Venus SDK] [RpcAdsApi] showRewardedAdAsync");
356
586
  const result = await this.rpcClient.call(
357
587
  "H5_SHOW_REWARDED_AD" /* SHOW_REWARDED_AD */,
358
- {},
588
+ options || {},
359
589
  -1
360
590
  );
361
591
  const resultAsString = JSON.stringify(result, null, 2);
@@ -379,14 +609,16 @@ var MockAdsApi = class {
379
609
  await createMockDelay(MOCK_DELAYS.short);
380
610
  return true;
381
611
  }
382
- async showRewardedAdAsync() {
612
+ async showRewardedAdAsync(options) {
383
613
  this.log("[MockAdsApi] showRewardedAdAsync called");
384
- await this.mockOverlay.showAdOverlay();
614
+ await this.mockOverlay.showAdOverlay(options);
385
615
  this.log("[MockAdsApi] Rewarded ad completed");
386
616
  return true;
387
617
  }
388
- async showInterstitialAd() {
618
+ async showInterstitialAd(options) {
389
619
  this.log(`[MockAdsApi] showInterstitialAd`);
620
+ await this.mockOverlay.showAdOverlay(options);
621
+ this.log("[MockAdsApi] interstitial ad shown");
390
622
  return true;
391
623
  }
392
624
  log(message, ...args) {
@@ -736,7 +968,7 @@ var MockNotificationsApi = class {
736
968
  __publicField(this, "venusApi");
737
969
  this.venusApi = venusApi;
738
970
  }
739
- async cancelLocalNotification(notificationId) {
971
+ async cancelNotification(notificationId) {
740
972
  const venusApi = this.venusApi;
741
973
  if (isWebPlatform()) {
742
974
  console.log(
@@ -777,7 +1009,8 @@ var MockNotificationsApi = class {
777
1009
  const isEnabled = venusApi._mock.notificationsEnabled !== false;
778
1010
  return isEnabled;
779
1011
  }
780
- async scheduleLocalNotification(title, body, options) {
1012
+ async scheduleAsync(title, body, seconds, notificationId, options) {
1013
+ const { priority = 50, groupId, payload } = options || {};
781
1014
  if (isWebPlatform()) {
782
1015
  console.log(
783
1016
  "[Venus Mock] Notifications not supported on web platform, simulating success"
@@ -792,7 +1025,7 @@ var MockNotificationsApi = class {
792
1025
  const mockId = `mock-web-notification-${Date.now()}`;
793
1026
  return mockId;
794
1027
  }
795
- console.log("[Venus Mock] Schedule local notification:", options);
1028
+ console.log("[Venus Mock] Schedule local notification:", { title, body, seconds, options });
796
1029
  const venusApi = this.venusApi;
797
1030
  if (!venusApi._mock.pendingRequests) {
798
1031
  console.log("[Venus Mock] Initializing pendingRequests");
@@ -802,17 +1035,19 @@ var MockNotificationsApi = class {
802
1035
  console.log("[Venus Mock] Creating request with ID:", requestId);
803
1036
  return new Promise((resolve) => {
804
1037
  venusApi._mock.pendingRequests[requestId] = { resolve };
805
- const notificationId = `mock-notification-${Date.now()}`;
1038
+ const id = notificationId || `mock-notification-${Date.now()}`;
806
1039
  if (!venusApi._mock.scheduledNotifications) {
807
1040
  venusApi._mock.scheduledNotifications = {};
808
1041
  }
809
- venusApi._mock.scheduledNotifications[notificationId] = {
810
- ...options,
811
- id: notificationId,
812
- createdAt: Date.now()
1042
+ venusApi._mock.scheduledNotifications[id] = {
1043
+ id,
1044
+ title,
1045
+ body,
1046
+ payload,
1047
+ seconds
813
1048
  };
814
1049
  setTimeout(() => {
815
- resolve(notificationId);
1050
+ resolve(id);
816
1051
  }, MOCK_DELAYS.short);
817
1052
  });
818
1053
  }
@@ -832,36 +1067,78 @@ var MockNotificationsApi = class {
832
1067
  }
833
1068
  };
834
1069
 
835
- // src/notifications/index.ts
836
- function initializeLocalNotifications(venusApi, host) {
837
- venusApi.setLocalNotifEnabledAsync = async (enable) => {
838
- await host.notifications.setLocalNotificationsEnabled(enable);
839
- };
840
- venusApi.isLocalNotifEnabledAsync = async () => {
841
- return host.notifications.isLocalNotificationsEnabled();
842
- };
843
- venusApi.getAllLocalNotifsAsync = async () => {
844
- return host.notifications.getAllScheduledLocalNotifications();
845
- };
846
- venusApi.cancelLocalNotifAsync = async (notificationId) => {
847
- await host.notifications.cancelLocalNotification(notificationId);
848
- };
849
- venusApi.scheduleLocalNotifAsync = async (options) => {
850
- const id = await host.notifications.scheduleLocalNotification(
851
- options.title,
852
- options.body,
1070
+ // src/notifications/RpcNotificationsApi.ts
1071
+ var RpcNotificationsApi = class {
1072
+ constructor(rpcClient) {
1073
+ __publicField(this, "rpcClient");
1074
+ this.rpcClient = rpcClient;
1075
+ }
1076
+ async scheduleAsync(title, body, seconds, notificationId, options) {
1077
+ const { priority = 50, groupId, payload } = options || {};
1078
+ const request = {
1079
+ title,
1080
+ body,
1081
+ priority,
1082
+ key: groupId,
1083
+ data: payload,
1084
+ seconds,
1085
+ notificationId
1086
+ };
1087
+ const response = await this.rpcClient.call(
1088
+ "H5_SCHEDULE_LOCAL_NOTIFICATION" /* SCHEDULE_LOCAL_NOTIFICATION */,
1089
+ request
1090
+ );
1091
+ if (response.scheduled) {
1092
+ return response.id;
1093
+ }
1094
+ return null;
1095
+ }
1096
+ async cancelNotification(id) {
1097
+ const result = await this.rpcClient.call(
1098
+ "H5_CANCEL_LOCAL_NOTIFICATION" /* CANCEL_LOCAL_NOTIFICATION */,
853
1099
  {
854
- trigger: options.trigger,
855
- priority: options.priority,
856
- groupId: options.groupId,
857
- payload: options.payload
1100
+ id
858
1101
  }
859
1102
  );
860
- if (id) {
861
- return id;
862
- }
863
- return "";
864
- };
1103
+ return result.canceled;
1104
+ }
1105
+ async getAllScheduledLocalNotifications() {
1106
+ const response = await this.rpcClient.call(
1107
+ "H5_GET_ALL_SCHEDULED_LOCAL_NOTIFICATIONS" /* GET_ALL_SCHEDULED_LOCAL_NOTIFICATIONS */,
1108
+ {}
1109
+ );
1110
+ const notifications = response.notifications.map((notif) => {
1111
+ return {
1112
+ id: notif.identifier,
1113
+ title: notif.content.title,
1114
+ body: notif.content.body,
1115
+ payload: notif.content.data,
1116
+ trigger: notif.trigger
1117
+ };
1118
+ });
1119
+ return notifications;
1120
+ }
1121
+ async isLocalNotificationsEnabled() {
1122
+ const response = await this.rpcClient.call(
1123
+ "H5_IS_LOCAL_NOTIFICATIONS_ENABLED" /* IS_LOCAL_NOTIFICATIONS_ENABLED */,
1124
+ {}
1125
+ );
1126
+ return response.enabled;
1127
+ }
1128
+ async setLocalNotificationsEnabled(enabled) {
1129
+ const response = await this.rpcClient.call(
1130
+ "H5_SET_LOCAL_NOTIFICATIONS_ENABLED" /* SET_LOCAL_NOTIFICATIONS_ENABLED */,
1131
+ {
1132
+ enabled
1133
+ }
1134
+ );
1135
+ return response.enabled;
1136
+ }
1137
+ };
1138
+
1139
+ // src/notifications/index.ts
1140
+ function initializeLocalNotifications(venusApi, host) {
1141
+ venusApi.notifications = host.notifications;
865
1142
  }
866
1143
 
867
1144
  // src/time/utils.ts
@@ -1797,1002 +2074,66 @@ function initializeAi(venusApi, host) {
1797
2074
  venusApi.ai = host.ai;
1798
2075
  }
1799
2076
 
1800
- // src/venus-api/systems/rooms.js
1801
- init_core();
1802
- var mockRooms = /* @__PURE__ */ new Map();
1803
- var mockMessages = /* @__PURE__ */ new Map();
1804
- var mockRoomMoves = /* @__PURE__ */ new Map();
1805
- var mockSubscriptions = /* @__PURE__ */ new Map();
1806
- function generateRoomId() {
1807
- return "room_" + Date.now() + "_" + Math.random().toString(36).substr(2, 9);
1808
- }
1809
- function generateMessageId() {
1810
- return "msg_" + Date.now() + "_" + Math.random().toString(36).substr(2, 9);
1811
- }
1812
- function generateRoomCode() {
1813
- const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
1814
- let code = "";
1815
- for (let i = 0; i < 6; i++) {
1816
- code += characters.charAt(Math.floor(Math.random() * characters.length));
1817
- }
1818
- return code;
1819
- }
1820
- function broadcastEvent(roomId, eventType, eventData) {
1821
- console.log(`[Venus Mock Rooms] Broadcasting ${eventType} for room ${roomId}:`, eventData);
1822
- for (const [instanceId, subscriptions] of mockSubscriptions.entries()) {
1823
- const roomSubscriptions = subscriptions.get(roomId);
1824
- if (roomSubscriptions) {
1825
- setTimeout(() => {
1826
- if (roomSubscriptions.onRoomDataUpdated && eventType === "room_data_updated") {
1827
- roomSubscriptions.onRoomDataUpdated(eventData);
1828
- }
1829
- if (roomSubscriptions.onMessageReceived && eventType === "message_received") {
1830
- roomSubscriptions.onMessageReceived(eventData);
1831
- }
1832
- if (roomSubscriptions.onPlayerJoined && eventType === "player_joined") {
1833
- roomSubscriptions.onPlayerJoined(eventData);
1834
- }
1835
- if (roomSubscriptions.onPlayerLeft && eventType === "player_left") {
1836
- roomSubscriptions.onPlayerLeft(eventData);
1837
- }
1838
- if (roomSubscriptions.onGameStarted && eventType === "game_started") {
1839
- roomSubscriptions.onGameStarted(eventData);
1840
- }
1841
- if (roomSubscriptions.onTurnChanged && eventType === "turn_changed") {
1842
- roomSubscriptions.onTurnChanged(eventData);
1843
- }
1844
- if (roomSubscriptions.onOptimisticGameStateUpdated && eventType === "app:h5:optimisticGameStateUpdated") {
1845
- roomSubscriptions.onOptimisticGameStateUpdated(eventData);
1846
- }
1847
- if (roomSubscriptions.onProposedMoveValidationUpdated && eventType === "app:h5:proposedMoveValidationUpdated") {
1848
- roomSubscriptions.onProposedMoveValidationUpdated(eventData);
1849
- }
1850
- }, 50);
1851
- }
1852
- }
1853
- }
1854
- var MockVenusRoom = class {
1855
- constructor(roomData) {
1856
- this.id = roomData.id;
1857
- this.roomId = roomData.id;
1858
- this.name = roomData.name;
1859
- this.players = roomData.currentPlayers || [];
1860
- this.maxPlayers = roomData.maxPlayers;
1861
- this.gameType = roomData.gameType;
1862
- this._subscriptions = /* @__PURE__ */ new Map();
1863
- this.appId = roomData.appId;
1864
- this.type = roomData.type;
1865
- this.createdBy = roomData.createdBy;
1866
- this.createdAt = roomData.createdAt;
1867
- this.updatedAt = roomData.updatedAt;
1868
- this.isPrivate = roomData.isPrivate;
1869
- this.currentPlayers = roomData.currentPlayers || [];
1870
- this.status = roomData.status;
1871
- this.customMetadata = roomData.customMetadata || {};
1872
- this.admins = roomData.admins || [];
1873
- this.roomCode = roomData.roomCode;
1874
- this.description = roomData.description;
1875
- this.data = roomData.data || {};
1876
- this.version = roomData.version;
1877
- console.log(`[Venus Mock VenusRoom] Created room object for ${this.id}`, {
1878
- hasCustomMetadata: !!this.customMetadata,
1879
- hasGameState: !!this.customMetadata?.rules?.gameState,
1880
- gamePhase: this.customMetadata?.rules?.gameState?.phase,
1881
- currentPlayer: this.customMetadata?.rules?.gameState?.currentPlayer
1882
- });
1883
- }
1884
- // Update room data
1885
- async updateData(updates, merge = true) {
1886
- return roomsMock.updateRoomData(this.roomId, updates, merge);
1887
- }
1888
- // Get room data
1889
- async getData() {
1890
- return roomsMock.getRoomData(this.roomId);
1891
- }
1892
- // Send message
1893
- async sendMessage(messageData) {
1894
- return roomsMock.sendMessage(this.roomId, messageData);
1895
- }
1896
- // Subscribe to room data changes
1897
- subscribeToData(callback) {
1898
- return roomsMock.subscribeToRoom(this.roomId, {
1899
- onRoomDataUpdated: callback
1900
- });
1901
- }
1902
- // Subscribe to messages
1903
- subscribeToMessages(callback) {
1904
- return roomsMock.subscribeToRoom(this.roomId, {
1905
- onMessageReceived: callback
1906
- });
1907
- }
1908
- // Leave room
1909
- async leave() {
1910
- this._subscriptions.forEach((sub) => {
1911
- if (sub.unsubscribe) sub.unsubscribe();
1912
- });
1913
- this._subscriptions.clear();
1914
- return { success: true };
1915
- }
1916
- // Start game
1917
- async startGame(gameConfig = {}, turnOrder = null) {
1918
- return roomsMock.startGame(this.roomId, gameConfig);
1919
- }
1920
- // End game
1921
- async endGame(winner = null, reason = null, gameResults = {}) {
1922
- return roomsMock.endGame(this.roomId, winner, reason, gameResults);
1923
- }
1924
- // Propose move (for client-proposed state architecture)
1925
- async proposeMove(proposalPayload) {
1926
- return roomsMock.proposeMove(this.roomId, proposalPayload);
1927
- }
1928
- // Validate move
1929
- async validateMove(moveId, isValid, reason = null, validatorId = null) {
1930
- console.log(`[Venus Mock VenusRoom] Validating move ${moveId}: ${isValid}`);
1931
- return { success: true, moveId, isValid, reason };
1932
- }
1933
- // Subscribe to game events
1934
- subscribeToGameEvents(callback) {
1935
- return roomsMock.subscribeToRoom(this.roomId, {
1936
- onOptimisticGameStateUpdated: callback,
1937
- onProposedMoveValidationUpdated: callback
1938
- });
2077
+ // src/venus-api/systems/asset-loader.js
2078
+ var VenusAssetLoader = class {
2079
+ constructor() {
2080
+ this.cache = /* @__PURE__ */ new Map();
2081
+ this.blobUrls = /* @__PURE__ */ new Map();
2082
+ this.isWebView = false;
2083
+ this.venusAPI = null;
1939
2084
  }
1940
- // Generic message handler for room-manager.js integration
1941
- onMessage(callback) {
1942
- return roomsMock.subscribeToRoom(this.roomId, {
1943
- onRoomDataUpdated: callback,
1944
- onMessageReceived: callback,
1945
- onGameStarted: callback,
1946
- onTurnChanged: callback,
1947
- onOptimisticGameStateUpdated: callback,
1948
- onProposedMoveValidationUpdated: callback
1949
- });
2085
+ // Set the VenusAPI reference during initialization
2086
+ setVenusAPI(api) {
2087
+ this.venusAPI = api;
2088
+ this.isWebView = !api.isWeb || !api.isWeb();
1950
2089
  }
1951
- // Unified subscription helper
1952
- subscribe(options = {}) {
1953
- const unsubFns = [];
1954
- if (options.onData) {
1955
- const sub = this.subscribeToData(options.onData);
1956
- unsubFns.push(() => sub.unsubscribe());
1957
- }
1958
- if (options.onMessages) {
1959
- const sub = this.subscribeToMessages(options.onMessages);
1960
- unsubFns.push(() => sub.unsubscribe());
1961
- }
1962
- if (options.onMoves || options.onGameEvents) {
1963
- const handler = options.onMoves || options.onGameEvents;
1964
- const sub = this.subscribeToGameEvents(handler);
1965
- unsubFns.push(() => sub.unsubscribe());
2090
+ /**
2091
+ * Load any asset with automatic optimization
2092
+ * @param {string} url - Asset URL
2093
+ * @param {Object} options - Loading options
2094
+ * @returns {Promise<string>} - URL to use (original, blob, or object URL)
2095
+ */
2096
+ async loadAsset(url, options = {}) {
2097
+ const {
2098
+ type = "auto",
2099
+ // 'image', 'audio', 'video', 'text', 'json', 'auto'
2100
+ cache = true,
2101
+ // Use cache
2102
+ timeout = 3e4,
2103
+ isOptional = false
2104
+ // New option to suppress error logging for optional assets
2105
+ } = options;
2106
+ const resolvedUrl = this.venusAPI && this.venusAPI.resolveAssetUrl ? this.venusAPI.resolveAssetUrl(url) : this._resolveAssetUrl(url);
2107
+ if (cache && this.cache.has(resolvedUrl)) {
2108
+ return this.cache.get(resolvedUrl);
1966
2109
  }
1967
- let called = false;
1968
- return () => {
1969
- if (called) return;
1970
- called = true;
1971
- unsubFns.forEach((fn) => {
1972
- try {
1973
- fn();
1974
- } catch (e) {
1975
- console.error("Mock room subscribe teardown error", e);
1976
- }
1977
- });
1978
- };
1979
- }
1980
- };
1981
- var roomsMock = {
1982
- createRoom(options = {}) {
2110
+ const assetType = type === "auto" ? this._detectType(resolvedUrl) : type;
1983
2111
  try {
1984
- console.log(`[Venus Mock Rooms] Creating room with options:`, options);
1985
- const roomId = generateRoomId();
1986
- const creatorId = options.userId || "mock-user-creator";
1987
- const creatorDisplayName = options.userDisplayName || `Creator ${creatorId.slice(-4)}`;
1988
- const initialGameState = {
1989
- phase: "waiting",
1990
- currentPlayer: creatorId,
1991
- // Creator might be the first player by default
1992
- turnOrder: [creatorId],
1993
- playerStates: {
1994
- [creatorId]: {
1995
- displayName: creatorDisplayName,
1996
- status: "active",
1997
- role: "admin",
1998
- // Creator is admin
1999
- joinedAt: /* @__PURE__ */ new Date()
2000
- }
2001
- },
2002
- gameStartedAt: null,
2003
- turnCount: 0
2004
- // other game-specific state can be added by the H5 app via customMetadata or startGame
2005
- };
2006
- const room = {
2007
- id: roomId,
2008
- appId: options.appId || "mock-app",
2009
- name: options.name || "Mock Room",
2010
- type: "shared",
2011
- createdBy: creatorId,
2012
- createdAt: /* @__PURE__ */ new Date(),
2013
- updatedAt: /* @__PURE__ */ new Date(),
2014
- isPrivate: options.isPrivate || false,
2015
- maxPlayers: options.maxPlayers || 4,
2016
- currentPlayers: [creatorId],
2017
- status: "active",
2018
- customMetadata: {
2019
- ...options.customMetadata || {},
2020
- rules: {
2021
- ...options.customMetadata?.rules || {},
2022
- // Default generic rules, can be overridden by H5 app's options
2023
- ruleEngine: options.customMetadata?.rules?.ruleEngine || "generic-v1",
2024
- turnBased: options.customMetadata?.rules?.turnBased ?? true,
2025
- minPlayers: options.customMetadata?.rules?.minPlayers || 1,
2026
- maxPlayers: options.maxPlayers || 4,
2027
- gameState: initialGameState
2112
+ let resultUrl = resolvedUrl;
2113
+ if (assetType === "text" || assetType === "json") {
2114
+ const content = await this._fetchText(resolvedUrl, timeout);
2115
+ this.cache.set(resolvedUrl, content);
2116
+ return content;
2117
+ }
2118
+ const isMockMode = this.venusAPI && this.venusAPI.isMock && this.venusAPI.isMock();
2119
+ if (this.isWebView && !isMockMode && ["image", "audio", "video"].includes(assetType)) {
2120
+ if (assetType === "video") {
2121
+ resultUrl = await this._loadAsBlob(resolvedUrl, assetType);
2122
+ if (cache) {
2123
+ this.cache.set(resolvedUrl, resultUrl);
2028
2124
  }
2029
- },
2030
- admins: [creatorId],
2031
- roomCode: options.roomCode || (options.isPrivate ? generateRoomCode() : null),
2032
- description: options.description,
2033
- gameType: options.gameType,
2034
- data: {},
2035
- // General purpose data, game state is in customMetadata.rules.gameState
2036
- version: 1
2037
- };
2038
- mockRooms.set(roomId, room);
2039
- mockMessages.set(roomId, []);
2040
- mockRoomMoves.set(roomId, []);
2041
- console.log(`[Venus Mock Rooms] Created room ${roomId} with initial state:`, room);
2042
- return Promise.resolve(new MockVenusRoom(room));
2043
- } catch (error) {
2044
- console.error(`[Venus Mock Rooms] Error creating room:`, error);
2045
- return Promise.reject({ success: false, error: error.message || "Failed to create room" });
2046
- }
2047
- },
2048
- joinRoom(roomId, playerMetadata = {}) {
2049
- try {
2050
- console.log(`[Venus Mock Rooms] Joining room ${roomId}`);
2051
- const room = mockRooms.get(roomId);
2052
- if (!room) {
2053
- return Promise.reject({ success: false, error: "Room not found" });
2054
- }
2055
- const joiningPlayerId = playerMetadata.userId || "mock-user-" + Math.random().toString(36).substr(2, 5);
2056
- const joiningPlayerDisplayName = playerMetadata.displayName || `Player ${joiningPlayerId.slice(-4)}`;
2057
- if (room.currentPlayers.includes(joiningPlayerId)) {
2058
- console.log(`[Venus Mock Rooms] Player ${joiningPlayerId} already in room ${roomId}. Updating display name if needed.`);
2059
- if (room.customMetadata.rules.gameState.playerStates[joiningPlayerId]) {
2060
- room.customMetadata.rules.gameState.playerStates[joiningPlayerId].displayName = joiningPlayerDisplayName;
2061
- room.customMetadata.rules.gameState.playerStates[joiningPlayerId].status = "active";
2125
+ return resultUrl;
2126
+ } else if (assetType === "audio") {
2127
+ resultUrl = await this._loadAsBlob(resolvedUrl, assetType);
2062
2128
  } else {
2063
- room.customMetadata.rules.gameState.playerStates[joiningPlayerId] = {
2064
- displayName: joiningPlayerDisplayName,
2065
- status: "active",
2066
- role: "player",
2067
- joinedAt: /* @__PURE__ */ new Date()
2068
- };
2069
- }
2070
- room.updatedAt = /* @__PURE__ */ new Date();
2071
- room.version++;
2072
- broadcastEvent(roomId, "room_data_updated", { roomId, roomData: room, timestamp: Date.now() });
2073
- return Promise.resolve(new MockVenusRoom(room));
2074
- }
2075
- if (room.currentPlayers.length >= room.maxPlayers) {
2076
- return Promise.reject({ success: false, error: "Room is full" });
2077
- }
2078
- room.currentPlayers.push(joiningPlayerId);
2079
- room.customMetadata.rules.gameState.playerStates[joiningPlayerId] = {
2080
- displayName: joiningPlayerDisplayName,
2081
- status: "active",
2082
- role: "player",
2083
- joinedAt: /* @__PURE__ */ new Date()
2084
- };
2085
- if (room.customMetadata.rules.gameState.phase === "waiting" && room.customMetadata.rules.gameState.turnOrder) {
2086
- if (!room.customMetadata.rules.gameState.turnOrder.includes(joiningPlayerId)) {
2087
- room.customMetadata.rules.gameState.turnOrder.push(joiningPlayerId);
2129
+ resultUrl = await this._loadAsBlob(resolvedUrl, assetType);
2088
2130
  }
2089
2131
  }
2090
- room.updatedAt = /* @__PURE__ */ new Date();
2091
- room.version++;
2092
- broadcastEvent(roomId, "player_joined", { roomId, player: { id: joiningPlayerId, displayName: joiningPlayerDisplayName } });
2093
- broadcastEvent(roomId, "room_data_updated", { roomId, roomData: room, timestamp: Date.now() });
2094
- console.log(`[Venus Mock Rooms] Player ${joiningPlayerId} joined room ${roomId}. Current state:`, room);
2095
- return Promise.resolve(new MockVenusRoom(room));
2096
- } catch (error) {
2097
- console.error(`[Venus Mock Rooms] Error joining room:`, error);
2098
- return Promise.reject({ success: false, error: error.message || "Failed to join room" });
2099
- }
2100
- },
2101
- updateRoomData(roomId, updates, merge = true) {
2102
- try {
2103
- console.log(`[Venus Mock Rooms] Updating room ${roomId} data:`, updates);
2104
- const room = mockRooms.get(roomId);
2105
- if (!room) {
2106
- throw new Error("Room not found");
2132
+ if (!(this.isWebView && !isMockMode && assetType === "video")) {
2133
+ await this._verifyAsset(resultUrl, assetType);
2107
2134
  }
2108
- if (merge) {
2109
- room.data = { ...room.data, ...updates };
2110
- } else {
2111
- room.data = updates;
2112
- }
2113
- room.updatedAt = /* @__PURE__ */ new Date();
2114
- room.version++;
2115
- broadcastEvent(roomId, "room_data_updated", {
2116
- roomId,
2117
- roomData: room,
2118
- timestamp: Date.now()
2119
- });
2120
- return Promise.resolve({
2121
- success: true
2122
- });
2123
- } catch (error) {
2124
- console.error(`[Venus Mock Rooms] Error updating room data:`, error);
2125
- return Promise.reject(new Error(error.message || "Failed to update room data"));
2126
- }
2127
- },
2128
- getRoomData(roomId) {
2129
- try {
2130
- console.log(`[Venus Mock Rooms] Getting room ${roomId} data`);
2131
- const room = mockRooms.get(roomId);
2132
- if (!room) {
2133
- throw new Error("Room not found");
2134
- }
2135
- return Promise.resolve({
2136
- success: true,
2137
- data: room.data || {}
2138
- });
2139
- } catch (error) {
2140
- console.error(`[Venus Mock Rooms] Error getting room data:`, error);
2141
- return Promise.reject(new Error(error.message || "Failed to get room data"));
2142
- }
2143
- },
2144
- sendMessage(roomId, message) {
2145
- try {
2146
- const room = mockRooms.get(roomId);
2147
- if (!room) {
2148
- return Promise.reject({ success: false, error: "Room not found" });
2149
- }
2150
- if (message.type === "chat") {
2151
- console.log(`[Venus Mock Rooms] Sending CHAT message to room ${roomId}:`, message);
2152
- const messageId = generateMessageId();
2153
- const messageData = {
2154
- id: messageId,
2155
- roomId,
2156
- senderId: message.senderId || "mock-user-chatter",
2157
- // H5 app should provide senderId
2158
- content: message.content || "",
2159
- type: "chat",
2160
- metadata: message.metadata || {},
2161
- timestamp: /* @__PURE__ */ new Date()
2162
- };
2163
- const messages = mockMessages.get(roomId) || [];
2164
- messages.push(messageData);
2165
- mockMessages.set(roomId, messages);
2166
- broadcastEvent(roomId, "message_received", { roomId, message: messageData });
2167
- return Promise.resolve({ success: true, messageId });
2168
- } else {
2169
- console.log(`[Venus Mock Rooms] Sending GAME ACTION/MOVE to room ${roomId} via moves subcollection:`, message);
2170
- const playerId = message.playerId || message.metadata?.playerId || "mock-player-action";
2171
- if (!playerId) ;
2172
- const move = {
2173
- playerId,
2174
- moveData: message.moveData || message.content || message.metadata || { type: message.type },
2175
- // Ensure type is captured
2176
- clientValidationHash: message.clientValidationHash,
2177
- timestamp: /* @__PURE__ */ new Date(),
2178
- // client-side timestamp for the move proposal
2179
- status: "pending_mock_processing"
2180
- };
2181
- const roomMoves = mockRoomMoves.get(roomId) || [];
2182
- roomMoves.push(move);
2183
- mockRoomMoves.set(roomId, roomMoves);
2184
- this._processMockMove(roomId, move, room);
2185
- return Promise.resolve({ success: true, moveId: "mock-move-" + Date.now() });
2186
- }
2187
- } catch (error) {
2188
- console.error(`[Venus Mock Rooms] Error sending message/move:`, error);
2189
- return Promise.reject({ success: false, error: error.message || "Failed to send message/move" });
2190
- }
2191
- },
2192
- subscribeToRoom(roomId, options = {}) {
2193
- try {
2194
- console.log(`[Venus Mock Rooms] Subscribing to room ${roomId}:`, options);
2195
- const room = mockRooms.get(roomId);
2196
- if (!room) {
2197
- throw new Error("Room not found");
2198
- }
2199
- const instanceId = "mock-instance-" + Date.now();
2200
- if (!mockSubscriptions.has(instanceId)) {
2201
- mockSubscriptions.set(instanceId, /* @__PURE__ */ new Map());
2202
- }
2203
- const subscriptions = mockSubscriptions.get(instanceId);
2204
- subscriptions.set(roomId, {
2205
- onRoomDataUpdated: options.onRoomDataUpdated,
2206
- onMessageReceived: options.onMessageReceived,
2207
- onPlayerJoined: options.onPlayerJoined,
2208
- onPlayerLeft: options.onPlayerLeft,
2209
- onGameStarted: options.onGameStarted,
2210
- onTurnChanged: options.onTurnChanged
2211
- });
2212
- return Promise.resolve({
2213
- success: true,
2214
- unsubscribe: () => {
2215
- subscriptions.delete(roomId);
2216
- console.log(`[Venus Mock Rooms] Unsubscribed from room ${roomId}`);
2217
- }
2218
- });
2219
- } catch (error) {
2220
- console.error(`[Venus Mock Rooms] Error subscribing to room:`, error);
2221
- return Promise.reject(new Error(error.message || "Failed to subscribe to room"));
2222
- }
2223
- },
2224
- listPublicRooms(gameType, limit = 20) {
2225
- try {
2226
- console.log(`[Venus Mock Rooms] Listing public rooms:`, { gameType, limit });
2227
- let rooms = Array.from(mockRooms.values()).filter(
2228
- (room) => !room.isPrivate && room.status === "active" && (!gameType || room.gameType === gameType)
2229
- );
2230
- rooms = rooms.slice(0, limit);
2231
- return Promise.resolve({
2232
- success: true,
2233
- rooms
2234
- });
2235
- } catch (error) {
2236
- console.error(`[Venus Mock Rooms] Error listing public rooms:`, error);
2237
- return Promise.reject(new Error(error.message || "Failed to list public rooms"));
2238
- }
2239
- },
2240
- searchRooms(searchQuery, gameType, limit = 20) {
2241
- try {
2242
- console.log(`[Venus Mock Rooms] Searching rooms:`, { searchQuery, gameType, limit });
2243
- let rooms = Array.from(mockRooms.values()).filter(
2244
- (room) => !room.isPrivate && room.status === "active" && (!gameType || room.gameType === gameType) && (!searchQuery || room.name.toLowerCase().includes(searchQuery.toLowerCase()) || room.description?.toLowerCase().includes(searchQuery.toLowerCase()))
2245
- );
2246
- rooms = rooms.slice(0, limit);
2247
- return Promise.resolve({
2248
- success: true,
2249
- rooms
2250
- });
2251
- } catch (error) {
2252
- console.error(`[Venus Mock Rooms] Error searching rooms:`, error);
2253
- return Promise.reject({ success: false, error: error.message || "Failed to search rooms" });
2254
- }
2255
- },
2256
- // Smart matchmaking - join existing room or create new one
2257
- joinOrCreateRoom(options = {}) {
2258
- try {
2259
- console.log(`[Venus Mock Rooms] Smart matchmaking with options:`, options);
2260
- const { matchCriteria = {}, createOptions = {} } = options;
2261
- let matchingRoom = null;
2262
- for (const room of mockRooms.values()) {
2263
- const matchesGameType = !matchCriteria.gameType || room.gameType === matchCriteria.gameType;
2264
- const matchesPrivacy = !matchCriteria.hasOwnProperty("isPrivate") || room.isPrivate === matchCriteria.isPrivate;
2265
- const hasSpace = !matchCriteria.hasSpace || room.currentPlayers.length < room.maxPlayers;
2266
- const isActive = room.status === "active";
2267
- const isWaiting = room.customMetadata?.rules?.gameState?.phase === "waiting";
2268
- if (matchesGameType && matchesPrivacy && hasSpace && isActive && isWaiting) {
2269
- matchingRoom = room;
2270
- console.log(`[Venus Mock Rooms] Found matching room: ${room.id}`);
2271
- break;
2272
- }
2273
- }
2274
- if (matchingRoom) {
2275
- console.log(`[Venus Mock Rooms] Joining existing room: ${matchingRoom.id}`);
2276
- const joiningPlayerId = createOptions.userId || options.userId || "mock-user-joiner";
2277
- const joiningPlayerDisplayName = createOptions.userDisplayName || options.userDisplayName || `Player ${joiningPlayerId.slice(-4)}`;
2278
- if (matchingRoom.currentPlayers.includes(joiningPlayerId)) {
2279
- return Promise.resolve({
2280
- action: "joined",
2281
- room: new MockVenusRoom(matchingRoom),
2282
- playersJoined: 0
2283
- });
2284
- }
2285
- matchingRoom.currentPlayers.push(joiningPlayerId);
2286
- matchingRoom.customMetadata.rules.gameState.playerStates[joiningPlayerId] = {
2287
- displayName: joiningPlayerDisplayName,
2288
- status: "active",
2289
- role: "player",
2290
- joinedAt: /* @__PURE__ */ new Date()
2291
- };
2292
- if (matchingRoom.customMetadata.rules.gameState.phase === "waiting" && matchingRoom.customMetadata.rules.gameState.turnOrder) {
2293
- if (!matchingRoom.customMetadata.rules.gameState.turnOrder.includes(joiningPlayerId)) {
2294
- matchingRoom.customMetadata.rules.gameState.turnOrder.push(joiningPlayerId);
2295
- }
2296
- }
2297
- matchingRoom.updatedAt = /* @__PURE__ */ new Date();
2298
- matchingRoom.version++;
2299
- if (matchingRoom.currentPlayers.length >= matchingRoom.maxPlayers) {
2300
- console.log(`[Venus Mock Rooms] Room ${matchingRoom.id} is full, auto-starting game`);
2301
- const gameState = matchingRoom.customMetadata.rules.gameState;
2302
- gameState.phase = "playing";
2303
- gameState.gameStartedAt = /* @__PURE__ */ new Date();
2304
- let turnOrder = [...matchingRoom.currentPlayers];
2305
- if (matchingRoom.customMetadata.rules.randomizePlayerOrder) {
2306
- for (let i = turnOrder.length - 1; i > 0; i--) {
2307
- const j = Math.floor(Math.random() * (i + 1));
2308
- [turnOrder[i], turnOrder[j]] = [turnOrder[j], turnOrder[i]];
2309
- }
2310
- }
2311
- gameState.turnOrder = turnOrder;
2312
- gameState.currentPlayer = turnOrder[0] || null;
2313
- if (matchingRoom.gameType === "chess" && turnOrder.length >= 2) {
2314
- gameState.playerStates[turnOrder[0]].gameRole = "white";
2315
- gameState.playerStates[turnOrder[1]].gameRole = "black";
2316
- }
2317
- broadcastEvent(matchingRoom.id, "game_started", {
2318
- roomId: matchingRoom.id,
2319
- gameState,
2320
- turnOrder: gameState.turnOrder,
2321
- currentPlayer: gameState.currentPlayer
2322
- });
2323
- }
2324
- broadcastEvent(matchingRoom.id, "player_joined", {
2325
- roomId: matchingRoom.id,
2326
- player: { id: joiningPlayerId, displayName: joiningPlayerDisplayName }
2327
- });
2328
- broadcastEvent(matchingRoom.id, "room_data_updated", {
2329
- roomId: matchingRoom.id,
2330
- roomData: matchingRoom,
2331
- timestamp: Date.now()
2332
- });
2333
- return Promise.resolve({
2334
- action: "joined",
2335
- room: new MockVenusRoom(matchingRoom),
2336
- playersJoined: 1
2337
- });
2338
- } else {
2339
- console.log(`[Venus Mock Rooms] No matching room found, creating new room`);
2340
- const roomCreationOptions = {
2341
- ...createOptions,
2342
- userId: createOptions.userId || options.userId || "mock-user-creator",
2343
- userDisplayName: createOptions.userDisplayName || options.userDisplayName || "Creator"
2344
- };
2345
- const createResult = this.createRoom(roomCreationOptions);
2346
- return createResult.then((room) => ({
2347
- action: "created",
2348
- room,
2349
- // createRoom already returns MockVenusRoom instance
2350
- playersJoined: 1
2351
- }));
2352
- }
2353
- } catch (error) {
2354
- console.error(`[Venus Mock Rooms] Error in joinOrCreateRoom:`, error);
2355
- return Promise.reject({ success: false, error: error.message || "Failed to join or create room" });
2356
- }
2357
- },
2358
- joinRoomByCode(roomCode, playerMetadata = {}) {
2359
- try {
2360
- console.log(`[Venus Mock Rooms] Joining room by code ${roomCode}`);
2361
- let foundRoom = null;
2362
- for (const [roomId, room] of mockRooms.entries()) {
2363
- if (room.roomCode === roomCode && room.status === "active") {
2364
- foundRoom = room;
2365
- break;
2366
- }
2367
- }
2368
- if (!foundRoom) {
2369
- return Promise.reject({ success: false, error: `Room not found with code: ${roomCode}` });
2370
- }
2371
- return this.joinRoom(foundRoom.id, playerMetadata);
2372
- } catch (error) {
2373
- console.error(`[Venus Mock Rooms] Error joining room by code:`, error);
2374
- return Promise.reject({ success: false, error: error.message || "Failed to join room by code" });
2375
- }
2376
- },
2377
- // Stage 2: Enhanced game features
2378
- startGame(roomId, gameConfig = {}, requestingUserId = "mock-admin-user") {
2379
- try {
2380
- console.log(`[Venus Mock Rooms] Starting game in room ${roomId} by ${requestingUserId}`);
2381
- const room = mockRooms.get(roomId);
2382
- if (!room) {
2383
- return Promise.reject({ success: false, error: "Room not found" });
2384
- }
2385
- if (!room.admins.includes(requestingUserId) && room.createdBy !== requestingUserId) {
2386
- return Promise.reject({ success: false, error: "Only admin or creator can start game" });
2387
- }
2388
- if (room.customMetadata.rules.gameState.phase === "playing") {
2389
- return Promise.reject({ success: false, error: "Game already in progress" });
2390
- }
2391
- const minPlayers = room.customMetadata.rules.minPlayers || 1;
2392
- if (room.currentPlayers.length < minPlayers) {
2393
- return Promise.reject({ success: false, error: `Not enough players. Needs ${minPlayers}` });
2394
- }
2395
- const gameState = room.customMetadata.rules.gameState;
2396
- gameState.phase = "playing";
2397
- gameState.gameStartedAt = /* @__PURE__ */ new Date();
2398
- let turnOrder = [...room.currentPlayers];
2399
- if (room.customMetadata.rules.randomizePlayerOrder) {
2400
- for (let i = turnOrder.length - 1; i > 0; i--) {
2401
- const j = Math.floor(Math.random() * (i + 1));
2402
- [turnOrder[i], turnOrder[j]] = [turnOrder[j], turnOrder[i]];
2403
- }
2404
- }
2405
- gameState.turnOrder = turnOrder;
2406
- gameState.currentPlayer = turnOrder[0] || null;
2407
- turnOrder.forEach((playerId) => {
2408
- if (!gameState.playerStates[playerId]) {
2409
- gameState.playerStates[playerId] = { displayName: `Player ${playerId.slice(-4)}`, status: "active", role: "player" };
2410
- } else {
2411
- gameState.playerStates[playerId].status = "active";
2412
- if (!gameState.playerStates[playerId].displayName) {
2413
- gameState.playerStates[playerId].displayName = `Player ${playerId.slice(-4)}`;
2414
- }
2415
- }
2416
- });
2417
- room.updatedAt = /* @__PURE__ */ new Date();
2418
- room.version++;
2419
- console.log(`[Venus Mock Rooms] Game started in room ${roomId}. New state:`, room);
2420
- broadcastEvent(roomId, "game_started", { roomId, gameState, turnOrder: gameState.turnOrder, currentPlayer: gameState.currentPlayer });
2421
- broadcastEvent(roomId, "room_data_updated", { roomId, roomData: room, timestamp: Date.now() });
2422
- return Promise.resolve({ success: true, ...room });
2423
- } catch (error) {
2424
- console.error(`[Venus Mock Rooms] Error starting game:`, error);
2425
- return Promise.reject({ success: false, error: error.message || "Failed to start game" });
2426
- }
2427
- },
2428
- endGame(roomId, winner = null, reason = null, gameResults = {}) {
2429
- try {
2430
- console.log(`[Venus Mock Rooms] Player requesting to end game in room ${roomId}`);
2431
- const room = mockRooms.get(roomId);
2432
- if (!room) return Promise.reject({ success: false, error: "Room not found" });
2433
- const playerId = gameResults.endedBy || "mock-player-ender";
2434
- const move = {
2435
- playerId,
2436
- moveData: {
2437
- type: "end_game",
2438
- winner,
2439
- reason,
2440
- gameResults
2441
- },
2442
- timestamp: /* @__PURE__ */ new Date(),
2443
- status: "pending_mock_processing"
2444
- };
2445
- const roomMoves = mockRoomMoves.get(roomId) || [];
2446
- roomMoves.push(move);
2447
- mockRoomMoves.set(roomId, roomMoves);
2448
- this._processMockMove(roomId, move, room);
2449
- return Promise.resolve({ success: true, moveId: "mock-move-" + Date.now() });
2450
- } catch (error) {
2451
- console.error(`[Venus Mock Rooms] Error ending game:`, error);
2452
- return Promise.reject({ success: false, error: error.message || "Failed to end game" });
2453
- }
2454
- },
2455
- // NEW: Propose move (client-proposed state architecture)
2456
- proposeMove(roomId, proposalPayload, proposerId = "mock-proposer") {
2457
- try {
2458
- console.log(`[Venus Mock Rooms] Player ${proposerId} proposing move in room ${roomId}:`, proposalPayload);
2459
- const room = mockRooms.get(roomId);
2460
- if (!room) return Promise.reject({ success: false, error: "Room not found" });
2461
- const proposedMoveId = `prop_move_${Date.now()}_${Math.random().toString(36).substr(2, 5)}`;
2462
- const proposedMove = {
2463
- id: proposedMoveId,
2464
- proposerProfileId: proposerId,
2465
- timestamp: /* @__PURE__ */ new Date(),
2466
- gameSpecificState: proposalPayload.gameSpecificState,
2467
- moveType: proposalPayload.moveType,
2468
- clientContext: proposalPayload.clientContext,
2469
- clientProposalId: proposalPayload.clientProposalId,
2470
- serverGenericValidationStatus: "pending",
2471
- serverCustomValidationStatus: "pending",
2472
- clientConsensusStatus: "pending",
2473
- ...proposalPayload.resignedBy && { resignedBy: proposalPayload.resignedBy },
2474
- ...proposalPayload.winner && { winner: proposalPayload.winner }
2475
- };
2476
- if (!mockRoomMoves.has(roomId + "_proposed")) {
2477
- mockRoomMoves.set(roomId + "_proposed", []);
2478
- }
2479
- mockRoomMoves.get(roomId + "_proposed").push(proposedMove);
2480
- if (proposalPayload.gameSpecificState) {
2481
- room.optimisticGameState = proposalPayload.gameSpecificState;
2482
- room.lastProposedMoveId = proposedMoveId;
2483
- room.lastProposedMoveBy = proposerId;
2484
- room.lastProposedMoveAt = /* @__PURE__ */ new Date();
2485
- room.updatedAt = /* @__PURE__ */ new Date();
2486
- room.version++;
2487
- }
2488
- setTimeout(() => {
2489
- this._processMockProposedMove(roomId, proposedMoveId, proposedMove, room);
2490
- }, 100);
2491
- broadcastEvent(roomId, "room_data_updated", {
2492
- roomId,
2493
- roomData: room,
2494
- timestamp: Date.now()
2495
- });
2496
- if (proposalPayload.gameSpecificState) {
2497
- broadcastEvent(roomId, "app:h5:optimisticGameStateUpdated", {
2498
- roomId,
2499
- optimisticGameState: proposalPayload.gameSpecificState
2500
- });
2501
- }
2502
- return Promise.resolve({
2503
- success: true,
2504
- proposedMoveId,
2505
- optimisticGameState: proposalPayload.gameSpecificState
2506
- });
2507
- } catch (error) {
2508
- console.error(`[Venus Mock Rooms] Error proposing move:`, error);
2509
- return Promise.reject({ success: false, error: error.message || "Failed to propose move" });
2510
- }
2511
- },
2512
- // NEW internal helper to simulate server-side move processing for mock API
2513
- _processMockMove(roomId, move, room) {
2514
- console.log("[Venus Mock Rooms] Simulating server processing for move:", move);
2515
- move.id = "processed-mock-move-" + Date.now();
2516
- setTimeout(() => {
2517
- const currentRoomState = mockRooms.get(roomId);
2518
- if (!currentRoomState) return;
2519
- const { rules, gameState } = currentRoomState.customMetadata;
2520
- const { playerId, moveData } = move;
2521
- let isValidMove = true;
2522
- let validationError = null;
2523
- if (rules.turnBased && gameState.currentPlayer !== playerId) {
2524
- isValidMove = false;
2525
- validationError = "Not current player's turn.";
2526
- console.warn(`[Venus Mock Rooms] Invalid move by ${playerId}: Not their turn. Current: ${gameState.currentPlayer}`);
2527
- }
2528
- const moveType = moveData?.type;
2529
- if (isValidMove && moveType && rules.allowedMessageTypes?.[gameState.phase]?.[moveType]) {
2530
- const ruleForMoveType = rules.allowedMessageTypes[gameState.phase][moveType];
2531
- if (ruleForMoveType.requiredFields) {
2532
- for (const field of ruleForMoveType.requiredFields) {
2533
- if (!(field in moveData)) {
2534
- isValidMove = false;
2535
- validationError = `Missing required field: ${field} for move type ${moveType}.`;
2536
- console.warn(`[Venus Mock Rooms] Invalid move by ${playerId}: ${validationError}`);
2537
- break;
2538
- }
2539
- }
2540
- }
2541
- } else if (isValidMove && moveType && !rules.allowedMessageTypes?.[gameState.phase]?.[moveType]) {
2542
- console.warn(`[Venus Mock Rooms] Move type "${moveType}" not defined in allowedMessageTypes for phase "${gameState.phase}". Processing by default.`);
2543
- }
2544
- if (isValidMove) {
2545
- console.log("[Venus Mock Rooms] Move considered valid by mock server. Updating game state.");
2546
- move.status = "mock_valid";
2547
- gameState.lastMoveBy = playerId;
2548
- gameState.lastMoveTimestamp = /* @__PURE__ */ new Date();
2549
- if (moveData.type === "end_game") {
2550
- gameState.phase = "ended";
2551
- gameState.endedAt = /* @__PURE__ */ new Date();
2552
- currentRoomState.status = "archived";
2553
- console.log("[Venus Mock Rooms] Mock: Game ended.");
2554
- } else if (moveData.type === "force_update_state") {
2555
- Object.assign(gameState, moveData.payload);
2556
- console.log("[Venus Mock Rooms] Mock: Game state forcibly updated with:", moveData.payload);
2557
- }
2558
- const nonTurnAdvancingMoves = ["end_game", "force_update_state"];
2559
- if (rules.turnBased && gameState.turnOrder && gameState.turnOrder.length > 0 && !nonTurnAdvancingMoves.includes(moveData.type)) {
2560
- const currentPlayerIndex = gameState.turnOrder.indexOf(gameState.currentPlayer || "");
2561
- if (currentPlayerIndex !== -1) {
2562
- const nextPlayerIndex = (currentPlayerIndex + 1) % gameState.turnOrder.length;
2563
- gameState.currentPlayer = gameState.turnOrder[nextPlayerIndex];
2564
- gameState.turnCount = (gameState.turnCount || 0) + 1;
2565
- console.log(`[Venus Mock Rooms] Mock: Turn advanced to ${gameState.currentPlayer}`);
2566
- broadcastEvent(roomId, "turn_changed", {
2567
- roomId,
2568
- currentPlayer: gameState.currentPlayer,
2569
- previousPlayer: playerId,
2570
- // The one who just moved
2571
- turnCount: gameState.turnCount
2572
- });
2573
- }
2574
- }
2575
- currentRoomState.updatedAt = /* @__PURE__ */ new Date();
2576
- currentRoomState.version++;
2577
- broadcastEvent(roomId, "room_data_updated", { roomId, roomData: currentRoomState, timestamp: Date.now() });
2578
- } else {
2579
- console.warn("[Venus Mock Rooms] Move considered invalid by mock server. No game state change.", { validationError });
2580
- move.status = "mock_invalid";
2581
- move.error = validationError;
2582
- }
2583
- console.log("[Venus Mock Rooms] Finished mock processing for move:", move);
2584
- }, 100);
2585
- },
2586
- // NEW: Process proposed move for mock API
2587
- _processMockProposedMove(roomId, proposedMoveId, proposedMove, room) {
2588
- console.log("[Venus Mock Rooms] Simulating server processing for proposed move:", proposedMoveId);
2589
- const { rules, gameState } = room.customMetadata;
2590
- const { proposerProfileId, gameSpecificState, moveType } = proposedMove;
2591
- let isGenericValid = true;
2592
- let genericValidationReason = "";
2593
- if (moveType === "resignation") {
2594
- const resignedBy = proposedMove.resignedBy || gameSpecificState?.resignedBy;
2595
- if (!resignedBy) {
2596
- isGenericValid = false;
2597
- genericValidationReason = "Security violation: Resignation move must specify who is resigning (resignedBy field required).";
2598
- } else if (resignedBy !== proposerProfileId) {
2599
- isGenericValid = false;
2600
- genericValidationReason = `Security violation: Player ${proposerProfileId} cannot resign on behalf of player ${resignedBy}. Players can only resign themselves.`;
2601
- } else if (!gameState.playerStates || !gameState.playerStates[proposerProfileId]) {
2602
- isGenericValid = false;
2603
- genericValidationReason = `Security violation: Player ${proposerProfileId} is not in this game and cannot resign.`;
2604
- } else {
2605
- console.log(`[Venus Mock Rooms] \u2705 Resignation move validated: ${proposerProfileId} is resigning themselves`);
2606
- }
2607
- } else {
2608
- if (rules.turnBased && gameState.currentPlayer !== proposerProfileId) {
2609
- isGenericValid = false;
2610
- genericValidationReason = `Not player's turn. Current: ${gameState.currentPlayer}`;
2611
- }
2612
- }
2613
- if (isGenericValid && moveType && rules.allowedMessageTypes?.[gameState.phase]?.[moveType]) {
2614
- const ruleForMoveType = rules.allowedMessageTypes[gameState.phase][moveType];
2615
- if (ruleForMoveType.requiredFields) {
2616
- for (const field of ruleForMoveType.requiredFields) {
2617
- const hasField = moveType === "resignation" ? proposedMove[field] !== void 0 || gameSpecificState[field] !== void 0 : gameSpecificState[field] !== void 0;
2618
- if (!hasField) {
2619
- isGenericValid = false;
2620
- genericValidationReason = `Missing required field: ${field}`;
2621
- break;
2622
- }
2623
- }
2624
- }
2625
- }
2626
- proposedMove.serverGenericValidationStatus = isGenericValid ? "valid" : "invalid";
2627
- proposedMove.serverGenericValidationReason = genericValidationReason;
2628
- proposedMove.serverCustomValidationStatus = "not_applicable";
2629
- proposedMove.clientConsensusStatus = "valid";
2630
- if (isGenericValid) {
2631
- Object.assign(gameState, gameSpecificState);
2632
- if (gameSpecificState.isGameOver === true) {
2633
- gameState.phase = "ended";
2634
- gameState.winner = gameSpecificState.winner || null;
2635
- gameState.endReason = gameSpecificState.gameStatus || "completed";
2636
- gameState.endedAt = /* @__PURE__ */ new Date();
2637
- gameState.currentPlayer = null;
2638
- console.log(`[Venus Mock Rooms] \u{1F3C1} Game ended in room ${roomId}: ${gameState.endReason}, winner: ${gameState.winner || "draw"}`);
2639
- } else {
2640
- if (rules.turnBased && gameState.turnOrder && gameState.turnOrder.length > 0) {
2641
- const currentPlayerIndex = gameState.turnOrder.indexOf(gameState.currentPlayer || "");
2642
- if (currentPlayerIndex !== -1) {
2643
- const nextPlayerIndex = (currentPlayerIndex + 1) % gameState.turnOrder.length;
2644
- gameState.currentPlayer = gameState.turnOrder[nextPlayerIndex];
2645
- gameState.turnCount = (gameState.turnCount || 0) + 1;
2646
- }
2647
- }
2648
- }
2649
- gameState.lastMoveBy = proposerProfileId;
2650
- gameState.lastMoveTimestamp = /* @__PURE__ */ new Date();
2651
- room.updatedAt = /* @__PURE__ */ new Date();
2652
- room.version++;
2653
- console.log(`[Venus Mock Rooms] Proposed move ${proposedMoveId} validated and applied`);
2654
- } else {
2655
- console.log(`[Venus Mock Rooms] Proposed move ${proposedMoveId} validation failed: ${genericValidationReason}`);
2656
- }
2657
- broadcastEvent(roomId, "app:h5:proposedMoveValidationUpdated", {
2658
- roomId,
2659
- proposedMoveId,
2660
- proposedMoveData: proposedMove
2661
- });
2662
- if (isGenericValid) {
2663
- broadcastEvent(roomId, "room_data_updated", {
2664
- roomId,
2665
- roomData: room,
2666
- timestamp: Date.now()
2667
- });
2668
- }
2669
- },
2670
- getUserRooms(appId, includeArchived = false) {
2671
- try {
2672
- console.log(`[Venus Mock Rooms] Getting user rooms:`, { appId, includeArchived });
2673
- const userId = "mock-user";
2674
- let rooms = Array.from(mockRooms.values()).filter(
2675
- (room) => room.currentPlayers.includes(userId) && (!appId || room.appId === appId) && (includeArchived || room.status === "active")
2676
- );
2677
- rooms.sort((a, b) => new Date(b.updatedAt) - new Date(a.updatedAt));
2678
- return Promise.resolve({
2679
- success: true,
2680
- rooms
2681
- });
2682
- } catch (error) {
2683
- console.error(`[Venus Mock Rooms] Error getting user rooms:`, error);
2684
- return Promise.reject(new Error(error.message || "Failed to get user rooms"));
2685
- }
2686
- },
2687
- getGameState(roomId) {
2688
- try {
2689
- console.log(`[Venus Mock Rooms] Getting game state for room ${roomId}`);
2690
- const room = mockRooms.get(roomId);
2691
- if (!room) {
2692
- return Promise.reject({ success: false, error: "Room not found" });
2693
- }
2694
- const gameState = room.customMetadata?.rules?.gameState || {};
2695
- return Promise.resolve({
2696
- success: true,
2697
- data: gameState
2698
- // Return the authoritative game state from the mock room
2699
- });
2700
- } catch (error) {
2701
- console.error(`[Venus Mock Rooms] Error getting game state:`, error);
2702
- return Promise.reject({ success: false, error: error.message || "Failed to get game state" });
2703
- }
2704
- }
2705
- };
2706
- function initializeRooms(venusApiInstance, mockData = null) {
2707
- if (mockData && Array.isArray(mockData.rooms)) {
2708
- mockData.rooms.forEach((room) => {
2709
- mockRooms.set(room.id, room);
2710
- mockMessages.set(room.id, []);
2711
- mockPlayers.set(room.id, room.currentPlayers.map((playerId) => ({
2712
- id: playerId,
2713
- roomId: room.id,
2714
- joinedAt: /* @__PURE__ */ new Date(),
2715
- lastActive: /* @__PURE__ */ new Date(),
2716
- status: "active",
2717
- customData: {},
2718
- role: playerId === room.createdBy ? "owner" : "member"
2719
- })));
2720
- });
2721
- }
2722
- venusApiInstance.rooms = createProxiedObject.call(venusApiInstance, "rooms", roomsMock);
2723
- venusApiInstance.getUserRooms = createProxiedMethod("getUserRooms", roomsMock.getUserRooms);
2724
- venusApiInstance.createRoom = createProxiedMethod("createRoom", roomsMock.createRoom);
2725
- venusApiInstance.joinRoom = createProxiedMethod("joinRoom", roomsMock.joinRoom);
2726
- venusApiInstance.joinOrCreateRoom = createProxiedMethod("joinOrCreateRoom", roomsMock.joinOrCreateRoom);
2727
- venusApiInstance.joinRoomByCode = createProxiedMethod("joinRoomByCode", roomsMock.joinRoomByCode);
2728
- venusApiInstance.listPublicRooms = createProxiedMethod("listPublicRooms", roomsMock.listPublicRooms);
2729
- venusApiInstance.searchRooms = createProxiedMethod("searchRooms", roomsMock.searchRooms);
2730
- venusApiInstance.subscribeToRoom = createProxiedMethod("subscribeToRoom", roomsMock.subscribeToRoom);
2731
- venusApiInstance.isRoomSystemEnabled = function() {
2732
- return true;
2733
- };
2734
- }
2735
-
2736
- // src/venus-api/systems/asset-loader.js
2737
- var VenusAssetLoader = class {
2738
- constructor() {
2739
- this.cache = /* @__PURE__ */ new Map();
2740
- this.blobUrls = /* @__PURE__ */ new Map();
2741
- this.isWebView = false;
2742
- this.venusAPI = null;
2743
- }
2744
- // Set the VenusAPI reference during initialization
2745
- setVenusAPI(api) {
2746
- this.venusAPI = api;
2747
- this.isWebView = !api.isWeb || !api.isWeb();
2748
- }
2749
- /**
2750
- * Load any asset with automatic optimization
2751
- * @param {string} url - Asset URL
2752
- * @param {Object} options - Loading options
2753
- * @returns {Promise<string>} - URL to use (original, blob, or object URL)
2754
- */
2755
- async loadAsset(url, options = {}) {
2756
- const {
2757
- type = "auto",
2758
- // 'image', 'audio', 'video', 'text', 'json', 'auto'
2759
- cache = true,
2760
- // Use cache
2761
- timeout = 3e4,
2762
- isOptional = false
2763
- // New option to suppress error logging for optional assets
2764
- } = options;
2765
- const resolvedUrl = this.venusAPI && this.venusAPI.resolveAssetUrl ? this.venusAPI.resolveAssetUrl(url) : this._resolveAssetUrl(url);
2766
- if (cache && this.cache.has(resolvedUrl)) {
2767
- return this.cache.get(resolvedUrl);
2768
- }
2769
- const assetType = type === "auto" ? this._detectType(resolvedUrl) : type;
2770
- try {
2771
- let resultUrl = resolvedUrl;
2772
- if (assetType === "text" || assetType === "json") {
2773
- const content = await this._fetchText(resolvedUrl, timeout);
2774
- this.cache.set(resolvedUrl, content);
2775
- return content;
2776
- }
2777
- const isMockMode = this.venusAPI && this.venusAPI.isMock && this.venusAPI.isMock();
2778
- if (this.isWebView && !isMockMode && ["image", "audio", "video"].includes(assetType)) {
2779
- if (assetType === "video") {
2780
- resultUrl = await this._loadAsBlob(resolvedUrl, assetType);
2781
- if (cache) {
2782
- this.cache.set(resolvedUrl, resultUrl);
2783
- }
2784
- return resultUrl;
2785
- } else if (assetType === "audio") {
2786
- resultUrl = await this._loadAsBlob(resolvedUrl, assetType);
2787
- } else {
2788
- resultUrl = await this._loadAsBlob(resolvedUrl, assetType);
2789
- }
2790
- }
2791
- if (!(this.isWebView && !isMockMode && assetType === "video")) {
2792
- await this._verifyAsset(resultUrl, assetType);
2793
- }
2794
- if (cache) {
2795
- this.cache.set(resolvedUrl, resultUrl);
2135
+ if (cache) {
2136
+ this.cache.set(resolvedUrl, resultUrl);
2796
2137
  }
2797
2138
  return resultUrl;
2798
2139
  } catch (error) {
@@ -4635,34 +3976,272 @@ function initializeIap(venusApiInstance, host) {
4635
3976
  venusApiInstance.iap = host.iap;
4636
3977
  }
4637
3978
 
4638
- // src/profile/HostProfileApi.ts
4639
- var HostProfileApi = class {
4640
- getCurrentProfile() {
4641
- if (window.venus._config && window.venus._config.profile) {
4642
- return {
4643
- id: window.venus._config.profile.id || "unknown",
4644
- name: window.venus._config.profile.username || "Unknown User",
4645
- username: window.venus._config.profile.username || "unknown"
3979
+ // src/leaderboard/RpcLeaderboardApi.ts
3980
+ var RpcLeaderboardApi = class {
3981
+ constructor(rpcClient) {
3982
+ __publicField(this, "rpcClient");
3983
+ this.rpcClient = rpcClient;
3984
+ }
3985
+ startRun(mode) {
3986
+ return this.rpcClient.call(
3987
+ "H5_LEADERBOARD_START_RUN" /* H5_LEADERBOARD_START_RUN */,
3988
+ mode ? { mode } : {}
3989
+ );
3990
+ }
3991
+ submitScore(sessionId, score, durationSec, options) {
3992
+ return this.rpcClient.call(
3993
+ "H5_LEADERBOARD_SUBMIT_SCORE" /* H5_LEADERBOARD_SUBMIT_SCORE */,
3994
+ {
3995
+ sessionId,
3996
+ score,
3997
+ durationSec,
3998
+ mode: options?.mode,
3999
+ telemetry: options?.telemetry,
4000
+ metadata: options?.metadata,
4001
+ hash: options?.hash
4002
+ }
4003
+ );
4004
+ }
4005
+ getLeaderboard(options) {
4006
+ return this.rpcClient.call(
4007
+ "H5_LEADERBOARD_GET" /* H5_LEADERBOARD_GET */,
4008
+ options ?? {}
4009
+ );
4010
+ }
4011
+ getPlayerStats(options) {
4012
+ return this.rpcClient.call(
4013
+ "H5_LEADERBOARD_GET_PLAYER_STATS" /* H5_LEADERBOARD_GET_PLAYER_STATS */,
4014
+ options ?? {}
4015
+ );
4016
+ }
4017
+ getLeaderboardHighlight(options) {
4018
+ return this.rpcClient.call(
4019
+ "H5_LEADERBOARD_GET_HIGHLIGHT" /* H5_LEADERBOARD_GET_HIGHLIGHT */,
4020
+ options ?? {}
4021
+ );
4022
+ }
4023
+ };
4024
+
4025
+ // src/leaderboard/MockLeaderboardApi.ts
4026
+ var MockLeaderboardApi = class {
4027
+ constructor(options) {
4028
+ __publicField(this, "sessions", /* @__PURE__ */ new Map());
4029
+ __publicField(this, "entriesByMode", /* @__PURE__ */ new Map());
4030
+ __publicField(this, "sessionCounter", 0);
4031
+ __publicField(this, "requiresHash", false);
4032
+ if (options?.requiresHash) {
4033
+ this.requiresHash = true;
4034
+ }
4035
+ }
4036
+ configure(options) {
4037
+ if (typeof options.requiresHash === "boolean") {
4038
+ this.requiresHash = options.requiresHash;
4039
+ }
4040
+ }
4041
+ generateNonce() {
4042
+ return (Math.random().toString(36).slice(2) + Math.random().toString(36).slice(2)).slice(0, 64);
4043
+ }
4044
+ getModeKey(mode) {
4045
+ const normalizedMode = mode || "default";
4046
+ return `${normalizedMode}`;
4047
+ }
4048
+ getEntriesForMode(mode) {
4049
+ const key = this.getModeKey(mode);
4050
+ if (!this.entriesByMode.has(key)) {
4051
+ this.entriesByMode.set(key, []);
4052
+ }
4053
+ return this.entriesByMode.get(key);
4054
+ }
4055
+ async startRun(mode) {
4056
+ const sessionId = `mock_session_${++this.sessionCounter}`;
4057
+ const startTime = Date.now();
4058
+ const expiresAt = startTime + 36e5;
4059
+ const resolvedMode = mode || "default";
4060
+ const hashNonce = this.requiresHash ? this.generateNonce() : null;
4061
+ this.sessions.set(sessionId, {
4062
+ id: sessionId,
4063
+ expiresAt,
4064
+ mode: resolvedMode,
4065
+ hashNonce,
4066
+ used: false
4067
+ });
4068
+ return {
4069
+ sessionId,
4070
+ startTime,
4071
+ expiresAt,
4072
+ hashNonce,
4073
+ mode: resolvedMode
4074
+ };
4075
+ }
4076
+ async submitScore(sessionId, score, durationSec, options) {
4077
+ const session = this.sessions.get(sessionId);
4078
+ if (!session) {
4079
+ throw new Error("Invalid leaderboard session");
4080
+ }
4081
+ if (session.expiresAt < Date.now()) {
4082
+ throw new Error("Invalid or expired leaderboard session");
4083
+ }
4084
+ if (session.used) {
4085
+ throw new Error("Leaderboard session already used");
4086
+ }
4087
+ if (options?.mode && options.mode !== session.mode) {
4088
+ throw new Error("Submission mode does not match session mode");
4089
+ }
4090
+ if (session.hashNonce && !options?.hash) {
4091
+ throw new Error("Score hash is required for sealed leaderboard submissions");
4092
+ }
4093
+ const submittedAt = Date.now();
4094
+ const entry = {
4095
+ profileId: `mock_profile`,
4096
+ username: "Mock Player",
4097
+ avatarUrl: null,
4098
+ score,
4099
+ durationSec,
4100
+ submittedAt,
4101
+ sessionId,
4102
+ rank: null,
4103
+ zScore: null,
4104
+ isAnomaly: false,
4105
+ trustScore: 50,
4106
+ metadata: options?.metadata ?? null,
4107
+ isSeed: false
4108
+ };
4109
+ const modeEntries = this.getEntriesForMode(session.mode);
4110
+ modeEntries.push(entry);
4111
+ modeEntries.sort((a, b) => {
4112
+ if (b.score !== a.score) {
4113
+ return b.score - a.score;
4114
+ }
4115
+ return a.submittedAt - b.submittedAt;
4116
+ });
4117
+ modeEntries.forEach((e, index) => {
4118
+ modeEntries[index] = {
4119
+ ...e,
4120
+ rank: index + 1
4646
4121
  };
4647
- }
4122
+ });
4123
+ session.used = true;
4124
+ session.hashNonce = null;
4125
+ const inserted = modeEntries.find((e) => e.sessionId === sessionId && e.submittedAt === submittedAt);
4648
4126
  return {
4649
- id: "mock_profile_123",
4650
- name: "Mock User",
4651
- username: "mockuser"
4127
+ accepted: true,
4128
+ rank: inserted?.rank ?? null
4652
4129
  };
4653
4130
  }
4654
- };
4655
-
4656
- // src/profile/MockProfileApi.ts
4657
- var MockProfileApi = class {
4658
- getCurrentProfile() {
4131
+ async getLeaderboard(options) {
4132
+ const limit = options?.limit ?? 10;
4133
+ const mode = options?.mode ?? "default";
4134
+ const modeEntries = [...this.getEntriesForMode(mode)];
4135
+ const entries = modeEntries.slice(0, limit).map((entry) => ({
4136
+ ...entry
4137
+ }));
4659
4138
  return {
4660
- id: "mock_profile_123",
4661
- name: "Mock User",
4662
- username: "mockuser"
4139
+ variant: "standard",
4140
+ entries,
4141
+ totalEntries: modeEntries.length,
4142
+ nextCursor: null,
4143
+ playerRank: null,
4144
+ periodInstance: options?.period ?? "alltime"
4663
4145
  };
4664
4146
  }
4665
- };
4147
+ async getPlayerStats(_options) {
4148
+ const mode = _options?.mode ?? "default";
4149
+ const modeEntries = this.getEntriesForMode(mode);
4150
+ const playerEntry = modeEntries[0] ?? null;
4151
+ return {
4152
+ rank: playerEntry?.rank ?? null,
4153
+ score: playerEntry?.score,
4154
+ totalPlayers: modeEntries.length,
4155
+ percentile: playerEntry ? Math.max(0, 1 - ((playerEntry.rank ?? 1) - 1) / Math.max(modeEntries.length, 1)) : void 0,
4156
+ trustScore: 50,
4157
+ periodInstance: _options?.period ?? "alltime"
4158
+ };
4159
+ }
4160
+ async getLeaderboardHighlight(options) {
4161
+ const mode = options?.mode ?? "default";
4162
+ const modeEntries = [...this.getEntriesForMode(mode)];
4163
+ const topCount = Math.max(1, Math.min(options?.topCount ?? 3, 10));
4164
+ const aheadCount = Math.max(0, Math.min(options?.contextAhead ?? 4, 10));
4165
+ const behindCount = Math.max(0, Math.min(options?.contextBehind ?? 2, 10));
4166
+ const topEntries = modeEntries.slice(0, topCount);
4167
+ const playerEntry = modeEntries[0] ?? null;
4168
+ const totalEntries = modeEntries.length;
4169
+ let playerRank = playerEntry?.rank ?? null;
4170
+ let beforePlayer = [];
4171
+ let afterPlayer = [];
4172
+ let totalBefore = playerRank ? playerRank - 1 : 0;
4173
+ let totalAfter = playerRank ? Math.max(totalEntries - playerRank, 0) : 0;
4174
+ let omittedBefore = totalBefore;
4175
+ let omittedAfter = totalAfter;
4176
+ if (playerRank && playerRank > 0) {
4177
+ const beforeStart = Math.max(playerRank - aheadCount - 1, 0);
4178
+ beforePlayer = modeEntries.slice(beforeStart, playerRank - 1);
4179
+ const afterEnd = Math.min(playerRank + behindCount, totalEntries);
4180
+ afterPlayer = modeEntries.slice(playerRank, afterEnd);
4181
+ const shownTopAhead = topEntries.filter((entry) => (entry.rank ?? 0) > 0 && (entry.rank ?? 0) < playerRank).length;
4182
+ omittedBefore = Math.max(totalBefore - (beforePlayer.length + shownTopAhead), 0);
4183
+ omittedAfter = Math.max(totalAfter - afterPlayer.length, 0);
4184
+ }
4185
+ return {
4186
+ variant: "highlight",
4187
+ entries: topEntries,
4188
+ totalEntries,
4189
+ nextCursor: null,
4190
+ playerRank: playerRank ?? null,
4191
+ periodInstance: options?.period ?? "alltime",
4192
+ context: {
4193
+ topEntries,
4194
+ beforePlayer,
4195
+ playerEntry: playerEntry ?? null,
4196
+ afterPlayer,
4197
+ totalBefore,
4198
+ totalAfter,
4199
+ omittedBefore,
4200
+ omittedAfter
4201
+ }
4202
+ };
4203
+ }
4204
+ };
4205
+
4206
+ // src/leaderboard/index.ts
4207
+ function initializeLeaderboard(venusApiInstance, host) {
4208
+ venusApiInstance.leaderboard = host.leaderboard;
4209
+ }
4210
+
4211
+ // src/profile/HostProfileApi.ts
4212
+ var HostProfileApi = class {
4213
+ getCurrentProfile() {
4214
+ const profile = window.venus?.profile;
4215
+ if (!profile) {
4216
+ throw new Error(
4217
+ "[Venus SDK] Host profile handshake did not complete. Await VenusAPI.initializeAsync() so INIT_SDK can deliver the profile before calling profile APIs."
4218
+ );
4219
+ }
4220
+ if (!profile.id || !profile.username) {
4221
+ throw new Error(
4222
+ "[Venus SDK] INIT_SDK returned an incomplete profile (missing id/username). The host must supply real credentials before rooms APIs are used."
4223
+ );
4224
+ }
4225
+ return {
4226
+ id: profile.id,
4227
+ username: profile.username,
4228
+ avatarUrl: profile.avatarUrl,
4229
+ isAnonymous: profile.isAnonymous
4230
+ };
4231
+ }
4232
+ };
4233
+
4234
+ // src/profile/MockProfileApi.ts
4235
+ var MockProfileApi = class {
4236
+ getCurrentProfile() {
4237
+ return {
4238
+ id: "mock_profile_123",
4239
+ name: "Mock User",
4240
+ username: "mockuser",
4241
+ isAnonymous: false
4242
+ };
4243
+ }
4244
+ };
4666
4245
 
4667
4246
  // src/profile/index.ts
4668
4247
  function initializeProfile(venusApi, host) {
@@ -4921,14 +4500,6 @@ var MockPostApi = class {
4921
4500
  commentsCount: 0
4922
4501
  };
4923
4502
  }
4924
- async sharePostAsync(context) {
4925
- console.log("[Venus Mock] Sharing post with additionalInfo:", context);
4926
- await createMockDelay(MOCK_DELAYS.short);
4927
- return {
4928
- shared: true,
4929
- platform: "mock"
4930
- };
4931
- }
4932
4503
  async toggleFollowAsync() {
4933
4504
  const venusApi = this.venusApi;
4934
4505
  console.log("[Venus Mock] *Toggling follow status");
@@ -4973,11 +4544,6 @@ var RpcPostApi = class {
4973
4544
  openCommentsAsync() {
4974
4545
  return this.rpcClient.call("H5_OPEN_COMMENTS" /* OPEN_COMMENTS */, {});
4975
4546
  }
4976
- sharePostAsync(context) {
4977
- return this.rpcClient.call("H5_SHARE_POST" /* SHARE_POST */, {
4978
- shareContext: context
4979
- });
4980
- }
4981
4547
  toggleFollowAsync() {
4982
4548
  return this.rpcClient.call(
4983
4549
  "H5_TOGGLE_FOLLOW" /* TOGGLE_FOLLOW */,
@@ -5000,9 +4566,6 @@ function initializePost(venusApi, host) {
5000
4566
  venusApi.toggleLikeAsync = () => {
5001
4567
  return host.post.toggleLikeAsync();
5002
4568
  };
5003
- venusApi.sharePostAsync = async (options) => {
5004
- await host.post.sharePostAsync(options);
5005
- };
5006
4569
  venusApi.openCommentsAsync = async () => {
5007
4570
  await host.post.openCommentsAsync();
5008
4571
  };
@@ -5097,59 +4660,73 @@ function initializeFeaturesApi(venusApi, host) {
5097
4660
  // src/lifecycles/MockLifecycleApi.ts
5098
4661
  var MockLifecycleApi = class {
5099
4662
  constructor() {
5100
- __publicField(this, "playCallbacks", []);
5101
- __publicField(this, "pauseCallbacks", []);
5102
- __publicField(this, "resumeCallbacks", []);
5103
- __publicField(this, "quitCallbacks", []);
5104
- __publicField(this, "showCallbacks", []);
5105
- __publicField(this, "hideCallbacks", []);
5106
- }
5107
- onCleanup(callback) {
5108
- }
5109
- onShow(callback) {
5110
- this.showCallbacks.push(callback);
4663
+ __publicField(this, "pauseCallbacks", /* @__PURE__ */ new Set());
4664
+ __publicField(this, "resumeCallbacks", /* @__PURE__ */ new Set());
4665
+ __publicField(this, "awakeCallbacks", /* @__PURE__ */ new Set());
4666
+ __publicField(this, "sleepCallbacks", /* @__PURE__ */ new Set());
4667
+ __publicField(this, "quitCallbacks", /* @__PURE__ */ new Set());
4668
+ }
4669
+ onSleep(callback) {
4670
+ this.sleepCallbacks.add(callback);
4671
+ return {
4672
+ unsubscribe: () => {
4673
+ this.sleepCallbacks.delete(callback);
4674
+ }
4675
+ };
5111
4676
  }
5112
- onHide(callback) {
5113
- this.hideCallbacks.push(callback);
4677
+ onAwake(callback) {
4678
+ this.awakeCallbacks.add(callback);
4679
+ return {
4680
+ unsubscribe: () => {
4681
+ this.awakeCallbacks.delete(callback);
4682
+ }
4683
+ };
5114
4684
  }
5115
4685
  onPause(callback) {
5116
- this.pauseCallbacks.push(callback);
5117
- }
5118
- onPlay(callback) {
5119
- this.playCallbacks.push(callback);
5120
- }
5121
- onQuit(callback) {
5122
- this.quitCallbacks.push(callback);
4686
+ this.pauseCallbacks.add(callback);
4687
+ return {
4688
+ unsubscribe: () => {
4689
+ this.pauseCallbacks.delete(callback);
4690
+ }
4691
+ };
5123
4692
  }
5124
4693
  onResume(callback) {
5125
- this.resumeCallbacks.push(callback);
4694
+ this.resumeCallbacks.add(callback);
4695
+ return {
4696
+ unsubscribe: () => {
4697
+ this.resumeCallbacks.delete(callback);
4698
+ }
4699
+ };
5126
4700
  }
5127
- triggerOnPlayCallbacks(context) {
5128
- for (const callback of this.playCallbacks) {
5129
- callback(context);
5130
- }
4701
+ onQuit(callback) {
4702
+ this.quitCallbacks.add(callback);
4703
+ return {
4704
+ unsubscribe: () => {
4705
+ this.quitCallbacks.delete(callback);
4706
+ }
4707
+ };
5131
4708
  }
5132
- triggerOnPauseCallbacks() {
4709
+ triggerPauseCallbacks() {
5133
4710
  for (const callback of this.pauseCallbacks) {
5134
4711
  callback();
5135
4712
  }
5136
4713
  }
5137
- triggerOnResumeCallbacks() {
4714
+ triggerResumeCallbacks() {
5138
4715
  for (const callback of this.resumeCallbacks) {
5139
4716
  callback();
5140
4717
  }
5141
4718
  }
5142
- triggerOnShowCallbacks(context) {
5143
- for (const callback of this.showCallbacks) {
5144
- callback(context);
4719
+ triggerAwakeCallbacks() {
4720
+ for (const callback of this.awakeCallbacks) {
4721
+ callback();
5145
4722
  }
5146
4723
  }
5147
- triggerOnHideCallbacks() {
5148
- for (const callback of this.hideCallbacks) {
4724
+ triggerSleepCallbacks() {
4725
+ for (const callback of this.sleepCallbacks) {
5149
4726
  callback();
5150
4727
  }
5151
4728
  }
5152
- triggerOnQuitCallbacks() {
4729
+ triggerQuitCallbacks() {
5153
4730
  for (const callback of this.quitCallbacks) {
5154
4731
  callback();
5155
4732
  }
@@ -5162,52 +4739,26 @@ var RpcLifecycleApi = class {
5162
4739
  __publicField(this, "rpcClient");
5163
4740
  this.rpcClient = rpcClient;
5164
4741
  }
5165
- onCleanup(callback) {
5166
- this.rpcClient.onNotification("CLEANUP" /* CLEANUP */, callback);
5167
- }
5168
- onHide(callback) {
5169
- this.rpcClient.onNotification("HIDDEN" /* HIDDEN */, callback);
5170
- }
5171
- onPause(callback) {
5172
- this.rpcClient.onNotification("PAUSE" /* PAUSE */, callback);
4742
+ onQuit(callback) {
4743
+ return this.rpcClient.onNotification("QUIT" /* QUIT */, callback);
5173
4744
  }
5174
- onPlay(callback) {
5175
- this.rpcClient.onNotification("PLAY" /* PLAY */, callback);
4745
+ onSleep(callback) {
4746
+ return this.rpcClient.onNotification("SLEEP" /* SLEEP */, callback);
5176
4747
  }
5177
- onQuit(callback) {
5178
- this.rpcClient.onNotification("QUIT" /* QUIT */, callback);
4748
+ onAwake(callback) {
4749
+ return this.rpcClient.onNotification("AWAKE" /* AWAKE */, callback);
5179
4750
  }
5180
4751
  onResume(callback) {
5181
- this.rpcClient.onNotification("RESUME" /* RESUME */, callback);
4752
+ return this.rpcClient.onNotification("RESUME" /* RESUME */, callback);
5182
4753
  }
5183
- onShow(callback) {
5184
- this.rpcClient.onNotification("SHOWN" /* SHOWN */, callback);
4754
+ onPause(callback) {
4755
+ return this.rpcClient.onNotification("PAUSE" /* PAUSE */, callback);
5185
4756
  }
5186
4757
  };
5187
4758
 
5188
4759
  // src/lifecycles/index.ts
5189
4760
  function initializeLifecycleApi(venusApi, host) {
5190
- venusApi.onPlay = (callback) => {
5191
- host.lifecycle.onPlay(callback);
5192
- };
5193
- venusApi.onPause = (callback) => {
5194
- host.lifecycle.onPause(callback);
5195
- };
5196
- venusApi.onResume = (callback) => {
5197
- host.lifecycle.onResume(callback);
5198
- };
5199
- venusApi.onShow = (callback) => {
5200
- host.lifecycle.onShow(callback);
5201
- };
5202
- venusApi.onHide = (callback) => {
5203
- host.lifecycle.onHide(callback);
5204
- };
5205
- venusApi.onQuit = (callback) => {
5206
- host.lifecycle.onQuit(callback);
5207
- };
5208
- venusApi.onCleanup = (callback) => {
5209
- host.lifecycle.onCleanup(callback);
5210
- };
4761
+ venusApi.lifecycles = host.lifecycle;
5211
4762
  }
5212
4763
 
5213
4764
  // src/simulation/utils.ts
@@ -6072,41 +5623,8 @@ function initializeSimulation(venusApi, host) {
6072
5623
  };
6073
5624
  }
6074
5625
 
6075
- // src/rooms/MockRoomsApi.ts
6076
- var MockRoomsApi = class {
6077
- constructor() {
6078
- // Mock room storage to simulate real-time rooms in development
6079
- __publicField(this, "mockRooms", /* @__PURE__ */ new Map());
6080
- __publicField(this, "mockMessages", /* @__PURE__ */ new Map());
6081
- // roomId -> messages[]
6082
- __publicField(this, "mockRoomMoves", /* @__PURE__ */ new Map());
6083
- // roomId -> moves[]
6084
- __publicField(this, "mockSubscriptions", /* @__PURE__ */ new Map());
6085
- }
6086
- join(roomId) {
6087
- throw new Error("Method not implemented.");
6088
- }
6089
- // instanceId -> subscriptions
6090
- createRoom(options) {
6091
- return Promise.resolve(void 0);
6092
- }
6093
- generateRoomId() {
6094
- return "room_" + Date.now() + "_" + Math.random().toString(36).substr(2, 9);
6095
- }
6096
- // Helper to generate message IDs
6097
- generateMessageId() {
6098
- return "msg_" + Date.now() + "_" + Math.random().toString(36).substr(2, 9);
6099
- }
6100
- // Helper to generate room codes
6101
- generateRoomCode() {
6102
- const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
6103
- let code = "";
6104
- for (let i = 0; i < 6; i++) {
6105
- code += characters.charAt(Math.floor(Math.random() * characters.length));
6106
- }
6107
- return code;
6108
- }
6109
- };
5626
+ // src/MockHost.ts
5627
+ init_rooms();
6110
5628
 
6111
5629
  // src/logging/MockLoggingApi.ts
6112
5630
  var MockLoggingApi = class {
@@ -6252,7 +5770,121 @@ var MockSharedAssetsApi = class {
6252
5770
  }
6253
5771
  };
6254
5772
 
5773
+ // src/game-preloader/MockPreloaderApi.ts
5774
+ var MockPreloaderApi = class {
5775
+ async showLoadScreen() {
5776
+ console.log("showLoadScreen");
5777
+ }
5778
+ async hideLoadScreen() {
5779
+ console.log("hideLoadScreen");
5780
+ }
5781
+ async setLoaderText(text) {
5782
+ console.log("setLoaderText", text);
5783
+ }
5784
+ async setLoaderProgress(progress) {
5785
+ console.log("setLoaderProgress", progress);
5786
+ }
5787
+ };
5788
+
5789
+ // src/game-preloader/RpcPreloaderApi.ts
5790
+ var RpcPreloaderApi = class {
5791
+ constructor(rpcClient) {
5792
+ __publicField(this, "rpcClient");
5793
+ this.rpcClient = rpcClient;
5794
+ }
5795
+ async showLoadScreen() {
5796
+ await this.rpcClient.call("H5_SHOW_LOAD_SCREEN" /* H5_SHOW_LOAD_SCREEN */);
5797
+ }
5798
+ async hideLoadScreen() {
5799
+ await this.rpcClient.call("H5_HIDE_LOAD_SCREEN" /* H5_HIDE_LOAD_SCREEN */);
5800
+ }
5801
+ async setLoaderText(text) {
5802
+ await this.rpcClient.call("H5_SET_LOADER_TEXT" /* H5_SET_LOADER_TEXT */, { text });
5803
+ }
5804
+ async setLoaderProgress(progress) {
5805
+ await this.rpcClient.call("H5_SET_LOADER_PROGRESS" /* H5_SET_LOADER_PROGRESS */, { progress });
5806
+ }
5807
+ };
5808
+
5809
+ // src/game-preloader/index.ts
5810
+ function initializePreloader(venusApi, host) {
5811
+ venusApi.preloader = host.preloader;
5812
+ }
5813
+
5814
+ // src/social/MockSocialApi.ts
5815
+ var MOCK_QR_CODE = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==";
5816
+ var MockSocialApi = class {
5817
+ async shareLinkAsync(options) {
5818
+ const shareUrl = this.createMockUrl(options.launchParams);
5819
+ if (typeof navigator !== "undefined" && navigator.clipboard) {
5820
+ try {
5821
+ await navigator.clipboard.writeText(shareUrl);
5822
+ console.log("[Venus SDK] (mock) Copied share URL to clipboard");
5823
+ } catch (error) {
5824
+ console.warn(
5825
+ "[Venus SDK] (mock) Failed to copy share URL to clipboard",
5826
+ error
5827
+ );
5828
+ }
5829
+ }
5830
+ return { shareUrl };
5831
+ }
5832
+ async createQRCodeAsync(options) {
5833
+ const shareUrl = this.createMockUrl(options.launchParams);
5834
+ return {
5835
+ shareUrl,
5836
+ qrCode: MOCK_QR_CODE
5837
+ };
5838
+ }
5839
+ createMockUrl(launchParams) {
5840
+ const params = new URLSearchParams(launchParams);
5841
+ return `https://mock-share.venus.test/share?${params.toString()}`;
5842
+ }
5843
+ };
5844
+
6255
5845
  // src/MockHost.ts
5846
+ var ROOMS_UNAVAILABLE_MESSAGE = "[Venus SDK] Rooms API is only available when running inside the Venus host environment.";
5847
+ function createUnavailableRoomsApi() {
5848
+ const roomsUnavailableError = () => new Error(ROOMS_UNAVAILABLE_MESSAGE);
5849
+ return {
5850
+ async createRoom() {
5851
+ throw roomsUnavailableError();
5852
+ },
5853
+ async joinOrCreateRoom() {
5854
+ throw roomsUnavailableError();
5855
+ },
5856
+ async getUserRooms() {
5857
+ throw roomsUnavailableError();
5858
+ },
5859
+ async joinRoomByCode() {
5860
+ throw roomsUnavailableError();
5861
+ },
5862
+ subscribe() {
5863
+ throw roomsUnavailableError();
5864
+ },
5865
+ async updateData() {
5866
+ throw roomsUnavailableError();
5867
+ },
5868
+ async getData() {
5869
+ throw roomsUnavailableError();
5870
+ },
5871
+ async sendMessage() {
5872
+ throw roomsUnavailableError();
5873
+ },
5874
+ async leave() {
5875
+ throw roomsUnavailableError();
5876
+ },
5877
+ async startGame() {
5878
+ throw roomsUnavailableError();
5879
+ },
5880
+ async proposeMove() {
5881
+ throw roomsUnavailableError();
5882
+ },
5883
+ async validateMove() {
5884
+ throw roomsUnavailableError();
5885
+ }
5886
+ };
5887
+ }
6256
5888
  var MockHost = class {
6257
5889
  constructor(venusApi) {
6258
5890
  __publicField(this, "ads");
@@ -6276,6 +5908,9 @@ var MockHost = class {
6276
5908
  __publicField(this, "rooms");
6277
5909
  __publicField(this, "logging");
6278
5910
  __publicField(this, "iap");
5911
+ __publicField(this, "leaderboard");
5912
+ __publicField(this, "preloader");
5913
+ __publicField(this, "social");
6279
5914
  __publicField(this, "state", 0 /* PLAYING */);
6280
5915
  __publicField(this, "venusApi");
6281
5916
  __publicField(this, "_isInitialized", false);
@@ -6305,18 +5940,24 @@ var MockHost = class {
6305
5940
  this.features = new MockFeaturesApi();
6306
5941
  this.lifecycle = this._mockLifecyclesApi;
6307
5942
  this.simulation = new MockSimulationApi();
6308
- this.rooms = new MockRoomsApi();
5943
+ this.rooms = createUnavailableRoomsApi();
6309
5944
  this.logging = new MockLoggingApi();
6310
5945
  this.iap = new MockIapApi();
5946
+ this.social = new MockSocialApi();
5947
+ this.leaderboard = new MockLeaderboardApi();
5948
+ initializeRoomsApi(this.venusApi, this);
5949
+ this.preloader = new MockPreloaderApi();
6311
5950
  venusApi.isMock = () => true;
6312
5951
  this.venusApi.sharedAssets = new MockSharedAssetsApi(this.venusApi);
6313
5952
  }
6314
5953
  get isInitialized() {
6315
5954
  return this._isInitialized;
6316
5955
  }
6317
- initialize() {
5956
+ initialize(options) {
6318
5957
  this._isInitialized = true;
6319
- return Promise.resolve();
5958
+ return Promise.resolve({
5959
+ initializeAsleep: false
5960
+ });
6320
5961
  }
6321
5962
  updateUiControls() {
6322
5963
  const controls = {
@@ -6387,27 +6028,87 @@ var MockHost = class {
6387
6028
  };
6388
6029
  }
6389
6030
  async handleMenuButtonClicked() {
6390
- this.triggerLifecycleEvent("PAUSE" /* PAUSE */);
6391
- const sleepAwakeToggleAction = {
6031
+ if (this.state === 0 /* PLAYING */) {
6032
+ this.triggerLifecycleEvent("PAUSE" /* PAUSE */);
6033
+ this.state = 1 /* PAUSED */;
6034
+ }
6035
+ const actionSheetItems = [];
6036
+ const awakeAction = {
6392
6037
  label: "\u23F0 Awake",
6393
- id: "sleepAwakeToggle"
6038
+ id: "awakeAction"
6039
+ };
6040
+ const sleepAction = {
6041
+ label: "\u{1F4A4} Sleep",
6042
+ id: "sleepAction"
6043
+ };
6044
+ const quitAction = {
6045
+ label: "\u{1F6D1} Quit",
6046
+ id: "quitAction"
6047
+ };
6048
+ const playAction = {
6049
+ label: "\u25B6\uFE0F Play",
6050
+ id: "playAction"
6394
6051
  };
6395
6052
  if (this.state === 1 /* PAUSED */) {
6396
- sleepAwakeToggleAction.label = "\u{1F4A4} Sleep";
6397
- }
6398
- const action = await this.showActionSheetOverlay([sleepAwakeToggleAction]);
6399
- if (action === sleepAwakeToggleAction.id) {
6400
- if (this.state === 1 /* PAUSED */) {
6401
- this.state = 2 /* SLEEPING */;
6402
- this.triggerLifecycleEvent("HIDDEN" /* HIDDEN */);
6403
- } else {
6404
- this.state = 1 /* PAUSED */;
6405
- this.triggerLifecycleEvent("SHOWN" /* SHOWN */);
6406
- }
6053
+ actionSheetItems.push(sleepAction);
6054
+ } else if (this.state === 2 /* SLEEPING */) {
6055
+ actionSheetItems.push(awakeAction);
6056
+ }
6057
+ if (this.state !== 3 /* TERMINATED */) {
6058
+ actionSheetItems.push(quitAction);
6059
+ } else if (this.state === 3 /* TERMINATED */) {
6060
+ actionSheetItems.push(playAction);
6061
+ }
6062
+ const action = await this.showActionSheetOverlay(actionSheetItems);
6063
+ if (action === awakeAction.id) {
6064
+ this.tryAwake();
6065
+ } else if (action === sleepAction.id) {
6066
+ this.trySleep();
6067
+ } else if (action === playAction.id) {
6068
+ this.tryPlay();
6069
+ } else if (action === quitAction.id) {
6070
+ this.tryQuit();
6407
6071
  } else {
6408
- if (this.state === 1 /* PAUSED */) {
6409
- this.triggerLifecycleEvent("RESUME" /* RESUME */);
6410
- }
6072
+ this.tryResume();
6073
+ }
6074
+ }
6075
+ tryAwake() {
6076
+ if (this.state === 2 /* SLEEPING */) {
6077
+ this.triggerLifecycleEvent("AWAKE" /* AWAKE */);
6078
+ this.state = 1 /* PAUSED */;
6079
+ }
6080
+ }
6081
+ trySleep() {
6082
+ if (this.state === 1 /* PAUSED */) {
6083
+ this.triggerLifecycleEvent("SLEEP" /* SLEEP */);
6084
+ this.state = 2 /* SLEEPING */;
6085
+ }
6086
+ }
6087
+ tryPlay() {
6088
+ if (this.state === 3 /* TERMINATED */) {
6089
+ this.triggerLifecycleEvent("AWAKE" /* AWAKE */);
6090
+ this.state = 1 /* PAUSED */;
6091
+ this.triggerLifecycleEvent("RESUME" /* RESUME */);
6092
+ this.state = 0 /* PLAYING */;
6093
+ }
6094
+ }
6095
+ tryQuit() {
6096
+ if (this.state === 0 /* PLAYING */) {
6097
+ this.triggerLifecycleEvent("PAUSE" /* PAUSE */);
6098
+ this.state = 1 /* PAUSED */;
6099
+ }
6100
+ if (this.state === 1 /* PAUSED */) {
6101
+ this.triggerLifecycleEvent("SLEEP" /* SLEEP */);
6102
+ this.state = 2 /* SLEEPING */;
6103
+ }
6104
+ if (this.state === 2 /* SLEEPING */) {
6105
+ this.triggerLifecycleEvent("QUIT" /* QUIT */);
6106
+ this.state = 3 /* TERMINATED */;
6107
+ }
6108
+ }
6109
+ tryResume() {
6110
+ if (this.state === 1 /* PAUSED */) {
6111
+ this.triggerLifecycleEvent("RESUME" /* RESUME */);
6411
6112
  }
6412
6113
  }
6413
6114
  async showAdOverlay(type) {
@@ -6538,28 +6239,16 @@ var MockHost = class {
6538
6239
  }
6539
6240
  triggerLifecycleEvent(name) {
6540
6241
  console.log("Trigger Lifecycle Event: ", name);
6541
- if (name == "PLAY" /* PLAY */) {
6542
- this._mockLifecyclesApi.triggerOnPlayCallbacks({
6543
- hudInsets: { top: 60, right: 0, bottom: 0, left: 0 },
6544
- // shareData: {
6545
- // title: 'Mock Share Title',
6546
- // description: 'Mock share description for testing',
6547
- // },
6548
- format: "post"
6549
- // stackData: null,
6550
- });
6551
- } else if (name == "PAUSE" /* PAUSE */) {
6552
- this._mockLifecyclesApi.triggerOnPauseCallbacks();
6242
+ if (name == "PAUSE" /* PAUSE */) {
6243
+ this._mockLifecyclesApi.triggerPauseCallbacks();
6553
6244
  } else if (name == "RESUME" /* RESUME */) {
6554
- this._mockLifecyclesApi.triggerOnResumeCallbacks();
6245
+ this._mockLifecyclesApi.triggerResumeCallbacks();
6555
6246
  } else if (name == "QUIT" /* QUIT */) {
6556
- this._mockLifecyclesApi.triggerOnQuitCallbacks();
6557
- } else if (name == "SHOWN" /* SHOWN */) {
6558
- this._mockLifecyclesApi.triggerOnShowCallbacks({
6559
- hudInsets: { top: 60, bottom: 120, left: 0, right: 0 }
6560
- });
6561
- } else if (name == "HIDDEN" /* HIDDEN */) {
6562
- this._mockLifecyclesApi.triggerOnHideCallbacks();
6247
+ this._mockLifecyclesApi.triggerQuitCallbacks();
6248
+ } else if (name == "AWAKE" /* AWAKE */) {
6249
+ this._mockLifecyclesApi.triggerAwakeCallbacks();
6250
+ } else if (name == "SLEEP" /* SLEEP */) {
6251
+ this._mockLifecyclesApi.triggerSleepCallbacks();
6563
6252
  }
6564
6253
  }
6565
6254
  setOverlayElementVisibility(element, visible) {
@@ -6862,7 +6551,7 @@ var VenusTransport = class {
6862
6551
  return;
6863
6552
  }
6864
6553
  this.notifyVenusMessageReceived(message);
6865
- 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 */) {
6554
+ if (message.type === "PAUSE" /* PAUSE */ || message.type === "RESUME" /* RESUME */ || message.type === "AWAKE" /* AWAKE */ || message.type === "SLEEP" /* SLEEP */ || message.type === "QUIT" /* QUIT */) {
6866
6555
  const notification = {
6867
6556
  type: "rpc-notification",
6868
6557
  id: message.type,
@@ -7044,177 +6733,49 @@ var VenusTransport = class {
7044
6733
  }
7045
6734
  };
7046
6735
 
7047
- // src/notifications/RpcNotificationsApi.ts
7048
- var RpcNotificationsApi = class {
6736
+ // src/RemoteHost.ts
6737
+ init_rooms();
6738
+
6739
+ // src/rooms/RpcRoomsApi.ts
6740
+ init_VenusRoom();
6741
+ var RpcRoomsApi = class {
7049
6742
  constructor(rpcClient) {
7050
6743
  __publicField(this, "rpcClient");
6744
+ __publicField(this, "subscriptions");
6745
+ __publicField(this, "transportSubscription", null);
7051
6746
  this.rpcClient = rpcClient;
7052
- }
7053
- async scheduleLocalNotification(title, body, options) {
7054
- const request = {
7055
- title,
7056
- body,
7057
- data: options?.payload,
7058
- key: options?.groupId,
7059
- priority: options?.priority || 1,
7060
- trigger: options?.trigger ?? null
6747
+ this.subscriptions = {
6748
+ data: {},
6749
+ messages: {},
6750
+ gameEvents: {},
6751
+ allEvents: {}
7061
6752
  };
7062
- const response = await this.rpcClient.call(
7063
- "H5_SCHEDULE_LOCAL_NOTIFICATION" /* SCHEDULE_LOCAL_NOTIFICATION */,
7064
- request
7065
- );
7066
- if (response.scheduled) {
7067
- return response.id;
7068
- }
7069
- return null;
7070
- }
7071
- async cancelLocalNotification(id) {
7072
- const result = await this.rpcClient.call(
7073
- "H5_CANCEL_LOCAL_NOTIFICATION" /* CANCEL_LOCAL_NOTIFICATION */,
7074
- {
7075
- id
7076
- }
7077
- );
7078
- return result.canceled;
7079
6753
  }
7080
- async getAllScheduledLocalNotifications() {
7081
- const response = await this.rpcClient.call(
7082
- "H5_GET_ALL_SCHEDULED_LOCAL_NOTIFICATIONS" /* GET_ALL_SCHEDULED_LOCAL_NOTIFICATIONS */,
7083
- {}
7084
- );
7085
- const notifications = response.notifications.map((notif) => {
7086
- return {
7087
- id: notif.identifier,
7088
- title: notif.content.title,
7089
- body: notif.content.body,
7090
- payload: notif.content.data,
7091
- trigger: notif.trigger
7092
- };
7093
- });
7094
- return notifications;
7095
- }
7096
- async isLocalNotificationsEnabled() {
7097
- const response = await this.rpcClient.call(
7098
- "H5_IS_LOCAL_NOTIFICATIONS_ENABLED" /* IS_LOCAL_NOTIFICATIONS_ENABLED */,
7099
- {}
7100
- );
7101
- return response.enabled;
6754
+ /**
6755
+ * Get the subscription state for external access (used by setupRoomNotifications)
6756
+ */
6757
+ getSubscriptions() {
6758
+ return this.subscriptions;
7102
6759
  }
7103
- async setLocalNotificationsEnabled(enabled) {
7104
- const response = await this.rpcClient.call(
7105
- "H5_SET_LOCAL_NOTIFICATIONS_ENABLED" /* SET_LOCAL_NOTIFICATIONS_ENABLED */,
7106
- {
7107
- enabled
7108
- }
6760
+ /**
6761
+ * Set up room notification routing from the transport
6762
+ */
6763
+ setupNotifications(transport) {
6764
+ const { setupRoomNotifications: setupRoomNotifications2 } = (init_rooms(), __toCommonJS(rooms_exports));
6765
+ this.transportSubscription = setupRoomNotifications2(
6766
+ transport,
6767
+ () => this.getSubscriptions()
7109
6768
  );
7110
- return response.enabled;
7111
6769
  }
7112
- };
7113
-
7114
- // src/rooms/VenusRoom.ts
7115
- var VenusRoom = class {
7116
- constructor(roomData) {
7117
- __publicField(this, "id");
7118
- __publicField(this, "name");
7119
- __publicField(this, "players");
7120
- __publicField(this, "maxPlayers");
7121
- __publicField(this, "gameType");
7122
- __publicField(this, "appId");
7123
- __publicField(this, "type");
7124
- __publicField(this, "createdBy");
7125
- __publicField(this, "createdAt");
7126
- __publicField(this, "updatedAt");
7127
- __publicField(this, "isPrivate");
7128
- __publicField(this, "currentPlayers");
7129
- __publicField(this, "status");
7130
- __publicField(this, "customMetadata");
7131
- __publicField(this, "admins");
7132
- __publicField(this, "roomCode");
7133
- __publicField(this, "description");
7134
- __publicField(this, "data");
7135
- __publicField(this, "version");
7136
- __publicField(this, "_subscriptions", /* @__PURE__ */ new Map());
7137
- this.id = roomData.id;
7138
- this.name = roomData.name;
7139
- this.players = roomData.currentPlayers || [];
7140
- this.maxPlayers = roomData.maxPlayers;
7141
- this.gameType = roomData.gameType;
7142
- this.appId = roomData.appId;
7143
- this.type = roomData.type;
7144
- this.createdBy = roomData.createdBy;
7145
- this.createdAt = roomData.createdAt;
7146
- this.updatedAt = roomData.updatedAt;
7147
- this.isPrivate = roomData.isPrivate;
7148
- this.currentPlayers = roomData.currentPlayers || [];
7149
- this.status = roomData.status;
7150
- this.customMetadata = roomData.customMetadata || {};
7151
- this.admins = roomData.admins || [];
7152
- this.roomCode = roomData.roomCode;
7153
- this.description = roomData.description;
7154
- this.data = roomData.data || {};
7155
- this.version = roomData.version;
7156
- console.log(`VenusRoom: Created room object for ${this.id}`, {
7157
- hasCustomMetadata: !!this.customMetadata,
7158
- hasGameState: !!this.customMetadata?.rules?.gameState,
7159
- gamePhase: this.customMetadata?.rules?.gameState?.phase,
7160
- currentPlayer: this.customMetadata?.rules?.gameState?.currentPlayer
7161
- });
7162
- }
7163
- updateFromRoomData(newRoomData) {
7164
- if (newRoomData.id === this.id) {
7165
- this.name = newRoomData.name || this.name;
7166
- this.players = newRoomData.currentPlayers || this.players;
7167
- this.maxPlayers = newRoomData.maxPlayers || this.maxPlayers;
7168
- this.gameType = newRoomData.gameType || this.gameType;
7169
- this.currentPlayers = newRoomData.currentPlayers || this.currentPlayers;
7170
- this.customMetadata = newRoomData.customMetadata || this.customMetadata;
7171
- this.data = newRoomData.data || this.data;
7172
- this.status = newRoomData.status || this.status;
7173
- this.updatedAt = newRoomData.updatedAt || this.updatedAt;
7174
- console.log(`VenusRoom: Updated room object ${this.id} with fresh data`, {
7175
- hasCustomMetadata: !!this.customMetadata,
7176
- hasGameState: !!this.customMetadata?.rules?.gameState,
7177
- gamePhase: this.customMetadata?.rules?.gameState?.phase,
7178
- currentPlayer: this.customMetadata?.rules?.gameState?.currentPlayer
7179
- });
7180
- }
7181
- }
7182
- // NEW: Generic message handler for room-manager.js integration
7183
- onMessage(callback) {
7184
- const subscriptionId = "messages_" + Date.now() + "_" + Math.random().toString(36).substr(2, 9);
7185
- if (!window.venus._roomSubscriptions.allEvents) {
7186
- window.venus._roomSubscriptions.allEvents = {};
7187
- }
7188
- if (!window.venus._roomSubscriptions.allEvents[this.id]) {
7189
- window.venus._roomSubscriptions.allEvents[this.id] = [];
6770
+ /**
6771
+ * Clean up subscriptions and resources
6772
+ */
6773
+ dispose() {
6774
+ if (this.transportSubscription) {
6775
+ this.transportSubscription.unsubscribe();
6776
+ this.transportSubscription = null;
6777
+ console.log("[Venus Rooms] Cleaned up room notification subscription");
7190
6778
  }
7191
- window.venus._roomSubscriptions.allEvents[this.id].push(callback);
7192
- this._subscriptions.set(subscriptionId, {
7193
- type: "allEvents",
7194
- callback
7195
- });
7196
- return {
7197
- unsubscribe: () => {
7198
- const callbacks = window.venus._roomSubscriptions.allEvents[this.id] || [];
7199
- const index = callbacks.indexOf(callback);
7200
- if (index > -1) callbacks.splice(index, 1);
7201
- this._subscriptions.delete(subscriptionId);
7202
- }
7203
- };
7204
- }
7205
- };
7206
-
7207
- // src/rooms/RpcRoomsApi.ts
7208
- var RpcRoomsApi = class {
7209
- constructor(rpcClient) {
7210
- __publicField(this, "rpcClient");
7211
- __publicField(this, "isRoomSystemEnabled", function() {
7212
- return true;
7213
- });
7214
- this.rpcClient = rpcClient;
7215
- }
7216
- join(roomId) {
7217
- throw new Error("Method not implemented.");
7218
6779
  }
7219
6780
  async createRoom(options) {
7220
6781
  const response = await this.rpcClient.call(
@@ -7248,33 +6809,6 @@ var RpcRoomsApi = class {
7248
6809
  playersJoined: data.playersJoined
7249
6810
  };
7250
6811
  }
7251
- async listPublicRooms(gameType, limit = 20) {
7252
- const response = await this.rpcClient.call(
7253
- "H5_ROOM_LIST_PUBLIC" /* H5_ROOM_LIST_PUBLIC */,
7254
- {
7255
- gameType,
7256
- limit
7257
- }
7258
- );
7259
- if (!response.success) {
7260
- throw new Error(response.error || "Failed to list public rooms");
7261
- }
7262
- return response.rooms || [];
7263
- }
7264
- async searchRooms(searchQuery, gameType, limit = 20) {
7265
- const response = await this.rpcClient.call(
7266
- "H5_ROOM_SEARCH" /* H5_ROOM_SEARCH */,
7267
- {
7268
- searchQuery,
7269
- gameType,
7270
- limit
7271
- }
7272
- );
7273
- if (!response.success) {
7274
- throw new Error(response.error || "Failed to search rooms");
7275
- }
7276
- return response.rooms || [];
7277
- }
7278
6812
  async joinRoomByCode(roomCode) {
7279
6813
  const response = await this.rpcClient.call(
7280
6814
  "H5_ROOM_JOIN_BY_CODE" /* H5_ROOM_JOIN_BY_CODE */,
@@ -7282,7 +6816,7 @@ var RpcRoomsApi = class {
7282
6816
  roomCode
7283
6817
  }
7284
6818
  );
7285
- if (!response.success) {
6819
+ if (response?.success === false) {
7286
6820
  throw new Error(response.error || "Failed to join room by code");
7287
6821
  }
7288
6822
  const roomData = response.roomData || response;
@@ -7290,15 +6824,14 @@ var RpcRoomsApi = class {
7290
6824
  return room;
7291
6825
  }
7292
6826
  // Get user's rooms with optional filtering
7293
- async getUserRooms(appId, includeArchived = false) {
6827
+ async getUserRooms(includeArchived = false) {
7294
6828
  const response = await this.rpcClient.call(
7295
6829
  "H5_ROOM_GET_USER_ROOMS" /* H5_ROOM_GET_USER_ROOMS */,
7296
6830
  {
7297
- appId,
7298
- includePersonal: includeArchived
6831
+ includeArchived
7299
6832
  }
7300
6833
  );
7301
- if (!response.success) {
6834
+ if (response?.success === false) {
7302
6835
  throw new Error(response.error || "Failed to get user rooms");
7303
6836
  }
7304
6837
  const rawRooms = response.rooms || [];
@@ -7321,62 +6854,6 @@ var RpcRoomsApi = class {
7321
6854
  }
7322
6855
  return venusRooms;
7323
6856
  }
7324
- // Convenience method for common use case
7325
- quickMatch(gameType) {
7326
- return this.joinOrCreateRoom({
7327
- matchCriteria: {
7328
- gameType,
7329
- isPrivate: false,
7330
- hasSpace: true
7331
- },
7332
- createOptions: {
7333
- name: gameType + " Game",
7334
- gameType,
7335
- isPrivate: false,
7336
- maxPlayers: 4
7337
- // sensible default
7338
- }
7339
- });
7340
- }
7341
- // Enhanced room creation with game rules
7342
- async createGameRoom(options) {
7343
- const enhancedOptions = {
7344
- ...options,
7345
- customMetadata: {
7346
- ...options.customMetadata,
7347
- rules: {
7348
- ruleEngine: options.ruleEngine || "basic",
7349
- validateMessages: options.validateMessages || false,
7350
- randomizePlayerOrder: options.randomizePlayerOrder || false,
7351
- clientValidation: options.clientValidation || false,
7352
- allowedMessageTypes: options.allowedMessageTypes || {},
7353
- gameState: {
7354
- phase: "waiting",
7355
- currentPlayer: null,
7356
- turnOrder: [],
7357
- playerStates: {},
7358
- ...options.initialGameState
7359
- },
7360
- ...options.rules
7361
- }
7362
- }
7363
- };
7364
- return this.createRoom(enhancedOptions);
7365
- }
7366
- // Convenience method for subscribing to all game events
7367
- subscribeToGameEvents(roomId, callback) {
7368
- if (!window.venus._roomSubscriptions.gameEvents[roomId]) {
7369
- window.venus._roomSubscriptions.gameEvents[roomId] = [];
7370
- }
7371
- window.venus._roomSubscriptions.gameEvents[roomId].push(callback);
7372
- return {
7373
- unsubscribe: () => {
7374
- const callbacks = window.venus._roomSubscriptions.gameEvents[roomId] || [];
7375
- const index = callbacks.indexOf(callback);
7376
- if (index > -1) callbacks.splice(index, 1);
7377
- }
7378
- };
7379
- }
7380
6857
  async updateData(room, updates, merge = true) {
7381
6858
  const response = await this.rpcClient.call(
7382
6859
  "H5_ROOM_UPDATE_DATA" /* H5_ROOM_UPDATE_DATA */,
@@ -7386,7 +6863,7 @@ var RpcRoomsApi = class {
7386
6863
  merge
7387
6864
  }
7388
6865
  );
7389
- if (!response.success) {
6866
+ if (response?.success === false) {
7390
6867
  throw new Error(response.error || "Failed to update room data");
7391
6868
  }
7392
6869
  return response.data;
@@ -7398,7 +6875,7 @@ var RpcRoomsApi = class {
7398
6875
  roomId: room.id
7399
6876
  }
7400
6877
  );
7401
- if (!response.success) {
6878
+ if (response?.success === false) {
7402
6879
  throw new Error(response.error || "Failed to get room data");
7403
6880
  }
7404
6881
  return response.data;
@@ -7411,7 +6888,7 @@ var RpcRoomsApi = class {
7411
6888
  message: messageData
7412
6889
  }
7413
6890
  );
7414
- if (!response.success) {
6891
+ if (response?.success === false) {
7415
6892
  throw new Error(response.error || "Failed to send message");
7416
6893
  }
7417
6894
  return response.messageId;
@@ -7423,7 +6900,7 @@ var RpcRoomsApi = class {
7423
6900
  roomId: room.id
7424
6901
  }
7425
6902
  );
7426
- if (!response.success) {
6903
+ if (response?.success === false) {
7427
6904
  throw new Error(response.error || "Failed to leave room");
7428
6905
  }
7429
6906
  return response;
@@ -7437,7 +6914,7 @@ var RpcRoomsApi = class {
7437
6914
  turnOrder
7438
6915
  }
7439
6916
  );
7440
- if (!response.success) {
6917
+ if (response?.success === false) {
7441
6918
  throw new Error(response.error || "Failed to start game");
7442
6919
  }
7443
6920
  return response.data;
@@ -7453,7 +6930,7 @@ var RpcRoomsApi = class {
7453
6930
  clientProposalId: proposalPayload.clientProposalId
7454
6931
  }
7455
6932
  );
7456
- if (!response.success) {
6933
+ if (response?.success === false) {
7457
6934
  throw new Error(response.error || "Failed to propose move");
7458
6935
  }
7459
6936
  return response.data;
@@ -7464,20 +6941,20 @@ var RpcRoomsApi = class {
7464
6941
  }
7465
6942
  async roomSubscribeToGameEvents(room, callback) {
7466
6943
  "game_" + Date.now() + "_" + Math.random().toString(36).substr(2, 9);
7467
- if (!window.venus._roomSubscriptions.gameEvents[room.id]) {
7468
- window.venus._roomSubscriptions.gameEvents[room.id] = [];
6944
+ if (!this.subscriptions.gameEvents[room.id]) {
6945
+ this.subscriptions.gameEvents[room.id] = [];
7469
6946
  }
7470
- window.venus._roomSubscriptions.gameEvents[room.id].push(callback);
6947
+ this.subscriptions.gameEvents[room.id].push(callback);
7471
6948
  }
7472
6949
  subscribe(room, options = {}) {
7473
6950
  const subscriptionIds = [];
7474
6951
  const roomId = room.id;
7475
6952
  if (options.onData) {
7476
6953
  const dataSubId = "data_" + Date.now() + "_" + Math.random().toString(36).substr(2, 9);
7477
- if (!window.venus._roomSubscriptions.data[roomId]) {
7478
- window.venus._roomSubscriptions.data[roomId] = [];
6954
+ if (!this.subscriptions.data[roomId]) {
6955
+ this.subscriptions.data[roomId] = [];
7479
6956
  }
7480
- window.venus._roomSubscriptions.data[roomId].push(options.onData);
6957
+ this.subscriptions.data[roomId].push(options.onData);
7481
6958
  subscriptionIds.push({
7482
6959
  type: "data",
7483
6960
  id: dataSubId,
@@ -7486,10 +6963,10 @@ var RpcRoomsApi = class {
7486
6963
  }
7487
6964
  if (options.onMessages) {
7488
6965
  const msgSubId = "messages_" + Date.now() + "_" + Math.random().toString(36).substr(2, 9);
7489
- if (!window.venus._roomSubscriptions.messages[roomId]) {
7490
- window.venus._roomSubscriptions.messages[roomId] = [];
6966
+ if (!this.subscriptions.messages[roomId]) {
6967
+ this.subscriptions.messages[roomId] = [];
7491
6968
  }
7492
- window.venus._roomSubscriptions.messages[roomId].push(options.onMessages);
6969
+ this.subscriptions.messages[roomId].push(options.onMessages);
7493
6970
  subscriptionIds.push({
7494
6971
  type: "messages",
7495
6972
  id: msgSubId,
@@ -7498,18 +6975,20 @@ var RpcRoomsApi = class {
7498
6975
  }
7499
6976
  if (options.onMoves || options.onGameEvents) {
7500
6977
  const handler = options.onMoves || options.onGameEvents;
7501
- const gameSubId = "game_" + Date.now() + "_" + Math.random().toString(36).substr(2, 9);
7502
- if (!window.venus._roomSubscriptions.gameEvents[roomId]) {
7503
- window.venus._roomSubscriptions.gameEvents[roomId] = [];
6978
+ if (handler) {
6979
+ const gameSubId = "game_" + Date.now() + "_" + Math.random().toString(36).substr(2, 9);
6980
+ if (!this.subscriptions.gameEvents[roomId]) {
6981
+ this.subscriptions.gameEvents[roomId] = [];
6982
+ }
6983
+ this.subscriptions.gameEvents[roomId].push(handler);
6984
+ subscriptionIds.push({
6985
+ type: "gameEvents",
6986
+ id: gameSubId,
6987
+ callback: handler
6988
+ });
7504
6989
  }
7505
- window.venus._roomSubscriptions.gameEvents[roomId].push(handler);
7506
- subscriptionIds.push({
7507
- type: "gameEvents",
7508
- id: gameSubId,
7509
- callback: handler
7510
- });
7511
6990
  }
7512
- 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);
6991
+ const needsSubscription = subscriptionIds.length > 0 && (this.subscriptions.data[roomId]?.length ?? 0) <= 1 && (this.subscriptions.messages[roomId]?.length ?? 0) <= 1 && (this.subscriptions.gameEvents[roomId]?.length ?? 0) <= 1;
7513
6992
  if (needsSubscription) {
7514
6993
  this.rpcClient.call("H5_ROOM_SUBSCRIBE" /* H5_ROOM_SUBSCRIBE */, {
7515
6994
  roomId,
@@ -7525,11 +7004,12 @@ var RpcRoomsApi = class {
7525
7004
  if (called) return;
7526
7005
  called = true;
7527
7006
  subscriptionIds.forEach((sub) => {
7528
- const callbacks = window.venus._roomSubscriptions[sub.type][roomId] || [];
7007
+ const bucket = this.subscriptions[sub.type];
7008
+ const callbacks = bucket && bucket[roomId] || [];
7529
7009
  const index = callbacks.indexOf(sub.callback);
7530
7010
  if (index > -1) callbacks.splice(index, 1);
7531
7011
  });
7532
- 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);
7012
+ const hasNoCallbacks = (this.subscriptions.data[roomId]?.length ?? 0) === 0 && (this.subscriptions.messages[roomId]?.length ?? 0) === 0 && (this.subscriptions.gameEvents[roomId]?.length ?? 0) === 0;
7533
7013
  if (hasNoCallbacks) {
7534
7014
  this.rpcClient.call("H5_ROOM_UNSUBSCRIBE" /* H5_ROOM_UNSUBSCRIBE */, {
7535
7015
  roomId
@@ -7541,6 +7021,36 @@ var RpcRoomsApi = class {
7541
7021
  }
7542
7022
  };
7543
7023
 
7024
+ // src/social/RpcSocialApi.ts
7025
+ var RpcSocialApi = class {
7026
+ constructor(rpcClient) {
7027
+ this.rpcClient = rpcClient;
7028
+ }
7029
+ async shareLinkAsync(options) {
7030
+ const result = await this.rpcClient.call("H5_SHARE_LINK" /* SHARE_LINK */, {
7031
+ launchParams: options.launchParams,
7032
+ metadata: options.metadata ?? {}
7033
+ });
7034
+ return {
7035
+ shareUrl: result.shareUrl
7036
+ };
7037
+ }
7038
+ async createQRCodeAsync(options) {
7039
+ const result = await this.rpcClient.call(
7040
+ "H5_CREATE_SHARE_QRCODE" /* CREATE_SHARE_QRCODE */,
7041
+ {
7042
+ launchParams: options.launchParams,
7043
+ metadata: options.metadata ?? {},
7044
+ qrOptions: options.qrOptions ?? {}
7045
+ }
7046
+ );
7047
+ return {
7048
+ shareUrl: result.shareUrl,
7049
+ qrCode: result.qrCode
7050
+ };
7051
+ }
7052
+ };
7053
+
7544
7054
  // src/RemoteHost.ts
7545
7055
  var getCdnBaseUrl = () => {
7546
7056
  return "https://venus-static-01293ak.web.app/";
@@ -7568,6 +7078,9 @@ var RemoteHost = class {
7568
7078
  __publicField(this, "rooms");
7569
7079
  __publicField(this, "logging");
7570
7080
  __publicField(this, "iap");
7081
+ __publicField(this, "leaderboard");
7082
+ __publicField(this, "preloader");
7083
+ __publicField(this, "social");
7571
7084
  __publicField(this, "venusApi");
7572
7085
  __publicField(this, "rpcClient");
7573
7086
  __publicField(this, "_isInitialized", false);
@@ -7622,97 +7135,62 @@ var RemoteHost = class {
7622
7135
  this.rooms = new RpcRoomsApi(rpcClient);
7623
7136
  this.logging = new RpcLoggingApi(this, rpcClient);
7624
7137
  this.iap = new RpcIapApi(rpcClient);
7138
+ this.leaderboard = new RpcLeaderboardApi(rpcClient);
7139
+ this.preloader = new RpcPreloaderApi(rpcClient);
7140
+ this.social = new RpcSocialApi(rpcClient);
7625
7141
  venusApi.isMock = () => false;
7626
7142
  this.venusApi.sharedAssets = new RpcSharedAssetsApi(rpcClient, venusApi);
7143
+ initializeRoomsApi(this.venusApi, this);
7627
7144
  console.log("[Venus SDK] Remote host created");
7628
7145
  }
7629
7146
  get isInitialized() {
7630
7147
  return this._isInitialized;
7631
7148
  }
7632
- async initialize() {
7149
+ async initialize(options) {
7633
7150
  this.log("Initializing Remote Host...");
7634
7151
  const transport = new VenusTransport();
7635
7152
  transport.start();
7636
7153
  this.rpcClient.start(transport);
7637
- try {
7638
- this.log("Trying to initialize using NEW method...");
7639
- transport.instanceId = await this.initNew();
7640
- } catch (error) {
7641
- this.log(`Failed to initialize using NEW method: ${error}`);
7642
- this.log(`Trying to initialize using OLD method...`);
7643
- transport.instanceId = await this.initOld(transport);
7644
- }
7645
- this.log(`Remote Host Initialized with id: ${transport.instanceId}`);
7646
- this._isInitialized = true;
7647
- this.venusApi._bootstrap.apiInjected = true;
7648
- this.venusApi._bootstrap.venus = window.venus;
7649
- await this.rpcClient.call("READY" /* READY */, {});
7650
- }
7651
- registerIFrame(transport) {
7652
- return new Promise((resolve, reject) => {
7653
- this.log("Registering IFrame...");
7654
- const location = window.location;
7655
- const pathName = location.pathname;
7656
- const tokens = pathName.split("/");
7657
- const appId = tokens[2];
7658
- console.log("[Venus SDK] App ID ", appId);
7659
- const registrationMessage = {
7660
- type: "H5_IFRAME_REGISTER",
7661
- instanceId: appId,
7662
- direction: "H5_TO_APP",
7663
- timestamp: Date.now()
7664
- };
7665
- const subscription = transport.onVenusMessage((message) => {
7666
- if (message.type == "INJECT_VENUS_API_SCRIPT") {
7667
- const scriptContent = message.data?.script;
7668
- if (!scriptContent) {
7669
- throw new Error("Failed to inject venus api, no script found.");
7670
- }
7671
- const script = document.createElement("script");
7672
- script.type = "text/javascript";
7673
- script.textContent = scriptContent;
7674
- document.head.appendChild(script);
7675
- setTimeout(() => {
7676
- if (window.venus) {
7677
- subscription.unsubscribe();
7678
- resolve(window.venus?._config?.instanceId);
7679
- }
7680
- }, 100);
7681
- }
7682
- });
7683
- transport.sendVenusMessage(registrationMessage);
7684
- setTimeout(() => {
7685
- subscription.unsubscribe();
7686
- reject();
7687
- }, 1e3);
7688
- });
7689
- }
7690
- async initNew() {
7154
+ const roomsApi = this.rooms;
7155
+ roomsApi.setupNotifications(transport);
7691
7156
  const response = await this.rpcClient.call(
7692
7157
  "INITIALIZE_SDK" /* INIT_SDK */,
7693
7158
  {},
7694
- 1e3
7159
+ 5e3
7695
7160
  );
7696
- return response.instanceId;
7697
- }
7698
- async initOld(transport) {
7699
- const isInIframe = window.self !== window.top;
7700
- const hasReactNativeWebView = typeof window.ReactNativeWebView !== "undefined";
7701
- if (hasReactNativeWebView) {
7702
- return this.useInjectedId();
7703
- } else if (isInIframe) {
7704
- return await this.registerIFrame(transport);
7705
- } else {
7706
- throw new Error("Failed to initialize. Unknown Error");
7161
+ transport.instanceId = response.instanceId;
7162
+ this.log(`Remote Host Initialized with id: ${transport.instanceId}`);
7163
+ if (response.profile) {
7164
+ const profile = response.profile;
7165
+ const sanitizedProfile = {
7166
+ id: profile.id,
7167
+ username: profile.username,
7168
+ avatarUrl: profile.avatarUrl ?? null,
7169
+ isAnonymous: Boolean(profile.isAnonymous)
7170
+ };
7171
+ if (typeof window !== "undefined") {
7172
+ const globalWindow = window;
7173
+ const venus = globalWindow.venus || (globalWindow.venus = {});
7174
+ venus.profile = sanitizedProfile;
7175
+ if (venus._config) {
7176
+ venus._config.profile = sanitizedProfile;
7177
+ }
7178
+ if (venus.config) {
7179
+ venus.config.profile = sanitizedProfile;
7180
+ }
7181
+ }
7707
7182
  }
7708
- }
7709
- useInjectedId() {
7710
- const instanceId = window.venus?._config?.instanceId || window._venusInitState?.poolId;
7711
- this.log(`On mobile, using injected instanceId: ${instanceId}`);
7712
- if (!instanceId) {
7713
- throw new Error("Expected injected instanceId on mobile");
7183
+ this._isInitialized = true;
7184
+ this.venusApi.launchParams = response.launchParams || {};
7185
+ await this.rpcClient.call("READY" /* READY */, {});
7186
+ const hudInsets = response.hudInsets;
7187
+ if (hudInsets) {
7188
+ this.venusApi.config.ui.safeArea = hudInsets;
7714
7189
  }
7715
- return instanceId;
7190
+ return {
7191
+ hudInsets,
7192
+ initializeAsleep: response.initializeAsleep
7193
+ };
7716
7194
  }
7717
7195
  log(message) {
7718
7196
  console.log(`[Venus SDK] [Remote Host] ${message}`);
@@ -7730,8 +7208,19 @@ function createHost(venusApi, isMock) {
7730
7208
  }
7731
7209
  }
7732
7210
 
7211
+ // src/venus-api/index.js
7212
+ init_rooms();
7213
+
7733
7214
  // src/version.ts
7734
- var SDK_VERSION = "2.4.1";
7215
+ var SDK_VERSION = "3.0.0";
7216
+
7217
+ // src/social/index.ts
7218
+ function initializeSocial(venusApi, host) {
7219
+ venusApi.social = host.social;
7220
+ venusApi.getLaunchParams = () => {
7221
+ return venusApi.launchParams || {};
7222
+ };
7223
+ }
7735
7224
 
7736
7225
  // src/venus-api/index.js
7737
7226
  var HapticStyle = {
@@ -7848,12 +7337,7 @@ var VenusAPI2 = class {
7848
7337
  // Static locale data at top level
7849
7338
  locale: "en-US",
7850
7339
  languageCode: "en",
7851
- // Static profile data (renamed from currentProfile)
7852
- profile: {
7853
- id: "mock-profile-123",
7854
- username: "MockProfile",
7855
- avatarUrl: "https://i.pravatar.cc/150?u=mock"
7856
- },
7340
+ // Note: Profile is now separate from config and accessed via getCurrentProfile()
7857
7341
  // Complete environment info (matching buildStaticConfig)
7858
7342
  environment: {
7859
7343
  isDevelopment: true,
@@ -7920,14 +7404,11 @@ var VenusAPI2 = class {
7920
7404
  }
7921
7405
  };
7922
7406
  this._detectHostedEnvironment();
7407
+ this.launchParams = {};
7923
7408
  this.config = createProxiedObject.call(this, "config", {
7924
7409
  locale: "en-US",
7925
7410
  languageCode: "en",
7926
- profile: {
7927
- id: "mock-user-123",
7928
- username: "Test User",
7929
- avatarUrl: null
7930
- },
7411
+ // Note: Profile is no longer in config - use getCurrentProfile() instead
7931
7412
  environment: {
7932
7413
  isDevelopment: true,
7933
7414
  platform: typeof navigator !== "undefined" ? navigator.platform : "unknown",
@@ -8041,12 +7522,15 @@ var VenusAPI2 = class {
8041
7522
  const host = createHost(this, !isInsideHostedEnv);
8042
7523
  this.host = host;
8043
7524
  initializeStorage(this, host);
7525
+ initializeRoomsApi(this, host);
8044
7526
  initializeAds(this, host);
8045
7527
  initializeTheme(this);
8046
7528
  initializePopups(this, host);
8047
7529
  initializeAnalytics(this, host);
8048
7530
  initializeIap(this, host);
7531
+ initializeLeaderboard(this, host);
8049
7532
  initializeLocalNotifications(this, host);
7533
+ initializePreloader(this, host);
8050
7534
  initializeTime(this, host);
8051
7535
  initializeLifecycleApi(this, host);
8052
7536
  initializeHaptics(this, host);
@@ -8061,8 +7545,8 @@ var VenusAPI2 = class {
8061
7545
  initializeStackNavigation(this, host);
8062
7546
  initializePost(this, host);
8063
7547
  initializeAi(this, host);
8064
- initializeRooms(this);
8065
7548
  initializeSimulation(this, host);
7549
+ initializeSocial(this, host);
8066
7550
  initializeAssetLoader(this, createProxiedMethod);
8067
7551
  }
8068
7552
  // Generate deterministic instance ID based on current page URL
@@ -8117,97 +7601,31 @@ var VenusAPI2 = class {
8117
7601
  this.config.languageCode = this._mock.localeOverride.split("-")[0];
8118
7602
  }
8119
7603
  if (this._mock.roomsData) {
8120
- initializeRooms(this, this._mock.roomsData);
7604
+ console.warn(
7605
+ "[Venus Mock] Rooms mock data is no longer supported. Rooms functionality requires the Venus host environment."
7606
+ );
8121
7607
  }
8122
7608
  }
8123
7609
  //---------------------------------------
8124
7610
  // PUBLIC API METHODS
8125
7611
  //---------------------------------------
8126
- async initializeAsync(options = {}) {
7612
+ async initializeAsync(options) {
8127
7613
  if (this._shared.initialized) {
8128
7614
  return Promise.resolve(true);
8129
7615
  }
8130
7616
  if (this._shared.initPromise) {
8131
7617
  return this._shared.initPromise;
8132
7618
  }
8133
- this._shared.initPromise = new Promise(async (resolve) => {
7619
+ this._shared.initPromise = new Promise(async (resolve, reject) => {
8134
7620
  try {
8135
- if (options) {
8136
- const supportedRootParams = [
8137
- "hardDisableMock",
8138
- "mock",
8139
- "helpText",
8140
- "forceRemoteCdn"
8141
- ];
8142
- const supportedMockParams = [
8143
- "initDelay",
8144
- "isMobile",
8145
- "isWeb",
8146
- "locale",
8147
- "rooms",
8148
- "craftingConfig",
8149
- "onShowContext",
8150
- "onHideContext"
8151
- ];
8152
- Object.keys(options).forEach((param) => {
8153
- if (!supportedRootParams.includes(param)) {
8154
- this.log(`Unsupported parameter: ${param}`);
8155
- }
8156
- });
8157
- if (options.mockData && typeof options.mockData === "object") {
8158
- console.warn(
8159
- "[Venus Mock] mockData is deprecated, use options.mock instead"
8160
- );
8161
- options.mock = { ...options.mock, ...options.mockData };
8162
- }
8163
- if (options.mock && typeof options.mock === "object") {
8164
- Object.keys(options.mock).forEach((param) => {
8165
- if (!supportedMockParams.includes(param)) {
8166
- this.log(`Unsupported mock parameter: ${param}`);
8167
- }
8168
- });
8169
- }
8170
- if (options.helpText && typeof options.helpText === "string") {
8171
- this._mock.helpText = options.helpText;
8172
- }
8173
- if (typeof options.forceRemoteCdn === "boolean") {
8174
- this._mock.forceRemoteCdn = options.forceRemoteCdn;
8175
- console.log(
8176
- "[Venus Mock] Force remote CDN mode:",
8177
- options.forceRemoteCdn
8178
- );
8179
- }
8180
- }
8181
- await this.host.initialize();
8182
- if (this._bootstrap.isInsideHostedEnvironment) {
8183
- this._shared.initialized = true;
8184
- resolve(true);
8185
- return;
7621
+ const result = await this.host.initialize(options);
7622
+ this._shared.initialized = true;
7623
+ if (!options.usePreloader) {
7624
+ this.host.preloader.hideLoadScreen();
8186
7625
  }
8187
- const mockDelay = options.mock?.initDelay ?? 100;
8188
- this.log(`Using mock initialization delay: ${mockDelay}ms`);
8189
- setTimeout(async () => {
8190
- this._shared.initialized = true;
8191
- this._initializeMockMode();
8192
- resolve(true);
8193
- }, mockDelay);
7626
+ resolve(result);
8194
7627
  } catch (err) {
8195
- console.warn(
8196
- "[Venus Bootstrap] Initialization error, falling back to mock mode",
8197
- err
8198
- );
8199
- if (options.hardDisableMock) {
8200
- console.warn(
8201
- "[Venus Bootstrap] hardDisableMock is true, not using mock."
8202
- );
8203
- resolve(false);
8204
- return;
8205
- }
8206
- this._initializeMockMode();
8207
- setTimeout(async () => {
8208
- this._shared.initialized = true;
8209
- resolve(true);
8210
- }, 100);
7628
+ reject(err);
8211
7629
  }
8212
7630
  });
8213
7631
  return this._shared.initPromise;