@series-inc/venus-sdk 2.4.1 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +345 -249
- package/dist/AdsApi-3DEYUUuj.d.mts +1414 -0
- package/dist/AdsApi-3DEYUUuj.d.ts +1414 -0
- package/dist/{chunk-KQZIPQLJ.mjs → chunk-6DYG4RFQ.mjs} +2066 -133
- package/dist/chunk-6DYG4RFQ.mjs.map +1 -0
- package/dist/{chunk-MWUS3A7C.mjs → chunk-W7IPHM67.mjs} +22 -3
- package/dist/chunk-W7IPHM67.mjs.map +1 -0
- package/dist/core-R3FHW62G.mjs +3 -0
- package/dist/{core-RDMPQV6U.mjs.map → core-R3FHW62G.mjs.map} +1 -1
- package/dist/index.cjs +2084 -129
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +253 -303
- package/dist/index.d.ts +253 -303
- package/dist/index.mjs +6 -2
- package/dist/index.mjs.map +1 -1
- package/dist/venus-api/index.cjs +1072 -1654
- package/dist/venus-api/index.cjs.map +1 -1
- package/dist/venus-api/index.d.mts +2 -2
- package/dist/venus-api/index.d.ts +2 -2
- package/dist/venus-api/index.mjs +31 -2552
- package/dist/venus-api/index.mjs.map +1 -1
- package/package.json +2 -2
- package/dist/AdsApi-Cz0XgLM8.d.mts +0 -851
- package/dist/AdsApi-Cz0XgLM8.d.ts +0 -851
- package/dist/chunk-KQZIPQLJ.mjs.map +0 -1
- package/dist/chunk-MWUS3A7C.mjs.map +0 -1
- package/dist/core-RDMPQV6U.mjs +0 -3
|
@@ -1,4 +1,219 @@
|
|
|
1
|
-
import { __publicField, createMockDelay, MOCK_DELAYS, isWebPlatform } from './chunk-
|
|
1
|
+
import { __esm, __export, __publicField, createMockDelay, MOCK_DELAYS, isWebPlatform, __toCommonJS } from './chunk-W7IPHM67.mjs';
|
|
2
|
+
|
|
3
|
+
// src/rooms/VenusRoom.ts
|
|
4
|
+
var VenusRoom;
|
|
5
|
+
var init_VenusRoom = __esm({
|
|
6
|
+
"src/rooms/VenusRoom.ts"() {
|
|
7
|
+
VenusRoom = class {
|
|
8
|
+
constructor(roomData) {
|
|
9
|
+
__publicField(this, "id");
|
|
10
|
+
__publicField(this, "name");
|
|
11
|
+
__publicField(this, "players");
|
|
12
|
+
__publicField(this, "maxPlayers");
|
|
13
|
+
__publicField(this, "gameType");
|
|
14
|
+
__publicField(this, "appId");
|
|
15
|
+
__publicField(this, "type");
|
|
16
|
+
__publicField(this, "createdBy");
|
|
17
|
+
__publicField(this, "createdAt");
|
|
18
|
+
__publicField(this, "updatedAt");
|
|
19
|
+
__publicField(this, "isPrivate");
|
|
20
|
+
__publicField(this, "currentPlayers");
|
|
21
|
+
__publicField(this, "status");
|
|
22
|
+
__publicField(this, "customMetadata");
|
|
23
|
+
__publicField(this, "admins");
|
|
24
|
+
__publicField(this, "roomCode");
|
|
25
|
+
__publicField(this, "description");
|
|
26
|
+
__publicField(this, "data");
|
|
27
|
+
__publicField(this, "version");
|
|
28
|
+
__publicField(this, "_subscriptions", /* @__PURE__ */ new Map());
|
|
29
|
+
this.id = roomData.id;
|
|
30
|
+
this.name = roomData.name;
|
|
31
|
+
this.players = roomData.currentPlayers || [];
|
|
32
|
+
this.maxPlayers = roomData.maxPlayers;
|
|
33
|
+
this.gameType = roomData.gameType;
|
|
34
|
+
this.appId = roomData.appId;
|
|
35
|
+
this.type = roomData.type;
|
|
36
|
+
this.createdBy = roomData.createdBy;
|
|
37
|
+
this.createdAt = roomData.createdAt;
|
|
38
|
+
this.updatedAt = roomData.updatedAt;
|
|
39
|
+
this.isPrivate = roomData.isPrivate;
|
|
40
|
+
this.currentPlayers = roomData.currentPlayers || [];
|
|
41
|
+
this.status = roomData.status;
|
|
42
|
+
this.customMetadata = roomData.customMetadata || {};
|
|
43
|
+
this.admins = roomData.admins || [];
|
|
44
|
+
this.roomCode = roomData.roomCode;
|
|
45
|
+
this.description = roomData.description;
|
|
46
|
+
this.data = roomData.data || {};
|
|
47
|
+
this.version = roomData.version;
|
|
48
|
+
console.log(`VenusRoom: Created room object for ${this.id}`, {
|
|
49
|
+
hasCustomMetadata: !!this.customMetadata,
|
|
50
|
+
hasGameState: !!this.customMetadata?.rules?.gameState,
|
|
51
|
+
gamePhase: this.customMetadata?.rules?.gameState?.phase,
|
|
52
|
+
currentPlayer: this.customMetadata?.rules?.gameState?.currentPlayer
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
updateFromRoomData(newRoomData) {
|
|
56
|
+
if (newRoomData.id === this.id) {
|
|
57
|
+
this.name = newRoomData.name || this.name;
|
|
58
|
+
this.players = newRoomData.currentPlayers || this.players;
|
|
59
|
+
this.maxPlayers = newRoomData.maxPlayers || this.maxPlayers;
|
|
60
|
+
this.gameType = newRoomData.gameType || this.gameType;
|
|
61
|
+
this.currentPlayers = newRoomData.currentPlayers || this.currentPlayers;
|
|
62
|
+
this.customMetadata = newRoomData.customMetadata || this.customMetadata;
|
|
63
|
+
this.data = newRoomData.data || this.data;
|
|
64
|
+
this.status = newRoomData.status || this.status;
|
|
65
|
+
this.updatedAt = newRoomData.updatedAt || this.updatedAt;
|
|
66
|
+
console.log(`VenusRoom: Updated room object ${this.id} with fresh data`, {
|
|
67
|
+
hasCustomMetadata: !!this.customMetadata,
|
|
68
|
+
hasGameState: !!this.customMetadata?.rules?.gameState,
|
|
69
|
+
gamePhase: this.customMetadata?.rules?.gameState?.phase,
|
|
70
|
+
currentPlayer: this.customMetadata?.rules?.gameState?.currentPlayer
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
// src/rooms/RoomsApi.ts
|
|
79
|
+
var init_RoomsApi = __esm({
|
|
80
|
+
"src/rooms/RoomsApi.ts"() {
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
// src/rooms/index.ts
|
|
85
|
+
var rooms_exports = {};
|
|
86
|
+
__export(rooms_exports, {
|
|
87
|
+
VenusRoom: () => VenusRoom,
|
|
88
|
+
initializeRoomsApi: () => initializeRoomsApi,
|
|
89
|
+
setupRoomNotifications: () => setupRoomNotifications
|
|
90
|
+
});
|
|
91
|
+
function bindMethod(target, targetKey, source, sourceKey) {
|
|
92
|
+
const key = sourceKey ?? targetKey;
|
|
93
|
+
const fn = source?.[key];
|
|
94
|
+
if (typeof fn === "function") {
|
|
95
|
+
target[targetKey] = fn.bind(source);
|
|
96
|
+
return true;
|
|
97
|
+
}
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
function setupRoomNotifications(transport, getSubscriptions) {
|
|
101
|
+
console.log("[Venus Rooms] Setting up room notification listeners");
|
|
102
|
+
return transport.onVenusMessage((message) => {
|
|
103
|
+
const subscriptions = getSubscriptions();
|
|
104
|
+
if (!subscriptions) {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
if (message.type === "H5_ROOM_DATA_UPDATED") {
|
|
108
|
+
const messageData = message.data;
|
|
109
|
+
const { roomId, roomData } = messageData;
|
|
110
|
+
if (!roomId) return;
|
|
111
|
+
const callbacks = subscriptions.data?.[roomId] || [];
|
|
112
|
+
const allEventsCallbacks = subscriptions.allEvents?.[roomId] || [];
|
|
113
|
+
console.log(`[Venus Rooms] \u{1F514} Room data updated for ${roomId}, notifying ${callbacks.length} callbacks`, roomData);
|
|
114
|
+
callbacks.forEach((callback) => {
|
|
115
|
+
try {
|
|
116
|
+
callback(roomData);
|
|
117
|
+
} catch (error) {
|
|
118
|
+
console.error("[Venus Rooms] Error in room data callback:", error);
|
|
119
|
+
throw error;
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
allEventsCallbacks.forEach((callback) => {
|
|
123
|
+
try {
|
|
124
|
+
callback({ type: message.type, ...messageData });
|
|
125
|
+
} catch (error) {
|
|
126
|
+
console.error("[Venus Rooms] Error in allEvents callback:", error);
|
|
127
|
+
throw error;
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
if (message.type === "H5_ROOM_MESSAGE_RECEIVED" || message.type === "H5_ROOM_MESSAGE_UPDATED" || message.type === "H5_ROOM_MESSAGE_DELETED") {
|
|
132
|
+
const messageData = message.data;
|
|
133
|
+
const { roomId } = messageData;
|
|
134
|
+
if (!roomId) return;
|
|
135
|
+
const callbacks = subscriptions.messages?.[roomId] || [];
|
|
136
|
+
const allEventsCallbacks = subscriptions.allEvents?.[roomId] || [];
|
|
137
|
+
console.log(`[Venus Rooms] \u{1F514} Room message event for ${roomId}, notifying ${callbacks.length} callbacks`);
|
|
138
|
+
callbacks.forEach((callback) => {
|
|
139
|
+
try {
|
|
140
|
+
callback(messageData);
|
|
141
|
+
} catch (error) {
|
|
142
|
+
console.error("[Venus Rooms] Error in room message callback:", error);
|
|
143
|
+
throw error;
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
allEventsCallbacks.forEach((callback) => {
|
|
147
|
+
try {
|
|
148
|
+
callback({ type: message.type, ...messageData });
|
|
149
|
+
} catch (error) {
|
|
150
|
+
console.error("[Venus Rooms] Error in allEvents callback:", error);
|
|
151
|
+
throw error;
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
if (message.type === "app:h5:proposedMoveValidationUpdated") {
|
|
156
|
+
const messageData = message.data;
|
|
157
|
+
const { roomId } = messageData;
|
|
158
|
+
if (!roomId) return;
|
|
159
|
+
const callbacks = subscriptions.gameEvents?.[roomId] || [];
|
|
160
|
+
const allEventsCallbacks = subscriptions.allEvents?.[roomId] || [];
|
|
161
|
+
console.log(`[Venus Rooms] \u{1F514} Proposed move validation updated for ${roomId}, notifying ${callbacks.length} callbacks`);
|
|
162
|
+
callbacks.forEach((callback) => {
|
|
163
|
+
try {
|
|
164
|
+
callback(messageData);
|
|
165
|
+
} catch (error) {
|
|
166
|
+
console.error("[Venus Rooms] Error in game event callback:", error);
|
|
167
|
+
throw error;
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
allEventsCallbacks.forEach((callback) => {
|
|
171
|
+
try {
|
|
172
|
+
callback({ type: message.type, ...messageData });
|
|
173
|
+
} catch (error) {
|
|
174
|
+
console.error("[Venus Rooms] Error in allEvents callback:", error);
|
|
175
|
+
throw error;
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
function initializeRoomsApi(venusApi, host) {
|
|
182
|
+
const roomsApi = host?.rooms;
|
|
183
|
+
if (!roomsApi) {
|
|
184
|
+
console.warn(
|
|
185
|
+
"[Venus SDK] Host did not provide a rooms implementation. Rooms API will be unavailable."
|
|
186
|
+
);
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
const venus = venusApi;
|
|
190
|
+
const existingNamespace = venus.rooms || {};
|
|
191
|
+
const roomsNamespace = Object.assign({}, existingNamespace);
|
|
192
|
+
const namespaceBindings = [
|
|
193
|
+
["create", "createRoom"],
|
|
194
|
+
["joinOrCreate", "joinOrCreateRoom"],
|
|
195
|
+
["joinByCode", "joinRoomByCode"],
|
|
196
|
+
["list", "getUserRooms"],
|
|
197
|
+
["subscribeToRoom", "subscribe"],
|
|
198
|
+
["updateRoomData", "updateData"],
|
|
199
|
+
["getRoomData", "getData"],
|
|
200
|
+
["sendRoomMessage", "sendMessage"],
|
|
201
|
+
["leaveRoom", "leave"],
|
|
202
|
+
["startRoomGame", "startGame"],
|
|
203
|
+
["proposeMove"],
|
|
204
|
+
["validateMove"]
|
|
205
|
+
];
|
|
206
|
+
namespaceBindings.forEach(([targetKey, sourceKey]) => {
|
|
207
|
+
bindMethod(roomsNamespace, targetKey, roomsApi, sourceKey);
|
|
208
|
+
});
|
|
209
|
+
venus.rooms = roomsNamespace;
|
|
210
|
+
}
|
|
211
|
+
var init_rooms = __esm({
|
|
212
|
+
"src/rooms/index.ts"() {
|
|
213
|
+
init_RoomsApi();
|
|
214
|
+
init_VenusRoom();
|
|
215
|
+
}
|
|
216
|
+
});
|
|
2
217
|
|
|
3
218
|
// src/VenusMessageId.ts
|
|
4
219
|
var VenusMessageId = /* @__PURE__ */ ((VenusMessageId2) => {
|
|
@@ -50,7 +265,8 @@ var VenusMessageId = /* @__PURE__ */ ((VenusMessageId2) => {
|
|
|
50
265
|
VenusMessageId2["TOGGLE_LIKE"] = "H5_TOGGLE_LIKE";
|
|
51
266
|
VenusMessageId2["OPEN_COMMENTS"] = "H5_OPEN_COMMENTS";
|
|
52
267
|
VenusMessageId2["TOGGLE_FOLLOW"] = "H5_TOGGLE_FOLLOW";
|
|
53
|
-
VenusMessageId2["
|
|
268
|
+
VenusMessageId2["SHARE_LINK"] = "H5_SHARE_LINK";
|
|
269
|
+
VenusMessageId2["CREATE_SHARE_QRCODE"] = "H5_CREATE_SHARE_QRCODE";
|
|
54
270
|
VenusMessageId2["AI_CHAT_COMPLETION"] = "H5_AI_CHAT_COMPLETION";
|
|
55
271
|
VenusMessageId2["AI_GET_AVAILABLE_MODELS"] = "H5_AI_GET_AVAILABLE_MODELS";
|
|
56
272
|
VenusMessageId2["TRIGGER_HAPTIC"] = "H5_TRIGGER_HAPTIC";
|
|
@@ -62,13 +278,11 @@ var VenusMessageId = /* @__PURE__ */ ((VenusMessageId2) => {
|
|
|
62
278
|
VenusMessageId2["IAP_WALLET_UPDATE"] = "IAP_WALLET_UPDATE";
|
|
63
279
|
VenusMessageId2["READY"] = "READY";
|
|
64
280
|
VenusMessageId2["INIT_SDK"] = "INITIALIZE_SDK";
|
|
65
|
-
VenusMessageId2["PLAY"] = "PLAY";
|
|
66
281
|
VenusMessageId2["PAUSE"] = "PAUSE";
|
|
67
282
|
VenusMessageId2["RESUME"] = "RESUME";
|
|
68
|
-
VenusMessageId2["
|
|
69
|
-
VenusMessageId2["
|
|
283
|
+
VenusMessageId2["AWAKE"] = "AWAKE";
|
|
284
|
+
VenusMessageId2["SLEEP"] = "SLEEP";
|
|
70
285
|
VenusMessageId2["QUIT"] = "QUIT";
|
|
71
|
-
VenusMessageId2["CLEANUP"] = "CLEANUP";
|
|
72
286
|
VenusMessageId2["GET_EXPERIMENT"] = "H5_GET_EXPERIMENT";
|
|
73
287
|
VenusMessageId2["GET_FEATURE_FLAG"] = "H5_GET_FEATURE_FLAG";
|
|
74
288
|
VenusMessageId2["GET_FEATURE_GATE"] = "H5_GET_FEATURE_GATE";
|
|
@@ -92,6 +306,11 @@ var VenusMessageId = /* @__PURE__ */ ((VenusMessageId2) => {
|
|
|
92
306
|
VenusMessageId2["H5_SIMULATION_GET_AVAILABLE_ITEMS"] = "H5_SIMULATION_GET_AVAILABLE_ITEMS";
|
|
93
307
|
VenusMessageId2["H5_SIMULATION_VALIDATE_ASSIGNMENT"] = "H5_SIMULATION_VALIDATE_ASSIGNMENT";
|
|
94
308
|
VenusMessageId2["H5_SIMULATION_BATCH_OPERATIONS"] = "H5_SIMULATION_BATCH_OPERATIONS";
|
|
309
|
+
VenusMessageId2["H5_LEADERBOARD_START_RUN"] = "H5_LEADERBOARD_START_RUN";
|
|
310
|
+
VenusMessageId2["H5_LEADERBOARD_SUBMIT_SCORE"] = "H5_LEADERBOARD_SUBMIT_SCORE";
|
|
311
|
+
VenusMessageId2["H5_LEADERBOARD_GET"] = "H5_LEADERBOARD_GET";
|
|
312
|
+
VenusMessageId2["H5_LEADERBOARD_GET_HIGHLIGHT"] = "H5_LEADERBOARD_GET_HIGHLIGHT";
|
|
313
|
+
VenusMessageId2["H5_LEADERBOARD_GET_PLAYER_STATS"] = "H5_LEADERBOARD_GET_PLAYER_STATS";
|
|
95
314
|
VenusMessageId2["H5_ROOM_CREATE"] = "H5_ROOM_CREATE";
|
|
96
315
|
VenusMessageId2["H5_ROOM_JOIN"] = "H5_ROOM_JOIN";
|
|
97
316
|
VenusMessageId2["H5_ROOM_JOIN_OR_CREATE"] = "H5_ROOM_JOIN_OR_CREATE";
|
|
@@ -115,6 +334,10 @@ var VenusMessageId = /* @__PURE__ */ ((VenusMessageId2) => {
|
|
|
115
334
|
VenusMessageId2["H5_ROOM_ELIMINATE_PLAYER"] = "H5_ROOM_ELIMINATE_PLAYER";
|
|
116
335
|
VenusMessageId2["H5_ROOM_PROMOTE_TO_SPECTATOR"] = "H5_ROOM_PROMOTE_TO_SPECTATOR";
|
|
117
336
|
VenusMessageId2["H5_LOAD_EMBEDDED_ASSET"] = "H5_LOAD_EMBEDDED_ASSET";
|
|
337
|
+
VenusMessageId2["H5_SHOW_LOAD_SCREEN"] = "H5_SHOW_LOAD_SCREEN";
|
|
338
|
+
VenusMessageId2["H5_HIDE_LOAD_SCREEN"] = "H5_HIDE_LOAD_SCREEN";
|
|
339
|
+
VenusMessageId2["H5_SET_LOADER_TEXT"] = "H5_SET_LOADER_TEXT";
|
|
340
|
+
VenusMessageId2["H5_SET_LOADER_PROGRESS"] = "H5_SET_LOADER_PROGRESS";
|
|
118
341
|
VenusMessageId2["H5_IAP_OPEN_STORE"] = "H5_IAP_OPEN_STORE";
|
|
119
342
|
VenusMessageId2["H5_IAP_GET_CURRENCY_ICON"] = "H5_IAP_GET_CURRENCY_ICON";
|
|
120
343
|
return VenusMessageId2;
|
|
@@ -126,23 +349,27 @@ var RpcAdsApi = class {
|
|
|
126
349
|
__publicField(this, "rpcClient");
|
|
127
350
|
this.rpcClient = rpcClient;
|
|
128
351
|
}
|
|
129
|
-
async showInterstitialAd() {
|
|
352
|
+
async showInterstitialAd(options) {
|
|
130
353
|
console.log(`[Venus SDK] [RpcAdsApi] showInterstitialAd`);
|
|
131
354
|
const response = await this.rpcClient.call(
|
|
132
355
|
"H5_SHOW_INTERSTITIAL_AD" /* SHOW_INTERSTITIAL_AD */,
|
|
133
|
-
{},
|
|
356
|
+
options || {},
|
|
134
357
|
-1
|
|
135
358
|
);
|
|
136
359
|
return response.shown;
|
|
137
360
|
}
|
|
138
361
|
async isRewardedAdReadyAsync() {
|
|
139
|
-
|
|
362
|
+
console.log(`[Venus SDK] [RpcAdsApi] isRewardedAdReadyAsync`);
|
|
363
|
+
const response = await this.rpcClient.call(
|
|
364
|
+
"H5_IS_REWARDED_AD_READY" /* IS_REWARDED_AD_READY */
|
|
365
|
+
);
|
|
366
|
+
return response.ready;
|
|
140
367
|
}
|
|
141
|
-
async showRewardedAdAsync() {
|
|
368
|
+
async showRewardedAdAsync(options) {
|
|
142
369
|
console.log("[Venus SDK] [RpcAdsApi] showRewardedAdAsync");
|
|
143
370
|
const result = await this.rpcClient.call(
|
|
144
371
|
"H5_SHOW_REWARDED_AD" /* SHOW_REWARDED_AD */,
|
|
145
|
-
{},
|
|
372
|
+
options || {},
|
|
146
373
|
-1
|
|
147
374
|
);
|
|
148
375
|
const resultAsString = JSON.stringify(result, null, 2);
|
|
@@ -165,14 +392,16 @@ var MockAdsApi = class {
|
|
|
165
392
|
await createMockDelay(MOCK_DELAYS.short);
|
|
166
393
|
return true;
|
|
167
394
|
}
|
|
168
|
-
async showRewardedAdAsync() {
|
|
395
|
+
async showRewardedAdAsync(options) {
|
|
169
396
|
this.log("[MockAdsApi] showRewardedAdAsync called");
|
|
170
|
-
await this.mockOverlay.showAdOverlay();
|
|
397
|
+
await this.mockOverlay.showAdOverlay(options);
|
|
171
398
|
this.log("[MockAdsApi] Rewarded ad completed");
|
|
172
399
|
return true;
|
|
173
400
|
}
|
|
174
|
-
async showInterstitialAd() {
|
|
401
|
+
async showInterstitialAd(options) {
|
|
175
402
|
this.log(`[MockAdsApi] showInterstitialAd`);
|
|
403
|
+
await this.mockOverlay.showAdOverlay(options);
|
|
404
|
+
this.log("[MockAdsApi] interstitial ad shown");
|
|
176
405
|
return true;
|
|
177
406
|
}
|
|
178
407
|
log(message, ...args) {
|
|
@@ -1220,59 +1449,73 @@ function initializeIap(venusApiInstance, host) {
|
|
|
1220
1449
|
// src/lifecycles/MockLifecycleApi.ts
|
|
1221
1450
|
var MockLifecycleApi = class {
|
|
1222
1451
|
constructor() {
|
|
1223
|
-
__publicField(this, "
|
|
1224
|
-
__publicField(this, "
|
|
1225
|
-
__publicField(this, "
|
|
1226
|
-
__publicField(this, "
|
|
1227
|
-
__publicField(this, "
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1452
|
+
__publicField(this, "pauseCallbacks", /* @__PURE__ */ new Set());
|
|
1453
|
+
__publicField(this, "resumeCallbacks", /* @__PURE__ */ new Set());
|
|
1454
|
+
__publicField(this, "awakeCallbacks", /* @__PURE__ */ new Set());
|
|
1455
|
+
__publicField(this, "sleepCallbacks", /* @__PURE__ */ new Set());
|
|
1456
|
+
__publicField(this, "quitCallbacks", /* @__PURE__ */ new Set());
|
|
1457
|
+
}
|
|
1458
|
+
onSleep(callback) {
|
|
1459
|
+
this.sleepCallbacks.add(callback);
|
|
1460
|
+
return {
|
|
1461
|
+
unsubscribe: () => {
|
|
1462
|
+
this.sleepCallbacks.delete(callback);
|
|
1463
|
+
}
|
|
1464
|
+
};
|
|
1234
1465
|
}
|
|
1235
|
-
|
|
1236
|
-
this.
|
|
1466
|
+
onAwake(callback) {
|
|
1467
|
+
this.awakeCallbacks.add(callback);
|
|
1468
|
+
return {
|
|
1469
|
+
unsubscribe: () => {
|
|
1470
|
+
this.awakeCallbacks.delete(callback);
|
|
1471
|
+
}
|
|
1472
|
+
};
|
|
1237
1473
|
}
|
|
1238
1474
|
onPause(callback) {
|
|
1239
|
-
this.pauseCallbacks.
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
this.quitCallbacks.push(callback);
|
|
1475
|
+
this.pauseCallbacks.add(callback);
|
|
1476
|
+
return {
|
|
1477
|
+
unsubscribe: () => {
|
|
1478
|
+
this.pauseCallbacks.delete(callback);
|
|
1479
|
+
}
|
|
1480
|
+
};
|
|
1246
1481
|
}
|
|
1247
1482
|
onResume(callback) {
|
|
1248
|
-
this.resumeCallbacks.
|
|
1483
|
+
this.resumeCallbacks.add(callback);
|
|
1484
|
+
return {
|
|
1485
|
+
unsubscribe: () => {
|
|
1486
|
+
this.resumeCallbacks.delete(callback);
|
|
1487
|
+
}
|
|
1488
|
+
};
|
|
1249
1489
|
}
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1490
|
+
onQuit(callback) {
|
|
1491
|
+
this.quitCallbacks.add(callback);
|
|
1492
|
+
return {
|
|
1493
|
+
unsubscribe: () => {
|
|
1494
|
+
this.quitCallbacks.delete(callback);
|
|
1495
|
+
}
|
|
1496
|
+
};
|
|
1254
1497
|
}
|
|
1255
|
-
|
|
1498
|
+
triggerPauseCallbacks() {
|
|
1256
1499
|
for (const callback of this.pauseCallbacks) {
|
|
1257
1500
|
callback();
|
|
1258
1501
|
}
|
|
1259
1502
|
}
|
|
1260
|
-
|
|
1503
|
+
triggerResumeCallbacks() {
|
|
1261
1504
|
for (const callback of this.resumeCallbacks) {
|
|
1262
1505
|
callback();
|
|
1263
1506
|
}
|
|
1264
1507
|
}
|
|
1265
|
-
|
|
1266
|
-
for (const callback of this.
|
|
1267
|
-
callback(
|
|
1508
|
+
triggerAwakeCallbacks() {
|
|
1509
|
+
for (const callback of this.awakeCallbacks) {
|
|
1510
|
+
callback();
|
|
1268
1511
|
}
|
|
1269
1512
|
}
|
|
1270
|
-
|
|
1271
|
-
for (const callback of this.
|
|
1513
|
+
triggerSleepCallbacks() {
|
|
1514
|
+
for (const callback of this.sleepCallbacks) {
|
|
1272
1515
|
callback();
|
|
1273
1516
|
}
|
|
1274
1517
|
}
|
|
1275
|
-
|
|
1518
|
+
triggerQuitCallbacks() {
|
|
1276
1519
|
for (const callback of this.quitCallbacks) {
|
|
1277
1520
|
callback();
|
|
1278
1521
|
}
|
|
@@ -1285,52 +1528,26 @@ var RpcLifecycleApi = class {
|
|
|
1285
1528
|
__publicField(this, "rpcClient");
|
|
1286
1529
|
this.rpcClient = rpcClient;
|
|
1287
1530
|
}
|
|
1288
|
-
|
|
1289
|
-
this.rpcClient.onNotification("
|
|
1290
|
-
}
|
|
1291
|
-
onHide(callback) {
|
|
1292
|
-
this.rpcClient.onNotification("HIDDEN" /* HIDDEN */, callback);
|
|
1293
|
-
}
|
|
1294
|
-
onPause(callback) {
|
|
1295
|
-
this.rpcClient.onNotification("PAUSE" /* PAUSE */, callback);
|
|
1531
|
+
onQuit(callback) {
|
|
1532
|
+
return this.rpcClient.onNotification("QUIT" /* QUIT */, callback);
|
|
1296
1533
|
}
|
|
1297
|
-
|
|
1298
|
-
this.rpcClient.onNotification("
|
|
1534
|
+
onSleep(callback) {
|
|
1535
|
+
return this.rpcClient.onNotification("SLEEP" /* SLEEP */, callback);
|
|
1299
1536
|
}
|
|
1300
|
-
|
|
1301
|
-
this.rpcClient.onNotification("
|
|
1537
|
+
onAwake(callback) {
|
|
1538
|
+
return this.rpcClient.onNotification("AWAKE" /* AWAKE */, callback);
|
|
1302
1539
|
}
|
|
1303
1540
|
onResume(callback) {
|
|
1304
|
-
this.rpcClient.onNotification("RESUME" /* RESUME */, callback);
|
|
1541
|
+
return this.rpcClient.onNotification("RESUME" /* RESUME */, callback);
|
|
1305
1542
|
}
|
|
1306
|
-
|
|
1307
|
-
this.rpcClient.onNotification("
|
|
1543
|
+
onPause(callback) {
|
|
1544
|
+
return this.rpcClient.onNotification("PAUSE" /* PAUSE */, callback);
|
|
1308
1545
|
}
|
|
1309
1546
|
};
|
|
1310
1547
|
|
|
1311
1548
|
// src/lifecycles/index.ts
|
|
1312
1549
|
function initializeLifecycleApi(venusApi, host) {
|
|
1313
|
-
venusApi.
|
|
1314
|
-
host.lifecycle.onPlay(callback);
|
|
1315
|
-
};
|
|
1316
|
-
venusApi.onPause = (callback) => {
|
|
1317
|
-
host.lifecycle.onPause(callback);
|
|
1318
|
-
};
|
|
1319
|
-
venusApi.onResume = (callback) => {
|
|
1320
|
-
host.lifecycle.onResume(callback);
|
|
1321
|
-
};
|
|
1322
|
-
venusApi.onShow = (callback) => {
|
|
1323
|
-
host.lifecycle.onShow(callback);
|
|
1324
|
-
};
|
|
1325
|
-
venusApi.onHide = (callback) => {
|
|
1326
|
-
host.lifecycle.onHide(callback);
|
|
1327
|
-
};
|
|
1328
|
-
venusApi.onQuit = (callback) => {
|
|
1329
|
-
host.lifecycle.onQuit(callback);
|
|
1330
|
-
};
|
|
1331
|
-
venusApi.onCleanup = (callback) => {
|
|
1332
|
-
host.lifecycle.onCleanup(callback);
|
|
1333
|
-
};
|
|
1550
|
+
venusApi.lifecycles = host.lifecycle;
|
|
1334
1551
|
}
|
|
1335
1552
|
|
|
1336
1553
|
// src/logging/MockLoggingApi.ts
|
|
@@ -1537,7 +1754,7 @@ var MockNotificationsApi = class {
|
|
|
1537
1754
|
__publicField(this, "venusApi");
|
|
1538
1755
|
this.venusApi = venusApi;
|
|
1539
1756
|
}
|
|
1540
|
-
async
|
|
1757
|
+
async cancelNotification(notificationId) {
|
|
1541
1758
|
const venusApi = this.venusApi;
|
|
1542
1759
|
if (isWebPlatform()) {
|
|
1543
1760
|
console.log(
|
|
@@ -1578,7 +1795,8 @@ var MockNotificationsApi = class {
|
|
|
1578
1795
|
const isEnabled = venusApi._mock.notificationsEnabled !== false;
|
|
1579
1796
|
return isEnabled;
|
|
1580
1797
|
}
|
|
1581
|
-
async
|
|
1798
|
+
async scheduleAsync(title, body, seconds, notificationId, options) {
|
|
1799
|
+
const { priority = 50, groupId, payload } = options || {};
|
|
1582
1800
|
if (isWebPlatform()) {
|
|
1583
1801
|
console.log(
|
|
1584
1802
|
"[Venus Mock] Notifications not supported on web platform, simulating success"
|
|
@@ -1593,7 +1811,7 @@ var MockNotificationsApi = class {
|
|
|
1593
1811
|
const mockId = `mock-web-notification-${Date.now()}`;
|
|
1594
1812
|
return mockId;
|
|
1595
1813
|
}
|
|
1596
|
-
console.log("[Venus Mock] Schedule local notification:", options);
|
|
1814
|
+
console.log("[Venus Mock] Schedule local notification:", { title, body, seconds, options });
|
|
1597
1815
|
const venusApi = this.venusApi;
|
|
1598
1816
|
if (!venusApi._mock.pendingRequests) {
|
|
1599
1817
|
console.log("[Venus Mock] Initializing pendingRequests");
|
|
@@ -1603,17 +1821,19 @@ var MockNotificationsApi = class {
|
|
|
1603
1821
|
console.log("[Venus Mock] Creating request with ID:", requestId);
|
|
1604
1822
|
return new Promise((resolve) => {
|
|
1605
1823
|
venusApi._mock.pendingRequests[requestId] = { resolve };
|
|
1606
|
-
const
|
|
1824
|
+
const id = notificationId || `mock-notification-${Date.now()}`;
|
|
1607
1825
|
if (!venusApi._mock.scheduledNotifications) {
|
|
1608
1826
|
venusApi._mock.scheduledNotifications = {};
|
|
1609
1827
|
}
|
|
1610
|
-
venusApi._mock.scheduledNotifications[
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1828
|
+
venusApi._mock.scheduledNotifications[id] = {
|
|
1829
|
+
id,
|
|
1830
|
+
title,
|
|
1831
|
+
body,
|
|
1832
|
+
payload,
|
|
1833
|
+
seconds
|
|
1614
1834
|
};
|
|
1615
1835
|
setTimeout(() => {
|
|
1616
|
-
resolve(
|
|
1836
|
+
resolve(id);
|
|
1617
1837
|
}, MOCK_DELAYS.short);
|
|
1618
1838
|
});
|
|
1619
1839
|
}
|
|
@@ -1633,36 +1853,78 @@ var MockNotificationsApi = class {
|
|
|
1633
1853
|
}
|
|
1634
1854
|
};
|
|
1635
1855
|
|
|
1636
|
-
// src/notifications/
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1856
|
+
// src/notifications/RpcNotificationsApi.ts
|
|
1857
|
+
var RpcNotificationsApi = class {
|
|
1858
|
+
constructor(rpcClient) {
|
|
1859
|
+
__publicField(this, "rpcClient");
|
|
1860
|
+
this.rpcClient = rpcClient;
|
|
1861
|
+
}
|
|
1862
|
+
async scheduleAsync(title, body, seconds, notificationId, options) {
|
|
1863
|
+
const { priority = 50, groupId, payload } = options || {};
|
|
1864
|
+
const request = {
|
|
1865
|
+
title,
|
|
1866
|
+
body,
|
|
1867
|
+
priority,
|
|
1868
|
+
key: groupId,
|
|
1869
|
+
data: payload,
|
|
1870
|
+
seconds,
|
|
1871
|
+
notificationId
|
|
1872
|
+
};
|
|
1873
|
+
const response = await this.rpcClient.call(
|
|
1874
|
+
"H5_SCHEDULE_LOCAL_NOTIFICATION" /* SCHEDULE_LOCAL_NOTIFICATION */,
|
|
1875
|
+
request
|
|
1876
|
+
);
|
|
1877
|
+
if (response.scheduled) {
|
|
1878
|
+
return response.id;
|
|
1879
|
+
}
|
|
1880
|
+
return null;
|
|
1881
|
+
}
|
|
1882
|
+
async cancelNotification(id) {
|
|
1883
|
+
const result = await this.rpcClient.call(
|
|
1884
|
+
"H5_CANCEL_LOCAL_NOTIFICATION" /* CANCEL_LOCAL_NOTIFICATION */,
|
|
1654
1885
|
{
|
|
1655
|
-
|
|
1656
|
-
priority: options.priority,
|
|
1657
|
-
groupId: options.groupId,
|
|
1658
|
-
payload: options.payload
|
|
1886
|
+
id
|
|
1659
1887
|
}
|
|
1660
1888
|
);
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1889
|
+
return result.canceled;
|
|
1890
|
+
}
|
|
1891
|
+
async getAllScheduledLocalNotifications() {
|
|
1892
|
+
const response = await this.rpcClient.call(
|
|
1893
|
+
"H5_GET_ALL_SCHEDULED_LOCAL_NOTIFICATIONS" /* GET_ALL_SCHEDULED_LOCAL_NOTIFICATIONS */,
|
|
1894
|
+
{}
|
|
1895
|
+
);
|
|
1896
|
+
const notifications = response.notifications.map((notif) => {
|
|
1897
|
+
return {
|
|
1898
|
+
id: notif.identifier,
|
|
1899
|
+
title: notif.content.title,
|
|
1900
|
+
body: notif.content.body,
|
|
1901
|
+
payload: notif.content.data,
|
|
1902
|
+
trigger: notif.trigger
|
|
1903
|
+
};
|
|
1904
|
+
});
|
|
1905
|
+
return notifications;
|
|
1906
|
+
}
|
|
1907
|
+
async isLocalNotificationsEnabled() {
|
|
1908
|
+
const response = await this.rpcClient.call(
|
|
1909
|
+
"H5_IS_LOCAL_NOTIFICATIONS_ENABLED" /* IS_LOCAL_NOTIFICATIONS_ENABLED */,
|
|
1910
|
+
{}
|
|
1911
|
+
);
|
|
1912
|
+
return response.enabled;
|
|
1913
|
+
}
|
|
1914
|
+
async setLocalNotificationsEnabled(enabled) {
|
|
1915
|
+
const response = await this.rpcClient.call(
|
|
1916
|
+
"H5_SET_LOCAL_NOTIFICATIONS_ENABLED" /* SET_LOCAL_NOTIFICATIONS_ENABLED */,
|
|
1917
|
+
{
|
|
1918
|
+
enabled
|
|
1919
|
+
}
|
|
1920
|
+
);
|
|
1921
|
+
return response.enabled;
|
|
1922
|
+
}
|
|
1923
|
+
};
|
|
1924
|
+
|
|
1925
|
+
// src/notifications/index.ts
|
|
1926
|
+
function initializeLocalNotifications(venusApi, host) {
|
|
1927
|
+
venusApi.notifications = host.notifications;
|
|
1666
1928
|
}
|
|
1667
1929
|
|
|
1668
1930
|
// src/popups/RpcPopupsApi.ts
|
|
@@ -1810,17 +2072,22 @@ function initializePopups(venusApi, host) {
|
|
|
1810
2072
|
// src/profile/HostProfileApi.ts
|
|
1811
2073
|
var HostProfileApi = class {
|
|
1812
2074
|
getCurrentProfile() {
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
2075
|
+
const profile = window.venus?.profile;
|
|
2076
|
+
if (!profile) {
|
|
2077
|
+
throw new Error(
|
|
2078
|
+
"[Venus SDK] Host profile handshake did not complete. Await VenusAPI.initializeAsync() so INIT_SDK can deliver the profile before calling profile APIs."
|
|
2079
|
+
);
|
|
2080
|
+
}
|
|
2081
|
+
if (!profile.id || !profile.username) {
|
|
2082
|
+
throw new Error(
|
|
2083
|
+
"[Venus SDK] INIT_SDK returned an incomplete profile (missing id/username). The host must supply real credentials before rooms APIs are used."
|
|
2084
|
+
);
|
|
1819
2085
|
}
|
|
1820
2086
|
return {
|
|
1821
|
-
id:
|
|
1822
|
-
|
|
1823
|
-
|
|
2087
|
+
id: profile.id,
|
|
2088
|
+
username: profile.username,
|
|
2089
|
+
avatarUrl: profile.avatarUrl,
|
|
2090
|
+
isAnonymous: profile.isAnonymous
|
|
1824
2091
|
};
|
|
1825
2092
|
}
|
|
1826
2093
|
};
|
|
@@ -1831,7 +2098,8 @@ var MockProfileApi = class {
|
|
|
1831
2098
|
return {
|
|
1832
2099
|
id: "mock_profile_123",
|
|
1833
2100
|
name: "Mock User",
|
|
1834
|
-
username: "mockuser"
|
|
2101
|
+
username: "mockuser",
|
|
2102
|
+
isAnonymous: false
|
|
1835
2103
|
};
|
|
1836
2104
|
}
|
|
1837
2105
|
};
|
|
@@ -3276,7 +3544,7 @@ function initializeTime(venusApi, host) {
|
|
|
3276
3544
|
}
|
|
3277
3545
|
|
|
3278
3546
|
// src/version.ts
|
|
3279
|
-
var SDK_VERSION = "
|
|
3547
|
+
var SDK_VERSION = "3.0.0";
|
|
3280
3548
|
|
|
3281
3549
|
// src/shared-assets/consts.ts
|
|
3282
3550
|
var BurgerTimeAssetsCdnPath = "burger-time/Core.stow";
|
|
@@ -3347,6 +3615,1671 @@ var MockSharedAssetsApi = class {
|
|
|
3347
3615
|
}
|
|
3348
3616
|
};
|
|
3349
3617
|
|
|
3350
|
-
|
|
3351
|
-
|
|
3352
|
-
|
|
3618
|
+
// src/leaderboard/RpcLeaderboardApi.ts
|
|
3619
|
+
var RpcLeaderboardApi = class {
|
|
3620
|
+
constructor(rpcClient) {
|
|
3621
|
+
__publicField(this, "rpcClient");
|
|
3622
|
+
this.rpcClient = rpcClient;
|
|
3623
|
+
}
|
|
3624
|
+
startRun(mode) {
|
|
3625
|
+
return this.rpcClient.call(
|
|
3626
|
+
"H5_LEADERBOARD_START_RUN" /* H5_LEADERBOARD_START_RUN */,
|
|
3627
|
+
mode ? { mode } : {}
|
|
3628
|
+
);
|
|
3629
|
+
}
|
|
3630
|
+
submitScore(sessionId, score, durationSec, options) {
|
|
3631
|
+
return this.rpcClient.call(
|
|
3632
|
+
"H5_LEADERBOARD_SUBMIT_SCORE" /* H5_LEADERBOARD_SUBMIT_SCORE */,
|
|
3633
|
+
{
|
|
3634
|
+
sessionId,
|
|
3635
|
+
score,
|
|
3636
|
+
durationSec,
|
|
3637
|
+
mode: options?.mode,
|
|
3638
|
+
telemetry: options?.telemetry,
|
|
3639
|
+
metadata: options?.metadata,
|
|
3640
|
+
hash: options?.hash
|
|
3641
|
+
}
|
|
3642
|
+
);
|
|
3643
|
+
}
|
|
3644
|
+
getLeaderboard(options) {
|
|
3645
|
+
return this.rpcClient.call(
|
|
3646
|
+
"H5_LEADERBOARD_GET" /* H5_LEADERBOARD_GET */,
|
|
3647
|
+
options ?? {}
|
|
3648
|
+
);
|
|
3649
|
+
}
|
|
3650
|
+
getPlayerStats(options) {
|
|
3651
|
+
return this.rpcClient.call(
|
|
3652
|
+
"H5_LEADERBOARD_GET_PLAYER_STATS" /* H5_LEADERBOARD_GET_PLAYER_STATS */,
|
|
3653
|
+
options ?? {}
|
|
3654
|
+
);
|
|
3655
|
+
}
|
|
3656
|
+
getLeaderboardHighlight(options) {
|
|
3657
|
+
return this.rpcClient.call(
|
|
3658
|
+
"H5_LEADERBOARD_GET_HIGHLIGHT" /* H5_LEADERBOARD_GET_HIGHLIGHT */,
|
|
3659
|
+
options ?? {}
|
|
3660
|
+
);
|
|
3661
|
+
}
|
|
3662
|
+
};
|
|
3663
|
+
|
|
3664
|
+
// src/leaderboard/MockLeaderboardApi.ts
|
|
3665
|
+
var MockLeaderboardApi = class {
|
|
3666
|
+
constructor(options) {
|
|
3667
|
+
__publicField(this, "sessions", /* @__PURE__ */ new Map());
|
|
3668
|
+
__publicField(this, "entriesByMode", /* @__PURE__ */ new Map());
|
|
3669
|
+
__publicField(this, "sessionCounter", 0);
|
|
3670
|
+
__publicField(this, "requiresHash", false);
|
|
3671
|
+
if (options?.requiresHash) {
|
|
3672
|
+
this.requiresHash = true;
|
|
3673
|
+
}
|
|
3674
|
+
}
|
|
3675
|
+
configure(options) {
|
|
3676
|
+
if (typeof options.requiresHash === "boolean") {
|
|
3677
|
+
this.requiresHash = options.requiresHash;
|
|
3678
|
+
}
|
|
3679
|
+
}
|
|
3680
|
+
generateNonce() {
|
|
3681
|
+
return (Math.random().toString(36).slice(2) + Math.random().toString(36).slice(2)).slice(0, 64);
|
|
3682
|
+
}
|
|
3683
|
+
getModeKey(mode) {
|
|
3684
|
+
const normalizedMode = mode || "default";
|
|
3685
|
+
return `${normalizedMode}`;
|
|
3686
|
+
}
|
|
3687
|
+
getEntriesForMode(mode) {
|
|
3688
|
+
const key = this.getModeKey(mode);
|
|
3689
|
+
if (!this.entriesByMode.has(key)) {
|
|
3690
|
+
this.entriesByMode.set(key, []);
|
|
3691
|
+
}
|
|
3692
|
+
return this.entriesByMode.get(key);
|
|
3693
|
+
}
|
|
3694
|
+
async startRun(mode) {
|
|
3695
|
+
const sessionId = `mock_session_${++this.sessionCounter}`;
|
|
3696
|
+
const startTime = Date.now();
|
|
3697
|
+
const expiresAt = startTime + 36e5;
|
|
3698
|
+
const resolvedMode = mode || "default";
|
|
3699
|
+
const hashNonce = this.requiresHash ? this.generateNonce() : null;
|
|
3700
|
+
this.sessions.set(sessionId, {
|
|
3701
|
+
id: sessionId,
|
|
3702
|
+
expiresAt,
|
|
3703
|
+
mode: resolvedMode,
|
|
3704
|
+
hashNonce,
|
|
3705
|
+
used: false
|
|
3706
|
+
});
|
|
3707
|
+
return {
|
|
3708
|
+
sessionId,
|
|
3709
|
+
startTime,
|
|
3710
|
+
expiresAt,
|
|
3711
|
+
hashNonce,
|
|
3712
|
+
mode: resolvedMode
|
|
3713
|
+
};
|
|
3714
|
+
}
|
|
3715
|
+
async submitScore(sessionId, score, durationSec, options) {
|
|
3716
|
+
const session = this.sessions.get(sessionId);
|
|
3717
|
+
if (!session) {
|
|
3718
|
+
throw new Error("Invalid leaderboard session");
|
|
3719
|
+
}
|
|
3720
|
+
if (session.expiresAt < Date.now()) {
|
|
3721
|
+
throw new Error("Invalid or expired leaderboard session");
|
|
3722
|
+
}
|
|
3723
|
+
if (session.used) {
|
|
3724
|
+
throw new Error("Leaderboard session already used");
|
|
3725
|
+
}
|
|
3726
|
+
if (options?.mode && options.mode !== session.mode) {
|
|
3727
|
+
throw new Error("Submission mode does not match session mode");
|
|
3728
|
+
}
|
|
3729
|
+
if (session.hashNonce && !options?.hash) {
|
|
3730
|
+
throw new Error("Score hash is required for sealed leaderboard submissions");
|
|
3731
|
+
}
|
|
3732
|
+
const submittedAt = Date.now();
|
|
3733
|
+
const entry = {
|
|
3734
|
+
profileId: `mock_profile`,
|
|
3735
|
+
username: "Mock Player",
|
|
3736
|
+
avatarUrl: null,
|
|
3737
|
+
score,
|
|
3738
|
+
durationSec,
|
|
3739
|
+
submittedAt,
|
|
3740
|
+
sessionId,
|
|
3741
|
+
rank: null,
|
|
3742
|
+
zScore: null,
|
|
3743
|
+
isAnomaly: false,
|
|
3744
|
+
trustScore: 50,
|
|
3745
|
+
metadata: options?.metadata ?? null,
|
|
3746
|
+
isSeed: false
|
|
3747
|
+
};
|
|
3748
|
+
const modeEntries = this.getEntriesForMode(session.mode);
|
|
3749
|
+
modeEntries.push(entry);
|
|
3750
|
+
modeEntries.sort((a, b) => {
|
|
3751
|
+
if (b.score !== a.score) {
|
|
3752
|
+
return b.score - a.score;
|
|
3753
|
+
}
|
|
3754
|
+
return a.submittedAt - b.submittedAt;
|
|
3755
|
+
});
|
|
3756
|
+
modeEntries.forEach((e, index) => {
|
|
3757
|
+
modeEntries[index] = {
|
|
3758
|
+
...e,
|
|
3759
|
+
rank: index + 1
|
|
3760
|
+
};
|
|
3761
|
+
});
|
|
3762
|
+
session.used = true;
|
|
3763
|
+
session.hashNonce = null;
|
|
3764
|
+
const inserted = modeEntries.find((e) => e.sessionId === sessionId && e.submittedAt === submittedAt);
|
|
3765
|
+
return {
|
|
3766
|
+
accepted: true,
|
|
3767
|
+
rank: inserted?.rank ?? null
|
|
3768
|
+
};
|
|
3769
|
+
}
|
|
3770
|
+
async getLeaderboard(options) {
|
|
3771
|
+
const limit = options?.limit ?? 10;
|
|
3772
|
+
const mode = options?.mode ?? "default";
|
|
3773
|
+
const modeEntries = [...this.getEntriesForMode(mode)];
|
|
3774
|
+
const entries = modeEntries.slice(0, limit).map((entry) => ({
|
|
3775
|
+
...entry
|
|
3776
|
+
}));
|
|
3777
|
+
return {
|
|
3778
|
+
variant: "standard",
|
|
3779
|
+
entries,
|
|
3780
|
+
totalEntries: modeEntries.length,
|
|
3781
|
+
nextCursor: null,
|
|
3782
|
+
playerRank: null,
|
|
3783
|
+
periodInstance: options?.period ?? "alltime"
|
|
3784
|
+
};
|
|
3785
|
+
}
|
|
3786
|
+
async getPlayerStats(_options) {
|
|
3787
|
+
const mode = _options?.mode ?? "default";
|
|
3788
|
+
const modeEntries = this.getEntriesForMode(mode);
|
|
3789
|
+
const playerEntry = modeEntries[0] ?? null;
|
|
3790
|
+
return {
|
|
3791
|
+
rank: playerEntry?.rank ?? null,
|
|
3792
|
+
score: playerEntry?.score,
|
|
3793
|
+
totalPlayers: modeEntries.length,
|
|
3794
|
+
percentile: playerEntry ? Math.max(0, 1 - ((playerEntry.rank ?? 1) - 1) / Math.max(modeEntries.length, 1)) : void 0,
|
|
3795
|
+
trustScore: 50,
|
|
3796
|
+
periodInstance: _options?.period ?? "alltime"
|
|
3797
|
+
};
|
|
3798
|
+
}
|
|
3799
|
+
async getLeaderboardHighlight(options) {
|
|
3800
|
+
const mode = options?.mode ?? "default";
|
|
3801
|
+
const modeEntries = [...this.getEntriesForMode(mode)];
|
|
3802
|
+
const topCount = Math.max(1, Math.min(options?.topCount ?? 3, 10));
|
|
3803
|
+
const aheadCount = Math.max(0, Math.min(options?.contextAhead ?? 4, 10));
|
|
3804
|
+
const behindCount = Math.max(0, Math.min(options?.contextBehind ?? 2, 10));
|
|
3805
|
+
const topEntries = modeEntries.slice(0, topCount);
|
|
3806
|
+
const playerEntry = modeEntries[0] ?? null;
|
|
3807
|
+
const totalEntries = modeEntries.length;
|
|
3808
|
+
let playerRank = playerEntry?.rank ?? null;
|
|
3809
|
+
let beforePlayer = [];
|
|
3810
|
+
let afterPlayer = [];
|
|
3811
|
+
let totalBefore = playerRank ? playerRank - 1 : 0;
|
|
3812
|
+
let totalAfter = playerRank ? Math.max(totalEntries - playerRank, 0) : 0;
|
|
3813
|
+
let omittedBefore = totalBefore;
|
|
3814
|
+
let omittedAfter = totalAfter;
|
|
3815
|
+
if (playerRank && playerRank > 0) {
|
|
3816
|
+
const beforeStart = Math.max(playerRank - aheadCount - 1, 0);
|
|
3817
|
+
beforePlayer = modeEntries.slice(beforeStart, playerRank - 1);
|
|
3818
|
+
const afterEnd = Math.min(playerRank + behindCount, totalEntries);
|
|
3819
|
+
afterPlayer = modeEntries.slice(playerRank, afterEnd);
|
|
3820
|
+
const shownTopAhead = topEntries.filter((entry) => (entry.rank ?? 0) > 0 && (entry.rank ?? 0) < playerRank).length;
|
|
3821
|
+
omittedBefore = Math.max(totalBefore - (beforePlayer.length + shownTopAhead), 0);
|
|
3822
|
+
omittedAfter = Math.max(totalAfter - afterPlayer.length, 0);
|
|
3823
|
+
}
|
|
3824
|
+
return {
|
|
3825
|
+
variant: "highlight",
|
|
3826
|
+
entries: topEntries,
|
|
3827
|
+
totalEntries,
|
|
3828
|
+
nextCursor: null,
|
|
3829
|
+
playerRank: playerRank ?? null,
|
|
3830
|
+
periodInstance: options?.period ?? "alltime",
|
|
3831
|
+
context: {
|
|
3832
|
+
topEntries,
|
|
3833
|
+
beforePlayer,
|
|
3834
|
+
playerEntry: playerEntry ?? null,
|
|
3835
|
+
afterPlayer,
|
|
3836
|
+
totalBefore,
|
|
3837
|
+
totalAfter,
|
|
3838
|
+
omittedBefore,
|
|
3839
|
+
omittedAfter
|
|
3840
|
+
}
|
|
3841
|
+
};
|
|
3842
|
+
}
|
|
3843
|
+
};
|
|
3844
|
+
|
|
3845
|
+
// src/leaderboard/index.ts
|
|
3846
|
+
function initializeLeaderboard(venusApiInstance, host) {
|
|
3847
|
+
venusApiInstance.leaderboard = host.leaderboard;
|
|
3848
|
+
}
|
|
3849
|
+
|
|
3850
|
+
// src/game-preloader/MockPreloaderApi.ts
|
|
3851
|
+
var MockPreloaderApi = class {
|
|
3852
|
+
async showLoadScreen() {
|
|
3853
|
+
console.log("showLoadScreen");
|
|
3854
|
+
}
|
|
3855
|
+
async hideLoadScreen() {
|
|
3856
|
+
console.log("hideLoadScreen");
|
|
3857
|
+
}
|
|
3858
|
+
async setLoaderText(text) {
|
|
3859
|
+
console.log("setLoaderText", text);
|
|
3860
|
+
}
|
|
3861
|
+
async setLoaderProgress(progress) {
|
|
3862
|
+
console.log("setLoaderProgress", progress);
|
|
3863
|
+
}
|
|
3864
|
+
};
|
|
3865
|
+
|
|
3866
|
+
// src/game-preloader/RpcPreloaderApi.ts
|
|
3867
|
+
var RpcPreloaderApi = class {
|
|
3868
|
+
constructor(rpcClient) {
|
|
3869
|
+
__publicField(this, "rpcClient");
|
|
3870
|
+
this.rpcClient = rpcClient;
|
|
3871
|
+
}
|
|
3872
|
+
async showLoadScreen() {
|
|
3873
|
+
await this.rpcClient.call("H5_SHOW_LOAD_SCREEN" /* H5_SHOW_LOAD_SCREEN */);
|
|
3874
|
+
}
|
|
3875
|
+
async hideLoadScreen() {
|
|
3876
|
+
await this.rpcClient.call("H5_HIDE_LOAD_SCREEN" /* H5_HIDE_LOAD_SCREEN */);
|
|
3877
|
+
}
|
|
3878
|
+
async setLoaderText(text) {
|
|
3879
|
+
await this.rpcClient.call("H5_SET_LOADER_TEXT" /* H5_SET_LOADER_TEXT */, { text });
|
|
3880
|
+
}
|
|
3881
|
+
async setLoaderProgress(progress) {
|
|
3882
|
+
await this.rpcClient.call("H5_SET_LOADER_PROGRESS" /* H5_SET_LOADER_PROGRESS */, { progress });
|
|
3883
|
+
}
|
|
3884
|
+
};
|
|
3885
|
+
|
|
3886
|
+
// src/game-preloader/index.ts
|
|
3887
|
+
function initializePreloader(venusApi, host) {
|
|
3888
|
+
venusApi.preloader = host.preloader;
|
|
3889
|
+
}
|
|
3890
|
+
|
|
3891
|
+
// src/post/MockPostApi.ts
|
|
3892
|
+
var MockPostApi = class {
|
|
3893
|
+
constructor(venusApi) {
|
|
3894
|
+
__publicField(this, "venusApi");
|
|
3895
|
+
this.venusApi = venusApi;
|
|
3896
|
+
}
|
|
3897
|
+
async getPostInfo() {
|
|
3898
|
+
const venusApi = this.venusApi;
|
|
3899
|
+
await createMockDelay(MOCK_DELAYS.short);
|
|
3900
|
+
return venusApi._mock.currentPostInteractions;
|
|
3901
|
+
}
|
|
3902
|
+
async openCommentsAsync() {
|
|
3903
|
+
await createMockDelay(MOCK_DELAYS.short);
|
|
3904
|
+
return {
|
|
3905
|
+
opened: true,
|
|
3906
|
+
commentsCount: 0
|
|
3907
|
+
};
|
|
3908
|
+
}
|
|
3909
|
+
async toggleFollowAsync() {
|
|
3910
|
+
const venusApi = this.venusApi;
|
|
3911
|
+
console.log("[Venus Mock] *Toggling follow status");
|
|
3912
|
+
await createMockDelay(MOCK_DELAYS.short);
|
|
3913
|
+
venusApi._mock.currentPostInteractions.isFollowing = !venusApi._mock.currentPostInteractions.isFollowing;
|
|
3914
|
+
const isFollowing = venusApi._mock.currentPostInteractions.isFollowing;
|
|
3915
|
+
return {
|
|
3916
|
+
isFollowing,
|
|
3917
|
+
action: isFollowing ? "followed" : "unfollowed"
|
|
3918
|
+
};
|
|
3919
|
+
}
|
|
3920
|
+
async toggleLikeAsync() {
|
|
3921
|
+
const venusApi = this.venusApi;
|
|
3922
|
+
await createMockDelay(MOCK_DELAYS.short);
|
|
3923
|
+
venusApi._mock.currentPostInteractions.isLiked = !venusApi._mock.currentPostInteractions.isLiked;
|
|
3924
|
+
const isLiked = venusApi._mock.currentPostInteractions.isLiked;
|
|
3925
|
+
if (isLiked) {
|
|
3926
|
+
venusApi._mock.currentPostInteractions.likesCount++;
|
|
3927
|
+
} else {
|
|
3928
|
+
venusApi._mock.currentPostInteractions.likesCount = Math.max(
|
|
3929
|
+
0,
|
|
3930
|
+
venusApi._mock.currentPostInteractions.likesCount - 1
|
|
3931
|
+
);
|
|
3932
|
+
}
|
|
3933
|
+
return {
|
|
3934
|
+
isLiked,
|
|
3935
|
+
likesCount: venusApi._mock.currentPostInteractions.likesCount,
|
|
3936
|
+
action: isLiked ? "liked" : "unliked"
|
|
3937
|
+
};
|
|
3938
|
+
}
|
|
3939
|
+
};
|
|
3940
|
+
|
|
3941
|
+
// src/post/RpcPostApi.ts
|
|
3942
|
+
var RpcPostApi = class {
|
|
3943
|
+
constructor(rpcClient) {
|
|
3944
|
+
__publicField(this, "rpcClient");
|
|
3945
|
+
this.rpcClient = rpcClient;
|
|
3946
|
+
}
|
|
3947
|
+
getPostInfo() {
|
|
3948
|
+
return this.rpcClient.call("H5_GET_POST_INTERACTIONS" /* GET_POST_INTERACTIONS */, {});
|
|
3949
|
+
}
|
|
3950
|
+
openCommentsAsync() {
|
|
3951
|
+
return this.rpcClient.call("H5_OPEN_COMMENTS" /* OPEN_COMMENTS */, {});
|
|
3952
|
+
}
|
|
3953
|
+
toggleFollowAsync() {
|
|
3954
|
+
return this.rpcClient.call(
|
|
3955
|
+
"H5_TOGGLE_FOLLOW" /* TOGGLE_FOLLOW */,
|
|
3956
|
+
{}
|
|
3957
|
+
);
|
|
3958
|
+
}
|
|
3959
|
+
toggleLikeAsync() {
|
|
3960
|
+
return this.rpcClient.call("H5_TOGGLE_LIKE" /* TOGGLE_LIKE */, {});
|
|
3961
|
+
}
|
|
3962
|
+
};
|
|
3963
|
+
|
|
3964
|
+
// src/post/index.ts
|
|
3965
|
+
function initializePost(venusApi, host) {
|
|
3966
|
+
venusApi.getPostInteractionsAsync = () => {
|
|
3967
|
+
return host.post.getPostInfo();
|
|
3968
|
+
};
|
|
3969
|
+
venusApi.toggleFollowAsync = () => {
|
|
3970
|
+
return host.post.toggleFollowAsync();
|
|
3971
|
+
};
|
|
3972
|
+
venusApi.toggleLikeAsync = () => {
|
|
3973
|
+
return host.post.toggleLikeAsync();
|
|
3974
|
+
};
|
|
3975
|
+
venusApi.openCommentsAsync = async () => {
|
|
3976
|
+
await host.post.openCommentsAsync();
|
|
3977
|
+
};
|
|
3978
|
+
}
|
|
3979
|
+
|
|
3980
|
+
// src/social/MockSocialApi.ts
|
|
3981
|
+
var MOCK_QR_CODE = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==";
|
|
3982
|
+
var MockSocialApi = class {
|
|
3983
|
+
async shareLinkAsync(options) {
|
|
3984
|
+
const shareUrl = this.createMockUrl(options.launchParams);
|
|
3985
|
+
if (typeof navigator !== "undefined" && navigator.clipboard) {
|
|
3986
|
+
try {
|
|
3987
|
+
await navigator.clipboard.writeText(shareUrl);
|
|
3988
|
+
console.log("[Venus SDK] (mock) Copied share URL to clipboard");
|
|
3989
|
+
} catch (error) {
|
|
3990
|
+
console.warn(
|
|
3991
|
+
"[Venus SDK] (mock) Failed to copy share URL to clipboard",
|
|
3992
|
+
error
|
|
3993
|
+
);
|
|
3994
|
+
}
|
|
3995
|
+
}
|
|
3996
|
+
return { shareUrl };
|
|
3997
|
+
}
|
|
3998
|
+
async createQRCodeAsync(options) {
|
|
3999
|
+
const shareUrl = this.createMockUrl(options.launchParams);
|
|
4000
|
+
return {
|
|
4001
|
+
shareUrl,
|
|
4002
|
+
qrCode: MOCK_QR_CODE
|
|
4003
|
+
};
|
|
4004
|
+
}
|
|
4005
|
+
createMockUrl(launchParams) {
|
|
4006
|
+
const params = new URLSearchParams(launchParams);
|
|
4007
|
+
return `https://mock-share.venus.test/share?${params.toString()}`;
|
|
4008
|
+
}
|
|
4009
|
+
};
|
|
4010
|
+
|
|
4011
|
+
// src/social/RpcSocialApi.ts
|
|
4012
|
+
var RpcSocialApi = class {
|
|
4013
|
+
constructor(rpcClient) {
|
|
4014
|
+
this.rpcClient = rpcClient;
|
|
4015
|
+
}
|
|
4016
|
+
async shareLinkAsync(options) {
|
|
4017
|
+
const result = await this.rpcClient.call("H5_SHARE_LINK" /* SHARE_LINK */, {
|
|
4018
|
+
launchParams: options.launchParams,
|
|
4019
|
+
metadata: options.metadata ?? {}
|
|
4020
|
+
});
|
|
4021
|
+
return {
|
|
4022
|
+
shareUrl: result.shareUrl
|
|
4023
|
+
};
|
|
4024
|
+
}
|
|
4025
|
+
async createQRCodeAsync(options) {
|
|
4026
|
+
const result = await this.rpcClient.call(
|
|
4027
|
+
"H5_CREATE_SHARE_QRCODE" /* CREATE_SHARE_QRCODE */,
|
|
4028
|
+
{
|
|
4029
|
+
launchParams: options.launchParams,
|
|
4030
|
+
metadata: options.metadata ?? {},
|
|
4031
|
+
qrOptions: options.qrOptions ?? {}
|
|
4032
|
+
}
|
|
4033
|
+
);
|
|
4034
|
+
return {
|
|
4035
|
+
shareUrl: result.shareUrl,
|
|
4036
|
+
qrCode: result.qrCode
|
|
4037
|
+
};
|
|
4038
|
+
}
|
|
4039
|
+
};
|
|
4040
|
+
|
|
4041
|
+
// src/VenusTransport.ts
|
|
4042
|
+
var VenusTransport = class {
|
|
4043
|
+
constructor() {
|
|
4044
|
+
__publicField(this, "messageHandler");
|
|
4045
|
+
__publicField(this, "onNotificationCallbacks", []);
|
|
4046
|
+
__publicField(this, "onNotificationCallbacksToRemove", []);
|
|
4047
|
+
__publicField(this, "onVenusMessageCallbacks", []);
|
|
4048
|
+
__publicField(this, "onResponseCallbacks", []);
|
|
4049
|
+
__publicField(this, "onResponseCallbacksToRemove", []);
|
|
4050
|
+
__publicField(this, "_instanceId", null);
|
|
4051
|
+
__publicField(this, "isStarted", false);
|
|
4052
|
+
__publicField(this, "isProcessingMessage", false);
|
|
4053
|
+
this.messageHandler = async (event) => {
|
|
4054
|
+
this.isProcessingMessage = true;
|
|
4055
|
+
let message;
|
|
4056
|
+
if (typeof event.data === "string") {
|
|
4057
|
+
message = JSON.parse(event.data);
|
|
4058
|
+
} else {
|
|
4059
|
+
message = event.data;
|
|
4060
|
+
}
|
|
4061
|
+
if (!message) {
|
|
4062
|
+
this.logInfo("No message found. Ignoring message...");
|
|
4063
|
+
return;
|
|
4064
|
+
}
|
|
4065
|
+
this.notifyVenusMessageReceived(message);
|
|
4066
|
+
if (message.type === "PAUSE" /* PAUSE */ || message.type === "RESUME" /* RESUME */ || message.type === "AWAKE" /* AWAKE */ || message.type === "SLEEP" /* SLEEP */ || message.type === "QUIT" /* QUIT */) {
|
|
4067
|
+
const notification = {
|
|
4068
|
+
type: "rpc-notification",
|
|
4069
|
+
id: message.type,
|
|
4070
|
+
payload: message.data
|
|
4071
|
+
};
|
|
4072
|
+
this.handleNotification(notification);
|
|
4073
|
+
this.isProcessingMessage = false;
|
|
4074
|
+
return;
|
|
4075
|
+
}
|
|
4076
|
+
const messageData = message.data;
|
|
4077
|
+
if (!messageData) {
|
|
4078
|
+
this.logWarn("No data found. Ignoring message...");
|
|
4079
|
+
this.isProcessingMessage = false;
|
|
4080
|
+
return;
|
|
4081
|
+
}
|
|
4082
|
+
const requestId = messageData.requestId;
|
|
4083
|
+
if (!requestId) {
|
|
4084
|
+
this.logWarn("No requestId. Ignoring message...");
|
|
4085
|
+
this.isProcessingMessage = false;
|
|
4086
|
+
return;
|
|
4087
|
+
}
|
|
4088
|
+
if (message.type !== "H5_RESPONSE" /* H5_RESPONSE */) {
|
|
4089
|
+
this.logWarn(`Ignoring unknown message type: ${message.type}`);
|
|
4090
|
+
this.isProcessingMessage = false;
|
|
4091
|
+
return;
|
|
4092
|
+
}
|
|
4093
|
+
const success = messageData.success;
|
|
4094
|
+
let error = void 0;
|
|
4095
|
+
if (!success) {
|
|
4096
|
+
error = {
|
|
4097
|
+
message: messageData.error || "Unknown error"
|
|
4098
|
+
};
|
|
4099
|
+
}
|
|
4100
|
+
let result = messageData.value;
|
|
4101
|
+
if (result === void 0) {
|
|
4102
|
+
result = messageData.data;
|
|
4103
|
+
}
|
|
4104
|
+
const response = {
|
|
4105
|
+
type: "rpc-response",
|
|
4106
|
+
id: requestId,
|
|
4107
|
+
result,
|
|
4108
|
+
method: message.type,
|
|
4109
|
+
error
|
|
4110
|
+
};
|
|
4111
|
+
await this.handleResponse(response);
|
|
4112
|
+
this.isProcessingMessage = false;
|
|
4113
|
+
};
|
|
4114
|
+
}
|
|
4115
|
+
onNotification(callback) {
|
|
4116
|
+
this.onNotificationCallbacks.push(callback);
|
|
4117
|
+
return {
|
|
4118
|
+
unsubscribe: () => {
|
|
4119
|
+
if (this.isProcessingMessage) {
|
|
4120
|
+
this.onNotificationCallbacks.push(callback);
|
|
4121
|
+
} else {
|
|
4122
|
+
this.removeOnNotificationCallback(callback);
|
|
4123
|
+
}
|
|
4124
|
+
}
|
|
4125
|
+
};
|
|
4126
|
+
}
|
|
4127
|
+
onRequest(callback) {
|
|
4128
|
+
throw new Error("Method not implemented.");
|
|
4129
|
+
}
|
|
4130
|
+
onResponse(callback) {
|
|
4131
|
+
this.onResponseCallbacks.push(callback);
|
|
4132
|
+
return {
|
|
4133
|
+
unsubscribe: () => {
|
|
4134
|
+
if (this.isProcessingMessage) {
|
|
4135
|
+
this.onResponseCallbacksToRemove.push(callback);
|
|
4136
|
+
} else {
|
|
4137
|
+
this.removeOnResponseCallback(callback);
|
|
4138
|
+
}
|
|
4139
|
+
}
|
|
4140
|
+
};
|
|
4141
|
+
}
|
|
4142
|
+
get instanceId() {
|
|
4143
|
+
return this._instanceId;
|
|
4144
|
+
}
|
|
4145
|
+
set instanceId(instanceId) {
|
|
4146
|
+
this._instanceId = instanceId;
|
|
4147
|
+
}
|
|
4148
|
+
sendRequest(request) {
|
|
4149
|
+
const instanceId = this.instanceId || "unknown";
|
|
4150
|
+
const method = request.method;
|
|
4151
|
+
const message = {
|
|
4152
|
+
type: method,
|
|
4153
|
+
direction: "H5_TO_APP",
|
|
4154
|
+
data: {
|
|
4155
|
+
...request.args,
|
|
4156
|
+
requestId: request.id
|
|
4157
|
+
},
|
|
4158
|
+
instanceId,
|
|
4159
|
+
timestamp: Date.now()
|
|
4160
|
+
};
|
|
4161
|
+
this.sendVenusMessage(message);
|
|
4162
|
+
}
|
|
4163
|
+
sendVenusMessage(message) {
|
|
4164
|
+
const messageAsString = JSON.stringify(message, null, 2);
|
|
4165
|
+
const reactNativeWebView = window.ReactNativeWebView;
|
|
4166
|
+
if (reactNativeWebView) {
|
|
4167
|
+
reactNativeWebView.postMessage(messageAsString);
|
|
4168
|
+
} else {
|
|
4169
|
+
window.parent.postMessage(messageAsString, "*");
|
|
4170
|
+
}
|
|
4171
|
+
}
|
|
4172
|
+
sendResponse(response) {
|
|
4173
|
+
throw new Error("Method not implemented.");
|
|
4174
|
+
}
|
|
4175
|
+
start() {
|
|
4176
|
+
if (this.isStarted) {
|
|
4177
|
+
return;
|
|
4178
|
+
}
|
|
4179
|
+
this.isStarted = true;
|
|
4180
|
+
window.addEventListener("message", this.messageHandler, true);
|
|
4181
|
+
this.logInfo(`Started`);
|
|
4182
|
+
}
|
|
4183
|
+
stop() {
|
|
4184
|
+
if (!this.isStarted) {
|
|
4185
|
+
return;
|
|
4186
|
+
}
|
|
4187
|
+
this.isStarted = false;
|
|
4188
|
+
window.removeEventListener("message", this.messageHandler);
|
|
4189
|
+
this.logInfo(`Stopped`);
|
|
4190
|
+
}
|
|
4191
|
+
handleNotification(notification) {
|
|
4192
|
+
for (const callback of this.onNotificationCallbacks) {
|
|
4193
|
+
callback(notification);
|
|
4194
|
+
}
|
|
4195
|
+
for (const callback of this.onNotificationCallbacksToRemove) {
|
|
4196
|
+
this.removeOnNotificationCallback(callback);
|
|
4197
|
+
}
|
|
4198
|
+
this.onNotificationCallbacksToRemove.length = 0;
|
|
4199
|
+
}
|
|
4200
|
+
async handleResponse(response) {
|
|
4201
|
+
for (const callback of this.onResponseCallbacks) {
|
|
4202
|
+
const consumed = await callback(response);
|
|
4203
|
+
if (consumed) {
|
|
4204
|
+
break;
|
|
4205
|
+
}
|
|
4206
|
+
}
|
|
4207
|
+
for (const callback of this.onResponseCallbacksToRemove) {
|
|
4208
|
+
this.removeOnResponseCallback(callback);
|
|
4209
|
+
}
|
|
4210
|
+
this.onResponseCallbacksToRemove.length = 0;
|
|
4211
|
+
}
|
|
4212
|
+
removeOnResponseCallback(callback) {
|
|
4213
|
+
this.onResponseCallbacks.splice(
|
|
4214
|
+
this.onResponseCallbacks.indexOf(callback),
|
|
4215
|
+
1
|
|
4216
|
+
);
|
|
4217
|
+
}
|
|
4218
|
+
removeOnNotificationCallback(callback) {
|
|
4219
|
+
this.onNotificationCallbacks.splice(
|
|
4220
|
+
this.onNotificationCallbacks.indexOf(callback),
|
|
4221
|
+
1
|
|
4222
|
+
);
|
|
4223
|
+
}
|
|
4224
|
+
logInfo(message, ...params) {
|
|
4225
|
+
console.log(`[Venus Transport] ${message}`, ...params);
|
|
4226
|
+
}
|
|
4227
|
+
logWarn(message, ...params) {
|
|
4228
|
+
console.warn(`[Venus Transport] ${message}`, ...params);
|
|
4229
|
+
}
|
|
4230
|
+
onVenusMessage(callback) {
|
|
4231
|
+
this.onVenusMessageCallbacks.push(callback);
|
|
4232
|
+
return {
|
|
4233
|
+
unsubscribe: () => {
|
|
4234
|
+
this.onVenusMessageCallbacks.splice(
|
|
4235
|
+
this.onVenusMessageCallbacks.indexOf(callback),
|
|
4236
|
+
1
|
|
4237
|
+
);
|
|
4238
|
+
}
|
|
4239
|
+
};
|
|
4240
|
+
}
|
|
4241
|
+
notifyVenusMessageReceived(message) {
|
|
4242
|
+
for (const callback of this.onVenusMessageCallbacks) {
|
|
4243
|
+
callback(message);
|
|
4244
|
+
}
|
|
4245
|
+
}
|
|
4246
|
+
};
|
|
4247
|
+
|
|
4248
|
+
// src/RemoteHost.ts
|
|
4249
|
+
init_rooms();
|
|
4250
|
+
|
|
4251
|
+
// src/rooms/RpcRoomsApi.ts
|
|
4252
|
+
init_VenusRoom();
|
|
4253
|
+
var RpcRoomsApi = class {
|
|
4254
|
+
constructor(rpcClient) {
|
|
4255
|
+
__publicField(this, "rpcClient");
|
|
4256
|
+
__publicField(this, "subscriptions");
|
|
4257
|
+
__publicField(this, "transportSubscription", null);
|
|
4258
|
+
this.rpcClient = rpcClient;
|
|
4259
|
+
this.subscriptions = {
|
|
4260
|
+
data: {},
|
|
4261
|
+
messages: {},
|
|
4262
|
+
gameEvents: {},
|
|
4263
|
+
allEvents: {}
|
|
4264
|
+
};
|
|
4265
|
+
}
|
|
4266
|
+
/**
|
|
4267
|
+
* Get the subscription state for external access (used by setupRoomNotifications)
|
|
4268
|
+
*/
|
|
4269
|
+
getSubscriptions() {
|
|
4270
|
+
return this.subscriptions;
|
|
4271
|
+
}
|
|
4272
|
+
/**
|
|
4273
|
+
* Set up room notification routing from the transport
|
|
4274
|
+
*/
|
|
4275
|
+
setupNotifications(transport) {
|
|
4276
|
+
const { setupRoomNotifications: setupRoomNotifications2 } = (init_rooms(), __toCommonJS(rooms_exports));
|
|
4277
|
+
this.transportSubscription = setupRoomNotifications2(
|
|
4278
|
+
transport,
|
|
4279
|
+
() => this.getSubscriptions()
|
|
4280
|
+
);
|
|
4281
|
+
}
|
|
4282
|
+
/**
|
|
4283
|
+
* Clean up subscriptions and resources
|
|
4284
|
+
*/
|
|
4285
|
+
dispose() {
|
|
4286
|
+
if (this.transportSubscription) {
|
|
4287
|
+
this.transportSubscription.unsubscribe();
|
|
4288
|
+
this.transportSubscription = null;
|
|
4289
|
+
console.log("[Venus Rooms] Cleaned up room notification subscription");
|
|
4290
|
+
}
|
|
4291
|
+
}
|
|
4292
|
+
async createRoom(options) {
|
|
4293
|
+
const response = await this.rpcClient.call(
|
|
4294
|
+
"H5_ROOM_CREATE" /* H5_ROOM_CREATE */,
|
|
4295
|
+
{
|
|
4296
|
+
options
|
|
4297
|
+
}
|
|
4298
|
+
);
|
|
4299
|
+
if (response.success === false) {
|
|
4300
|
+
throw new Error(response.error || "Failed to create room");
|
|
4301
|
+
}
|
|
4302
|
+
const roomData = response.roomData || response;
|
|
4303
|
+
const room = new VenusRoom(roomData);
|
|
4304
|
+
return room;
|
|
4305
|
+
}
|
|
4306
|
+
async joinOrCreateRoom(options) {
|
|
4307
|
+
const response = await this.rpcClient.call(
|
|
4308
|
+
"H5_ROOM_JOIN_OR_CREATE" /* H5_ROOM_JOIN_OR_CREATE */,
|
|
4309
|
+
{
|
|
4310
|
+
options
|
|
4311
|
+
}
|
|
4312
|
+
);
|
|
4313
|
+
if (response.success === false) {
|
|
4314
|
+
throw new Error(response.error || "Failed to join or create room");
|
|
4315
|
+
}
|
|
4316
|
+
const data = response.value || response;
|
|
4317
|
+
const room = new VenusRoom(data.roomData);
|
|
4318
|
+
return {
|
|
4319
|
+
action: data.action,
|
|
4320
|
+
room,
|
|
4321
|
+
playersJoined: data.playersJoined
|
|
4322
|
+
};
|
|
4323
|
+
}
|
|
4324
|
+
async joinRoomByCode(roomCode) {
|
|
4325
|
+
const response = await this.rpcClient.call(
|
|
4326
|
+
"H5_ROOM_JOIN_BY_CODE" /* H5_ROOM_JOIN_BY_CODE */,
|
|
4327
|
+
{
|
|
4328
|
+
roomCode
|
|
4329
|
+
}
|
|
4330
|
+
);
|
|
4331
|
+
if (response?.success === false) {
|
|
4332
|
+
throw new Error(response.error || "Failed to join room by code");
|
|
4333
|
+
}
|
|
4334
|
+
const roomData = response.roomData || response;
|
|
4335
|
+
const room = new VenusRoom(roomData);
|
|
4336
|
+
return room;
|
|
4337
|
+
}
|
|
4338
|
+
// Get user's rooms with optional filtering
|
|
4339
|
+
async getUserRooms(includeArchived = false) {
|
|
4340
|
+
const response = await this.rpcClient.call(
|
|
4341
|
+
"H5_ROOM_GET_USER_ROOMS" /* H5_ROOM_GET_USER_ROOMS */,
|
|
4342
|
+
{
|
|
4343
|
+
includeArchived
|
|
4344
|
+
}
|
|
4345
|
+
);
|
|
4346
|
+
if (response?.success === false) {
|
|
4347
|
+
throw new Error(response.error || "Failed to get user rooms");
|
|
4348
|
+
}
|
|
4349
|
+
const rawRooms = response.rooms || [];
|
|
4350
|
+
const venusRooms = [];
|
|
4351
|
+
for (const roomData of rawRooms) {
|
|
4352
|
+
if (!roomData.id) {
|
|
4353
|
+
console.warn("getUserRooms: Skipping room with missing ID:", roomData);
|
|
4354
|
+
continue;
|
|
4355
|
+
}
|
|
4356
|
+
try {
|
|
4357
|
+
const venusRoom = new VenusRoom(roomData);
|
|
4358
|
+
venusRooms.push(venusRoom);
|
|
4359
|
+
} catch (error) {
|
|
4360
|
+
console.warn(
|
|
4361
|
+
"getUserRooms: Failed to create VenusRoom object:",
|
|
4362
|
+
error,
|
|
4363
|
+
roomData
|
|
4364
|
+
);
|
|
4365
|
+
}
|
|
4366
|
+
}
|
|
4367
|
+
return venusRooms;
|
|
4368
|
+
}
|
|
4369
|
+
async updateData(room, updates, merge = true) {
|
|
4370
|
+
const response = await this.rpcClient.call(
|
|
4371
|
+
"H5_ROOM_UPDATE_DATA" /* H5_ROOM_UPDATE_DATA */,
|
|
4372
|
+
{
|
|
4373
|
+
roomId: room.id,
|
|
4374
|
+
updates,
|
|
4375
|
+
merge
|
|
4376
|
+
}
|
|
4377
|
+
);
|
|
4378
|
+
if (response?.success === false) {
|
|
4379
|
+
throw new Error(response.error || "Failed to update room data");
|
|
4380
|
+
}
|
|
4381
|
+
return response.data;
|
|
4382
|
+
}
|
|
4383
|
+
async getData(room) {
|
|
4384
|
+
const response = await this.rpcClient.call(
|
|
4385
|
+
"H5_ROOM_GET_DATA" /* H5_ROOM_GET_DATA */,
|
|
4386
|
+
{
|
|
4387
|
+
roomId: room.id
|
|
4388
|
+
}
|
|
4389
|
+
);
|
|
4390
|
+
if (response?.success === false) {
|
|
4391
|
+
throw new Error(response.error || "Failed to get room data");
|
|
4392
|
+
}
|
|
4393
|
+
return response.data;
|
|
4394
|
+
}
|
|
4395
|
+
async sendMessage(venusRoom, messageData) {
|
|
4396
|
+
const response = await this.rpcClient.call(
|
|
4397
|
+
"H5_ROOM_SEND_MESSAGE" /* H5_ROOM_SEND_MESSAGE */,
|
|
4398
|
+
{
|
|
4399
|
+
roomId: venusRoom.id,
|
|
4400
|
+
message: messageData
|
|
4401
|
+
}
|
|
4402
|
+
);
|
|
4403
|
+
if (response?.success === false) {
|
|
4404
|
+
throw new Error(response.error || "Failed to send message");
|
|
4405
|
+
}
|
|
4406
|
+
return response.messageId;
|
|
4407
|
+
}
|
|
4408
|
+
async leave(room) {
|
|
4409
|
+
const response = await this.rpcClient.call(
|
|
4410
|
+
"H5_ROOM_LEAVE" /* H5_ROOM_LEAVE */,
|
|
4411
|
+
{
|
|
4412
|
+
roomId: room.id
|
|
4413
|
+
}
|
|
4414
|
+
);
|
|
4415
|
+
if (response?.success === false) {
|
|
4416
|
+
throw new Error(response.error || "Failed to leave room");
|
|
4417
|
+
}
|
|
4418
|
+
return response;
|
|
4419
|
+
}
|
|
4420
|
+
async startGame(room, gameConfig = {}, turnOrder = null) {
|
|
4421
|
+
const response = await this.rpcClient.call(
|
|
4422
|
+
"H5_ROOM_START_GAME" /* H5_ROOM_START_GAME */,
|
|
4423
|
+
{
|
|
4424
|
+
roomId: room.id,
|
|
4425
|
+
gameConfig,
|
|
4426
|
+
turnOrder
|
|
4427
|
+
}
|
|
4428
|
+
);
|
|
4429
|
+
if (response?.success === false) {
|
|
4430
|
+
throw new Error(response.error || "Failed to start game");
|
|
4431
|
+
}
|
|
4432
|
+
return response.data;
|
|
4433
|
+
}
|
|
4434
|
+
async proposeMove(room, proposalPayload) {
|
|
4435
|
+
const response = await this.rpcClient.call(
|
|
4436
|
+
"h5:room:proposeMove" /* H5_ROOM_PROPOSE_MOVE */,
|
|
4437
|
+
{
|
|
4438
|
+
roomId: room.id,
|
|
4439
|
+
gameSpecificState: proposalPayload.gameSpecificState,
|
|
4440
|
+
moveType: proposalPayload.moveType,
|
|
4441
|
+
clientContext: proposalPayload.clientContext,
|
|
4442
|
+
clientProposalId: proposalPayload.clientProposalId
|
|
4443
|
+
}
|
|
4444
|
+
);
|
|
4445
|
+
if (response?.success === false) {
|
|
4446
|
+
throw new Error(response.error || "Failed to propose move");
|
|
4447
|
+
}
|
|
4448
|
+
return response.data;
|
|
4449
|
+
}
|
|
4450
|
+
async validateMove(room, moveId, isValid, reason = null, validatorId = null) {
|
|
4451
|
+
console.log(`[Venus Rooms] Validating move ${moveId}: ${isValid}`);
|
|
4452
|
+
return { success: true, moveId, isValid, reason };
|
|
4453
|
+
}
|
|
4454
|
+
async roomSubscribeToGameEvents(room, callback) {
|
|
4455
|
+
"game_" + Date.now() + "_" + Math.random().toString(36).substr(2, 9);
|
|
4456
|
+
if (!this.subscriptions.gameEvents[room.id]) {
|
|
4457
|
+
this.subscriptions.gameEvents[room.id] = [];
|
|
4458
|
+
}
|
|
4459
|
+
this.subscriptions.gameEvents[room.id].push(callback);
|
|
4460
|
+
}
|
|
4461
|
+
subscribe(room, options = {}) {
|
|
4462
|
+
const subscriptionIds = [];
|
|
4463
|
+
const roomId = room.id;
|
|
4464
|
+
if (options.onData) {
|
|
4465
|
+
const dataSubId = "data_" + Date.now() + "_" + Math.random().toString(36).substr(2, 9);
|
|
4466
|
+
if (!this.subscriptions.data[roomId]) {
|
|
4467
|
+
this.subscriptions.data[roomId] = [];
|
|
4468
|
+
}
|
|
4469
|
+
this.subscriptions.data[roomId].push(options.onData);
|
|
4470
|
+
subscriptionIds.push({
|
|
4471
|
+
type: "data",
|
|
4472
|
+
id: dataSubId,
|
|
4473
|
+
callback: options.onData
|
|
4474
|
+
});
|
|
4475
|
+
}
|
|
4476
|
+
if (options.onMessages) {
|
|
4477
|
+
const msgSubId = "messages_" + Date.now() + "_" + Math.random().toString(36).substr(2, 9);
|
|
4478
|
+
if (!this.subscriptions.messages[roomId]) {
|
|
4479
|
+
this.subscriptions.messages[roomId] = [];
|
|
4480
|
+
}
|
|
4481
|
+
this.subscriptions.messages[roomId].push(options.onMessages);
|
|
4482
|
+
subscriptionIds.push({
|
|
4483
|
+
type: "messages",
|
|
4484
|
+
id: msgSubId,
|
|
4485
|
+
callback: options.onMessages
|
|
4486
|
+
});
|
|
4487
|
+
}
|
|
4488
|
+
if (options.onMoves || options.onGameEvents) {
|
|
4489
|
+
const handler = options.onMoves || options.onGameEvents;
|
|
4490
|
+
if (handler) {
|
|
4491
|
+
const gameSubId = "game_" + Date.now() + "_" + Math.random().toString(36).substr(2, 9);
|
|
4492
|
+
if (!this.subscriptions.gameEvents[roomId]) {
|
|
4493
|
+
this.subscriptions.gameEvents[roomId] = [];
|
|
4494
|
+
}
|
|
4495
|
+
this.subscriptions.gameEvents[roomId].push(handler);
|
|
4496
|
+
subscriptionIds.push({
|
|
4497
|
+
type: "gameEvents",
|
|
4498
|
+
id: gameSubId,
|
|
4499
|
+
callback: handler
|
|
4500
|
+
});
|
|
4501
|
+
}
|
|
4502
|
+
}
|
|
4503
|
+
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;
|
|
4504
|
+
if (needsSubscription) {
|
|
4505
|
+
this.rpcClient.call("H5_ROOM_SUBSCRIBE" /* H5_ROOM_SUBSCRIBE */, {
|
|
4506
|
+
roomId,
|
|
4507
|
+
subscribeToData: !!options.onData,
|
|
4508
|
+
subscribeToMessages: !!options.onMessages,
|
|
4509
|
+
subscribeToProposedMoves: !!(options.onMoves || options.onGameEvents)
|
|
4510
|
+
}).catch((error) => {
|
|
4511
|
+
console.error("Failed to set up room subscription:", error);
|
|
4512
|
+
});
|
|
4513
|
+
}
|
|
4514
|
+
let called = false;
|
|
4515
|
+
return () => {
|
|
4516
|
+
if (called) return;
|
|
4517
|
+
called = true;
|
|
4518
|
+
subscriptionIds.forEach((sub) => {
|
|
4519
|
+
const bucket = this.subscriptions[sub.type];
|
|
4520
|
+
const callbacks = bucket && bucket[roomId] || [];
|
|
4521
|
+
const index = callbacks.indexOf(sub.callback);
|
|
4522
|
+
if (index > -1) callbacks.splice(index, 1);
|
|
4523
|
+
});
|
|
4524
|
+
const hasNoCallbacks = (this.subscriptions.data[roomId]?.length ?? 0) === 0 && (this.subscriptions.messages[roomId]?.length ?? 0) === 0 && (this.subscriptions.gameEvents[roomId]?.length ?? 0) === 0;
|
|
4525
|
+
if (hasNoCallbacks) {
|
|
4526
|
+
this.rpcClient.call("H5_ROOM_UNSUBSCRIBE" /* H5_ROOM_UNSUBSCRIBE */, {
|
|
4527
|
+
roomId
|
|
4528
|
+
}).catch((error) => {
|
|
4529
|
+
console.error("Failed to clean up room subscription:", error);
|
|
4530
|
+
});
|
|
4531
|
+
}
|
|
4532
|
+
};
|
|
4533
|
+
}
|
|
4534
|
+
};
|
|
4535
|
+
|
|
4536
|
+
// src/RemoteHost.ts
|
|
4537
|
+
var getCdnBaseUrl = () => {
|
|
4538
|
+
return "https://venus-static-01293ak.web.app/";
|
|
4539
|
+
};
|
|
4540
|
+
var RemoteHost = class {
|
|
4541
|
+
constructor(venusApi) {
|
|
4542
|
+
__publicField(this, "ads");
|
|
4543
|
+
__publicField(this, "analytics");
|
|
4544
|
+
__publicField(this, "deviceCache");
|
|
4545
|
+
__publicField(this, "appStorage");
|
|
4546
|
+
__publicField(this, "globalStorage");
|
|
4547
|
+
__publicField(this, "avatar3d");
|
|
4548
|
+
__publicField(this, "navigation");
|
|
4549
|
+
__publicField(this, "notifications");
|
|
4550
|
+
__publicField(this, "popups");
|
|
4551
|
+
__publicField(this, "profile");
|
|
4552
|
+
__publicField(this, "cdn");
|
|
4553
|
+
__publicField(this, "time");
|
|
4554
|
+
__publicField(this, "post");
|
|
4555
|
+
__publicField(this, "ai");
|
|
4556
|
+
__publicField(this, "haptics");
|
|
4557
|
+
__publicField(this, "features");
|
|
4558
|
+
__publicField(this, "lifecycle");
|
|
4559
|
+
__publicField(this, "simulation");
|
|
4560
|
+
__publicField(this, "rooms");
|
|
4561
|
+
__publicField(this, "logging");
|
|
4562
|
+
__publicField(this, "iap");
|
|
4563
|
+
__publicField(this, "leaderboard");
|
|
4564
|
+
__publicField(this, "preloader");
|
|
4565
|
+
__publicField(this, "social");
|
|
4566
|
+
__publicField(this, "venusApi");
|
|
4567
|
+
__publicField(this, "rpcClient");
|
|
4568
|
+
__publicField(this, "_isInitialized", false);
|
|
4569
|
+
this.venusApi = venusApi;
|
|
4570
|
+
const rpcClient = new RpcClient();
|
|
4571
|
+
this.rpcClient = rpcClient;
|
|
4572
|
+
this.ads = new RpcAdsApi(rpcClient);
|
|
4573
|
+
this.analytics = new RpcAnalyticsApi(rpcClient);
|
|
4574
|
+
this.deviceCache = new RpcStorageApi(rpcClient, {
|
|
4575
|
+
clear: "H5_DEVICE_CACHE_CLEAR" /* DEVICE_CACHE_CLEAR */,
|
|
4576
|
+
getItem: "H5_DEVICE_CACHE_GET_ITEM" /* DEVICE_CACHE_GET_ITEM */,
|
|
4577
|
+
getKey: "H5_DEVICE_CACHE_KEY" /* DEVICE_CACHE_KEY */,
|
|
4578
|
+
length: "H5_DEVICE_CACHE_LENGTH" /* DEVICE_CACHE_LENGTH */,
|
|
4579
|
+
removeItem: "H5_DEVICE_CACHE_REMOVE_ITEM" /* DEVICE_CACHE_REMOVE_ITEM */,
|
|
4580
|
+
setItem: "H5_DEVICE_CACHE_SET_ITEM" /* DEVICE_CACHE_SET_ITEM */
|
|
4581
|
+
});
|
|
4582
|
+
this.appStorage = new RpcStorageApi(rpcClient, {
|
|
4583
|
+
clear: "H5_APP_STORAGE_CLEAR" /* APP_STORAGE_CLEAR */,
|
|
4584
|
+
getItem: "H5_APP_STORAGE_GET_ITEM" /* APP_STORAGE_GET_ITEM */,
|
|
4585
|
+
getKey: "H5_APP_STORAGE_KEY" /* APP_STORAGE_KEY */,
|
|
4586
|
+
length: "H5_APP_STORAGE_LENGTH" /* APP_STORAGE_LENGTH */,
|
|
4587
|
+
removeItem: "H5_APP_STORAGE_REMOVE_ITEM" /* APP_STORAGE_REMOVE_ITEM */,
|
|
4588
|
+
setItem: "H5_APP_STORAGE_SET_ITEM" /* APP_STORAGE_SET_ITEM */,
|
|
4589
|
+
getAllItems: "H5_APP_STORAGE_GET_ALL_ITEMS" /* APP_STORAGE_GET_ALL_ITEMS */,
|
|
4590
|
+
setMultipleItems: "H5_APP_STORAGE_SET_ITEM" /* APP_STORAGE_SET_ITEM */,
|
|
4591
|
+
removeMultipleItems: "H5_APP_STORAGE_REMOVE_ITEM" /* APP_STORAGE_REMOVE_ITEM */
|
|
4592
|
+
});
|
|
4593
|
+
this.globalStorage = new RpcStorageApi(rpcClient, {
|
|
4594
|
+
clear: "H5_GLOBAL_STORAGE_CLEAR" /* GLOBAL_STORAGE_CLEAR */,
|
|
4595
|
+
getItem: "H5_GLOBAL_STORAGE_GET_ITEM" /* GLOBAL_STORAGE_GET_ITEM */,
|
|
4596
|
+
getKey: "H5_GLOBAL_STORAGE_KEY" /* GLOBAL_STORAGE_KEY */,
|
|
4597
|
+
length: "H5_GLOBAL_STORAGE_LENGTH" /* GLOBAL_STORAGE_LENGTH */,
|
|
4598
|
+
removeItem: "H5_GLOBAL_STORAGE_REMOVE_ITEM" /* GLOBAL_STORAGE_REMOVE_ITEM */,
|
|
4599
|
+
setItem: "H5_GLOBAL_STORAGE_SET_ITEM" /* GLOBAL_STORAGE_SET_ITEM */,
|
|
4600
|
+
getAllItems: "H5_GLOBAL_STORAGE_GET_ALL_ITEMS" /* GLOBAL_STORAGE_GET_ALL_ITEMS */,
|
|
4601
|
+
setMultipleItems: "H5_GLOBAL_STORAGE_SET_MULTIPLE_ITEMS" /* GLOBAL_STORAGE_SET_MULTIPLE_ITEMS */,
|
|
4602
|
+
removeMultipleItems: "H5_GLOBAL_STORAGE_REMOVE_MULTIPLE_ITEMS" /* GLOBAL_STORAGE_REMOVE_MULTIPLE_ITEMS */
|
|
4603
|
+
});
|
|
4604
|
+
this.avatar3d = new RpcAvatarApi(rpcClient, venusApi);
|
|
4605
|
+
this.navigation = new RpcNavigationApi(rpcClient, venusApi);
|
|
4606
|
+
this.notifications = new RpcNotificationsApi(rpcClient);
|
|
4607
|
+
this.popups = new RpcPopupsApi(rpcClient);
|
|
4608
|
+
this.profile = new HostProfileApi();
|
|
4609
|
+
this.cdn = new HostCdnApi(getCdnBaseUrl());
|
|
4610
|
+
this.time = new HostTimeApi(rpcClient);
|
|
4611
|
+
this.post = new RpcPostApi(rpcClient);
|
|
4612
|
+
this.ai = new RpcAiApi(rpcClient);
|
|
4613
|
+
this.haptics = new RpcHapticsApi(rpcClient);
|
|
4614
|
+
this.features = new RpcFeaturesApi(rpcClient);
|
|
4615
|
+
this.lifecycle = new RpcLifecycleApi(rpcClient);
|
|
4616
|
+
this.simulation = new RpcSimulationApi(rpcClient);
|
|
4617
|
+
this.rooms = new RpcRoomsApi(rpcClient);
|
|
4618
|
+
this.logging = new RpcLoggingApi(this, rpcClient);
|
|
4619
|
+
this.iap = new RpcIapApi(rpcClient);
|
|
4620
|
+
this.leaderboard = new RpcLeaderboardApi(rpcClient);
|
|
4621
|
+
this.preloader = new RpcPreloaderApi(rpcClient);
|
|
4622
|
+
this.social = new RpcSocialApi(rpcClient);
|
|
4623
|
+
venusApi.isMock = () => false;
|
|
4624
|
+
this.venusApi.sharedAssets = new RpcSharedAssetsApi(rpcClient, venusApi);
|
|
4625
|
+
initializeRoomsApi(this.venusApi, this);
|
|
4626
|
+
console.log("[Venus SDK] Remote host created");
|
|
4627
|
+
}
|
|
4628
|
+
get isInitialized() {
|
|
4629
|
+
return this._isInitialized;
|
|
4630
|
+
}
|
|
4631
|
+
async initialize(options) {
|
|
4632
|
+
this.log("Initializing Remote Host...");
|
|
4633
|
+
const transport = new VenusTransport();
|
|
4634
|
+
transport.start();
|
|
4635
|
+
this.rpcClient.start(transport);
|
|
4636
|
+
const roomsApi = this.rooms;
|
|
4637
|
+
roomsApi.setupNotifications(transport);
|
|
4638
|
+
const response = await this.rpcClient.call(
|
|
4639
|
+
"INITIALIZE_SDK" /* INIT_SDK */,
|
|
4640
|
+
{},
|
|
4641
|
+
5e3
|
|
4642
|
+
);
|
|
4643
|
+
transport.instanceId = response.instanceId;
|
|
4644
|
+
this.log(`Remote Host Initialized with id: ${transport.instanceId}`);
|
|
4645
|
+
if (response.profile) {
|
|
4646
|
+
const profile = response.profile;
|
|
4647
|
+
const sanitizedProfile = {
|
|
4648
|
+
id: profile.id,
|
|
4649
|
+
username: profile.username,
|
|
4650
|
+
avatarUrl: profile.avatarUrl ?? null,
|
|
4651
|
+
isAnonymous: Boolean(profile.isAnonymous)
|
|
4652
|
+
};
|
|
4653
|
+
if (typeof window !== "undefined") {
|
|
4654
|
+
const globalWindow = window;
|
|
4655
|
+
const venus = globalWindow.venus || (globalWindow.venus = {});
|
|
4656
|
+
venus.profile = sanitizedProfile;
|
|
4657
|
+
if (venus._config) {
|
|
4658
|
+
venus._config.profile = sanitizedProfile;
|
|
4659
|
+
}
|
|
4660
|
+
if (venus.config) {
|
|
4661
|
+
venus.config.profile = sanitizedProfile;
|
|
4662
|
+
}
|
|
4663
|
+
}
|
|
4664
|
+
}
|
|
4665
|
+
this._isInitialized = true;
|
|
4666
|
+
this.venusApi.launchParams = response.launchParams || {};
|
|
4667
|
+
await this.rpcClient.call("READY" /* READY */, {});
|
|
4668
|
+
const hudInsets = response.hudInsets;
|
|
4669
|
+
if (hudInsets) {
|
|
4670
|
+
this.venusApi.config.ui.safeArea = hudInsets;
|
|
4671
|
+
}
|
|
4672
|
+
return {
|
|
4673
|
+
hudInsets,
|
|
4674
|
+
initializeAsleep: response.initializeAsleep
|
|
4675
|
+
};
|
|
4676
|
+
}
|
|
4677
|
+
log(message) {
|
|
4678
|
+
console.log(`[Venus SDK] [Remote Host] ${message}`);
|
|
4679
|
+
}
|
|
4680
|
+
};
|
|
4681
|
+
|
|
4682
|
+
// src/MockHost.ts
|
|
4683
|
+
init_rooms();
|
|
4684
|
+
var ROOMS_UNAVAILABLE_MESSAGE = "[Venus SDK] Rooms API is only available when running inside the Venus host environment.";
|
|
4685
|
+
function createUnavailableRoomsApi() {
|
|
4686
|
+
const roomsUnavailableError = () => new Error(ROOMS_UNAVAILABLE_MESSAGE);
|
|
4687
|
+
return {
|
|
4688
|
+
async createRoom() {
|
|
4689
|
+
throw roomsUnavailableError();
|
|
4690
|
+
},
|
|
4691
|
+
async joinOrCreateRoom() {
|
|
4692
|
+
throw roomsUnavailableError();
|
|
4693
|
+
},
|
|
4694
|
+
async getUserRooms() {
|
|
4695
|
+
throw roomsUnavailableError();
|
|
4696
|
+
},
|
|
4697
|
+
async joinRoomByCode() {
|
|
4698
|
+
throw roomsUnavailableError();
|
|
4699
|
+
},
|
|
4700
|
+
subscribe() {
|
|
4701
|
+
throw roomsUnavailableError();
|
|
4702
|
+
},
|
|
4703
|
+
async updateData() {
|
|
4704
|
+
throw roomsUnavailableError();
|
|
4705
|
+
},
|
|
4706
|
+
async getData() {
|
|
4707
|
+
throw roomsUnavailableError();
|
|
4708
|
+
},
|
|
4709
|
+
async sendMessage() {
|
|
4710
|
+
throw roomsUnavailableError();
|
|
4711
|
+
},
|
|
4712
|
+
async leave() {
|
|
4713
|
+
throw roomsUnavailableError();
|
|
4714
|
+
},
|
|
4715
|
+
async startGame() {
|
|
4716
|
+
throw roomsUnavailableError();
|
|
4717
|
+
},
|
|
4718
|
+
async proposeMove() {
|
|
4719
|
+
throw roomsUnavailableError();
|
|
4720
|
+
},
|
|
4721
|
+
async validateMove() {
|
|
4722
|
+
throw roomsUnavailableError();
|
|
4723
|
+
}
|
|
4724
|
+
};
|
|
4725
|
+
}
|
|
4726
|
+
var MockHost = class {
|
|
4727
|
+
constructor(venusApi) {
|
|
4728
|
+
__publicField(this, "ads");
|
|
4729
|
+
__publicField(this, "analytics");
|
|
4730
|
+
__publicField(this, "deviceCache");
|
|
4731
|
+
__publicField(this, "appStorage");
|
|
4732
|
+
__publicField(this, "globalStorage");
|
|
4733
|
+
__publicField(this, "avatar3d");
|
|
4734
|
+
__publicField(this, "navigation");
|
|
4735
|
+
__publicField(this, "notifications");
|
|
4736
|
+
__publicField(this, "popups");
|
|
4737
|
+
__publicField(this, "profile");
|
|
4738
|
+
__publicField(this, "cdn");
|
|
4739
|
+
__publicField(this, "time");
|
|
4740
|
+
__publicField(this, "post");
|
|
4741
|
+
__publicField(this, "ai");
|
|
4742
|
+
__publicField(this, "haptics");
|
|
4743
|
+
__publicField(this, "features");
|
|
4744
|
+
__publicField(this, "lifecycle");
|
|
4745
|
+
__publicField(this, "simulation");
|
|
4746
|
+
__publicField(this, "rooms");
|
|
4747
|
+
__publicField(this, "logging");
|
|
4748
|
+
__publicField(this, "iap");
|
|
4749
|
+
__publicField(this, "leaderboard");
|
|
4750
|
+
__publicField(this, "preloader");
|
|
4751
|
+
__publicField(this, "social");
|
|
4752
|
+
__publicField(this, "state", 0 /* PLAYING */);
|
|
4753
|
+
__publicField(this, "venusApi");
|
|
4754
|
+
__publicField(this, "_isInitialized", false);
|
|
4755
|
+
__publicField(this, "_overlay");
|
|
4756
|
+
__publicField(this, "_mockLifecyclesApi");
|
|
4757
|
+
__publicField(this, "_mockAdsApi");
|
|
4758
|
+
this.venusApi = venusApi;
|
|
4759
|
+
this._overlay = this.createOverlay();
|
|
4760
|
+
this._mockAdsApi = new MockAdsApi(this._overlay);
|
|
4761
|
+
this._mockLifecyclesApi = new MockLifecycleApi();
|
|
4762
|
+
this.ads = this._mockAdsApi;
|
|
4763
|
+
this.analytics = new MockAnalyticsApi();
|
|
4764
|
+
const appUrl = typeof window !== "undefined" ? window.location.href : "";
|
|
4765
|
+
this.deviceCache = createMockStorageApi("deviceCache", appUrl);
|
|
4766
|
+
this.appStorage = createMockStorageApi("appStorage", appUrl);
|
|
4767
|
+
this.globalStorage = createMockStorageApi("globalStorage");
|
|
4768
|
+
this.avatar3d = new MockAvatarApi(venusApi);
|
|
4769
|
+
this.navigation = new MockNavigationApi(venusApi);
|
|
4770
|
+
this.notifications = new MockNotificationsApi(venusApi);
|
|
4771
|
+
this.popups = new MockPopupsApi(this._overlay);
|
|
4772
|
+
this.profile = new MockProfileApi();
|
|
4773
|
+
this.cdn = new MockCdnApi();
|
|
4774
|
+
this.time = new MockTimeApi(venusApi);
|
|
4775
|
+
this.post = new MockPostApi(venusApi);
|
|
4776
|
+
this.ai = new MockAiApi();
|
|
4777
|
+
this.haptics = new MockHapticsApi(venusApi);
|
|
4778
|
+
this.features = new MockFeaturesApi();
|
|
4779
|
+
this.lifecycle = this._mockLifecyclesApi;
|
|
4780
|
+
this.simulation = new MockSimulationApi();
|
|
4781
|
+
this.rooms = createUnavailableRoomsApi();
|
|
4782
|
+
this.logging = new MockLoggingApi();
|
|
4783
|
+
this.iap = new MockIapApi();
|
|
4784
|
+
this.social = new MockSocialApi();
|
|
4785
|
+
this.leaderboard = new MockLeaderboardApi();
|
|
4786
|
+
initializeRoomsApi(this.venusApi, this);
|
|
4787
|
+
this.preloader = new MockPreloaderApi();
|
|
4788
|
+
venusApi.isMock = () => true;
|
|
4789
|
+
this.venusApi.sharedAssets = new MockSharedAssetsApi(this.venusApi);
|
|
4790
|
+
}
|
|
4791
|
+
get isInitialized() {
|
|
4792
|
+
return this._isInitialized;
|
|
4793
|
+
}
|
|
4794
|
+
initialize(options) {
|
|
4795
|
+
this._isInitialized = true;
|
|
4796
|
+
return Promise.resolve({
|
|
4797
|
+
initializeAsleep: false
|
|
4798
|
+
});
|
|
4799
|
+
}
|
|
4800
|
+
updateUiControls() {
|
|
4801
|
+
const controls = {
|
|
4802
|
+
closeButton: { x: 16, y: 16, width: 32, height: 32 },
|
|
4803
|
+
menuButton: {
|
|
4804
|
+
x: window.innerWidth - 48,
|
|
4805
|
+
y: 16,
|
|
4806
|
+
width: 32,
|
|
4807
|
+
height: 32
|
|
4808
|
+
},
|
|
4809
|
+
feedHeader: { x: 0, y: 0, width: window.innerWidth, height: 56 },
|
|
4810
|
+
playButton: {
|
|
4811
|
+
x: 0,
|
|
4812
|
+
y: window.innerHeight - 60,
|
|
4813
|
+
width: window.innerWidth,
|
|
4814
|
+
height: 60
|
|
4815
|
+
}
|
|
4816
|
+
};
|
|
4817
|
+
return controls;
|
|
4818
|
+
}
|
|
4819
|
+
createOverlay() {
|
|
4820
|
+
const venusApi = this.venusApi;
|
|
4821
|
+
venusApi.config.ui.controls = this.updateUiControls();
|
|
4822
|
+
const uiControls = venusApi.config.ui.controls;
|
|
4823
|
+
const overlayContainer = document.createElement("div");
|
|
4824
|
+
overlayContainer.id = "venus-mock-overlay";
|
|
4825
|
+
overlayContainer.style.cssText = `
|
|
4826
|
+
position: fixed;
|
|
4827
|
+
top: 0;
|
|
4828
|
+
left: 0;
|
|
4829
|
+
width: 100%;
|
|
4830
|
+
height: 100%;
|
|
4831
|
+
pointer-events: none;
|
|
4832
|
+
z-index: 10000;
|
|
4833
|
+
`;
|
|
4834
|
+
document.body.appendChild(overlayContainer);
|
|
4835
|
+
const menuButton = this.createOverlayButton(
|
|
4836
|
+
"close",
|
|
4837
|
+
"Menu",
|
|
4838
|
+
uiControls.menuButton,
|
|
4839
|
+
() => {
|
|
4840
|
+
this.handleMenuButtonClicked();
|
|
4841
|
+
},
|
|
4842
|
+
"rgba(59, 130, 246, 0.7)",
|
|
4843
|
+
// Blue background instead of black
|
|
4844
|
+
"#FFFFFF"
|
|
4845
|
+
);
|
|
4846
|
+
overlayContainer.appendChild(menuButton);
|
|
4847
|
+
const adOverlay = this.setupAdOverlay();
|
|
4848
|
+
const actionSheet = this.setupActionSheetOverlay();
|
|
4849
|
+
window.addEventListener("resize", () => {
|
|
4850
|
+
this.updateOverlayLayout();
|
|
4851
|
+
});
|
|
4852
|
+
return {
|
|
4853
|
+
container: overlayContainer,
|
|
4854
|
+
elements: {
|
|
4855
|
+
menuButton
|
|
4856
|
+
},
|
|
4857
|
+
appVisibilityState: "visible",
|
|
4858
|
+
actionSheetOverlay: actionSheet,
|
|
4859
|
+
adOverlay,
|
|
4860
|
+
showAdOverlay: () => {
|
|
4861
|
+
return this.showAdOverlay("REWARDED VIDEO AD");
|
|
4862
|
+
},
|
|
4863
|
+
showActionSheet: (items, options) => {
|
|
4864
|
+
return this.showActionSheetOverlay(items, options);
|
|
4865
|
+
}
|
|
4866
|
+
};
|
|
4867
|
+
}
|
|
4868
|
+
async handleMenuButtonClicked() {
|
|
4869
|
+
if (this.state === 0 /* PLAYING */) {
|
|
4870
|
+
this.triggerLifecycleEvent("PAUSE" /* PAUSE */);
|
|
4871
|
+
this.state = 1 /* PAUSED */;
|
|
4872
|
+
}
|
|
4873
|
+
const actionSheetItems = [];
|
|
4874
|
+
const awakeAction = {
|
|
4875
|
+
label: "\u23F0 Awake",
|
|
4876
|
+
id: "awakeAction"
|
|
4877
|
+
};
|
|
4878
|
+
const sleepAction = {
|
|
4879
|
+
label: "\u{1F4A4} Sleep",
|
|
4880
|
+
id: "sleepAction"
|
|
4881
|
+
};
|
|
4882
|
+
const quitAction = {
|
|
4883
|
+
label: "\u{1F6D1} Quit",
|
|
4884
|
+
id: "quitAction"
|
|
4885
|
+
};
|
|
4886
|
+
const playAction = {
|
|
4887
|
+
label: "\u25B6\uFE0F Play",
|
|
4888
|
+
id: "playAction"
|
|
4889
|
+
};
|
|
4890
|
+
if (this.state === 1 /* PAUSED */) {
|
|
4891
|
+
actionSheetItems.push(sleepAction);
|
|
4892
|
+
} else if (this.state === 2 /* SLEEPING */) {
|
|
4893
|
+
actionSheetItems.push(awakeAction);
|
|
4894
|
+
}
|
|
4895
|
+
if (this.state !== 3 /* TERMINATED */) {
|
|
4896
|
+
actionSheetItems.push(quitAction);
|
|
4897
|
+
} else if (this.state === 3 /* TERMINATED */) {
|
|
4898
|
+
actionSheetItems.push(playAction);
|
|
4899
|
+
}
|
|
4900
|
+
const action = await this.showActionSheetOverlay(actionSheetItems);
|
|
4901
|
+
if (action === awakeAction.id) {
|
|
4902
|
+
this.tryAwake();
|
|
4903
|
+
} else if (action === sleepAction.id) {
|
|
4904
|
+
this.trySleep();
|
|
4905
|
+
} else if (action === playAction.id) {
|
|
4906
|
+
this.tryPlay();
|
|
4907
|
+
} else if (action === quitAction.id) {
|
|
4908
|
+
this.tryQuit();
|
|
4909
|
+
} else {
|
|
4910
|
+
this.tryResume();
|
|
4911
|
+
}
|
|
4912
|
+
}
|
|
4913
|
+
tryAwake() {
|
|
4914
|
+
if (this.state === 2 /* SLEEPING */) {
|
|
4915
|
+
this.triggerLifecycleEvent("AWAKE" /* AWAKE */);
|
|
4916
|
+
this.state = 1 /* PAUSED */;
|
|
4917
|
+
}
|
|
4918
|
+
}
|
|
4919
|
+
trySleep() {
|
|
4920
|
+
if (this.state === 1 /* PAUSED */) {
|
|
4921
|
+
this.triggerLifecycleEvent("SLEEP" /* SLEEP */);
|
|
4922
|
+
this.state = 2 /* SLEEPING */;
|
|
4923
|
+
}
|
|
4924
|
+
}
|
|
4925
|
+
tryPlay() {
|
|
4926
|
+
if (this.state === 3 /* TERMINATED */) {
|
|
4927
|
+
this.triggerLifecycleEvent("AWAKE" /* AWAKE */);
|
|
4928
|
+
this.state = 1 /* PAUSED */;
|
|
4929
|
+
this.triggerLifecycleEvent("RESUME" /* RESUME */);
|
|
4930
|
+
this.state = 0 /* PLAYING */;
|
|
4931
|
+
}
|
|
4932
|
+
}
|
|
4933
|
+
tryQuit() {
|
|
4934
|
+
if (this.state === 0 /* PLAYING */) {
|
|
4935
|
+
this.triggerLifecycleEvent("PAUSE" /* PAUSE */);
|
|
4936
|
+
this.state = 1 /* PAUSED */;
|
|
4937
|
+
}
|
|
4938
|
+
if (this.state === 1 /* PAUSED */) {
|
|
4939
|
+
this.triggerLifecycleEvent("SLEEP" /* SLEEP */);
|
|
4940
|
+
this.state = 2 /* SLEEPING */;
|
|
4941
|
+
}
|
|
4942
|
+
if (this.state === 2 /* SLEEPING */) {
|
|
4943
|
+
this.triggerLifecycleEvent("QUIT" /* QUIT */);
|
|
4944
|
+
this.state = 3 /* TERMINATED */;
|
|
4945
|
+
}
|
|
4946
|
+
}
|
|
4947
|
+
tryResume() {
|
|
4948
|
+
if (this.state === 1 /* PAUSED */) {
|
|
4949
|
+
this.triggerLifecycleEvent("RESUME" /* RESUME */);
|
|
4950
|
+
}
|
|
4951
|
+
}
|
|
4952
|
+
async showAdOverlay(type) {
|
|
4953
|
+
return new Promise((resolve, reject) => {
|
|
4954
|
+
const overlay = this._overlay;
|
|
4955
|
+
const adOverlay = overlay.adOverlay;
|
|
4956
|
+
overlay.adOverlay.innerHTML = "";
|
|
4957
|
+
const heading = document.createElement("h1");
|
|
4958
|
+
heading.style.cssText = `
|
|
4959
|
+
font-size: 24px;
|
|
4960
|
+
margin-bottom: 20px;
|
|
4961
|
+
text-align: center;
|
|
4962
|
+
`;
|
|
4963
|
+
heading.innerText = type === "interstitial" ? "INTERSTITIAL AD" : "REWARDED VIDEO AD";
|
|
4964
|
+
overlay.adOverlay.appendChild(heading);
|
|
4965
|
+
const content = document.createElement("div");
|
|
4966
|
+
content.style.cssText = `
|
|
4967
|
+
width: 300px;
|
|
4968
|
+
height: 250px;
|
|
4969
|
+
background-color: #1e40af;
|
|
4970
|
+
display: flex;
|
|
4971
|
+
align-items: center;
|
|
4972
|
+
justify-content: center;
|
|
4973
|
+
margin-bottom: 20px;
|
|
4974
|
+
border-radius: 8px;
|
|
4975
|
+
`;
|
|
4976
|
+
content.innerText = "Mock Ad Content";
|
|
4977
|
+
adOverlay.appendChild(content);
|
|
4978
|
+
const timer = document.createElement("p");
|
|
4979
|
+
timer.style.cssText = `
|
|
4980
|
+
margin-bottom: 20px;
|
|
4981
|
+
font-size: 16px;
|
|
4982
|
+
`;
|
|
4983
|
+
timer.innerText = "Normally ads would have a timer...";
|
|
4984
|
+
adOverlay.appendChild(timer);
|
|
4985
|
+
const okButton = document.createElement("button");
|
|
4986
|
+
okButton.style.cssText = `
|
|
4987
|
+
padding: 10px 40px;
|
|
4988
|
+
background-color: #2563eb;
|
|
4989
|
+
color: white;
|
|
4990
|
+
border: none;
|
|
4991
|
+
border-radius: 4px;
|
|
4992
|
+
font-size: 16px;
|
|
4993
|
+
cursor: pointer;
|
|
4994
|
+
`;
|
|
4995
|
+
okButton.innerText = "Close Ad";
|
|
4996
|
+
adOverlay.appendChild(okButton);
|
|
4997
|
+
adOverlay.style.display = "flex";
|
|
4998
|
+
okButton.onclick = () => {
|
|
4999
|
+
this.hideAdOverlay();
|
|
5000
|
+
resolve(true);
|
|
5001
|
+
};
|
|
5002
|
+
});
|
|
5003
|
+
}
|
|
5004
|
+
hideAdOverlay() {
|
|
5005
|
+
const overlay = this._overlay;
|
|
5006
|
+
if (overlay.adOverlay) {
|
|
5007
|
+
overlay.adOverlay.style.display = "none";
|
|
5008
|
+
}
|
|
5009
|
+
}
|
|
5010
|
+
setupActionSheetOverlay() {
|
|
5011
|
+
const actionSheetOverlay = document.createElement("div");
|
|
5012
|
+
actionSheetOverlay.id = "venus-action-sheet-overlay";
|
|
5013
|
+
actionSheetOverlay.style.cssText = `
|
|
5014
|
+
position: fixed;
|
|
5015
|
+
top: 0;
|
|
5016
|
+
left: 0;
|
|
5017
|
+
width: 100%;
|
|
5018
|
+
height: 100%;
|
|
5019
|
+
background-color: rgba(0, 0, 0, 0.5);
|
|
5020
|
+
display: flex;
|
|
5021
|
+
align-items: center;
|
|
5022
|
+
justify-content: center;
|
|
5023
|
+
z-index: 10600;
|
|
5024
|
+
font-family: sans-serif;
|
|
5025
|
+
display: none;
|
|
5026
|
+
`;
|
|
5027
|
+
document.body.appendChild(actionSheetOverlay);
|
|
5028
|
+
return actionSheetOverlay;
|
|
5029
|
+
}
|
|
5030
|
+
createOverlayButton(id, text, position, onClick, background, color) {
|
|
5031
|
+
const button = document.createElement("button");
|
|
5032
|
+
button.id = `venus-mock-${id}-button`;
|
|
5033
|
+
button.innerText = text;
|
|
5034
|
+
button.style.cssText = `
|
|
5035
|
+
position: absolute;
|
|
5036
|
+
left: ${position.x}px;
|
|
5037
|
+
top: ${position.y}px;
|
|
5038
|
+
width: ${position.width}px;
|
|
5039
|
+
min-width: ${position.width}px;
|
|
5040
|
+
height: ${position.height}px;
|
|
5041
|
+
background: ${background};
|
|
5042
|
+
color: ${color};
|
|
5043
|
+
border: none;
|
|
5044
|
+
border-radius: 8px;
|
|
5045
|
+
font-family: sans-serif;
|
|
5046
|
+
font-weight: bold;
|
|
5047
|
+
font-size: ${Math.min(position.width, position.height) / 3}px;
|
|
5048
|
+
cursor: pointer;
|
|
5049
|
+
pointer-events: auto;
|
|
5050
|
+
display: flex;
|
|
5051
|
+
align-items: center;
|
|
5052
|
+
justify-content: center;
|
|
5053
|
+
opacity: 0.9;
|
|
5054
|
+
transition: opacity 0.2s;
|
|
5055
|
+
`;
|
|
5056
|
+
button.addEventListener("click", onClick);
|
|
5057
|
+
button.addEventListener("mouseover", () => {
|
|
5058
|
+
button.style.opacity = "1";
|
|
5059
|
+
});
|
|
5060
|
+
button.addEventListener("mouseout", () => {
|
|
5061
|
+
button.style.opacity = "0.9";
|
|
5062
|
+
});
|
|
5063
|
+
return button;
|
|
5064
|
+
}
|
|
5065
|
+
updateOverlayLayout() {
|
|
5066
|
+
const venusApi = this.venusApi;
|
|
5067
|
+
const overlay = this._overlay;
|
|
5068
|
+
venusApi.config.ui.controls = this.updateUiControls();
|
|
5069
|
+
const uiControls = venusApi.config.ui.controls;
|
|
5070
|
+
const menuBtn = overlay.elements.menuButton;
|
|
5071
|
+
const menuPos = uiControls.menuButton;
|
|
5072
|
+
menuBtn.style.left = `${menuPos.x}px`;
|
|
5073
|
+
menuBtn.style.top = `${menuPos.y}px`;
|
|
5074
|
+
menuBtn.style.width = `${menuPos.width}px`;
|
|
5075
|
+
menuBtn.style.minWidth = `${menuPos.width}px`;
|
|
5076
|
+
menuBtn.style.height = `${menuPos.height}px`;
|
|
5077
|
+
}
|
|
5078
|
+
triggerLifecycleEvent(name) {
|
|
5079
|
+
console.log("Trigger Lifecycle Event: ", name);
|
|
5080
|
+
if (name == "PAUSE" /* PAUSE */) {
|
|
5081
|
+
this._mockLifecyclesApi.triggerPauseCallbacks();
|
|
5082
|
+
} else if (name == "RESUME" /* RESUME */) {
|
|
5083
|
+
this._mockLifecyclesApi.triggerResumeCallbacks();
|
|
5084
|
+
} else if (name == "QUIT" /* QUIT */) {
|
|
5085
|
+
this._mockLifecyclesApi.triggerQuitCallbacks();
|
|
5086
|
+
} else if (name == "AWAKE" /* AWAKE */) {
|
|
5087
|
+
this._mockLifecyclesApi.triggerAwakeCallbacks();
|
|
5088
|
+
} else if (name == "SLEEP" /* SLEEP */) {
|
|
5089
|
+
this._mockLifecyclesApi.triggerSleepCallbacks();
|
|
5090
|
+
}
|
|
5091
|
+
}
|
|
5092
|
+
setOverlayElementVisibility(element, visible) {
|
|
5093
|
+
const overlay = this._overlay;
|
|
5094
|
+
const elements = overlay.elements;
|
|
5095
|
+
if (elements[element]) {
|
|
5096
|
+
elements[element].style.display = visible ? "flex" : "none";
|
|
5097
|
+
}
|
|
5098
|
+
}
|
|
5099
|
+
setupAdOverlay() {
|
|
5100
|
+
const adOverlay = document.createElement("div");
|
|
5101
|
+
adOverlay.id = "venus-ad-overlay";
|
|
5102
|
+
adOverlay.style.cssText = `
|
|
5103
|
+
position: fixed;
|
|
5104
|
+
top: 0;
|
|
5105
|
+
left: 0;
|
|
5106
|
+
width: 100%;
|
|
5107
|
+
height: 100%;
|
|
5108
|
+
background-color: rgba(37, 99, 235, 0.9);
|
|
5109
|
+
color: white;
|
|
5110
|
+
display: flex;
|
|
5111
|
+
flex-direction: column;
|
|
5112
|
+
align-items: center;
|
|
5113
|
+
justify-content: center;
|
|
5114
|
+
z-index: 10500;
|
|
5115
|
+
font-family: sans-serif;
|
|
5116
|
+
display: none;
|
|
5117
|
+
`;
|
|
5118
|
+
document.body.appendChild(adOverlay);
|
|
5119
|
+
return adOverlay;
|
|
5120
|
+
}
|
|
5121
|
+
log(msg, ...args) {
|
|
5122
|
+
console.log(`[Venus Mock] ${msg}`, ...args);
|
|
5123
|
+
}
|
|
5124
|
+
showActionSheetOverlay(items, options) {
|
|
5125
|
+
this.log("Showing ActionSheetOverlay...");
|
|
5126
|
+
return new Promise((resolve, reject) => {
|
|
5127
|
+
const overlay = this._overlay;
|
|
5128
|
+
overlay.actionSheetOverlay.innerHTML = "";
|
|
5129
|
+
overlay.actionSheetOverlay.style.display = "flex";
|
|
5130
|
+
const actionSheet = document.createElement("div");
|
|
5131
|
+
actionSheet.className = "venus-action-sheet";
|
|
5132
|
+
actionSheet.style.cssText = `
|
|
5133
|
+
background-color: white;
|
|
5134
|
+
border-radius: 8px;
|
|
5135
|
+
width: 80%;
|
|
5136
|
+
max-width: 400px;
|
|
5137
|
+
max-height: 80%;
|
|
5138
|
+
display: flex;
|
|
5139
|
+
flex-direction: column;
|
|
5140
|
+
overflow: hidden;
|
|
5141
|
+
color: black;
|
|
5142
|
+
`;
|
|
5143
|
+
if (options?.title) {
|
|
5144
|
+
const titleContainer = document.createElement("div");
|
|
5145
|
+
titleContainer.style.cssText = `
|
|
5146
|
+
padding: 16px;
|
|
5147
|
+
border-bottom: 1px solid #eaeaea;
|
|
5148
|
+
font-weight: bold;
|
|
5149
|
+
font-size: 18px;
|
|
5150
|
+
text-align: center;
|
|
5151
|
+
color: black;
|
|
5152
|
+
`;
|
|
5153
|
+
titleContainer.innerText = options.title;
|
|
5154
|
+
actionSheet.appendChild(titleContainer);
|
|
5155
|
+
}
|
|
5156
|
+
if (options?.message) {
|
|
5157
|
+
const messageContainer = document.createElement("div");
|
|
5158
|
+
messageContainer.style.cssText = `
|
|
5159
|
+
padding: 8px 16px;
|
|
5160
|
+
color: #666;
|
|
5161
|
+
font-size: 14px;
|
|
5162
|
+
text-align: center;
|
|
5163
|
+
`;
|
|
5164
|
+
messageContainer.innerText = options.message;
|
|
5165
|
+
actionSheet.appendChild(messageContainer);
|
|
5166
|
+
}
|
|
5167
|
+
const optionsContainer = document.createElement("div");
|
|
5168
|
+
optionsContainer.style.cssText = `
|
|
5169
|
+
overflow-y: auto;
|
|
5170
|
+
max-height: 300px;
|
|
5171
|
+
`;
|
|
5172
|
+
items.forEach((item, index) => {
|
|
5173
|
+
const optionItem = document.createElement("div");
|
|
5174
|
+
optionItem.style.cssText = `
|
|
5175
|
+
padding: 12px 16px;
|
|
5176
|
+
border-bottom: 1px solid #eaeaea;
|
|
5177
|
+
cursor: pointer;
|
|
5178
|
+
display: flex;
|
|
5179
|
+
align-items: center;
|
|
5180
|
+
transition: background-color 0.2s;
|
|
5181
|
+
color: black;
|
|
5182
|
+
`;
|
|
5183
|
+
optionItem.addEventListener("mouseover", () => {
|
|
5184
|
+
optionItem.style.backgroundColor = "#f5f5f5";
|
|
5185
|
+
});
|
|
5186
|
+
optionItem.addEventListener("mouseout", () => {
|
|
5187
|
+
optionItem.style.backgroundColor = "white";
|
|
5188
|
+
});
|
|
5189
|
+
if (item.icon) {
|
|
5190
|
+
const iconSpan = document.createElement("span");
|
|
5191
|
+
iconSpan.style.cssText = `
|
|
5192
|
+
margin-right: 12px;
|
|
5193
|
+
font-size: 16px;
|
|
5194
|
+
`;
|
|
5195
|
+
iconSpan.innerText = item.icon;
|
|
5196
|
+
optionItem.appendChild(iconSpan);
|
|
5197
|
+
}
|
|
5198
|
+
const labelSpan = document.createElement("span");
|
|
5199
|
+
labelSpan.style.cssText = `
|
|
5200
|
+
color: black;
|
|
5201
|
+
`;
|
|
5202
|
+
labelSpan.innerText = item.label;
|
|
5203
|
+
optionItem.appendChild(labelSpan);
|
|
5204
|
+
optionItem.addEventListener("click", () => {
|
|
5205
|
+
this.hideActionSheetOverlay();
|
|
5206
|
+
const optionId = item.id !== void 0 ? item.id : index;
|
|
5207
|
+
resolve(optionId);
|
|
5208
|
+
});
|
|
5209
|
+
optionsContainer.appendChild(optionItem);
|
|
5210
|
+
});
|
|
5211
|
+
actionSheet.appendChild(optionsContainer);
|
|
5212
|
+
if (!options?.disableCancel) {
|
|
5213
|
+
const cancelButton = document.createElement("div");
|
|
5214
|
+
cancelButton.style.cssText = `
|
|
5215
|
+
padding: 14px 16px;
|
|
5216
|
+
text-align: center;
|
|
5217
|
+
font-weight: bold;
|
|
5218
|
+
cursor: pointer;
|
|
5219
|
+
color: #3b82f6;
|
|
5220
|
+
border-top: 1px solid #eaeaea;
|
|
5221
|
+
`;
|
|
5222
|
+
cancelButton.innerText = options?.cancelButtonText || "Cancel";
|
|
5223
|
+
cancelButton.addEventListener("click", () => {
|
|
5224
|
+
this.hideActionSheetOverlay();
|
|
5225
|
+
resolve(null);
|
|
5226
|
+
});
|
|
5227
|
+
actionSheet.appendChild(cancelButton);
|
|
5228
|
+
}
|
|
5229
|
+
if (!options?.disableCancel) {
|
|
5230
|
+
const closeButton = document.createElement("div");
|
|
5231
|
+
closeButton.style.cssText = `
|
|
5232
|
+
position: absolute;
|
|
5233
|
+
top: 8px;
|
|
5234
|
+
right: 8px;
|
|
5235
|
+
width: 24px;
|
|
5236
|
+
height: 24px;
|
|
5237
|
+
border-radius: 12px;
|
|
5238
|
+
background-color: rgba(0,0,0,0.1);
|
|
5239
|
+
color: #666;
|
|
5240
|
+
display: flex;
|
|
5241
|
+
align-items: center;
|
|
5242
|
+
justify-content: center;
|
|
5243
|
+
cursor: pointer;
|
|
5244
|
+
font-size: 14px;
|
|
5245
|
+
`;
|
|
5246
|
+
closeButton.innerText = "\u2715";
|
|
5247
|
+
closeButton.addEventListener("click", () => {
|
|
5248
|
+
this.hideActionSheetOverlay();
|
|
5249
|
+
resolve(null);
|
|
5250
|
+
});
|
|
5251
|
+
actionSheet.appendChild(closeButton);
|
|
5252
|
+
overlay.actionSheetOverlay.appendChild(actionSheet);
|
|
5253
|
+
}
|
|
5254
|
+
});
|
|
5255
|
+
}
|
|
5256
|
+
hideActionSheetOverlay() {
|
|
5257
|
+
const overlay = this._overlay;
|
|
5258
|
+
if (overlay.actionSheetOverlay) {
|
|
5259
|
+
overlay.actionSheetOverlay.style.display = "none";
|
|
5260
|
+
}
|
|
5261
|
+
}
|
|
5262
|
+
};
|
|
5263
|
+
|
|
5264
|
+
// src/Host.ts
|
|
5265
|
+
function createHost(venusApi, isMock) {
|
|
5266
|
+
if (isMock) {
|
|
5267
|
+
console.log("[Venus SDK] Creating Local Host");
|
|
5268
|
+
return new MockHost(venusApi);
|
|
5269
|
+
} else {
|
|
5270
|
+
console.log("[Venus SDK] Creating Remote Host");
|
|
5271
|
+
return new RemoteHost(venusApi);
|
|
5272
|
+
}
|
|
5273
|
+
}
|
|
5274
|
+
|
|
5275
|
+
// src/social/index.ts
|
|
5276
|
+
function initializeSocial(venusApi, host) {
|
|
5277
|
+
venusApi.social = host.social;
|
|
5278
|
+
venusApi.getLaunchParams = () => {
|
|
5279
|
+
return venusApi.launchParams || {};
|
|
5280
|
+
};
|
|
5281
|
+
}
|
|
5282
|
+
|
|
5283
|
+
export { HapticFeedbackStyle, HostCdnApi, HostProfileApi, HostTimeApi, MockAdsApi, MockAiApi, MockAnalyticsApi, MockAvatarApi, MockCdnApi, MockFeaturesApi, MockHapticsApi, MockIapApi, MockLeaderboardApi, MockLifecycleApi, MockLoggingApi, MockNavigationApi, MockNotificationsApi, MockPopupsApi, MockPreloaderApi, MockProfileApi, MockSharedAssetsApi, MockSimulationApi, MockSocialApi, MockStorageApi, MockTimeApi, RemoteHost, RpcAdsApi, RpcAiApi, RpcAnalyticsApi, RpcAvatarApi, RpcClient, RpcFeaturesApi, RpcHapticsApi, RpcIapApi, RpcLeaderboardApi, RpcLifecycleApi, RpcLoggingApi, RpcNavigationApi, RpcNotificationsApi, RpcPopupsApi, RpcPreloaderApi, RpcSharedAssetsApi, RpcSimulationApi, RpcSocialApi, RpcStorageApi, SDK_VERSION, VenusMessageId, VenusRoom, createHost, createMockStorageApi, init_rooms, initializeAds, initializeAi, initializeAnalytics, initializeAvatar3d, initializeCdn, initializeFeaturesApi, initializeHaptics, initializeIap, initializeLeaderboard, initializeLifecycleApi, initializeLocalNotifications, initializeLoggingApi, initializePopups, initializePost, initializePreloader, initializeProfile, initializeRoomsApi, initializeSimulation, initializeSocial, initializeStackNavigation, initializeStorage, initializeTime, isPacificDaylightTime, setupRoomNotifications };
|
|
5284
|
+
//# sourceMappingURL=chunk-6DYG4RFQ.mjs.map
|
|
5285
|
+
//# sourceMappingURL=chunk-6DYG4RFQ.mjs.map
|