@series-inc/venus-sdk 3.4.2-beta.2 → 3.4.3-beta.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.
@@ -112,7 +112,7 @@ var VenusMessageId = /* @__PURE__ */ ((VenusMessageId2) => {
112
112
  VenusMessageId2["H5_ROOM_START_GAME"] = "H5_ROOM_START_GAME";
113
113
  VenusMessageId2["H5_ROOM_PROPOSE_MOVE"] = "h5:room:proposeMove";
114
114
  VenusMessageId2["H5_ROOM_END_GAME"] = "H5_ROOM_END_GAME";
115
- VenusMessageId2["H5_ROOM_ELIMINATE_PLAYER"] = "H5_ROOM_ELIMINATE_PLAYER";
115
+ VenusMessageId2["H5_ROOM_KICK_PLAYER"] = "H5_ROOM_KICK_PLAYER";
116
116
  VenusMessageId2["H5_ROOM_PROMOTE_TO_SPECTATOR"] = "H5_ROOM_PROMOTE_TO_SPECTATOR";
117
117
  VenusMessageId2["H5_LOAD_EMBEDDED_ASSET"] = "H5_LOAD_EMBEDDED_ASSET";
118
118
  VenusMessageId2["H5_SHOW_LOAD_SCREEN"] = "H5_SHOW_LOAD_SCREEN";
@@ -1599,6 +1599,9 @@ var RpcLoggingApi = class {
1599
1599
  return message;
1600
1600
  }
1601
1601
  toStringArg(arg) {
1602
+ if (arg instanceof Error) {
1603
+ return `${arg.name}: ${arg.message}`;
1604
+ }
1602
1605
  if (arg) {
1603
1606
  if (typeof arg === "object") {
1604
1607
  try {
@@ -2017,109 +2020,6 @@ function initializeProfile(venusApi, host) {
2017
2020
  };
2018
2021
  }
2019
2022
 
2020
- // src/utils/idGenerator.ts
2021
- function generateId() {
2022
- return `${Date.now()}-${Math.random().toString(36).substring(2, 9)}`;
2023
- }
2024
-
2025
- // src/rpc/RpcClient.ts
2026
- var RpcClient = class {
2027
- pendingCalls = /* @__PURE__ */ new Map();
2028
- notificationCallbacks = /* @__PURE__ */ new Map();
2029
- onResponseSub = null;
2030
- onNotificationSub = null;
2031
- transport = null;
2032
- start(transport) {
2033
- this.transport = transport;
2034
- this.onResponseSub = transport.onResponse(async (response) => {
2035
- return this.handleRpcResponse(response);
2036
- });
2037
- this.onNotificationSub = transport.onNotification(async (notification) => {
2038
- return this.handleRpcNotification(notification);
2039
- });
2040
- }
2041
- stop() {
2042
- if (this.onResponseSub) {
2043
- this.onResponseSub.unsubscribe();
2044
- this.onResponseSub = null;
2045
- }
2046
- if (this.onNotificationSub) {
2047
- this.onNotificationSub.unsubscribe();
2048
- this.onNotificationSub = null;
2049
- }
2050
- this.transport = null;
2051
- }
2052
- onNotification(id, callback) {
2053
- this.notificationCallbacks.set(id, callback);
2054
- return {
2055
- unsubscribe: () => {
2056
- this.notificationCallbacks.delete(id);
2057
- }
2058
- };
2059
- }
2060
- callT(method, args, timeout = 5e3) {
2061
- return this.call(method, args, timeout);
2062
- }
2063
- async call(method, args, timeout = 5e3) {
2064
- return new Promise((resolve, reject) => {
2065
- const id = generateId();
2066
- this.addPendingCall(id, resolve, reject);
2067
- const request = {
2068
- type: "rpc-request",
2069
- id,
2070
- method,
2071
- args
2072
- };
2073
- if (this.transport) {
2074
- this.transport.sendRequest(request);
2075
- }
2076
- if (timeout > 0) {
2077
- setTimeout(() => {
2078
- if (this.hasPendingCall(id)) {
2079
- this.removePendingCall(id);
2080
- reject(new Error(`RPC call ${method} timed out`));
2081
- }
2082
- }, timeout);
2083
- }
2084
- });
2085
- }
2086
- hasPendingCall(id) {
2087
- return this.pendingCalls.has(id);
2088
- }
2089
- addPendingCall(id, resolve, reject) {
2090
- this.pendingCalls.set(id, {
2091
- id,
2092
- resolve,
2093
- reject
2094
- });
2095
- }
2096
- removePendingCall(id) {
2097
- this.pendingCalls.delete(id);
2098
- }
2099
- getPendingCall(id) {
2100
- return this.pendingCalls.get(id);
2101
- }
2102
- handleRpcResponse(response) {
2103
- const pending = this.getPendingCall(response.id);
2104
- if (!pending) {
2105
- return false;
2106
- }
2107
- this.removePendingCall(response.id);
2108
- if (response.error) {
2109
- pending.reject(new Error(response.error.message));
2110
- return true;
2111
- }
2112
- pending.resolve(response.result);
2113
- return true;
2114
- }
2115
- handleRpcNotification(notification) {
2116
- const callback = this.notificationCallbacks.get(notification.id);
2117
- if (callback) {
2118
- callback(notification.payload);
2119
- }
2120
- }
2121
- };
2122
-
2123
2023
  // src/rooms/VenusRoom.ts
2124
2024
  var ROOM_GAME_PHASES = ["waiting", "playing", "ended"];
2125
2025
  var VenusRoom = class {
@@ -2351,6 +2251,16 @@ var RpcRoomsApi = class {
2351
2251
  }
2352
2252
  );
2353
2253
  }
2254
+ async kickPlayerAsync(room, targetProfileId, options = {}) {
2255
+ const args = {
2256
+ roomId: room.id,
2257
+ targetProfileId
2258
+ };
2259
+ if (options.reason !== void 0) {
2260
+ args.reason = options.reason;
2261
+ }
2262
+ await this.rpcClient.call("H5_ROOM_KICK_PLAYER" /* H5_ROOM_KICK_PLAYER */, args);
2263
+ }
2354
2264
  async startRoomGameAsync(room, options = {}) {
2355
2265
  await this.rpcClient.call(
2356
2266
  "H5_ROOM_START_GAME" /* H5_ROOM_START_GAME */,
@@ -2364,15 +2274,20 @@ var RpcRoomsApi = class {
2364
2274
  );
2365
2275
  }
2366
2276
  async proposeMoveAsync(room, proposalPayload) {
2277
+ const args = {
2278
+ roomId: room.id,
2279
+ gameSpecificState: proposalPayload.gameSpecificState,
2280
+ moveType: proposalPayload.moveType
2281
+ };
2282
+ if (proposalPayload.clientContext !== void 0) {
2283
+ args.clientContext = proposalPayload.clientContext;
2284
+ }
2285
+ if (proposalPayload.clientProposalId !== void 0) {
2286
+ args.clientProposalId = proposalPayload.clientProposalId;
2287
+ }
2367
2288
  const data = await this.rpcClient.call(
2368
2289
  "h5:room:proposeMove" /* H5_ROOM_PROPOSE_MOVE */,
2369
- {
2370
- roomId: room.id,
2371
- gameSpecificState: proposalPayload.gameSpecificState,
2372
- moveType: proposalPayload.moveType,
2373
- clientContext: proposalPayload.clientContext,
2374
- clientProposalId: proposalPayload.clientProposalId
2375
- }
2290
+ args
2376
2291
  );
2377
2292
  return data;
2378
2293
  }
@@ -2497,6 +2412,7 @@ function initializeRoomsApi(venusApi, host) {
2497
2412
  ["getRoomDataAsync"],
2498
2413
  ["sendRoomMessageAsync"],
2499
2414
  ["leaveRoomAsync"],
2415
+ ["kickPlayerAsync"],
2500
2416
  ["startRoomGameAsync"],
2501
2417
  ["proposeMoveAsync"],
2502
2418
  ["validateMoveAsync"]
@@ -2573,6 +2489,19 @@ var MockStorageApi = class {
2573
2489
  }
2574
2490
  return items;
2575
2491
  }
2492
+ async getAllData() {
2493
+ const result = {};
2494
+ const orderedKeys = this.keys();
2495
+ for (const key of orderedKeys) {
2496
+ const value = localStorage.getItem(this.buildKey(key));
2497
+ if (value !== null) {
2498
+ result[key] = value;
2499
+ } else {
2500
+ this.removeFromOrder(key);
2501
+ }
2502
+ }
2503
+ return result;
2504
+ }
2576
2505
  async getItem(key) {
2577
2506
  const fullKey = this.buildKey(key);
2578
2507
  await this.simulateSyncDelay();
@@ -2850,6 +2779,20 @@ var RpcStorageApi = class {
2850
2779
  }
2851
2780
  return this.rpcClient.call(this.methodIds.getAllItems);
2852
2781
  }
2782
+ async getAllData() {
2783
+ const result = {};
2784
+ const len = await this.length();
2785
+ for (let i = 0; i < len; i++) {
2786
+ const key = await this.key(i);
2787
+ if (key !== null) {
2788
+ const value = await this.getItem(key);
2789
+ if (value !== null) {
2790
+ result[key] = value;
2791
+ }
2792
+ }
2793
+ }
2794
+ return result;
2795
+ }
2853
2796
  setMultipleItems(items) {
2854
2797
  if (!this.methodIds.setMultipleItems) {
2855
2798
  throw new Error("Method not implemented");
@@ -2867,361 +2810,6 @@ function initializeStorage(venusApiInstance, host) {
2867
2810
  venusApiInstance.globalStorage = host.globalStorage;
2868
2811
  }
2869
2812
 
2870
- // src/simulation/RpcSimulationApi.ts
2871
- var RpcSimulationApi = class {
2872
- rpcClient;
2873
- _simulationConfig = null;
2874
- subscriptionCallbacks = /* @__PURE__ */ new Map();
2875
- constructor(rpcClient) {
2876
- this.rpcClient = rpcClient;
2877
- this.rpcClient.onNotification(
2878
- "H5_SIMULATION_UPDATE" /* H5_SIMULATION_UPDATE */,
2879
- this.handleSimulationUpdate.bind(this)
2880
- );
2881
- }
2882
- isEnabled() {
2883
- return true;
2884
- }
2885
- async validateSlotAssignmentAsync(containerId, slotId, itemId) {
2886
- return this.rpcClient.call(
2887
- "H5_SIMULATION_VALIDATE_ASSIGNMENT" /* H5_SIMULATION_VALIDATE_ASSIGNMENT */,
2888
- {
2889
- containerId,
2890
- slotId,
2891
- itemId
2892
- }
2893
- );
2894
- }
2895
- async subscribeAsync(options) {
2896
- this.ensureValidSubscribeOptions(options);
2897
- const subscriptionId = generateId();
2898
- this.subscriptionCallbacks.set(subscriptionId, options.onUpdate);
2899
- try {
2900
- await this.rpcClient.call("H5_SIMULATION_SUBSCRIBE" /* H5_SIMULATION_SUBSCRIBE */, {
2901
- subscriptionId,
2902
- entities: options.entities,
2903
- tags: options.tags,
2904
- activeRuns: options.activeRuns,
2905
- roomId: options.roomId
2906
- });
2907
- } catch (error) {
2908
- this.subscriptionCallbacks.delete(subscriptionId);
2909
- throw error;
2910
- }
2911
- let unsubscribed = false;
2912
- return () => {
2913
- if (unsubscribed) {
2914
- return;
2915
- }
2916
- unsubscribed = true;
2917
- this.subscriptionCallbacks.delete(subscriptionId);
2918
- void this.rpcClient.call("H5_SIMULATION_UNSUBSCRIBE" /* H5_SIMULATION_UNSUBSCRIBE */, {
2919
- subscriptionId
2920
- }).catch((error) => {
2921
- console.error(
2922
- "[Venus SDK] Failed to unsubscribe simulation listener",
2923
- error
2924
- );
2925
- });
2926
- };
2927
- }
2928
- executeBatchOperationsAsync(operations, validateOnly) {
2929
- return this.rpcClient.call(
2930
- "H5_SIMULATION_BATCH_OPERATIONS" /* H5_SIMULATION_BATCH_OPERATIONS */,
2931
- {
2932
- operations,
2933
- validateOnly
2934
- }
2935
- );
2936
- }
2937
- async getAvailableItemsAsync(containerId, slotId) {
2938
- const response = await this.rpcClient.call(
2939
- "H5_SIMULATION_GET_AVAILABLE_ITEMS" /* H5_SIMULATION_GET_AVAILABLE_ITEMS */,
2940
- {
2941
- containerId,
2942
- slotId
2943
- }
2944
- );
2945
- return response.availableItems || [];
2946
- }
2947
- calculatePowerPreviewAsync(containerId, slotId, candidateItemId) {
2948
- return this.rpcClient.call(
2949
- "H5_SIMULATION_CALCULATE_POWER_PREVIEW" /* H5_SIMULATION_CALCULATE_POWER_PREVIEW */,
2950
- {
2951
- containerId,
2952
- slotId,
2953
- candidateItemId
2954
- }
2955
- );
2956
- }
2957
- assignItemToSlotAsync(containerId, slotId, itemId) {
2958
- return this.rpcClient.call(
2959
- "H5_SIMULATION_ASSIGN_ITEM" /* H5_SIMULATION_ASSIGN_ITEM */,
2960
- {
2961
- containerId,
2962
- slotId,
2963
- itemId
2964
- }
2965
- );
2966
- }
2967
- removeItemFromSlotAsync(containerId, slotId) {
2968
- return this.rpcClient.call(
2969
- "H5_SIMULATION_REMOVE_ITEM" /* H5_SIMULATION_REMOVE_ITEM */,
2970
- {
2971
- containerId,
2972
- slotId
2973
- }
2974
- );
2975
- }
2976
- async getSlotContainersAsync() {
2977
- const response = await this.rpcClient.call(
2978
- "H5_SIMULATION_GET_CONTAINERS" /* H5_SIMULATION_GET_CONTAINERS */,
2979
- {}
2980
- );
2981
- return response.containers || [];
2982
- }
2983
- async getSlotAssignmentsAsync(containerId) {
2984
- const response = await this.rpcClient.call(
2985
- "H5_SIMULATION_GET_ASSIGNMENTS" /* H5_SIMULATION_GET_ASSIGNMENTS */,
2986
- {
2987
- containerId
2988
- }
2989
- );
2990
- return Array.isArray(response) ? response : response.assignments || [];
2991
- }
2992
- async getStateAsync(roomId) {
2993
- const response = await this.rpcClient.call(
2994
- "H5_SIMULATION_GET_STATE" /* H5_SIMULATION_GET_STATE */,
2995
- {
2996
- roomId
2997
- }
2998
- );
2999
- if (response.configuration) {
3000
- this._simulationConfig = response.configuration;
3001
- }
3002
- return response;
3003
- }
3004
- async getConfigAsync(roomId) {
3005
- if (this._simulationConfig) {
3006
- return this._simulationConfig;
3007
- }
3008
- const config = await this.rpcClient.call(
3009
- "H5_SIMULATION_GET_CONFIG" /* H5_SIMULATION_GET_CONFIG */,
3010
- {
3011
- roomId
3012
- }
3013
- );
3014
- if (config) {
3015
- this._simulationConfig = config;
3016
- return config;
3017
- }
3018
- throw new Error("No simulation configuration available");
3019
- }
3020
- executeRecipeAsync(recipeId, inputs, options) {
3021
- return this.rpcClient.call(
3022
- "H5_SIMULATION_EXECUTE_RECIPE" /* H5_SIMULATION_EXECUTE_RECIPE */,
3023
- {
3024
- recipeId,
3025
- inputs,
3026
- roomId: options?.roomId,
3027
- batchAmount: options?.batchAmount,
3028
- allowPartialBatch: options?.allowPartialBatch,
3029
- entity: options?.entity
3030
- }
3031
- );
3032
- }
3033
- collectRecipeAsync(runId) {
3034
- return this.rpcClient.call("H5_SIMULATION_COLLECT_RECIPE" /* H5_SIMULATION_COLLECT_RECIPE */, {
3035
- runId
3036
- });
3037
- }
3038
- getActiveRunsAsync(options) {
3039
- return this.rpcClient.call(
3040
- "H5_SIMULATION_GET_ACTIVE_RUNS" /* H5_SIMULATION_GET_ACTIVE_RUNS */,
3041
- {
3042
- roomId: options?.roomId
3043
- }
3044
- );
3045
- }
3046
- executeScopedRecipeAsync(recipeId, entity, inputs, options) {
3047
- return this.rpcClient.call(
3048
- "H5_SIMULATION_EXECUTE_SCOPED_RECIPE" /* H5_SIMULATION_EXECUTE_SCOPED_RECIPE */,
3049
- {
3050
- recipeId,
3051
- entity,
3052
- inputs,
3053
- roomId: options?.roomId ?? null,
3054
- options
3055
- }
3056
- );
3057
- }
3058
- getAvailableRecipesAsync(options) {
3059
- return this.rpcClient.call(
3060
- "H5_SIMULATION_GET_AVAILABLE_RECIPES" /* H5_SIMULATION_GET_AVAILABLE_RECIPES */,
3061
- {
3062
- roomId: options?.roomId || null,
3063
- includeActorRecipes: options?.includeActorRecipes || false
3064
- }
3065
- );
3066
- }
3067
- getRecipeRequirementsAsync(recipe) {
3068
- return this.rpcClient.call(
3069
- "H5_SIMULATION_GET_RECIPE_REQUIREMENTS" /* H5_SIMULATION_GET_RECIPE_REQUIREMENTS */,
3070
- {
3071
- recipeId: recipe.recipeId,
3072
- entity: recipe.entity,
3073
- batchAmount: recipe.batchAmount
3074
- }
3075
- );
3076
- }
3077
- getBatchRecipeRequirementsAsync(recipes) {
3078
- return this.rpcClient.call(
3079
- "H5_SIMULATION_GET_BATCH_RECIPE_REQUIREMENTS" /* H5_SIMULATION_GET_BATCH_RECIPE_REQUIREMENTS */,
3080
- {
3081
- recipes
3082
- }
3083
- );
3084
- }
3085
- triggerRecipeChainAsync(recipeId, options) {
3086
- return this.rpcClient.call(
3087
- "H5_SIMULATION_TRIGGER_RECIPE_CHAIN" /* H5_SIMULATION_TRIGGER_RECIPE_CHAIN */,
3088
- {
3089
- triggerRecipeId: recipeId,
3090
- context: options?.context,
3091
- roomId: options?.roomId
3092
- }
3093
- );
3094
- }
3095
- getEntityMetadataAsync(entityId) {
3096
- return this.rpcClient.call(
3097
- "H5_SIMULATION_GET_ENTITY_METADATA" /* H5_SIMULATION_GET_ENTITY_METADATA */,
3098
- {
3099
- entityId
3100
- }
3101
- );
3102
- }
3103
- async resolveFieldValueAsync(entityId, fieldPath, entity) {
3104
- const response = await this.rpcClient.call(
3105
- "H5_SIMULATION_RESOLVE_VALUE" /* H5_SIMULATION_RESOLVE_VALUE */,
3106
- {
3107
- entityId,
3108
- fieldPath,
3109
- entity
3110
- }
3111
- );
3112
- return response.value;
3113
- }
3114
- handleSimulationUpdate(notification) {
3115
- if (!notification || !notification.subscriptionId) {
3116
- console.warn("[Venus SDK] Received malformed simulation update");
3117
- return;
3118
- }
3119
- const callback = this.subscriptionCallbacks.get(notification.subscriptionId);
3120
- if (!callback) {
3121
- console.warn(
3122
- "[Venus SDK] Received update for unknown subscription:",
3123
- notification.subscriptionId
3124
- );
3125
- return;
3126
- }
3127
- try {
3128
- callback(notification.updates);
3129
- } catch (error) {
3130
- console.error("[Venus SDK] Error in simulation subscription callback", error);
3131
- }
3132
- }
3133
- ensureValidSubscribeOptions(options) {
3134
- if (typeof options !== "object" || options === null) {
3135
- throw new Error("Simulation subscribe requires an options object");
3136
- }
3137
- const opts = options;
3138
- if (typeof opts.onUpdate !== "function") {
3139
- throw new Error("Simulation subscribe requires an onUpdate callback");
3140
- }
3141
- const hasFilter = Array.isArray(opts.entities) && opts.entities.length > 0 || Array.isArray(opts.tags) && opts.tags.length > 0 || Boolean(opts.activeRuns);
3142
- if (!hasFilter) {
3143
- throw new Error(
3144
- "Simulation subscribe requires at least one filter (entities, tags, activeRuns)"
3145
- );
3146
- }
3147
- }
3148
- };
3149
-
3150
- // src/simulation/index.ts
3151
- function initializeSimulation(venusApi, host) {
3152
- venusApi.simulation = {
3153
- isEnabled: () => true
3154
- };
3155
- venusApi.simulation.getConfigAsync = () => {
3156
- return host.simulation.getConfigAsync();
3157
- };
3158
- venusApi.simulation.getStateAsync = (roomId) => {
3159
- return host.simulation.getStateAsync(roomId);
3160
- };
3161
- venusApi.simulation.executeRecipeAsync = (recipeId, inputs, options) => {
3162
- return host.simulation.executeRecipeAsync(recipeId, inputs, options);
3163
- };
3164
- venusApi.simulation.getActiveRunsAsync = () => {
3165
- return host.simulation.getActiveRunsAsync();
3166
- };
3167
- venusApi.simulation.collectRecipeAsync = (runId) => {
3168
- return host.simulation.collectRecipeAsync(runId);
3169
- };
3170
- venusApi.simulation.executeScopedRecipeAsync = (recipeId, entity, inputs, options) => {
3171
- return host.simulation.executeScopedRecipeAsync(recipeId, entity, inputs, options);
3172
- };
3173
- venusApi.simulation.triggerRecipeChainAsync = (recipeId, options) => {
3174
- return host.simulation.triggerRecipeChainAsync(recipeId, options);
3175
- };
3176
- venusApi.simulation.getAvailableRecipesAsync = async (options) => {
3177
- return host.simulation.getAvailableRecipesAsync(options);
3178
- };
3179
- venusApi.simulation.getRecipeRequirementsAsync = (recipe) => {
3180
- return host.simulation.getRecipeRequirementsAsync(recipe);
3181
- };
3182
- venusApi.simulation.getBatchRecipeRequirementsAsync = (recipes) => {
3183
- return host.simulation.getBatchRecipeRequirementsAsync(recipes);
3184
- };
3185
- venusApi.simulation.resolveFieldValueAsync = (entityId, fieldPath, entity) => {
3186
- return host.simulation.resolveFieldValueAsync(entityId, fieldPath, entity);
3187
- };
3188
- venusApi.simulation.getEntityMetadataAsync = (entityId) => {
3189
- return host.simulation.getEntityMetadataAsync(entityId);
3190
- };
3191
- venusApi.simulation.getSlotAssignmentsAsync = (containerId) => {
3192
- return host.simulation.getSlotAssignmentsAsync(containerId);
3193
- };
3194
- venusApi.simulation.getSlotContainersAsync = () => {
3195
- return host.simulation.getSlotContainersAsync();
3196
- };
3197
- venusApi.simulation.assignItemToSlotAsync = (containerId, slotId, itemId) => {
3198
- return host.simulation.assignItemToSlotAsync(containerId, slotId, itemId);
3199
- };
3200
- venusApi.simulation.removeItemFromSlotAsync = (containerId, slotId) => {
3201
- return host.simulation.removeItemFromSlotAsync(containerId, slotId);
3202
- };
3203
- venusApi.simulation.getAvailableItemsAsync = (containerId, slotId) => {
3204
- return host.simulation.getAvailableItemsAsync(containerId, slotId);
3205
- };
3206
- venusApi.simulation.calculatePowerPreviewAsync = (containerId, slotId, candidateItemId) => {
3207
- return host.simulation.calculatePowerPreviewAsync(
3208
- containerId,
3209
- slotId,
3210
- candidateItemId
3211
- );
3212
- };
3213
- venusApi.simulation.executeBatchOperationsAsync = (operations, validateOnly) => {
3214
- return host.simulation.executeBatchOperationsAsync(operations, validateOnly);
3215
- };
3216
- venusApi.simulation.validateSlotAssignmentAsync = (containerId, slotId, itemId) => {
3217
- return host.simulation.validateSlotAssignmentAsync(
3218
- containerId,
3219
- slotId,
3220
- itemId
3221
- );
3222
- };
3223
- }
3224
-
3225
2813
  // src/time/utils.ts
3226
2814
  function isPacificDaylightTime(date) {
3227
2815
  const year = date.getFullYear();
@@ -3425,9 +3013,6 @@ function initializeTime(venusApi, host) {
3425
3013
  };
3426
3014
  }
3427
3015
 
3428
- // src/version.ts
3429
- var SDK_VERSION = "3.4.2-beta.2";
3430
-
3431
3016
  // src/shared-assets/base64Utils.ts
3432
3017
  function base64ToArrayBuffer(base64) {
3433
3018
  const binaryString = atob(base64);
@@ -3634,377 +3219,6 @@ function getLibraryDefinition(libraryKey) {
3634
3219
  return definition;
3635
3220
  }
3636
3221
 
3637
- // src/leaderboard/utils.ts
3638
- var HASH_ALGORITHM_WEB_CRYPTO = "SHA-256";
3639
- var HASH_ALGORITHM_NODE = "sha256";
3640
- async function computeScoreHash(score, duration, token, sealingNonce, sealingSecret) {
3641
- const payload = `score:${score}|duration:${duration}|token:${token}`;
3642
- const fullPayload = `${payload}|nonce:${sealingNonce}`;
3643
- const encoder = new TextEncoder();
3644
- const keyData = encoder.encode(sealingSecret);
3645
- const messageData = encoder.encode(fullPayload);
3646
- const cryptoKey = await crypto.subtle.importKey(
3647
- "raw",
3648
- keyData,
3649
- { name: "HMAC", hash: HASH_ALGORITHM_WEB_CRYPTO },
3650
- false,
3651
- ["sign"]
3652
- );
3653
- const signature = await crypto.subtle.sign("HMAC", cryptoKey, messageData);
3654
- return Array.from(new Uint8Array(signature)).map((b) => b.toString(16).padStart(2, "0")).join("");
3655
- }
3656
-
3657
- // src/leaderboard/RpcLeaderboardApi.ts
3658
- var RpcLeaderboardApi = class {
3659
- rpcClient;
3660
- /** Cache of score tokens for automatic hash computation */
3661
- tokenCache = /* @__PURE__ */ new Map();
3662
- constructor(rpcClient) {
3663
- this.rpcClient = rpcClient;
3664
- }
3665
- /**
3666
- * Create a score token for submitting a score.
3667
- * Token is cached for automatic hash computation if score sealing is enabled.
3668
- *
3669
- * @param mode - Optional game mode
3670
- * @returns Score token with sealing data if enabled
3671
- */
3672
- async createScoreToken(mode) {
3673
- const token = await this.rpcClient.call(
3674
- "H5_LEADERBOARD_CREATE_SCORE_TOKEN" /* H5_LEADERBOARD_CREATE_SCORE_TOKEN */,
3675
- mode ? { mode } : {}
3676
- );
3677
- this.tokenCache.set(token.token, token);
3678
- return token;
3679
- }
3680
- /**
3681
- * Submit a score to the leaderboard.
3682
- * Automatically computes hash if score sealing is enabled and token was created via createScoreToken().
3683
- *
3684
- * @param params - Score submission parameters
3685
- * @returns Submission result with acceptance status and rank
3686
- * @throws Error if token not found in cache
3687
- */
3688
- async submitScore(params) {
3689
- let hash;
3690
- if (params.token) {
3691
- const cachedToken = this.tokenCache.get(params.token);
3692
- if (!cachedToken) {
3693
- throw new Error(
3694
- "Invalid token: not found in cache. Did you call createScoreToken() first?"
3695
- );
3696
- }
3697
- if (cachedToken.sealingNonce && cachedToken.sealingSecret) {
3698
- hash = await computeScoreHash(
3699
- params.score,
3700
- params.duration,
3701
- params.token,
3702
- cachedToken.sealingNonce,
3703
- cachedToken.sealingSecret
3704
- );
3705
- }
3706
- this.tokenCache.delete(params.token);
3707
- }
3708
- return this.rpcClient.call(
3709
- "H5_LEADERBOARD_SUBMIT_SCORE" /* H5_LEADERBOARD_SUBMIT_SCORE */,
3710
- {
3711
- token: params.token,
3712
- score: params.score,
3713
- duration: params.duration,
3714
- mode: params.mode,
3715
- telemetry: params.telemetry,
3716
- metadata: params.metadata,
3717
- hash
3718
- // undefined if no sealing, computed if sealing enabled
3719
- }
3720
- );
3721
- }
3722
- getPagedScores(options) {
3723
- return this.rpcClient.call(
3724
- "H5_LEADERBOARD_GET_PAGED_SCORES" /* H5_LEADERBOARD_GET_PAGED_SCORES */,
3725
- options ?? {}
3726
- );
3727
- }
3728
- getMyRank(options) {
3729
- return this.rpcClient.call(
3730
- "H5_LEADERBOARD_GET_MY_RANK" /* H5_LEADERBOARD_GET_MY_RANK */,
3731
- options ?? {}
3732
- );
3733
- }
3734
- getPodiumScores(options) {
3735
- return this.rpcClient.call(
3736
- "H5_LEADERBOARD_GET_PODIUM_SCORES" /* H5_LEADERBOARD_GET_PODIUM_SCORES */,
3737
- options ?? {}
3738
- );
3739
- }
3740
- };
3741
-
3742
- // src/leaderboard/MockLeaderboardApi.ts
3743
- var MockLeaderboardApi = class {
3744
- tokens = /* @__PURE__ */ new Map();
3745
- /** Cache of score tokens for automatic hash computation */
3746
- tokenCache = /* @__PURE__ */ new Map();
3747
- entriesByMode = /* @__PURE__ */ new Map();
3748
- tokenCounter = 0;
3749
- enableScoreSealing = false;
3750
- scoreSealingSecret = "mock-leaderboard-secret-key";
3751
- constructor(options) {
3752
- if (options?.enableScoreSealing) {
3753
- this.enableScoreSealing = true;
3754
- }
3755
- if (options?.scoreSealingSecret) {
3756
- this.scoreSealingSecret = options.scoreSealingSecret;
3757
- }
3758
- }
3759
- /**
3760
- * Configure mock leaderboard settings
3761
- *
3762
- * @param options - Configuration options
3763
- */
3764
- configure(options) {
3765
- if (typeof options.enableScoreSealing === "boolean") {
3766
- this.enableScoreSealing = options.enableScoreSealing;
3767
- }
3768
- if (options.scoreSealingSecret) {
3769
- this.scoreSealingSecret = options.scoreSealingSecret;
3770
- }
3771
- }
3772
- generateNonce() {
3773
- return (Math.random().toString(36).slice(2) + Math.random().toString(36).slice(2)).slice(0, 64);
3774
- }
3775
- getModeKey(mode) {
3776
- const normalizedMode = mode || "default";
3777
- return `${normalizedMode}`;
3778
- }
3779
- getEntriesForMode(mode) {
3780
- const key = this.getModeKey(mode);
3781
- if (!this.entriesByMode.has(key)) {
3782
- this.entriesByMode.set(key, []);
3783
- }
3784
- return this.entriesByMode.get(key);
3785
- }
3786
- /**
3787
- * Create a mock score token for testing.
3788
- * Token is cached for automatic hash computation if score sealing is enabled.
3789
- *
3790
- * @param mode - Optional game mode
3791
- * @returns Score token with sealing data if enabled
3792
- */
3793
- async createScoreToken(mode) {
3794
- const token = `mock_token_${++this.tokenCounter}`;
3795
- const startTime = Date.now();
3796
- const expiresAt = startTime + 36e5;
3797
- const resolvedMode = mode || "default";
3798
- const sealingNonce = this.enableScoreSealing ? this.generateNonce() : null;
3799
- const sealingSecret = this.enableScoreSealing ? this.scoreSealingSecret : null;
3800
- this.tokens.set(token, {
3801
- id: token,
3802
- expiresAt,
3803
- mode: resolvedMode,
3804
- sealingNonce,
3805
- used: false
3806
- });
3807
- const result = {
3808
- token,
3809
- startTime,
3810
- expiresAt,
3811
- sealingNonce,
3812
- sealingSecret,
3813
- mode: resolvedMode
3814
- };
3815
- this.tokenCache.set(token, result);
3816
- return result;
3817
- }
3818
- /**
3819
- * Submit a mock score to the leaderboard.
3820
- * Automatically computes hash if score sealing is enabled and token was created via createScoreToken().
3821
- *
3822
- * @param params - Score submission parameters
3823
- * @returns Submission result with acceptance status and rank
3824
- * @throws Error if token not found in cache or validation fails
3825
- */
3826
- async submitScore(params) {
3827
- let hash;
3828
- if (params.token) {
3829
- const cachedToken = this.tokenCache.get(params.token);
3830
- if (!cachedToken) {
3831
- throw new Error(
3832
- "Invalid token: not found in cache. Did you call createScoreToken() first?"
3833
- );
3834
- }
3835
- if (cachedToken.sealingNonce && cachedToken.sealingSecret) {
3836
- hash = await computeScoreHash(
3837
- params.score,
3838
- params.duration,
3839
- params.token,
3840
- cachedToken.sealingNonce,
3841
- cachedToken.sealingSecret
3842
- );
3843
- }
3844
- }
3845
- if (!params.token) {
3846
- const mode = params.mode || "default";
3847
- const submittedAt2 = Date.now();
3848
- const entry2 = {
3849
- profileId: `mock_profile`,
3850
- username: "Mock Player",
3851
- avatarUrl: null,
3852
- score: params.score,
3853
- duration: params.duration,
3854
- submittedAt: submittedAt2,
3855
- token: "simple-mode",
3856
- rank: null,
3857
- zScore: null,
3858
- isAnomaly: false,
3859
- trustScore: 50,
3860
- metadata: params.metadata ?? null,
3861
- isSeed: false
3862
- };
3863
- const modeEntries2 = this.getEntriesForMode(mode);
3864
- modeEntries2.push(entry2);
3865
- modeEntries2.sort((a, b) => {
3866
- if (b.score !== a.score) return b.score - a.score;
3867
- return a.submittedAt - b.submittedAt;
3868
- });
3869
- modeEntries2.forEach((e, index) => {
3870
- modeEntries2[index] = { ...e, rank: index + 1 };
3871
- });
3872
- const inserted2 = modeEntries2.find((e) => e.submittedAt === submittedAt2);
3873
- return {
3874
- accepted: true,
3875
- rank: inserted2?.rank ?? null
3876
- };
3877
- }
3878
- const scoreToken = this.tokens.get(params.token);
3879
- if (!scoreToken) {
3880
- throw new Error("Invalid score token");
3881
- }
3882
- if (scoreToken.expiresAt < Date.now()) {
3883
- throw new Error("Invalid or expired score token");
3884
- }
3885
- if (scoreToken.used) {
3886
- throw new Error("Score token already used");
3887
- }
3888
- if (params.mode && params.mode !== scoreToken.mode) {
3889
- throw new Error("Submission mode does not match token mode");
3890
- }
3891
- if (scoreToken.sealingNonce && !hash) {
3892
- throw new Error("Score hash required when score sealing is enabled");
3893
- }
3894
- const submittedAt = Date.now();
3895
- const entry = {
3896
- profileId: `mock_profile`,
3897
- username: "Mock Player",
3898
- avatarUrl: null,
3899
- score: params.score,
3900
- duration: params.duration,
3901
- submittedAt,
3902
- token: params.token,
3903
- rank: null,
3904
- zScore: null,
3905
- isAnomaly: false,
3906
- trustScore: 50,
3907
- metadata: params.metadata ?? null,
3908
- isSeed: false
3909
- };
3910
- const modeEntries = this.getEntriesForMode(scoreToken.mode);
3911
- modeEntries.push(entry);
3912
- modeEntries.sort((a, b) => {
3913
- if (b.score !== a.score) return b.score - a.score;
3914
- return a.submittedAt - b.submittedAt;
3915
- });
3916
- modeEntries.forEach((e, index) => {
3917
- modeEntries[index] = { ...e, rank: index + 1 };
3918
- });
3919
- scoreToken.used = true;
3920
- scoreToken.sealingNonce = null;
3921
- this.tokenCache.delete(params.token);
3922
- const inserted = modeEntries.find((e) => e.token === params.token && e.submittedAt === submittedAt);
3923
- return {
3924
- accepted: true,
3925
- rank: inserted?.rank ?? null
3926
- };
3927
- }
3928
- async getPagedScores(options) {
3929
- const limit = options?.limit ?? 10;
3930
- const mode = options?.mode ?? "default";
3931
- const modeEntries = [...this.getEntriesForMode(mode)];
3932
- const entries = modeEntries.slice(0, limit).map((entry) => ({
3933
- ...entry
3934
- }));
3935
- return {
3936
- variant: "standard",
3937
- entries,
3938
- totalEntries: modeEntries.length,
3939
- nextCursor: null,
3940
- playerRank: null,
3941
- periodInstance: options?.period ?? "alltime"
3942
- };
3943
- }
3944
- async getMyRank(_options) {
3945
- const mode = _options?.mode ?? "default";
3946
- const modeEntries = this.getEntriesForMode(mode);
3947
- const playerEntry = modeEntries[0] ?? null;
3948
- return {
3949
- rank: playerEntry?.rank ?? null,
3950
- score: playerEntry?.score,
3951
- totalPlayers: modeEntries.length,
3952
- percentile: playerEntry ? Math.max(0, 1 - ((playerEntry.rank ?? 1) - 1) / Math.max(modeEntries.length, 1)) : void 0,
3953
- trustScore: 50,
3954
- periodInstance: _options?.period ?? "alltime"
3955
- };
3956
- }
3957
- async getPodiumScores(options) {
3958
- const mode = options?.mode ?? "default";
3959
- const modeEntries = [...this.getEntriesForMode(mode)];
3960
- const topCount = Math.max(1, Math.min(options?.topCount ?? 3, 10));
3961
- const aheadCount = Math.max(0, Math.min(options?.contextAhead ?? 4, 10));
3962
- const behindCount = Math.max(0, Math.min(options?.contextBehind ?? 2, 10));
3963
- const topEntries = modeEntries.slice(0, topCount);
3964
- const playerEntry = modeEntries[0] ?? null;
3965
- const totalEntries = modeEntries.length;
3966
- let playerRank = playerEntry?.rank ?? null;
3967
- let beforePlayer = [];
3968
- let afterPlayer = [];
3969
- let totalBefore = playerRank ? playerRank - 1 : 0;
3970
- let totalAfter = playerRank ? Math.max(totalEntries - playerRank, 0) : 0;
3971
- let omittedBefore = totalBefore;
3972
- let omittedAfter = totalAfter;
3973
- if (playerRank && playerRank > 0) {
3974
- const beforeStart = Math.max(playerRank - aheadCount - 1, 0);
3975
- beforePlayer = modeEntries.slice(beforeStart, playerRank - 1);
3976
- const afterEnd = Math.min(playerRank + behindCount, totalEntries);
3977
- afterPlayer = modeEntries.slice(playerRank, afterEnd);
3978
- const shownTopAhead = topEntries.filter((entry) => (entry.rank ?? 0) > 0 && (entry.rank ?? 0) < playerRank).length;
3979
- omittedBefore = Math.max(totalBefore - (beforePlayer.length + shownTopAhead), 0);
3980
- omittedAfter = Math.max(totalAfter - afterPlayer.length, 0);
3981
- }
3982
- return {
3983
- variant: "highlight",
3984
- entries: topEntries,
3985
- totalEntries,
3986
- nextCursor: null,
3987
- playerRank: playerRank ?? null,
3988
- periodInstance: options?.period ?? "alltime",
3989
- context: {
3990
- topEntries,
3991
- beforePlayer,
3992
- playerEntry: playerEntry ?? null,
3993
- afterPlayer,
3994
- totalBefore,
3995
- totalAfter,
3996
- omittedBefore,
3997
- omittedAfter
3998
- }
3999
- };
4000
- }
4001
- };
4002
-
4003
- // src/leaderboard/index.ts
4004
- function initializeLeaderboard(venusApiInstance, host) {
4005
- venusApiInstance.leaderboard = host.leaderboard;
4006
- }
4007
-
4008
3222
  // src/game-preloader/MockPreloaderApi.ts
4009
3223
  var MockPreloaderApi = class {
4010
3224
  async showLoadScreen() {
@@ -4077,1049 +3291,41 @@ var MockSocialApi = class {
4077
3291
  }
4078
3292
  };
4079
3293
 
4080
- // src/social/RpcSocialApi.ts
4081
- var RpcSocialApi = class {
4082
- constructor(rpcClient) {
4083
- this.rpcClient = rpcClient;
4084
- }
4085
- async shareLinkAsync(options) {
4086
- const result = await this.rpcClient.call("H5_SHARE_LINK" /* SHARE_LINK */, {
4087
- launchParams: options.launchParams,
4088
- metadata: options.metadata ?? {}
4089
- });
4090
- return {
4091
- shareUrl: result.shareUrl
4092
- };
4093
- }
4094
- async createQRCodeAsync(options) {
4095
- const result = await this.rpcClient.call(
4096
- "H5_CREATE_SHARE_QRCODE" /* CREATE_SHARE_QRCODE */,
4097
- {
4098
- launchParams: options.launchParams,
4099
- metadata: options.metadata ?? {},
4100
- qrOptions: options.qrOptions ?? {}
4101
- }
4102
- );
4103
- return {
4104
- shareUrl: result.shareUrl,
4105
- qrCode: result.qrCode
4106
- };
4107
- }
4108
- };
4109
-
4110
- // src/VenusTransport.ts
4111
- var VenusTransport = class {
4112
- messageHandler;
4113
- onNotificationCallbacks = [];
4114
- onNotificationCallbacksToRemove = [];
4115
- onVenusMessageCallbacks = [];
4116
- onResponseCallbacks = [];
4117
- onResponseCallbacksToRemove = [];
4118
- _instanceId = null;
4119
- isStarted = false;
4120
- isProcessingMessage = false;
4121
- constructor() {
4122
- this.messageHandler = async (event) => {
4123
- this.isProcessingMessage = true;
4124
- let message;
4125
- if (typeof event.data === "string") {
4126
- message = JSON.parse(event.data);
4127
- } else {
4128
- message = event.data;
4129
- }
4130
- if (!message) {
4131
- this.logInfo("No message found. Ignoring message...");
4132
- return;
4133
- }
4134
- this.notifyVenusMessageReceived(message);
4135
- if (message.type === "PAUSE" /* PAUSE */ || message.type === "RESUME" /* RESUME */ || message.type === "AWAKE" /* AWAKE */ || message.type === "SLEEP" /* SLEEP */ || message.type === "QUIT" /* QUIT */) {
4136
- const notification = {
4137
- type: "rpc-notification",
4138
- id: message.type,
4139
- payload: message.data
4140
- };
4141
- this.handleNotification(notification);
4142
- this.isProcessingMessage = false;
4143
- return;
4144
- }
4145
- const messageData = message.data;
4146
- if (!messageData) {
4147
- this.logWarn("No data found. Ignoring message...");
4148
- this.isProcessingMessage = false;
4149
- return;
4150
- }
4151
- if (message.type === "H5_SIMULATION_UPDATE" /* H5_SIMULATION_UPDATE */) {
4152
- const notification = {
4153
- type: "rpc-notification",
4154
- id: message.type,
4155
- payload: message.data
4156
- };
4157
- this.handleNotification(notification);
4158
- this.isProcessingMessage = false;
4159
- return;
4160
- }
4161
- const requestId = messageData.requestId;
4162
- if (!requestId) {
4163
- this.logWarn("No requestId. Ignoring message...");
4164
- this.isProcessingMessage = false;
4165
- return;
4166
- }
4167
- if (message.type !== "H5_RESPONSE" /* H5_RESPONSE */) {
4168
- this.logWarn(`Ignoring unknown message type: ${message.type}`);
4169
- this.isProcessingMessage = false;
4170
- return;
4171
- }
4172
- const success = messageData.success;
4173
- let error = void 0;
4174
- if (!success) {
4175
- error = {
4176
- message: messageData.error || "Unknown error"
4177
- };
4178
- }
4179
- let result = messageData.value;
4180
- if (result === void 0) {
4181
- result = messageData.data;
4182
- }
4183
- const response = {
4184
- type: "rpc-response",
4185
- id: requestId,
4186
- result,
4187
- method: message.type,
4188
- error
4189
- };
4190
- await this.handleResponse(response);
4191
- this.isProcessingMessage = false;
4192
- };
4193
- }
4194
- onNotification(callback) {
4195
- this.onNotificationCallbacks.push(callback);
4196
- return {
4197
- unsubscribe: () => {
4198
- if (this.isProcessingMessage) {
4199
- this.onNotificationCallbacks.push(callback);
4200
- } else {
4201
- this.removeOnNotificationCallback(callback);
4202
- }
4203
- }
4204
- };
4205
- }
4206
- onRequest(callback) {
4207
- throw new Error("Method not implemented.");
4208
- }
4209
- onResponse(callback) {
4210
- this.onResponseCallbacks.push(callback);
4211
- return {
4212
- unsubscribe: () => {
4213
- if (this.isProcessingMessage) {
4214
- this.onResponseCallbacksToRemove.push(callback);
4215
- } else {
4216
- this.removeOnResponseCallback(callback);
4217
- }
4218
- }
4219
- };
4220
- }
4221
- get instanceId() {
4222
- return this._instanceId;
4223
- }
4224
- set instanceId(instanceId) {
4225
- this._instanceId = instanceId;
4226
- }
4227
- sendRequest(request) {
4228
- const instanceId = this.instanceId || "unknown";
4229
- const method = request.method;
4230
- const message = {
4231
- type: method,
4232
- direction: "H5_TO_APP",
4233
- data: {
4234
- ...request.args,
4235
- requestId: request.id
4236
- },
4237
- instanceId,
4238
- timestamp: Date.now()
4239
- };
4240
- this.sendVenusMessage(message);
4241
- }
4242
- sendVenusMessage(message) {
4243
- const messageAsString = JSON.stringify(message, null, 2);
4244
- const reactNativeWebView = window.ReactNativeWebView;
4245
- if (reactNativeWebView) {
4246
- reactNativeWebView.postMessage(messageAsString);
4247
- } else {
4248
- window.parent.postMessage(messageAsString, "*");
4249
- }
4250
- }
4251
- sendResponse(response) {
4252
- throw new Error("Method not implemented.");
4253
- }
4254
- start() {
4255
- if (this.isStarted) {
4256
- return;
4257
- }
4258
- this.isStarted = true;
4259
- window.addEventListener("message", this.messageHandler, true);
4260
- this.logInfo(`Started`);
4261
- }
4262
- stop() {
4263
- if (!this.isStarted) {
4264
- return;
4265
- }
4266
- this.isStarted = false;
4267
- window.removeEventListener("message", this.messageHandler);
4268
- this.logInfo(`Stopped`);
4269
- }
4270
- handleNotification(notification) {
4271
- for (const callback of this.onNotificationCallbacks) {
4272
- callback(notification);
4273
- }
4274
- for (const callback of this.onNotificationCallbacksToRemove) {
4275
- this.removeOnNotificationCallback(callback);
4276
- }
4277
- this.onNotificationCallbacksToRemove.length = 0;
4278
- }
4279
- async handleResponse(response) {
4280
- for (const callback of this.onResponseCallbacks) {
4281
- const consumed = await callback(response);
4282
- if (consumed) {
4283
- break;
4284
- }
4285
- }
4286
- for (const callback of this.onResponseCallbacksToRemove) {
4287
- this.removeOnResponseCallback(callback);
4288
- }
4289
- this.onResponseCallbacksToRemove.length = 0;
4290
- }
4291
- removeOnResponseCallback(callback) {
4292
- this.onResponseCallbacks.splice(
4293
- this.onResponseCallbacks.indexOf(callback),
4294
- 1
4295
- );
4296
- }
4297
- removeOnNotificationCallback(callback) {
4298
- this.onNotificationCallbacks.splice(
4299
- this.onNotificationCallbacks.indexOf(callback),
4300
- 1
4301
- );
4302
- }
4303
- logInfo(message, ...params) {
4304
- console.log(`[Venus Transport] ${message}`, ...params);
4305
- }
4306
- logWarn(message, ...params) {
4307
- console.warn(`[Venus Transport] ${message}`, ...params);
4308
- }
4309
- onVenusMessage(callback) {
4310
- this.onVenusMessageCallbacks.push(callback);
4311
- return {
4312
- unsubscribe: () => {
4313
- this.onVenusMessageCallbacks.splice(
4314
- this.onVenusMessageCallbacks.indexOf(callback),
4315
- 1
4316
- );
4317
- }
4318
- };
4319
- }
4320
- notifyVenusMessageReceived(message) {
4321
- for (const callback of this.onVenusMessageCallbacks) {
4322
- callback(message);
4323
- }
4324
- }
4325
- };
4326
-
4327
- // src/RemoteHost.ts
4328
- var getCdnBaseUrl = () => {
4329
- return "https://venus-static-01293ak.web.app/";
4330
- };
4331
- var RemoteHost = class {
4332
- ads;
4333
- analytics;
4334
- deviceCache;
4335
- appStorage;
4336
- globalStorage;
4337
- avatar3d;
4338
- navigation;
4339
- notifications;
4340
- popups;
4341
- profile;
4342
- system;
4343
- cdn;
4344
- time;
4345
- ai;
4346
- haptics;
4347
- features;
4348
- lifecycle;
4349
- simulation;
4350
- rooms;
4351
- logging;
4352
- iap;
4353
- leaderboard;
4354
- preloader;
4355
- social;
4356
- context;
4357
- get isInitialized() {
4358
- return this._isInitialized;
4359
- }
4360
- venusApi;
4361
- rpcClient;
4362
- _isInitialized = false;
4363
- constructor(venusApi) {
4364
- this.venusApi = venusApi;
4365
- const rpcClient = new RpcClient();
4366
- this.rpcClient = rpcClient;
4367
- this.ads = new RpcAdsApi(rpcClient);
4368
- this.analytics = new RpcAnalyticsApi(rpcClient);
4369
- this.deviceCache = new RpcStorageApi(rpcClient, {
4370
- clear: "H5_DEVICE_CACHE_CLEAR" /* DEVICE_CACHE_CLEAR */,
4371
- getItem: "H5_DEVICE_CACHE_GET_ITEM" /* DEVICE_CACHE_GET_ITEM */,
4372
- getKey: "H5_DEVICE_CACHE_KEY" /* DEVICE_CACHE_KEY */,
4373
- length: "H5_DEVICE_CACHE_LENGTH" /* DEVICE_CACHE_LENGTH */,
4374
- removeItem: "H5_DEVICE_CACHE_REMOVE_ITEM" /* DEVICE_CACHE_REMOVE_ITEM */,
4375
- setItem: "H5_DEVICE_CACHE_SET_ITEM" /* DEVICE_CACHE_SET_ITEM */
4376
- });
4377
- this.appStorage = new RpcStorageApi(rpcClient, {
4378
- clear: "H5_APP_STORAGE_CLEAR" /* APP_STORAGE_CLEAR */,
4379
- getItem: "H5_APP_STORAGE_GET_ITEM" /* APP_STORAGE_GET_ITEM */,
4380
- getKey: "H5_APP_STORAGE_KEY" /* APP_STORAGE_KEY */,
4381
- length: "H5_APP_STORAGE_LENGTH" /* APP_STORAGE_LENGTH */,
4382
- removeItem: "H5_APP_STORAGE_REMOVE_ITEM" /* APP_STORAGE_REMOVE_ITEM */,
4383
- setItem: "H5_APP_STORAGE_SET_ITEM" /* APP_STORAGE_SET_ITEM */,
4384
- getAllItems: "H5_APP_STORAGE_GET_ALL_ITEMS" /* APP_STORAGE_GET_ALL_ITEMS */,
4385
- setMultipleItems: "H5_APP_STORAGE_SET_ITEM" /* APP_STORAGE_SET_ITEM */,
4386
- removeMultipleItems: "H5_APP_STORAGE_REMOVE_ITEM" /* APP_STORAGE_REMOVE_ITEM */
4387
- });
4388
- this.globalStorage = new RpcStorageApi(rpcClient, {
4389
- clear: "H5_GLOBAL_STORAGE_CLEAR" /* GLOBAL_STORAGE_CLEAR */,
4390
- getItem: "H5_GLOBAL_STORAGE_GET_ITEM" /* GLOBAL_STORAGE_GET_ITEM */,
4391
- getKey: "H5_GLOBAL_STORAGE_KEY" /* GLOBAL_STORAGE_KEY */,
4392
- length: "H5_GLOBAL_STORAGE_LENGTH" /* GLOBAL_STORAGE_LENGTH */,
4393
- removeItem: "H5_GLOBAL_STORAGE_REMOVE_ITEM" /* GLOBAL_STORAGE_REMOVE_ITEM */,
4394
- setItem: "H5_GLOBAL_STORAGE_SET_ITEM" /* GLOBAL_STORAGE_SET_ITEM */,
4395
- getAllItems: "H5_GLOBAL_STORAGE_GET_ALL_ITEMS" /* GLOBAL_STORAGE_GET_ALL_ITEMS */,
4396
- setMultipleItems: "H5_GLOBAL_STORAGE_SET_MULTIPLE_ITEMS" /* GLOBAL_STORAGE_SET_MULTIPLE_ITEMS */,
4397
- removeMultipleItems: "H5_GLOBAL_STORAGE_REMOVE_MULTIPLE_ITEMS" /* GLOBAL_STORAGE_REMOVE_MULTIPLE_ITEMS */
4398
- });
4399
- this.avatar3d = new RpcAvatarApi(rpcClient, venusApi);
4400
- this.navigation = new RpcNavigationApi(rpcClient, venusApi);
4401
- this.notifications = new RpcNotificationsApi(rpcClient);
4402
- this.popups = new RpcPopupsApi(rpcClient);
4403
- this.profile = new HostProfileApi(venusApi);
4404
- const deviceApi = new HostDeviceApi(venusApi);
4405
- const environmentApi = new HostEnvironmentApi(venusApi);
4406
- this.system = new HostSystemApi(deviceApi, environmentApi, venusApi);
4407
- this.cdn = new HostCdnApi(getCdnBaseUrl());
4408
- this.time = new HostTimeApi(rpcClient, venusApi);
4409
- this.ai = new RpcAiApi(rpcClient);
4410
- this.haptics = new RpcHapticsApi(rpcClient);
4411
- this.features = new RpcFeaturesApi(rpcClient);
4412
- this.lifecycle = new RpcLifecycleApi(rpcClient);
4413
- this.simulation = new RpcSimulationApi(rpcClient);
4414
- this.rooms = new RpcRoomsApi(rpcClient);
4415
- this.logging = new RpcLoggingApi(this, rpcClient);
4416
- this.iap = new RpcIapApi(rpcClient);
4417
- this.leaderboard = new RpcLeaderboardApi(rpcClient);
4418
- this.preloader = new RpcPreloaderApi(rpcClient);
4419
- this.social = new RpcSocialApi(rpcClient);
4420
- venusApi.isMock = () => false;
4421
- this.venusApi.sharedAssets = new RpcSharedAssetsApi(rpcClient, venusApi);
4422
- initializeRoomsApi(this.venusApi, this);
4423
- }
4424
- async initialize(options) {
4425
- this.log("Initializing Remote Host...");
4426
- const transport = new VenusTransport();
4427
- transport.start();
4428
- this.rpcClient.start(transport);
4429
- const roomsApi = this.rooms;
4430
- roomsApi.setupNotifications(transport);
4431
- const response = await this.rpcClient.call(
4432
- "INITIALIZE_SDK" /* INIT_SDK */,
4433
- {},
4434
- 5e3
4435
- );
4436
- transport.instanceId = response.instanceId;
4437
- this.log(`Remote Host Initialized with id: ${transport.instanceId}`);
4438
- const profile = response.profile;
4439
- const sanitizedProfile = {
4440
- id: profile.id,
4441
- username: profile.username,
4442
- avatarUrl: profile.avatarUrl ?? null,
4443
- isAnonymous: Boolean(profile.isAnonymous)
4444
- };
4445
- this.venusApi._profileData = sanitizedProfile;
4446
- this.venusApi._deviceData = response.device;
4447
- this.venusApi._environmentData = response.environment;
4448
- this.venusApi._localeData = response.locale;
4449
- this.venusApi._languageCodeData = response.languageCode;
4450
- this._isInitialized = true;
4451
- this.venusApi.launchParams = response.launchParams;
4452
- await this.rpcClient.call("READY" /* READY */, {});
4453
- const safeArea = response.safeArea;
4454
- if (safeArea) {
4455
- this.venusApi._safeAreaData = safeArea;
4456
- }
4457
- this.context = {
4458
- safeArea,
4459
- initializeAsleep: response.initializeAsleep
4460
- };
4461
- return this.context;
3294
+ // src/config/sandbox.ts
3295
+ function getSandboxConfig() {
3296
+ if (typeof globalThis === "undefined") {
3297
+ return null;
4462
3298
  }
4463
- log(message) {
4464
- console.log(`[Venus SDK] [Remote Host] ${message}`);
3299
+ const config = globalThis.__VENUS_SANDBOX__;
3300
+ if (!config?.enabled) {
3301
+ return null;
4465
3302
  }
4466
- };
4467
-
4468
- // src/MockHost.ts
4469
- var ROOMS_UNAVAILABLE_MESSAGE = "[Venus SDK] Rooms API is only available when running inside the Venus host environment.";
4470
- function createUnavailableRoomsApi() {
4471
- const roomsUnavailableError = () => new Error(ROOMS_UNAVAILABLE_MESSAGE);
4472
- return {
4473
- async createRoomAsync() {
4474
- throw roomsUnavailableError();
4475
- },
4476
- async joinOrCreateRoomAsync() {
4477
- throw roomsUnavailableError();
4478
- },
4479
- async joinRoomByCodeAsync() {
4480
- throw roomsUnavailableError();
4481
- },
4482
- async getUserRoomsAsync() {
4483
- throw roomsUnavailableError();
4484
- },
4485
- async subscribeAsync() {
4486
- throw roomsUnavailableError();
4487
- },
4488
- async updateRoomDataAsync() {
4489
- throw roomsUnavailableError();
4490
- },
4491
- async getRoomDataAsync() {
4492
- throw roomsUnavailableError();
4493
- },
4494
- async sendRoomMessageAsync() {
4495
- throw roomsUnavailableError();
4496
- },
4497
- async leaveRoomAsync() {
4498
- throw roomsUnavailableError();
4499
- },
4500
- async startRoomGameAsync() {
4501
- throw roomsUnavailableError();
4502
- },
4503
- async proposeMoveAsync() {
4504
- throw roomsUnavailableError();
4505
- },
4506
- async validateMoveAsync() {
4507
- throw roomsUnavailableError();
4508
- }
4509
- };
3303
+ return config;
4510
3304
  }
4511
- var SIMULATION_UNAVAILABLE_MESSAGE = "[Venus SDK] Simulation API is only available when running inside the Venus host environment.";
4512
- function createUnavailableSimulationApi() {
4513
- const simulationUnavailableError = () => new Error(SIMULATION_UNAVAILABLE_MESSAGE);
4514
- return {
4515
- isEnabled() {
4516
- return false;
4517
- },
4518
- async getStateAsync() {
4519
- throw simulationUnavailableError();
4520
- },
4521
- async getConfigAsync() {
4522
- throw simulationUnavailableError();
4523
- },
4524
- async executeRecipeAsync() {
4525
- throw simulationUnavailableError();
4526
- },
4527
- async getActiveRunsAsync() {
4528
- throw simulationUnavailableError();
4529
- },
4530
- async collectRecipeAsync() {
4531
- throw simulationUnavailableError();
4532
- },
4533
- async executeScopedRecipeAsync() {
4534
- throw simulationUnavailableError();
4535
- },
4536
- async triggerRecipeChainAsync() {
4537
- throw simulationUnavailableError();
4538
- },
4539
- async getAvailableRecipesAsync() {
4540
- throw simulationUnavailableError();
4541
- },
4542
- async getRecipeRequirementsAsync() {
4543
- throw simulationUnavailableError();
4544
- },
4545
- async getBatchRecipeRequirementsAsync() {
4546
- throw simulationUnavailableError();
4547
- },
4548
- async resolveFieldValueAsync() {
4549
- throw simulationUnavailableError();
4550
- },
4551
- async getEntityMetadataAsync() {
4552
- throw simulationUnavailableError();
4553
- },
4554
- async getSlotContainersAsync() {
4555
- throw simulationUnavailableError();
4556
- },
4557
- async getSlotAssignmentsAsync() {
4558
- throw simulationUnavailableError();
4559
- },
4560
- async assignItemToSlotAsync() {
4561
- throw simulationUnavailableError();
4562
- },
4563
- async removeItemFromSlotAsync() {
4564
- throw simulationUnavailableError();
4565
- },
4566
- async getAvailableItemsAsync() {
4567
- throw simulationUnavailableError();
4568
- },
4569
- async calculatePowerPreviewAsync() {
4570
- throw simulationUnavailableError();
4571
- },
4572
- async validateSlotAssignmentAsync() {
4573
- throw simulationUnavailableError();
4574
- },
4575
- async executeBatchOperationsAsync() {
4576
- throw simulationUnavailableError();
4577
- },
4578
- async subscribeAsync() {
4579
- throw simulationUnavailableError();
4580
- }
4581
- };
3305
+ function isSandboxEnabled() {
3306
+ const config = getSandboxConfig();
3307
+ return config?.enabled === true;
4582
3308
  }
4583
- var MockHost = class {
4584
- ads;
4585
- analytics;
4586
- deviceCache;
4587
- appStorage;
4588
- globalStorage;
4589
- avatar3d;
4590
- navigation;
4591
- notifications;
4592
- popups;
4593
- profile;
4594
- system;
4595
- cdn;
4596
- time;
4597
- ai;
4598
- haptics;
4599
- features;
4600
- lifecycle;
4601
- simulation;
4602
- rooms;
4603
- logging;
4604
- iap;
4605
- leaderboard;
4606
- preloader;
4607
- social;
4608
- context;
4609
- state = 0 /* PLAYING */;
4610
- get isInitialized() {
4611
- return this._isInitialized;
4612
- }
4613
- venusApi;
4614
- _isInitialized = false;
4615
- _overlay;
4616
- _mockLifecyclesApi;
4617
- _mockAdsApi;
4618
- constructor(venusApi) {
4619
- this.venusApi = venusApi;
4620
- this._overlay = this.createOverlay();
4621
- this._mockAdsApi = new MockAdsApi(this._overlay);
4622
- this._mockLifecyclesApi = new MockLifecycleApi();
4623
- this.ads = this._mockAdsApi;
4624
- this.analytics = new MockAnalyticsApi();
4625
- const appUrl = typeof window !== "undefined" ? window.location.href : "";
4626
- this.deviceCache = createMockStorageApi("deviceCache", appUrl);
4627
- this.appStorage = createMockStorageApi("appStorage", appUrl);
4628
- this.globalStorage = createMockStorageApi("globalStorage");
4629
- this.avatar3d = new MockAvatarApi(venusApi);
4630
- this.navigation = new MockNavigationApi(venusApi);
4631
- this.notifications = new MockNotificationsApi(venusApi);
4632
- this.popups = new MockPopupsApi(this._overlay);
4633
- this.profile = new MockProfileApi(venusApi);
4634
- const deviceApi = new MockDeviceApi(venusApi);
4635
- const environmentApi = new MockEnvironmentApi(venusApi);
4636
- this.system = new MockSystemApi(deviceApi, environmentApi, venusApi);
4637
- this.cdn = new MockCdnApi(venusApi);
4638
- this.time = new MockTimeApi(venusApi);
4639
- this.ai = new MockAiApi();
4640
- this.haptics = new MockHapticsApi(venusApi);
4641
- this.features = new MockFeaturesApi();
4642
- this.lifecycle = this._mockLifecyclesApi;
4643
- this.simulation = createUnavailableSimulationApi();
4644
- this.rooms = createUnavailableRoomsApi();
4645
- this.logging = new MockLoggingApi();
4646
- this.iap = new MockIapApi();
4647
- this.social = new MockSocialApi();
4648
- this.leaderboard = new MockLeaderboardApi();
4649
- initializeRoomsApi(this.venusApi, this);
4650
- this.preloader = new MockPreloaderApi();
4651
- venusApi.isMock = () => true;
4652
- this.venusApi.sharedAssets = new MockSharedAssetsApi(this.venusApi);
4653
- }
4654
- initialize(options) {
4655
- this._isInitialized = true;
4656
- this.venusApi._profileData = this.profile.getCurrentProfile();
4657
- this.venusApi._deviceData = this.system.getDevice();
4658
- this.venusApi._environmentData = this.system.getEnvironment();
4659
- this.venusApi._localeData = this.venusApi._mock?.locale || "en-US";
4660
- this.venusApi._languageCodeData = this.venusApi._mock?.languageCode || "en";
4661
- this.context = {
4662
- initializeAsleep: false,
4663
- safeArea: this.venusApi._safeAreaData
4664
- };
4665
- return Promise.resolve(this.context);
4666
- }
4667
- createOverlay() {
4668
- const overlayContainer = document.createElement("div");
4669
- overlayContainer.id = "venus-mock-overlay";
4670
- overlayContainer.style.cssText = `
4671
- position: fixed;
4672
- top: 0;
4673
- left: 0;
4674
- width: 100%;
4675
- height: 100%;
4676
- pointer-events: none;
4677
- z-index: 10000;
4678
- `;
4679
- document.body.appendChild(overlayContainer);
4680
- const menuButton = this.createOverlayButton(
4681
- "close",
4682
- "Menu",
4683
- { x: window.innerWidth - 48, y: 16, width: 32, height: 32 },
4684
- () => {
4685
- this.handleMenuButtonClicked();
4686
- },
4687
- "rgba(59, 130, 246, 0.7)",
4688
- // Blue background instead of black
4689
- "#FFFFFF"
4690
- );
4691
- overlayContainer.appendChild(menuButton);
4692
- const adOverlay = this.setupAdOverlay();
4693
- const actionSheet = this.setupActionSheetOverlay();
4694
- window.addEventListener("resize", () => {
4695
- this.updateOverlayLayout();
4696
- });
4697
- return {
4698
- container: overlayContainer,
4699
- elements: {
4700
- menuButton
4701
- },
4702
- appVisibilityState: "visible",
4703
- actionSheetOverlay: actionSheet,
4704
- adOverlay,
4705
- showAdOverlay: () => {
4706
- return this.showAdOverlay("REWARDED VIDEO AD");
4707
- },
4708
- showActionSheet: (items, options) => {
4709
- return this.showActionSheetOverlay(items, options);
4710
- }
4711
- };
4712
- }
4713
- async handleMenuButtonClicked() {
4714
- if (this.state === 0 /* PLAYING */) {
4715
- this.triggerLifecycleEvent("PAUSE" /* PAUSE */);
4716
- this.state = 1 /* PAUSED */;
4717
- }
4718
- const actionSheetItems = [];
4719
- const awakeAction = {
4720
- label: "\u23F0 Awake",
4721
- id: "awakeAction"
4722
- };
4723
- const sleepAction = {
4724
- label: "\u{1F4A4} Sleep",
4725
- id: "sleepAction"
4726
- };
4727
- const quitAction = {
4728
- label: "\u{1F6D1} Quit",
4729
- id: "quitAction"
4730
- };
4731
- const playAction = {
4732
- label: "\u25B6\uFE0F Play",
4733
- id: "playAction"
4734
- };
4735
- if (this.state === 1 /* PAUSED */) {
4736
- actionSheetItems.push(sleepAction);
4737
- } else if (this.state === 2 /* SLEEPING */) {
4738
- actionSheetItems.push(awakeAction);
4739
- }
4740
- if (this.state !== 3 /* TERMINATED */) {
4741
- actionSheetItems.push(quitAction);
4742
- } else if (this.state === 3 /* TERMINATED */) {
4743
- actionSheetItems.push(playAction);
4744
- }
4745
- const action = await this.showActionSheetOverlay(actionSheetItems);
4746
- if (action === awakeAction.id) {
4747
- this.tryAwake();
4748
- } else if (action === sleepAction.id) {
4749
- this.trySleep();
4750
- } else if (action === playAction.id) {
4751
- this.tryPlay();
4752
- } else if (action === quitAction.id) {
4753
- this.tryQuit();
4754
- } else {
4755
- this.tryResume();
4756
- }
3309
+ var VENUS_API_PROXY_PATH = "/__venusapi";
3310
+ function buildFunctionsBaseUrl(config) {
3311
+ if (config.backendUrl) {
3312
+ return config.backendUrl.replace(/\/$/, "");
4757
3313
  }
4758
- tryAwake() {
4759
- if (this.state === 2 /* SLEEPING */) {
4760
- this.triggerLifecycleEvent("AWAKE" /* AWAKE */);
4761
- this.state = 1 /* PAUSED */;
4762
- }
3314
+ if (config.target === "local" && config.functionsEmulatorHost && config.firebaseConfig?.projectId) {
3315
+ const region = config.functionsRegion || "us-central1";
3316
+ return `http://${config.functionsEmulatorHost}/${config.firebaseConfig.projectId}/${region}`;
4763
3317
  }
4764
- trySleep() {
4765
- if (this.state === 1 /* PAUSED */) {
4766
- this.triggerLifecycleEvent("SLEEP" /* SLEEP */);
4767
- this.state = 2 /* SLEEPING */;
4768
- }
3318
+ if (config.target !== "local" && typeof window !== "undefined") {
3319
+ return VENUS_API_PROXY_PATH;
4769
3320
  }
4770
- tryPlay() {
4771
- if (this.state === 3 /* TERMINATED */) {
4772
- this.triggerLifecycleEvent("AWAKE" /* AWAKE */);
4773
- this.state = 1 /* PAUSED */;
4774
- this.triggerLifecycleEvent("RESUME" /* RESUME */);
4775
- this.state = 0 /* PLAYING */;
4776
- }
3321
+ if (config.firebaseConfig?.projectId && config.functionsRegion) {
3322
+ return `https://${config.functionsRegion}-${config.firebaseConfig.projectId}.cloudfunctions.net`;
4777
3323
  }
4778
- tryQuit() {
4779
- if (this.state === 0 /* PLAYING */) {
4780
- this.triggerLifecycleEvent("PAUSE" /* PAUSE */);
4781
- this.state = 1 /* PAUSED */;
4782
- }
4783
- if (this.state === 1 /* PAUSED */) {
4784
- this.triggerLifecycleEvent("SLEEP" /* SLEEP */);
4785
- this.state = 2 /* SLEEPING */;
4786
- }
4787
- if (this.state === 2 /* SLEEPING */) {
4788
- this.triggerLifecycleEvent("QUIT" /* QUIT */);
4789
- this.state = 3 /* TERMINATED */;
4790
- }
4791
- }
4792
- tryResume() {
4793
- if (this.state === 1 /* PAUSED */) {
4794
- this.triggerLifecycleEvent("RESUME" /* RESUME */);
4795
- this.state = 0 /* PLAYING */;
4796
- }
4797
- }
4798
- async showAdOverlay(type) {
4799
- return new Promise((resolve, reject) => {
4800
- const overlay = this._overlay;
4801
- const adOverlay = overlay.adOverlay;
4802
- overlay.adOverlay.innerHTML = "";
4803
- const heading = document.createElement("h1");
4804
- heading.style.cssText = `
4805
- font-size: 24px;
4806
- margin-bottom: 20px;
4807
- text-align: center;
4808
- `;
4809
- heading.innerText = type === "interstitial" ? "INTERSTITIAL AD" : "REWARDED VIDEO AD";
4810
- overlay.adOverlay.appendChild(heading);
4811
- const content = document.createElement("div");
4812
- content.style.cssText = `
4813
- width: 300px;
4814
- height: 250px;
4815
- background-color: #1e40af;
4816
- display: flex;
4817
- align-items: center;
4818
- justify-content: center;
4819
- margin-bottom: 20px;
4820
- border-radius: 8px;
4821
- `;
4822
- content.innerText = "Mock Ad Content";
4823
- adOverlay.appendChild(content);
4824
- const timer = document.createElement("p");
4825
- timer.style.cssText = `
4826
- margin-bottom: 20px;
4827
- font-size: 16px;
4828
- `;
4829
- timer.innerText = "Normally ads would have a timer...";
4830
- adOverlay.appendChild(timer);
4831
- const okButton = document.createElement("button");
4832
- okButton.style.cssText = `
4833
- padding: 10px 40px;
4834
- background-color: #2563eb;
4835
- color: white;
4836
- border: none;
4837
- border-radius: 4px;
4838
- font-size: 16px;
4839
- cursor: pointer;
4840
- `;
4841
- okButton.innerText = "Close Ad";
4842
- adOverlay.appendChild(okButton);
4843
- adOverlay.style.display = "flex";
4844
- okButton.onclick = () => {
4845
- this.hideAdOverlay();
4846
- resolve(true);
4847
- };
4848
- });
4849
- }
4850
- hideAdOverlay() {
4851
- const overlay = this._overlay;
4852
- if (overlay.adOverlay) {
4853
- overlay.adOverlay.style.display = "none";
4854
- }
4855
- }
4856
- setupActionSheetOverlay() {
4857
- const actionSheetOverlay = document.createElement("div");
4858
- actionSheetOverlay.id = "venus-action-sheet-overlay";
4859
- actionSheetOverlay.style.cssText = `
4860
- position: fixed;
4861
- top: 0;
4862
- left: 0;
4863
- width: 100%;
4864
- height: 100%;
4865
- background-color: rgba(0, 0, 0, 0.5);
4866
- display: flex;
4867
- align-items: center;
4868
- justify-content: center;
4869
- z-index: 10600;
4870
- font-family: sans-serif;
4871
- display: none;
4872
- `;
4873
- document.body.appendChild(actionSheetOverlay);
4874
- return actionSheetOverlay;
4875
- }
4876
- createOverlayButton(id, text, position, onClick, background, color) {
4877
- const button = document.createElement("button");
4878
- button.id = `venus-mock-${id}-button`;
4879
- button.innerText = text;
4880
- button.style.cssText = `
4881
- position: absolute;
4882
- left: ${position.x}px;
4883
- top: ${position.y}px;
4884
- width: ${position.width}px;
4885
- min-width: ${position.width}px;
4886
- height: ${position.height}px;
4887
- background: ${background};
4888
- color: ${color};
4889
- border: none;
4890
- border-radius: 8px;
4891
- font-family: sans-serif;
4892
- font-weight: bold;
4893
- font-size: ${Math.min(position.width, position.height) / 3}px;
4894
- cursor: pointer;
4895
- pointer-events: auto;
4896
- display: flex;
4897
- align-items: center;
4898
- justify-content: center;
4899
- opacity: 0.9;
4900
- transition: opacity 0.2s;
4901
- `;
4902
- button.addEventListener("click", onClick);
4903
- button.addEventListener("mouseover", () => {
4904
- button.style.opacity = "1";
4905
- });
4906
- button.addEventListener("mouseout", () => {
4907
- button.style.opacity = "0.9";
4908
- });
4909
- return button;
4910
- }
4911
- updateOverlayLayout() {
4912
- const overlay = this._overlay;
4913
- const menuBtn = overlay.elements.menuButton;
4914
- menuBtn.style.left = `${window.innerWidth - 48}px`;
4915
- menuBtn.style.top = "16px";
4916
- menuBtn.style.width = "32px";
4917
- menuBtn.style.minWidth = "32px";
4918
- menuBtn.style.height = "32px";
4919
- }
4920
- triggerLifecycleEvent(name) {
4921
- console.log("Trigger Lifecycle Event: ", name);
4922
- if (name == "PAUSE" /* PAUSE */) {
4923
- this._mockLifecyclesApi.triggerPauseCallbacks();
4924
- } else if (name == "RESUME" /* RESUME */) {
4925
- this._mockLifecyclesApi.triggerResumeCallbacks();
4926
- } else if (name == "QUIT" /* QUIT */) {
4927
- this._mockLifecyclesApi.triggerQuitCallbacks();
4928
- } else if (name == "AWAKE" /* AWAKE */) {
4929
- this._mockLifecyclesApi.triggerAwakeCallbacks();
4930
- } else if (name == "SLEEP" /* SLEEP */) {
4931
- this._mockLifecyclesApi.triggerSleepCallbacks();
4932
- }
4933
- }
4934
- setOverlayElementVisibility(element, visible) {
4935
- const overlay = this._overlay;
4936
- const elements = overlay.elements;
4937
- if (elements[element]) {
4938
- elements[element].style.display = visible ? "flex" : "none";
4939
- }
4940
- }
4941
- setupAdOverlay() {
4942
- const adOverlay = document.createElement("div");
4943
- adOverlay.id = "venus-ad-overlay";
4944
- adOverlay.style.cssText = `
4945
- position: fixed;
4946
- top: 0;
4947
- left: 0;
4948
- width: 100%;
4949
- height: 100%;
4950
- background-color: rgba(37, 99, 235, 0.9);
4951
- color: white;
4952
- display: flex;
4953
- flex-direction: column;
4954
- align-items: center;
4955
- justify-content: center;
4956
- z-index: 10500;
4957
- font-family: sans-serif;
4958
- display: none;
4959
- `;
4960
- document.body.appendChild(adOverlay);
4961
- return adOverlay;
4962
- }
4963
- log(msg, ...args) {
4964
- console.log(`[Venus Mock] ${msg}`, ...args);
4965
- }
4966
- showActionSheetOverlay(items, options) {
4967
- this.log("Showing ActionSheetOverlay...");
4968
- return new Promise((resolve, reject) => {
4969
- const overlay = this._overlay;
4970
- overlay.actionSheetOverlay.innerHTML = "";
4971
- overlay.actionSheetOverlay.style.display = "flex";
4972
- const actionSheet = document.createElement("div");
4973
- actionSheet.className = "venus-action-sheet";
4974
- actionSheet.style.cssText = `
4975
- background-color: white;
4976
- border-radius: 8px;
4977
- width: 80%;
4978
- max-width: 400px;
4979
- max-height: 80%;
4980
- display: flex;
4981
- flex-direction: column;
4982
- overflow: hidden;
4983
- color: black;
4984
- `;
4985
- if (options?.title) {
4986
- const titleContainer = document.createElement("div");
4987
- titleContainer.style.cssText = `
4988
- padding: 16px;
4989
- border-bottom: 1px solid #eaeaea;
4990
- font-weight: bold;
4991
- font-size: 18px;
4992
- text-align: center;
4993
- color: black;
4994
- `;
4995
- titleContainer.innerText = options.title;
4996
- actionSheet.appendChild(titleContainer);
4997
- }
4998
- if (options?.message) {
4999
- const messageContainer = document.createElement("div");
5000
- messageContainer.style.cssText = `
5001
- padding: 8px 16px;
5002
- color: #666;
5003
- font-size: 14px;
5004
- text-align: center;
5005
- `;
5006
- messageContainer.innerText = options.message;
5007
- actionSheet.appendChild(messageContainer);
5008
- }
5009
- const optionsContainer = document.createElement("div");
5010
- optionsContainer.style.cssText = `
5011
- overflow-y: auto;
5012
- max-height: 300px;
5013
- `;
5014
- items.forEach((item, index) => {
5015
- const optionItem = document.createElement("div");
5016
- optionItem.style.cssText = `
5017
- padding: 12px 16px;
5018
- border-bottom: 1px solid #eaeaea;
5019
- cursor: pointer;
5020
- display: flex;
5021
- align-items: center;
5022
- transition: background-color 0.2s;
5023
- color: black;
5024
- `;
5025
- optionItem.addEventListener("mouseover", () => {
5026
- optionItem.style.backgroundColor = "#f5f5f5";
5027
- });
5028
- optionItem.addEventListener("mouseout", () => {
5029
- optionItem.style.backgroundColor = "white";
5030
- });
5031
- if (item.icon) {
5032
- const iconSpan = document.createElement("span");
5033
- iconSpan.style.cssText = `
5034
- margin-right: 12px;
5035
- font-size: 16px;
5036
- `;
5037
- iconSpan.innerText = item.icon;
5038
- optionItem.appendChild(iconSpan);
5039
- }
5040
- const labelSpan = document.createElement("span");
5041
- labelSpan.style.cssText = `
5042
- color: black;
5043
- `;
5044
- labelSpan.innerText = item.label;
5045
- optionItem.appendChild(labelSpan);
5046
- optionItem.addEventListener("click", () => {
5047
- this.hideActionSheetOverlay();
5048
- const optionId = item.id !== void 0 ? item.id : index;
5049
- resolve(optionId);
5050
- });
5051
- optionsContainer.appendChild(optionItem);
5052
- });
5053
- actionSheet.appendChild(optionsContainer);
5054
- if (!options?.disableCancel) {
5055
- const cancelButton = document.createElement("div");
5056
- cancelButton.style.cssText = `
5057
- padding: 14px 16px;
5058
- text-align: center;
5059
- font-weight: bold;
5060
- cursor: pointer;
5061
- color: #3b82f6;
5062
- border-top: 1px solid #eaeaea;
5063
- `;
5064
- cancelButton.innerText = options?.cancelButtonText || "Cancel";
5065
- cancelButton.addEventListener("click", () => {
5066
- this.hideActionSheetOverlay();
5067
- resolve(null);
5068
- });
5069
- actionSheet.appendChild(cancelButton);
5070
- }
5071
- if (!options?.disableCancel) {
5072
- const closeButton = document.createElement("div");
5073
- closeButton.style.cssText = `
5074
- position: absolute;
5075
- top: 8px;
5076
- right: 8px;
5077
- width: 24px;
5078
- height: 24px;
5079
- border-radius: 12px;
5080
- background-color: rgba(0,0,0,0.1);
5081
- color: #666;
5082
- display: flex;
5083
- align-items: center;
5084
- justify-content: center;
5085
- cursor: pointer;
5086
- font-size: 14px;
5087
- `;
5088
- closeButton.innerText = "\u2715";
5089
- closeButton.addEventListener("click", () => {
5090
- this.hideActionSheetOverlay();
5091
- resolve(null);
5092
- });
5093
- actionSheet.appendChild(closeButton);
5094
- overlay.actionSheetOverlay.appendChild(actionSheet);
5095
- }
5096
- });
5097
- }
5098
- hideActionSheetOverlay() {
5099
- const overlay = this._overlay;
5100
- if (overlay.actionSheetOverlay) {
5101
- overlay.actionSheetOverlay.style.display = "none";
5102
- }
5103
- }
5104
- };
5105
-
5106
- // src/Host.ts
5107
- function createHost(venusApi, isMock) {
5108
- if (isMock) {
5109
- return new MockHost(venusApi);
5110
- } else {
5111
- return new RemoteHost(venusApi);
5112
- }
5113
- }
5114
-
5115
- // src/social/index.ts
5116
- function initializeSocial(venusApi, host) {
5117
- venusApi.social = host.social;
5118
- venusApi.getLaunchParams = () => {
5119
- return venusApi.launchParams || {};
5120
- };
3324
+ throw new Error(
3325
+ `[Venus SDK] Cannot determine backend URL for target "${config.target}". Either provide backendUrl or configure Firebase project settings.`
3326
+ );
5121
3327
  }
5122
3328
 
5123
- export { DEFAULT_SHARED_LIB_CDN_BASE, EMBEDDED_LIBRARIES, EMBEDDED_LIBRARY_BY_KEY, HASH_ALGORITHM_NODE, HASH_ALGORITHM_WEB_CRYPTO, HapticFeedbackStyle, HostCdnApi, HostDeviceApi, HostEnvironmentApi, HostProfileApi, HostSystemApi, HostTimeApi, MODULE_TO_LIBRARY_SPECIFIERS, MockAdsApi, MockAiApi, MockAnalyticsApi, MockAvatarApi, MockCdnApi, MockDeviceApi, MockEnvironmentApi, MockFeaturesApi, MockHapticsApi, MockIapApi, MockLeaderboardApi, MockLifecycleApi, MockLoggingApi, MockNavigationApi, MockNotificationsApi, MockPopupsApi, MockPreloaderApi, MockProfileApi, MockSharedAssetsApi, MockSocialApi, MockStorageApi, MockSystemApi, MockTimeApi, ROOM_GAME_PHASES, RemoteHost, RpcAdsApi, RpcAiApi, RpcAnalyticsApi, RpcAvatarApi, RpcClient, RpcFeaturesApi, RpcHapticsApi, RpcIapApi, RpcLeaderboardApi, RpcLifecycleApi, RpcLoggingApi, RpcNavigationApi, RpcNotificationsApi, RpcPopupsApi, RpcPreloaderApi, RpcRoomsApi, RpcSharedAssetsApi, RpcSimulationApi, RpcSocialApi, RpcStorageApi, SDK_VERSION, VenusMessageId, VenusRoom, base64ToArrayBuffer, base64ToUtf8, computeScoreHash, createHost, createMockStorageApi, getLibraryDefinition, initializeAds, initializeAi, initializeAnalytics, initializeAvatar3d, initializeCdn, initializeFeaturesApi, initializeHaptics, initializeIap, initializeLeaderboard, initializeLifecycleApi, initializeLocalNotifications, initializeLoggingApi, initializePopups, initializePreloader, initializeProfile, initializeRoomsApi, initializeSimulation, initializeSocial, initializeStackNavigation, initializeStorage, initializeSystem, initializeTime, isPacificDaylightTime, setupRoomNotifications };
5124
- //# sourceMappingURL=chunk-OKOJGDZJ.js.map
5125
- //# sourceMappingURL=chunk-OKOJGDZJ.js.map
3329
+ export { DEFAULT_SHARED_LIB_CDN_BASE, EMBEDDED_LIBRARIES, EMBEDDED_LIBRARY_BY_KEY, HapticFeedbackStyle, HostCdnApi, HostDeviceApi, HostEnvironmentApi, HostProfileApi, HostSystemApi, HostTimeApi, MODULE_TO_LIBRARY_SPECIFIERS, MockAdsApi, MockAiApi, MockAnalyticsApi, MockAvatarApi, MockCdnApi, MockDeviceApi, MockEnvironmentApi, MockFeaturesApi, MockHapticsApi, MockIapApi, MockLifecycleApi, MockLoggingApi, MockNavigationApi, MockNotificationsApi, MockPopupsApi, MockPreloaderApi, MockProfileApi, MockSharedAssetsApi, MockSocialApi, MockStorageApi, MockSystemApi, MockTimeApi, ROOM_GAME_PHASES, RpcAdsApi, RpcAiApi, RpcAnalyticsApi, RpcAvatarApi, RpcFeaturesApi, RpcHapticsApi, RpcIapApi, RpcLifecycleApi, RpcLoggingApi, RpcNavigationApi, RpcNotificationsApi, RpcPopupsApi, RpcPreloaderApi, RpcRoomsApi, RpcSharedAssetsApi, RpcStorageApi, VenusMessageId, VenusRoom, base64ToArrayBuffer, base64ToUtf8, buildFunctionsBaseUrl, createMockStorageApi, getLibraryDefinition, getSandboxConfig, initializeAds, initializeAi, initializeAnalytics, initializeAvatar3d, initializeCdn, initializeFeaturesApi, initializeHaptics, initializeIap, initializeLifecycleApi, initializeLocalNotifications, initializeLoggingApi, initializePopups, initializePreloader, initializeProfile, initializeRoomsApi, initializeStackNavigation, initializeStorage, initializeSystem, initializeTime, isPacificDaylightTime, isSandboxEnabled, setupRoomNotifications };
3330
+ //# sourceMappingURL=chunk-Q7SNANYR.js.map
3331
+ //# sourceMappingURL=chunk-Q7SNANYR.js.map