@series-inc/venus-sdk 2.6.2 → 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 +131 -95
- package/dist/{AdsApi-C_GcWmfO.d.mts → AdsApi-3DEYUUuj.d.mts} +529 -60
- package/dist/{AdsApi-C_GcWmfO.d.ts → AdsApi-3DEYUUuj.d.ts} +529 -60
- package/dist/{chunk-YDXFZ2A2.mjs → chunk-6DYG4RFQ.mjs} +1725 -106
- package/dist/chunk-6DYG4RFQ.mjs.map +1 -0
- package/dist/index.cjs +1987 -330
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +208 -359
- package/dist/index.d.ts +208 -359
- package/dist/index.mjs +2 -2
- package/dist/index.mjs.map +1 -1
- package/dist/venus-api/index.cjs +511 -306
- 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 +12 -1422
- package/dist/venus-api/index.mjs.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-YDXFZ2A2.mjs.map +0 -1
package/dist/venus-api/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { init_rooms,
|
|
2
|
-
import { createProxiedObject, createProxiedMethod
|
|
1
|
+
import { init_rooms, SDK_VERSION, createHost, initializeStorage, initializeRoomsApi, initializeAds, initializePopups, initializeAnalytics, initializeIap, initializeLeaderboard, initializeLocalNotifications, initializePreloader, initializeTime, initializeLifecycleApi, initializeHaptics, initializeCdn, initializeFeaturesApi, initializeLoggingApi, initializeProfile, initializeAvatar3d, initializeStackNavigation, initializePost, initializeAi, initializeSimulation, initializeSocial } from '../chunk-6DYG4RFQ.mjs';
|
|
2
|
+
import { createProxiedObject, createProxiedMethod } from '../chunk-W7IPHM67.mjs';
|
|
3
3
|
|
|
4
4
|
// src/venus-api/systems/theme.js
|
|
5
5
|
var DEFAULT_TYPOGRAPHY = {
|
|
@@ -1955,1347 +1955,6 @@ async function initializeNumbers(venusApiInstance) {
|
|
|
1955
1955
|
);
|
|
1956
1956
|
}
|
|
1957
1957
|
|
|
1958
|
-
// src/post/MockPostApi.ts
|
|
1959
|
-
var MockPostApi = class {
|
|
1960
|
-
constructor(venusApi) {
|
|
1961
|
-
__publicField(this, "venusApi");
|
|
1962
|
-
this.venusApi = venusApi;
|
|
1963
|
-
}
|
|
1964
|
-
async getPostInfo() {
|
|
1965
|
-
const venusApi = this.venusApi;
|
|
1966
|
-
await createMockDelay(MOCK_DELAYS.short);
|
|
1967
|
-
return venusApi._mock.currentPostInteractions;
|
|
1968
|
-
}
|
|
1969
|
-
async openCommentsAsync() {
|
|
1970
|
-
await createMockDelay(MOCK_DELAYS.short);
|
|
1971
|
-
return {
|
|
1972
|
-
opened: true,
|
|
1973
|
-
commentsCount: 0
|
|
1974
|
-
};
|
|
1975
|
-
}
|
|
1976
|
-
async sharePostAsync(context) {
|
|
1977
|
-
console.log("[Venus Mock] Sharing post with additionalInfo:", context);
|
|
1978
|
-
await createMockDelay(MOCK_DELAYS.short);
|
|
1979
|
-
return {
|
|
1980
|
-
shared: true,
|
|
1981
|
-
platform: "mock"
|
|
1982
|
-
};
|
|
1983
|
-
}
|
|
1984
|
-
async toggleFollowAsync() {
|
|
1985
|
-
const venusApi = this.venusApi;
|
|
1986
|
-
console.log("[Venus Mock] *Toggling follow status");
|
|
1987
|
-
await createMockDelay(MOCK_DELAYS.short);
|
|
1988
|
-
venusApi._mock.currentPostInteractions.isFollowing = !venusApi._mock.currentPostInteractions.isFollowing;
|
|
1989
|
-
const isFollowing = venusApi._mock.currentPostInteractions.isFollowing;
|
|
1990
|
-
return {
|
|
1991
|
-
isFollowing,
|
|
1992
|
-
action: isFollowing ? "followed" : "unfollowed"
|
|
1993
|
-
};
|
|
1994
|
-
}
|
|
1995
|
-
async toggleLikeAsync() {
|
|
1996
|
-
const venusApi = this.venusApi;
|
|
1997
|
-
await createMockDelay(MOCK_DELAYS.short);
|
|
1998
|
-
venusApi._mock.currentPostInteractions.isLiked = !venusApi._mock.currentPostInteractions.isLiked;
|
|
1999
|
-
const isLiked = venusApi._mock.currentPostInteractions.isLiked;
|
|
2000
|
-
if (isLiked) {
|
|
2001
|
-
venusApi._mock.currentPostInteractions.likesCount++;
|
|
2002
|
-
} else {
|
|
2003
|
-
venusApi._mock.currentPostInteractions.likesCount = Math.max(
|
|
2004
|
-
0,
|
|
2005
|
-
venusApi._mock.currentPostInteractions.likesCount - 1
|
|
2006
|
-
);
|
|
2007
|
-
}
|
|
2008
|
-
return {
|
|
2009
|
-
isLiked,
|
|
2010
|
-
likesCount: venusApi._mock.currentPostInteractions.likesCount,
|
|
2011
|
-
action: isLiked ? "liked" : "unliked"
|
|
2012
|
-
};
|
|
2013
|
-
}
|
|
2014
|
-
};
|
|
2015
|
-
|
|
2016
|
-
// src/post/RpcPostApi.ts
|
|
2017
|
-
var RpcPostApi = class {
|
|
2018
|
-
constructor(rpcClient) {
|
|
2019
|
-
__publicField(this, "rpcClient");
|
|
2020
|
-
this.rpcClient = rpcClient;
|
|
2021
|
-
}
|
|
2022
|
-
getPostInfo() {
|
|
2023
|
-
return this.rpcClient.call("H5_GET_POST_INTERACTIONS" /* GET_POST_INTERACTIONS */, {});
|
|
2024
|
-
}
|
|
2025
|
-
openCommentsAsync() {
|
|
2026
|
-
return this.rpcClient.call("H5_OPEN_COMMENTS" /* OPEN_COMMENTS */, {});
|
|
2027
|
-
}
|
|
2028
|
-
sharePostAsync(context) {
|
|
2029
|
-
return this.rpcClient.call("H5_SHARE_POST" /* SHARE_POST */, {
|
|
2030
|
-
shareContext: context
|
|
2031
|
-
});
|
|
2032
|
-
}
|
|
2033
|
-
toggleFollowAsync() {
|
|
2034
|
-
return this.rpcClient.call(
|
|
2035
|
-
"H5_TOGGLE_FOLLOW" /* TOGGLE_FOLLOW */,
|
|
2036
|
-
{}
|
|
2037
|
-
);
|
|
2038
|
-
}
|
|
2039
|
-
toggleLikeAsync() {
|
|
2040
|
-
return this.rpcClient.call("H5_TOGGLE_LIKE" /* TOGGLE_LIKE */, {});
|
|
2041
|
-
}
|
|
2042
|
-
};
|
|
2043
|
-
|
|
2044
|
-
// src/post/index.ts
|
|
2045
|
-
function initializePost(venusApi, host) {
|
|
2046
|
-
venusApi.getPostInteractionsAsync = () => {
|
|
2047
|
-
return host.post.getPostInfo();
|
|
2048
|
-
};
|
|
2049
|
-
venusApi.toggleFollowAsync = () => {
|
|
2050
|
-
return host.post.toggleFollowAsync();
|
|
2051
|
-
};
|
|
2052
|
-
venusApi.toggleLikeAsync = () => {
|
|
2053
|
-
return host.post.toggleLikeAsync();
|
|
2054
|
-
};
|
|
2055
|
-
venusApi.sharePostAsync = async (options) => {
|
|
2056
|
-
await host.post.sharePostAsync(options);
|
|
2057
|
-
};
|
|
2058
|
-
venusApi.openCommentsAsync = async () => {
|
|
2059
|
-
await host.post.openCommentsAsync();
|
|
2060
|
-
};
|
|
2061
|
-
}
|
|
2062
|
-
|
|
2063
|
-
// src/MockHost.ts
|
|
2064
|
-
init_rooms();
|
|
2065
|
-
var ROOMS_UNAVAILABLE_MESSAGE = "[Venus SDK] Rooms API is only available when running inside the Venus host environment.";
|
|
2066
|
-
function createUnavailableRoomsApi() {
|
|
2067
|
-
const roomsUnavailableError = () => new Error(ROOMS_UNAVAILABLE_MESSAGE);
|
|
2068
|
-
return {
|
|
2069
|
-
async createRoom() {
|
|
2070
|
-
throw roomsUnavailableError();
|
|
2071
|
-
},
|
|
2072
|
-
async joinOrCreateRoom() {
|
|
2073
|
-
throw roomsUnavailableError();
|
|
2074
|
-
},
|
|
2075
|
-
async getUserRooms() {
|
|
2076
|
-
throw roomsUnavailableError();
|
|
2077
|
-
},
|
|
2078
|
-
async joinRoomByCode() {
|
|
2079
|
-
throw roomsUnavailableError();
|
|
2080
|
-
},
|
|
2081
|
-
subscribe() {
|
|
2082
|
-
throw roomsUnavailableError();
|
|
2083
|
-
},
|
|
2084
|
-
async updateData() {
|
|
2085
|
-
throw roomsUnavailableError();
|
|
2086
|
-
},
|
|
2087
|
-
async getData() {
|
|
2088
|
-
throw roomsUnavailableError();
|
|
2089
|
-
},
|
|
2090
|
-
async sendMessage() {
|
|
2091
|
-
throw roomsUnavailableError();
|
|
2092
|
-
},
|
|
2093
|
-
async leave() {
|
|
2094
|
-
throw roomsUnavailableError();
|
|
2095
|
-
},
|
|
2096
|
-
async startGame() {
|
|
2097
|
-
throw roomsUnavailableError();
|
|
2098
|
-
},
|
|
2099
|
-
async proposeMove() {
|
|
2100
|
-
throw roomsUnavailableError();
|
|
2101
|
-
},
|
|
2102
|
-
async validateMove() {
|
|
2103
|
-
throw roomsUnavailableError();
|
|
2104
|
-
}
|
|
2105
|
-
};
|
|
2106
|
-
}
|
|
2107
|
-
var MockHost = class {
|
|
2108
|
-
constructor(venusApi) {
|
|
2109
|
-
__publicField(this, "ads");
|
|
2110
|
-
__publicField(this, "analytics");
|
|
2111
|
-
__publicField(this, "deviceCache");
|
|
2112
|
-
__publicField(this, "appStorage");
|
|
2113
|
-
__publicField(this, "globalStorage");
|
|
2114
|
-
__publicField(this, "avatar3d");
|
|
2115
|
-
__publicField(this, "navigation");
|
|
2116
|
-
__publicField(this, "notifications");
|
|
2117
|
-
__publicField(this, "popups");
|
|
2118
|
-
__publicField(this, "profile");
|
|
2119
|
-
__publicField(this, "cdn");
|
|
2120
|
-
__publicField(this, "time");
|
|
2121
|
-
__publicField(this, "post");
|
|
2122
|
-
__publicField(this, "ai");
|
|
2123
|
-
__publicField(this, "haptics");
|
|
2124
|
-
__publicField(this, "features");
|
|
2125
|
-
__publicField(this, "lifecycle");
|
|
2126
|
-
__publicField(this, "simulation");
|
|
2127
|
-
__publicField(this, "rooms");
|
|
2128
|
-
__publicField(this, "logging");
|
|
2129
|
-
__publicField(this, "iap");
|
|
2130
|
-
__publicField(this, "preloader");
|
|
2131
|
-
__publicField(this, "state", 0 /* PLAYING */);
|
|
2132
|
-
__publicField(this, "venusApi");
|
|
2133
|
-
__publicField(this, "_isInitialized", false);
|
|
2134
|
-
__publicField(this, "_overlay");
|
|
2135
|
-
__publicField(this, "_mockLifecyclesApi");
|
|
2136
|
-
__publicField(this, "_mockAdsApi");
|
|
2137
|
-
this.venusApi = venusApi;
|
|
2138
|
-
this._overlay = this.createOverlay();
|
|
2139
|
-
this._mockAdsApi = new MockAdsApi(this._overlay);
|
|
2140
|
-
this._mockLifecyclesApi = new MockLifecycleApi();
|
|
2141
|
-
this.ads = this._mockAdsApi;
|
|
2142
|
-
this.analytics = new MockAnalyticsApi();
|
|
2143
|
-
const appUrl = typeof window !== "undefined" ? window.location.href : "";
|
|
2144
|
-
this.deviceCache = createMockStorageApi("deviceCache", appUrl);
|
|
2145
|
-
this.appStorage = createMockStorageApi("appStorage", appUrl);
|
|
2146
|
-
this.globalStorage = createMockStorageApi("globalStorage");
|
|
2147
|
-
this.avatar3d = new MockAvatarApi(venusApi);
|
|
2148
|
-
this.navigation = new MockNavigationApi(venusApi);
|
|
2149
|
-
this.notifications = new MockNotificationsApi(venusApi);
|
|
2150
|
-
this.popups = new MockPopupsApi(this._overlay);
|
|
2151
|
-
this.profile = new MockProfileApi();
|
|
2152
|
-
this.cdn = new MockCdnApi();
|
|
2153
|
-
this.time = new MockTimeApi(venusApi);
|
|
2154
|
-
this.post = new MockPostApi(venusApi);
|
|
2155
|
-
this.ai = new MockAiApi();
|
|
2156
|
-
this.haptics = new MockHapticsApi(venusApi);
|
|
2157
|
-
this.features = new MockFeaturesApi();
|
|
2158
|
-
this.lifecycle = this._mockLifecyclesApi;
|
|
2159
|
-
this.simulation = new MockSimulationApi();
|
|
2160
|
-
this.rooms = createUnavailableRoomsApi();
|
|
2161
|
-
this.logging = new MockLoggingApi();
|
|
2162
|
-
this.iap = new MockIapApi();
|
|
2163
|
-
initializeRoomsApi(this.venusApi, this);
|
|
2164
|
-
this.preloader = new MockPreloaderApi();
|
|
2165
|
-
venusApi.isMock = () => true;
|
|
2166
|
-
this.venusApi.sharedAssets = new MockSharedAssetsApi(this.venusApi);
|
|
2167
|
-
}
|
|
2168
|
-
get isInitialized() {
|
|
2169
|
-
return this._isInitialized;
|
|
2170
|
-
}
|
|
2171
|
-
async initialize(options = {}) {
|
|
2172
|
-
this._isInitialized = true;
|
|
2173
|
-
}
|
|
2174
|
-
updateUiControls() {
|
|
2175
|
-
const controls = {
|
|
2176
|
-
closeButton: { x: 16, y: 16, width: 32, height: 32 },
|
|
2177
|
-
menuButton: {
|
|
2178
|
-
x: window.innerWidth - 48,
|
|
2179
|
-
y: 16,
|
|
2180
|
-
width: 32,
|
|
2181
|
-
height: 32
|
|
2182
|
-
},
|
|
2183
|
-
feedHeader: { x: 0, y: 0, width: window.innerWidth, height: 56 },
|
|
2184
|
-
playButton: {
|
|
2185
|
-
x: 0,
|
|
2186
|
-
y: window.innerHeight - 60,
|
|
2187
|
-
width: window.innerWidth,
|
|
2188
|
-
height: 60
|
|
2189
|
-
}
|
|
2190
|
-
};
|
|
2191
|
-
return controls;
|
|
2192
|
-
}
|
|
2193
|
-
createOverlay() {
|
|
2194
|
-
const venusApi = this.venusApi;
|
|
2195
|
-
venusApi.config.ui.controls = this.updateUiControls();
|
|
2196
|
-
const uiControls = venusApi.config.ui.controls;
|
|
2197
|
-
const overlayContainer = document.createElement("div");
|
|
2198
|
-
overlayContainer.id = "venus-mock-overlay";
|
|
2199
|
-
overlayContainer.style.cssText = `
|
|
2200
|
-
position: fixed;
|
|
2201
|
-
top: 0;
|
|
2202
|
-
left: 0;
|
|
2203
|
-
width: 100%;
|
|
2204
|
-
height: 100%;
|
|
2205
|
-
pointer-events: none;
|
|
2206
|
-
z-index: 10000;
|
|
2207
|
-
`;
|
|
2208
|
-
document.body.appendChild(overlayContainer);
|
|
2209
|
-
const menuButton = this.createOverlayButton(
|
|
2210
|
-
"close",
|
|
2211
|
-
"Menu",
|
|
2212
|
-
uiControls.menuButton,
|
|
2213
|
-
() => {
|
|
2214
|
-
this.handleMenuButtonClicked();
|
|
2215
|
-
},
|
|
2216
|
-
"rgba(59, 130, 246, 0.7)",
|
|
2217
|
-
// Blue background instead of black
|
|
2218
|
-
"#FFFFFF"
|
|
2219
|
-
);
|
|
2220
|
-
overlayContainer.appendChild(menuButton);
|
|
2221
|
-
const adOverlay = this.setupAdOverlay();
|
|
2222
|
-
const actionSheet = this.setupActionSheetOverlay();
|
|
2223
|
-
window.addEventListener("resize", () => {
|
|
2224
|
-
this.updateOverlayLayout();
|
|
2225
|
-
});
|
|
2226
|
-
return {
|
|
2227
|
-
container: overlayContainer,
|
|
2228
|
-
elements: {
|
|
2229
|
-
menuButton
|
|
2230
|
-
},
|
|
2231
|
-
appVisibilityState: "visible",
|
|
2232
|
-
actionSheetOverlay: actionSheet,
|
|
2233
|
-
adOverlay,
|
|
2234
|
-
showAdOverlay: () => {
|
|
2235
|
-
return this.showAdOverlay("REWARDED VIDEO AD");
|
|
2236
|
-
},
|
|
2237
|
-
showActionSheet: (items, options) => {
|
|
2238
|
-
return this.showActionSheetOverlay(items, options);
|
|
2239
|
-
}
|
|
2240
|
-
};
|
|
2241
|
-
}
|
|
2242
|
-
async handleMenuButtonClicked() {
|
|
2243
|
-
this.triggerLifecycleEvent("PAUSE" /* PAUSE */);
|
|
2244
|
-
const sleepAwakeToggleAction = {
|
|
2245
|
-
label: "\u23F0 Awake",
|
|
2246
|
-
id: "sleepAwakeToggle"
|
|
2247
|
-
};
|
|
2248
|
-
if (this.state === 1 /* PAUSED */) {
|
|
2249
|
-
sleepAwakeToggleAction.label = "\u{1F4A4} Sleep";
|
|
2250
|
-
}
|
|
2251
|
-
const action = await this.showActionSheetOverlay([sleepAwakeToggleAction]);
|
|
2252
|
-
if (action === sleepAwakeToggleAction.id) {
|
|
2253
|
-
if (this.state === 1 /* PAUSED */) {
|
|
2254
|
-
this.state = 2 /* SLEEPING */;
|
|
2255
|
-
this.triggerLifecycleEvent("HIDDEN" /* HIDDEN */);
|
|
2256
|
-
} else {
|
|
2257
|
-
this.state = 1 /* PAUSED */;
|
|
2258
|
-
this.triggerLifecycleEvent("SHOWN" /* SHOWN */);
|
|
2259
|
-
}
|
|
2260
|
-
} else {
|
|
2261
|
-
if (this.state === 1 /* PAUSED */) {
|
|
2262
|
-
this.triggerLifecycleEvent("RESUME" /* RESUME */);
|
|
2263
|
-
}
|
|
2264
|
-
}
|
|
2265
|
-
}
|
|
2266
|
-
async showAdOverlay(type) {
|
|
2267
|
-
return new Promise((resolve, reject) => {
|
|
2268
|
-
const overlay = this._overlay;
|
|
2269
|
-
const adOverlay = overlay.adOverlay;
|
|
2270
|
-
overlay.adOverlay.innerHTML = "";
|
|
2271
|
-
const heading = document.createElement("h1");
|
|
2272
|
-
heading.style.cssText = `
|
|
2273
|
-
font-size: 24px;
|
|
2274
|
-
margin-bottom: 20px;
|
|
2275
|
-
text-align: center;
|
|
2276
|
-
`;
|
|
2277
|
-
heading.innerText = type === "interstitial" ? "INTERSTITIAL AD" : "REWARDED VIDEO AD";
|
|
2278
|
-
overlay.adOverlay.appendChild(heading);
|
|
2279
|
-
const content = document.createElement("div");
|
|
2280
|
-
content.style.cssText = `
|
|
2281
|
-
width: 300px;
|
|
2282
|
-
height: 250px;
|
|
2283
|
-
background-color: #1e40af;
|
|
2284
|
-
display: flex;
|
|
2285
|
-
align-items: center;
|
|
2286
|
-
justify-content: center;
|
|
2287
|
-
margin-bottom: 20px;
|
|
2288
|
-
border-radius: 8px;
|
|
2289
|
-
`;
|
|
2290
|
-
content.innerText = "Mock Ad Content";
|
|
2291
|
-
adOverlay.appendChild(content);
|
|
2292
|
-
const timer = document.createElement("p");
|
|
2293
|
-
timer.style.cssText = `
|
|
2294
|
-
margin-bottom: 20px;
|
|
2295
|
-
font-size: 16px;
|
|
2296
|
-
`;
|
|
2297
|
-
timer.innerText = "Normally ads would have a timer...";
|
|
2298
|
-
adOverlay.appendChild(timer);
|
|
2299
|
-
const okButton = document.createElement("button");
|
|
2300
|
-
okButton.style.cssText = `
|
|
2301
|
-
padding: 10px 40px;
|
|
2302
|
-
background-color: #2563eb;
|
|
2303
|
-
color: white;
|
|
2304
|
-
border: none;
|
|
2305
|
-
border-radius: 4px;
|
|
2306
|
-
font-size: 16px;
|
|
2307
|
-
cursor: pointer;
|
|
2308
|
-
`;
|
|
2309
|
-
okButton.innerText = "Close Ad";
|
|
2310
|
-
adOverlay.appendChild(okButton);
|
|
2311
|
-
adOverlay.style.display = "flex";
|
|
2312
|
-
okButton.onclick = () => {
|
|
2313
|
-
this.hideAdOverlay();
|
|
2314
|
-
resolve(true);
|
|
2315
|
-
};
|
|
2316
|
-
});
|
|
2317
|
-
}
|
|
2318
|
-
hideAdOverlay() {
|
|
2319
|
-
const overlay = this._overlay;
|
|
2320
|
-
if (overlay.adOverlay) {
|
|
2321
|
-
overlay.adOverlay.style.display = "none";
|
|
2322
|
-
}
|
|
2323
|
-
}
|
|
2324
|
-
setupActionSheetOverlay() {
|
|
2325
|
-
const actionSheetOverlay = document.createElement("div");
|
|
2326
|
-
actionSheetOverlay.id = "venus-action-sheet-overlay";
|
|
2327
|
-
actionSheetOverlay.style.cssText = `
|
|
2328
|
-
position: fixed;
|
|
2329
|
-
top: 0;
|
|
2330
|
-
left: 0;
|
|
2331
|
-
width: 100%;
|
|
2332
|
-
height: 100%;
|
|
2333
|
-
background-color: rgba(0, 0, 0, 0.5);
|
|
2334
|
-
display: flex;
|
|
2335
|
-
align-items: center;
|
|
2336
|
-
justify-content: center;
|
|
2337
|
-
z-index: 10600;
|
|
2338
|
-
font-family: sans-serif;
|
|
2339
|
-
display: none;
|
|
2340
|
-
`;
|
|
2341
|
-
document.body.appendChild(actionSheetOverlay);
|
|
2342
|
-
return actionSheetOverlay;
|
|
2343
|
-
}
|
|
2344
|
-
createOverlayButton(id, text, position, onClick, background, color) {
|
|
2345
|
-
const button = document.createElement("button");
|
|
2346
|
-
button.id = `venus-mock-${id}-button`;
|
|
2347
|
-
button.innerText = text;
|
|
2348
|
-
button.style.cssText = `
|
|
2349
|
-
position: absolute;
|
|
2350
|
-
left: ${position.x}px;
|
|
2351
|
-
top: ${position.y}px;
|
|
2352
|
-
width: ${position.width}px;
|
|
2353
|
-
min-width: ${position.width}px;
|
|
2354
|
-
height: ${position.height}px;
|
|
2355
|
-
background: ${background};
|
|
2356
|
-
color: ${color};
|
|
2357
|
-
border: none;
|
|
2358
|
-
border-radius: 8px;
|
|
2359
|
-
font-family: sans-serif;
|
|
2360
|
-
font-weight: bold;
|
|
2361
|
-
font-size: ${Math.min(position.width, position.height) / 3}px;
|
|
2362
|
-
cursor: pointer;
|
|
2363
|
-
pointer-events: auto;
|
|
2364
|
-
display: flex;
|
|
2365
|
-
align-items: center;
|
|
2366
|
-
justify-content: center;
|
|
2367
|
-
opacity: 0.9;
|
|
2368
|
-
transition: opacity 0.2s;
|
|
2369
|
-
`;
|
|
2370
|
-
button.addEventListener("click", onClick);
|
|
2371
|
-
button.addEventListener("mouseover", () => {
|
|
2372
|
-
button.style.opacity = "1";
|
|
2373
|
-
});
|
|
2374
|
-
button.addEventListener("mouseout", () => {
|
|
2375
|
-
button.style.opacity = "0.9";
|
|
2376
|
-
});
|
|
2377
|
-
return button;
|
|
2378
|
-
}
|
|
2379
|
-
updateOverlayLayout() {
|
|
2380
|
-
const venusApi = this.venusApi;
|
|
2381
|
-
const overlay = this._overlay;
|
|
2382
|
-
venusApi.config.ui.controls = this.updateUiControls();
|
|
2383
|
-
const uiControls = venusApi.config.ui.controls;
|
|
2384
|
-
const menuBtn = overlay.elements.menuButton;
|
|
2385
|
-
const menuPos = uiControls.menuButton;
|
|
2386
|
-
menuBtn.style.left = `${menuPos.x}px`;
|
|
2387
|
-
menuBtn.style.top = `${menuPos.y}px`;
|
|
2388
|
-
menuBtn.style.width = `${menuPos.width}px`;
|
|
2389
|
-
menuBtn.style.minWidth = `${menuPos.width}px`;
|
|
2390
|
-
menuBtn.style.height = `${menuPos.height}px`;
|
|
2391
|
-
}
|
|
2392
|
-
triggerLifecycleEvent(name) {
|
|
2393
|
-
console.log("Trigger Lifecycle Event: ", name);
|
|
2394
|
-
if (name == "PLAY" /* PLAY */) {
|
|
2395
|
-
this._mockLifecyclesApi.triggerOnPlayCallbacks({
|
|
2396
|
-
hudInsets: { top: 60, right: 0, bottom: 0, left: 0 },
|
|
2397
|
-
// shareData: {
|
|
2398
|
-
// title: 'Mock Share Title',
|
|
2399
|
-
// description: 'Mock share description for testing',
|
|
2400
|
-
// },
|
|
2401
|
-
format: "post"
|
|
2402
|
-
// stackData: null,
|
|
2403
|
-
});
|
|
2404
|
-
} else if (name == "PAUSE" /* PAUSE */) {
|
|
2405
|
-
this._mockLifecyclesApi.triggerOnPauseCallbacks();
|
|
2406
|
-
} else if (name == "RESUME" /* RESUME */) {
|
|
2407
|
-
this._mockLifecyclesApi.triggerOnResumeCallbacks();
|
|
2408
|
-
} else if (name == "QUIT" /* QUIT */) {
|
|
2409
|
-
this._mockLifecyclesApi.triggerOnQuitCallbacks();
|
|
2410
|
-
} else if (name == "SHOWN" /* SHOWN */) {
|
|
2411
|
-
this._mockLifecyclesApi.triggerOnShowCallbacks({
|
|
2412
|
-
hudInsets: { top: 60, bottom: 120, left: 0, right: 0 }
|
|
2413
|
-
});
|
|
2414
|
-
} else if (name == "HIDDEN" /* HIDDEN */) {
|
|
2415
|
-
this._mockLifecyclesApi.triggerOnHideCallbacks();
|
|
2416
|
-
}
|
|
2417
|
-
}
|
|
2418
|
-
setOverlayElementVisibility(element, visible) {
|
|
2419
|
-
const overlay = this._overlay;
|
|
2420
|
-
const elements = overlay.elements;
|
|
2421
|
-
if (elements[element]) {
|
|
2422
|
-
elements[element].style.display = visible ? "flex" : "none";
|
|
2423
|
-
}
|
|
2424
|
-
}
|
|
2425
|
-
setupAdOverlay() {
|
|
2426
|
-
const adOverlay = document.createElement("div");
|
|
2427
|
-
adOverlay.id = "venus-ad-overlay";
|
|
2428
|
-
adOverlay.style.cssText = `
|
|
2429
|
-
position: fixed;
|
|
2430
|
-
top: 0;
|
|
2431
|
-
left: 0;
|
|
2432
|
-
width: 100%;
|
|
2433
|
-
height: 100%;
|
|
2434
|
-
background-color: rgba(37, 99, 235, 0.9);
|
|
2435
|
-
color: white;
|
|
2436
|
-
display: flex;
|
|
2437
|
-
flex-direction: column;
|
|
2438
|
-
align-items: center;
|
|
2439
|
-
justify-content: center;
|
|
2440
|
-
z-index: 10500;
|
|
2441
|
-
font-family: sans-serif;
|
|
2442
|
-
display: none;
|
|
2443
|
-
`;
|
|
2444
|
-
document.body.appendChild(adOverlay);
|
|
2445
|
-
return adOverlay;
|
|
2446
|
-
}
|
|
2447
|
-
log(msg, ...args) {
|
|
2448
|
-
console.log(`[Venus Mock] ${msg}`, ...args);
|
|
2449
|
-
}
|
|
2450
|
-
showActionSheetOverlay(items, options) {
|
|
2451
|
-
this.log("Showing ActionSheetOverlay...");
|
|
2452
|
-
return new Promise((resolve, reject) => {
|
|
2453
|
-
const overlay = this._overlay;
|
|
2454
|
-
overlay.actionSheetOverlay.innerHTML = "";
|
|
2455
|
-
overlay.actionSheetOverlay.style.display = "flex";
|
|
2456
|
-
const actionSheet = document.createElement("div");
|
|
2457
|
-
actionSheet.className = "venus-action-sheet";
|
|
2458
|
-
actionSheet.style.cssText = `
|
|
2459
|
-
background-color: white;
|
|
2460
|
-
border-radius: 8px;
|
|
2461
|
-
width: 80%;
|
|
2462
|
-
max-width: 400px;
|
|
2463
|
-
max-height: 80%;
|
|
2464
|
-
display: flex;
|
|
2465
|
-
flex-direction: column;
|
|
2466
|
-
overflow: hidden;
|
|
2467
|
-
color: black;
|
|
2468
|
-
`;
|
|
2469
|
-
if (options?.title) {
|
|
2470
|
-
const titleContainer = document.createElement("div");
|
|
2471
|
-
titleContainer.style.cssText = `
|
|
2472
|
-
padding: 16px;
|
|
2473
|
-
border-bottom: 1px solid #eaeaea;
|
|
2474
|
-
font-weight: bold;
|
|
2475
|
-
font-size: 18px;
|
|
2476
|
-
text-align: center;
|
|
2477
|
-
color: black;
|
|
2478
|
-
`;
|
|
2479
|
-
titleContainer.innerText = options.title;
|
|
2480
|
-
actionSheet.appendChild(titleContainer);
|
|
2481
|
-
}
|
|
2482
|
-
if (options?.message) {
|
|
2483
|
-
const messageContainer = document.createElement("div");
|
|
2484
|
-
messageContainer.style.cssText = `
|
|
2485
|
-
padding: 8px 16px;
|
|
2486
|
-
color: #666;
|
|
2487
|
-
font-size: 14px;
|
|
2488
|
-
text-align: center;
|
|
2489
|
-
`;
|
|
2490
|
-
messageContainer.innerText = options.message;
|
|
2491
|
-
actionSheet.appendChild(messageContainer);
|
|
2492
|
-
}
|
|
2493
|
-
const optionsContainer = document.createElement("div");
|
|
2494
|
-
optionsContainer.style.cssText = `
|
|
2495
|
-
overflow-y: auto;
|
|
2496
|
-
max-height: 300px;
|
|
2497
|
-
`;
|
|
2498
|
-
items.forEach((item, index) => {
|
|
2499
|
-
const optionItem = document.createElement("div");
|
|
2500
|
-
optionItem.style.cssText = `
|
|
2501
|
-
padding: 12px 16px;
|
|
2502
|
-
border-bottom: 1px solid #eaeaea;
|
|
2503
|
-
cursor: pointer;
|
|
2504
|
-
display: flex;
|
|
2505
|
-
align-items: center;
|
|
2506
|
-
transition: background-color 0.2s;
|
|
2507
|
-
color: black;
|
|
2508
|
-
`;
|
|
2509
|
-
optionItem.addEventListener("mouseover", () => {
|
|
2510
|
-
optionItem.style.backgroundColor = "#f5f5f5";
|
|
2511
|
-
});
|
|
2512
|
-
optionItem.addEventListener("mouseout", () => {
|
|
2513
|
-
optionItem.style.backgroundColor = "white";
|
|
2514
|
-
});
|
|
2515
|
-
if (item.icon) {
|
|
2516
|
-
const iconSpan = document.createElement("span");
|
|
2517
|
-
iconSpan.style.cssText = `
|
|
2518
|
-
margin-right: 12px;
|
|
2519
|
-
font-size: 16px;
|
|
2520
|
-
`;
|
|
2521
|
-
iconSpan.innerText = item.icon;
|
|
2522
|
-
optionItem.appendChild(iconSpan);
|
|
2523
|
-
}
|
|
2524
|
-
const labelSpan = document.createElement("span");
|
|
2525
|
-
labelSpan.style.cssText = `
|
|
2526
|
-
color: black;
|
|
2527
|
-
`;
|
|
2528
|
-
labelSpan.innerText = item.label;
|
|
2529
|
-
optionItem.appendChild(labelSpan);
|
|
2530
|
-
optionItem.addEventListener("click", () => {
|
|
2531
|
-
this.hideActionSheetOverlay();
|
|
2532
|
-
const optionId = item.id !== void 0 ? item.id : index;
|
|
2533
|
-
resolve(optionId);
|
|
2534
|
-
});
|
|
2535
|
-
optionsContainer.appendChild(optionItem);
|
|
2536
|
-
});
|
|
2537
|
-
actionSheet.appendChild(optionsContainer);
|
|
2538
|
-
if (!options?.disableCancel) {
|
|
2539
|
-
const cancelButton = document.createElement("div");
|
|
2540
|
-
cancelButton.style.cssText = `
|
|
2541
|
-
padding: 14px 16px;
|
|
2542
|
-
text-align: center;
|
|
2543
|
-
font-weight: bold;
|
|
2544
|
-
cursor: pointer;
|
|
2545
|
-
color: #3b82f6;
|
|
2546
|
-
border-top: 1px solid #eaeaea;
|
|
2547
|
-
`;
|
|
2548
|
-
cancelButton.innerText = options?.cancelButtonText || "Cancel";
|
|
2549
|
-
cancelButton.addEventListener("click", () => {
|
|
2550
|
-
this.hideActionSheetOverlay();
|
|
2551
|
-
resolve(null);
|
|
2552
|
-
});
|
|
2553
|
-
actionSheet.appendChild(cancelButton);
|
|
2554
|
-
}
|
|
2555
|
-
if (!options?.disableCancel) {
|
|
2556
|
-
const closeButton = document.createElement("div");
|
|
2557
|
-
closeButton.style.cssText = `
|
|
2558
|
-
position: absolute;
|
|
2559
|
-
top: 8px;
|
|
2560
|
-
right: 8px;
|
|
2561
|
-
width: 24px;
|
|
2562
|
-
height: 24px;
|
|
2563
|
-
border-radius: 12px;
|
|
2564
|
-
background-color: rgba(0,0,0,0.1);
|
|
2565
|
-
color: #666;
|
|
2566
|
-
display: flex;
|
|
2567
|
-
align-items: center;
|
|
2568
|
-
justify-content: center;
|
|
2569
|
-
cursor: pointer;
|
|
2570
|
-
font-size: 14px;
|
|
2571
|
-
`;
|
|
2572
|
-
closeButton.innerText = "\u2715";
|
|
2573
|
-
closeButton.addEventListener("click", () => {
|
|
2574
|
-
this.hideActionSheetOverlay();
|
|
2575
|
-
resolve(null);
|
|
2576
|
-
});
|
|
2577
|
-
actionSheet.appendChild(closeButton);
|
|
2578
|
-
overlay.actionSheetOverlay.appendChild(actionSheet);
|
|
2579
|
-
}
|
|
2580
|
-
});
|
|
2581
|
-
}
|
|
2582
|
-
hideActionSheetOverlay() {
|
|
2583
|
-
const overlay = this._overlay;
|
|
2584
|
-
if (overlay.actionSheetOverlay) {
|
|
2585
|
-
overlay.actionSheetOverlay.style.display = "none";
|
|
2586
|
-
}
|
|
2587
|
-
}
|
|
2588
|
-
};
|
|
2589
|
-
|
|
2590
|
-
// src/VenusTransport.ts
|
|
2591
|
-
var VenusTransport = class {
|
|
2592
|
-
constructor() {
|
|
2593
|
-
__publicField(this, "messageHandler");
|
|
2594
|
-
__publicField(this, "onNotificationCallbacks", []);
|
|
2595
|
-
__publicField(this, "onNotificationCallbacksToRemove", []);
|
|
2596
|
-
__publicField(this, "onVenusMessageCallbacks", []);
|
|
2597
|
-
__publicField(this, "onResponseCallbacks", []);
|
|
2598
|
-
__publicField(this, "onResponseCallbacksToRemove", []);
|
|
2599
|
-
__publicField(this, "_instanceId", null);
|
|
2600
|
-
__publicField(this, "isStarted", false);
|
|
2601
|
-
__publicField(this, "isProcessingMessage", false);
|
|
2602
|
-
this.messageHandler = async (event) => {
|
|
2603
|
-
this.isProcessingMessage = true;
|
|
2604
|
-
let message;
|
|
2605
|
-
if (typeof event.data === "string") {
|
|
2606
|
-
message = JSON.parse(event.data);
|
|
2607
|
-
} else {
|
|
2608
|
-
message = event.data;
|
|
2609
|
-
}
|
|
2610
|
-
if (!message) {
|
|
2611
|
-
this.logInfo("No message found. Ignoring message...");
|
|
2612
|
-
return;
|
|
2613
|
-
}
|
|
2614
|
-
this.notifyVenusMessageReceived(message);
|
|
2615
|
-
if (message.type === "PLAY" /* PLAY */ || message.type === "PAUSE" /* PAUSE */ || message.type === "RESUME" /* RESUME */ || message.type === "SHOWN" /* SHOWN */ || message.type === "HIDDEN" /* HIDDEN */ || message.type === "CLEANUP" /* CLEANUP */ || message.type === "QUIT" /* QUIT */) {
|
|
2616
|
-
const notification = {
|
|
2617
|
-
type: "rpc-notification",
|
|
2618
|
-
id: message.type,
|
|
2619
|
-
payload: message.data
|
|
2620
|
-
};
|
|
2621
|
-
this.handleNotification(notification);
|
|
2622
|
-
this.isProcessingMessage = false;
|
|
2623
|
-
return;
|
|
2624
|
-
}
|
|
2625
|
-
const messageData = message.data;
|
|
2626
|
-
if (!messageData) {
|
|
2627
|
-
this.logWarn("No data found. Ignoring message...");
|
|
2628
|
-
this.isProcessingMessage = false;
|
|
2629
|
-
return;
|
|
2630
|
-
}
|
|
2631
|
-
const requestId = messageData.requestId;
|
|
2632
|
-
if (!requestId) {
|
|
2633
|
-
this.logWarn("No requestId. Ignoring message...");
|
|
2634
|
-
this.isProcessingMessage = false;
|
|
2635
|
-
return;
|
|
2636
|
-
}
|
|
2637
|
-
if (message.type !== "H5_RESPONSE" /* H5_RESPONSE */) {
|
|
2638
|
-
this.logWarn(`Ignoring unknown message type: ${message.type}`);
|
|
2639
|
-
this.isProcessingMessage = false;
|
|
2640
|
-
return;
|
|
2641
|
-
}
|
|
2642
|
-
const success = messageData.success;
|
|
2643
|
-
let error = void 0;
|
|
2644
|
-
if (!success) {
|
|
2645
|
-
error = {
|
|
2646
|
-
message: messageData.error || "Unknown error"
|
|
2647
|
-
};
|
|
2648
|
-
}
|
|
2649
|
-
let result = messageData.value;
|
|
2650
|
-
if (result === void 0) {
|
|
2651
|
-
result = messageData.data;
|
|
2652
|
-
}
|
|
2653
|
-
const response = {
|
|
2654
|
-
type: "rpc-response",
|
|
2655
|
-
id: requestId,
|
|
2656
|
-
result,
|
|
2657
|
-
method: message.type,
|
|
2658
|
-
error
|
|
2659
|
-
};
|
|
2660
|
-
await this.handleResponse(response);
|
|
2661
|
-
this.isProcessingMessage = false;
|
|
2662
|
-
};
|
|
2663
|
-
}
|
|
2664
|
-
onNotification(callback) {
|
|
2665
|
-
this.onNotificationCallbacks.push(callback);
|
|
2666
|
-
return {
|
|
2667
|
-
unsubscribe: () => {
|
|
2668
|
-
if (this.isProcessingMessage) {
|
|
2669
|
-
this.onNotificationCallbacks.push(callback);
|
|
2670
|
-
} else {
|
|
2671
|
-
this.removeOnNotificationCallback(callback);
|
|
2672
|
-
}
|
|
2673
|
-
}
|
|
2674
|
-
};
|
|
2675
|
-
}
|
|
2676
|
-
onRequest(callback) {
|
|
2677
|
-
throw new Error("Method not implemented.");
|
|
2678
|
-
}
|
|
2679
|
-
onResponse(callback) {
|
|
2680
|
-
this.onResponseCallbacks.push(callback);
|
|
2681
|
-
return {
|
|
2682
|
-
unsubscribe: () => {
|
|
2683
|
-
if (this.isProcessingMessage) {
|
|
2684
|
-
this.onResponseCallbacksToRemove.push(callback);
|
|
2685
|
-
} else {
|
|
2686
|
-
this.removeOnResponseCallback(callback);
|
|
2687
|
-
}
|
|
2688
|
-
}
|
|
2689
|
-
};
|
|
2690
|
-
}
|
|
2691
|
-
get instanceId() {
|
|
2692
|
-
return this._instanceId;
|
|
2693
|
-
}
|
|
2694
|
-
set instanceId(instanceId) {
|
|
2695
|
-
this._instanceId = instanceId;
|
|
2696
|
-
}
|
|
2697
|
-
sendRequest(request) {
|
|
2698
|
-
const instanceId = this.instanceId || "unknown";
|
|
2699
|
-
const method = request.method;
|
|
2700
|
-
const message = {
|
|
2701
|
-
type: method,
|
|
2702
|
-
direction: "H5_TO_APP",
|
|
2703
|
-
data: {
|
|
2704
|
-
...request.args,
|
|
2705
|
-
requestId: request.id
|
|
2706
|
-
},
|
|
2707
|
-
instanceId,
|
|
2708
|
-
timestamp: Date.now()
|
|
2709
|
-
};
|
|
2710
|
-
this.sendVenusMessage(message);
|
|
2711
|
-
}
|
|
2712
|
-
sendVenusMessage(message) {
|
|
2713
|
-
const messageAsString = JSON.stringify(message, null, 2);
|
|
2714
|
-
const reactNativeWebView = window.ReactNativeWebView;
|
|
2715
|
-
if (reactNativeWebView) {
|
|
2716
|
-
reactNativeWebView.postMessage(messageAsString);
|
|
2717
|
-
} else {
|
|
2718
|
-
window.parent.postMessage(messageAsString, "*");
|
|
2719
|
-
}
|
|
2720
|
-
}
|
|
2721
|
-
sendResponse(response) {
|
|
2722
|
-
throw new Error("Method not implemented.");
|
|
2723
|
-
}
|
|
2724
|
-
start() {
|
|
2725
|
-
if (this.isStarted) {
|
|
2726
|
-
return;
|
|
2727
|
-
}
|
|
2728
|
-
this.isStarted = true;
|
|
2729
|
-
window.addEventListener("message", this.messageHandler, true);
|
|
2730
|
-
this.logInfo(`Started`);
|
|
2731
|
-
}
|
|
2732
|
-
stop() {
|
|
2733
|
-
if (!this.isStarted) {
|
|
2734
|
-
return;
|
|
2735
|
-
}
|
|
2736
|
-
this.isStarted = false;
|
|
2737
|
-
window.removeEventListener("message", this.messageHandler);
|
|
2738
|
-
this.logInfo(`Stopped`);
|
|
2739
|
-
}
|
|
2740
|
-
handleNotification(notification) {
|
|
2741
|
-
for (const callback of this.onNotificationCallbacks) {
|
|
2742
|
-
callback(notification);
|
|
2743
|
-
}
|
|
2744
|
-
for (const callback of this.onNotificationCallbacksToRemove) {
|
|
2745
|
-
this.removeOnNotificationCallback(callback);
|
|
2746
|
-
}
|
|
2747
|
-
this.onNotificationCallbacksToRemove.length = 0;
|
|
2748
|
-
}
|
|
2749
|
-
async handleResponse(response) {
|
|
2750
|
-
for (const callback of this.onResponseCallbacks) {
|
|
2751
|
-
const consumed = await callback(response);
|
|
2752
|
-
if (consumed) {
|
|
2753
|
-
break;
|
|
2754
|
-
}
|
|
2755
|
-
}
|
|
2756
|
-
for (const callback of this.onResponseCallbacksToRemove) {
|
|
2757
|
-
this.removeOnResponseCallback(callback);
|
|
2758
|
-
}
|
|
2759
|
-
this.onResponseCallbacksToRemove.length = 0;
|
|
2760
|
-
}
|
|
2761
|
-
removeOnResponseCallback(callback) {
|
|
2762
|
-
this.onResponseCallbacks.splice(
|
|
2763
|
-
this.onResponseCallbacks.indexOf(callback),
|
|
2764
|
-
1
|
|
2765
|
-
);
|
|
2766
|
-
}
|
|
2767
|
-
removeOnNotificationCallback(callback) {
|
|
2768
|
-
this.onNotificationCallbacks.splice(
|
|
2769
|
-
this.onNotificationCallbacks.indexOf(callback),
|
|
2770
|
-
1
|
|
2771
|
-
);
|
|
2772
|
-
}
|
|
2773
|
-
logInfo(message, ...params) {
|
|
2774
|
-
console.log(`[Venus Transport] ${message}`, ...params);
|
|
2775
|
-
}
|
|
2776
|
-
logWarn(message, ...params) {
|
|
2777
|
-
console.warn(`[Venus Transport] ${message}`, ...params);
|
|
2778
|
-
}
|
|
2779
|
-
onVenusMessage(callback) {
|
|
2780
|
-
this.onVenusMessageCallbacks.push(callback);
|
|
2781
|
-
return {
|
|
2782
|
-
unsubscribe: () => {
|
|
2783
|
-
this.onVenusMessageCallbacks.splice(
|
|
2784
|
-
this.onVenusMessageCallbacks.indexOf(callback),
|
|
2785
|
-
1
|
|
2786
|
-
);
|
|
2787
|
-
}
|
|
2788
|
-
};
|
|
2789
|
-
}
|
|
2790
|
-
notifyVenusMessageReceived(message) {
|
|
2791
|
-
for (const callback of this.onVenusMessageCallbacks) {
|
|
2792
|
-
callback(message);
|
|
2793
|
-
}
|
|
2794
|
-
}
|
|
2795
|
-
};
|
|
2796
|
-
|
|
2797
|
-
// src/RemoteHost.ts
|
|
2798
|
-
init_rooms();
|
|
2799
|
-
|
|
2800
|
-
// src/rooms/RpcRoomsApi.ts
|
|
2801
|
-
init_VenusRoom();
|
|
2802
|
-
var RpcRoomsApi = class {
|
|
2803
|
-
constructor(rpcClient) {
|
|
2804
|
-
__publicField(this, "rpcClient");
|
|
2805
|
-
__publicField(this, "subscriptions");
|
|
2806
|
-
__publicField(this, "transportSubscription", null);
|
|
2807
|
-
this.rpcClient = rpcClient;
|
|
2808
|
-
this.subscriptions = {
|
|
2809
|
-
data: {},
|
|
2810
|
-
messages: {},
|
|
2811
|
-
gameEvents: {},
|
|
2812
|
-
allEvents: {}
|
|
2813
|
-
};
|
|
2814
|
-
}
|
|
2815
|
-
/**
|
|
2816
|
-
* Get the subscription state for external access (used by setupRoomNotifications)
|
|
2817
|
-
*/
|
|
2818
|
-
getSubscriptions() {
|
|
2819
|
-
return this.subscriptions;
|
|
2820
|
-
}
|
|
2821
|
-
/**
|
|
2822
|
-
* Set up room notification routing from the transport
|
|
2823
|
-
*/
|
|
2824
|
-
setupNotifications(transport) {
|
|
2825
|
-
const { setupRoomNotifications } = (init_rooms(), __toCommonJS(rooms_exports));
|
|
2826
|
-
this.transportSubscription = setupRoomNotifications(
|
|
2827
|
-
transport,
|
|
2828
|
-
() => this.getSubscriptions()
|
|
2829
|
-
);
|
|
2830
|
-
}
|
|
2831
|
-
/**
|
|
2832
|
-
* Clean up subscriptions and resources
|
|
2833
|
-
*/
|
|
2834
|
-
dispose() {
|
|
2835
|
-
if (this.transportSubscription) {
|
|
2836
|
-
this.transportSubscription.unsubscribe();
|
|
2837
|
-
this.transportSubscription = null;
|
|
2838
|
-
console.log("[Venus Rooms] Cleaned up room notification subscription");
|
|
2839
|
-
}
|
|
2840
|
-
}
|
|
2841
|
-
async createRoom(options) {
|
|
2842
|
-
const response = await this.rpcClient.call(
|
|
2843
|
-
"H5_ROOM_CREATE" /* H5_ROOM_CREATE */,
|
|
2844
|
-
{
|
|
2845
|
-
options
|
|
2846
|
-
}
|
|
2847
|
-
);
|
|
2848
|
-
if (response.success === false) {
|
|
2849
|
-
throw new Error(response.error || "Failed to create room");
|
|
2850
|
-
}
|
|
2851
|
-
const roomData = response.roomData || response;
|
|
2852
|
-
const room = new VenusRoom(roomData);
|
|
2853
|
-
return room;
|
|
2854
|
-
}
|
|
2855
|
-
async joinOrCreateRoom(options) {
|
|
2856
|
-
const response = await this.rpcClient.call(
|
|
2857
|
-
"H5_ROOM_JOIN_OR_CREATE" /* H5_ROOM_JOIN_OR_CREATE */,
|
|
2858
|
-
{
|
|
2859
|
-
options
|
|
2860
|
-
}
|
|
2861
|
-
);
|
|
2862
|
-
if (response.success === false) {
|
|
2863
|
-
throw new Error(response.error || "Failed to join or create room");
|
|
2864
|
-
}
|
|
2865
|
-
const data = response.value || response;
|
|
2866
|
-
const room = new VenusRoom(data.roomData);
|
|
2867
|
-
return {
|
|
2868
|
-
action: data.action,
|
|
2869
|
-
room,
|
|
2870
|
-
playersJoined: data.playersJoined
|
|
2871
|
-
};
|
|
2872
|
-
}
|
|
2873
|
-
async joinRoomByCode(roomCode) {
|
|
2874
|
-
const response = await this.rpcClient.call(
|
|
2875
|
-
"H5_ROOM_JOIN_BY_CODE" /* H5_ROOM_JOIN_BY_CODE */,
|
|
2876
|
-
{
|
|
2877
|
-
roomCode
|
|
2878
|
-
}
|
|
2879
|
-
);
|
|
2880
|
-
if (response?.success === false) {
|
|
2881
|
-
throw new Error(response.error || "Failed to join room by code");
|
|
2882
|
-
}
|
|
2883
|
-
const roomData = response.roomData || response;
|
|
2884
|
-
const room = new VenusRoom(roomData);
|
|
2885
|
-
return room;
|
|
2886
|
-
}
|
|
2887
|
-
// Get user's rooms with optional filtering
|
|
2888
|
-
async getUserRooms(includeArchived = false) {
|
|
2889
|
-
const response = await this.rpcClient.call(
|
|
2890
|
-
"H5_ROOM_GET_USER_ROOMS" /* H5_ROOM_GET_USER_ROOMS */,
|
|
2891
|
-
{
|
|
2892
|
-
includeArchived
|
|
2893
|
-
}
|
|
2894
|
-
);
|
|
2895
|
-
if (response?.success === false) {
|
|
2896
|
-
throw new Error(response.error || "Failed to get user rooms");
|
|
2897
|
-
}
|
|
2898
|
-
const rawRooms = response.rooms || [];
|
|
2899
|
-
const venusRooms = [];
|
|
2900
|
-
for (const roomData of rawRooms) {
|
|
2901
|
-
if (!roomData.id) {
|
|
2902
|
-
console.warn("getUserRooms: Skipping room with missing ID:", roomData);
|
|
2903
|
-
continue;
|
|
2904
|
-
}
|
|
2905
|
-
try {
|
|
2906
|
-
const venusRoom = new VenusRoom(roomData);
|
|
2907
|
-
venusRooms.push(venusRoom);
|
|
2908
|
-
} catch (error) {
|
|
2909
|
-
console.warn(
|
|
2910
|
-
"getUserRooms: Failed to create VenusRoom object:",
|
|
2911
|
-
error,
|
|
2912
|
-
roomData
|
|
2913
|
-
);
|
|
2914
|
-
}
|
|
2915
|
-
}
|
|
2916
|
-
return venusRooms;
|
|
2917
|
-
}
|
|
2918
|
-
async updateData(room, updates, merge = true) {
|
|
2919
|
-
const response = await this.rpcClient.call(
|
|
2920
|
-
"H5_ROOM_UPDATE_DATA" /* H5_ROOM_UPDATE_DATA */,
|
|
2921
|
-
{
|
|
2922
|
-
roomId: room.id,
|
|
2923
|
-
updates,
|
|
2924
|
-
merge
|
|
2925
|
-
}
|
|
2926
|
-
);
|
|
2927
|
-
if (response?.success === false) {
|
|
2928
|
-
throw new Error(response.error || "Failed to update room data");
|
|
2929
|
-
}
|
|
2930
|
-
return response.data;
|
|
2931
|
-
}
|
|
2932
|
-
async getData(room) {
|
|
2933
|
-
const response = await this.rpcClient.call(
|
|
2934
|
-
"H5_ROOM_GET_DATA" /* H5_ROOM_GET_DATA */,
|
|
2935
|
-
{
|
|
2936
|
-
roomId: room.id
|
|
2937
|
-
}
|
|
2938
|
-
);
|
|
2939
|
-
if (response?.success === false) {
|
|
2940
|
-
throw new Error(response.error || "Failed to get room data");
|
|
2941
|
-
}
|
|
2942
|
-
return response.data;
|
|
2943
|
-
}
|
|
2944
|
-
async sendMessage(venusRoom, messageData) {
|
|
2945
|
-
const response = await this.rpcClient.call(
|
|
2946
|
-
"H5_ROOM_SEND_MESSAGE" /* H5_ROOM_SEND_MESSAGE */,
|
|
2947
|
-
{
|
|
2948
|
-
roomId: venusRoom.id,
|
|
2949
|
-
message: messageData
|
|
2950
|
-
}
|
|
2951
|
-
);
|
|
2952
|
-
if (response?.success === false) {
|
|
2953
|
-
throw new Error(response.error || "Failed to send message");
|
|
2954
|
-
}
|
|
2955
|
-
return response.messageId;
|
|
2956
|
-
}
|
|
2957
|
-
async leave(room) {
|
|
2958
|
-
const response = await this.rpcClient.call(
|
|
2959
|
-
"H5_ROOM_LEAVE" /* H5_ROOM_LEAVE */,
|
|
2960
|
-
{
|
|
2961
|
-
roomId: room.id
|
|
2962
|
-
}
|
|
2963
|
-
);
|
|
2964
|
-
if (response?.success === false) {
|
|
2965
|
-
throw new Error(response.error || "Failed to leave room");
|
|
2966
|
-
}
|
|
2967
|
-
return response;
|
|
2968
|
-
}
|
|
2969
|
-
async startGame(room, gameConfig = {}, turnOrder = null) {
|
|
2970
|
-
const response = await this.rpcClient.call(
|
|
2971
|
-
"H5_ROOM_START_GAME" /* H5_ROOM_START_GAME */,
|
|
2972
|
-
{
|
|
2973
|
-
roomId: room.id,
|
|
2974
|
-
gameConfig,
|
|
2975
|
-
turnOrder
|
|
2976
|
-
}
|
|
2977
|
-
);
|
|
2978
|
-
if (response?.success === false) {
|
|
2979
|
-
throw new Error(response.error || "Failed to start game");
|
|
2980
|
-
}
|
|
2981
|
-
return response.data;
|
|
2982
|
-
}
|
|
2983
|
-
async proposeMove(room, proposalPayload) {
|
|
2984
|
-
const response = await this.rpcClient.call(
|
|
2985
|
-
"h5:room:proposeMove" /* H5_ROOM_PROPOSE_MOVE */,
|
|
2986
|
-
{
|
|
2987
|
-
roomId: room.id,
|
|
2988
|
-
gameSpecificState: proposalPayload.gameSpecificState,
|
|
2989
|
-
moveType: proposalPayload.moveType,
|
|
2990
|
-
clientContext: proposalPayload.clientContext,
|
|
2991
|
-
clientProposalId: proposalPayload.clientProposalId
|
|
2992
|
-
}
|
|
2993
|
-
);
|
|
2994
|
-
if (response?.success === false) {
|
|
2995
|
-
throw new Error(response.error || "Failed to propose move");
|
|
2996
|
-
}
|
|
2997
|
-
return response.data;
|
|
2998
|
-
}
|
|
2999
|
-
async validateMove(room, moveId, isValid, reason = null, validatorId = null) {
|
|
3000
|
-
console.log(`[Venus Rooms] Validating move ${moveId}: ${isValid}`);
|
|
3001
|
-
return { success: true, moveId, isValid, reason };
|
|
3002
|
-
}
|
|
3003
|
-
async roomSubscribeToGameEvents(room, callback) {
|
|
3004
|
-
"game_" + Date.now() + "_" + Math.random().toString(36).substr(2, 9);
|
|
3005
|
-
if (!this.subscriptions.gameEvents[room.id]) {
|
|
3006
|
-
this.subscriptions.gameEvents[room.id] = [];
|
|
3007
|
-
}
|
|
3008
|
-
this.subscriptions.gameEvents[room.id].push(callback);
|
|
3009
|
-
}
|
|
3010
|
-
subscribe(room, options = {}) {
|
|
3011
|
-
const subscriptionIds = [];
|
|
3012
|
-
const roomId = room.id;
|
|
3013
|
-
if (options.onData) {
|
|
3014
|
-
const dataSubId = "data_" + Date.now() + "_" + Math.random().toString(36).substr(2, 9);
|
|
3015
|
-
if (!this.subscriptions.data[roomId]) {
|
|
3016
|
-
this.subscriptions.data[roomId] = [];
|
|
3017
|
-
}
|
|
3018
|
-
this.subscriptions.data[roomId].push(options.onData);
|
|
3019
|
-
subscriptionIds.push({
|
|
3020
|
-
type: "data",
|
|
3021
|
-
id: dataSubId,
|
|
3022
|
-
callback: options.onData
|
|
3023
|
-
});
|
|
3024
|
-
}
|
|
3025
|
-
if (options.onMessages) {
|
|
3026
|
-
const msgSubId = "messages_" + Date.now() + "_" + Math.random().toString(36).substr(2, 9);
|
|
3027
|
-
if (!this.subscriptions.messages[roomId]) {
|
|
3028
|
-
this.subscriptions.messages[roomId] = [];
|
|
3029
|
-
}
|
|
3030
|
-
this.subscriptions.messages[roomId].push(options.onMessages);
|
|
3031
|
-
subscriptionIds.push({
|
|
3032
|
-
type: "messages",
|
|
3033
|
-
id: msgSubId,
|
|
3034
|
-
callback: options.onMessages
|
|
3035
|
-
});
|
|
3036
|
-
}
|
|
3037
|
-
if (options.onMoves || options.onGameEvents) {
|
|
3038
|
-
const handler = options.onMoves || options.onGameEvents;
|
|
3039
|
-
if (handler) {
|
|
3040
|
-
const gameSubId = "game_" + Date.now() + "_" + Math.random().toString(36).substr(2, 9);
|
|
3041
|
-
if (!this.subscriptions.gameEvents[roomId]) {
|
|
3042
|
-
this.subscriptions.gameEvents[roomId] = [];
|
|
3043
|
-
}
|
|
3044
|
-
this.subscriptions.gameEvents[roomId].push(handler);
|
|
3045
|
-
subscriptionIds.push({
|
|
3046
|
-
type: "gameEvents",
|
|
3047
|
-
id: gameSubId,
|
|
3048
|
-
callback: handler
|
|
3049
|
-
});
|
|
3050
|
-
}
|
|
3051
|
-
}
|
|
3052
|
-
const needsSubscription = subscriptionIds.length > 0 && (this.subscriptions.data[roomId]?.length ?? 0) <= 1 && (this.subscriptions.messages[roomId]?.length ?? 0) <= 1 && (this.subscriptions.gameEvents[roomId]?.length ?? 0) <= 1;
|
|
3053
|
-
if (needsSubscription) {
|
|
3054
|
-
this.rpcClient.call("H5_ROOM_SUBSCRIBE" /* H5_ROOM_SUBSCRIBE */, {
|
|
3055
|
-
roomId,
|
|
3056
|
-
subscribeToData: !!options.onData,
|
|
3057
|
-
subscribeToMessages: !!options.onMessages,
|
|
3058
|
-
subscribeToProposedMoves: !!(options.onMoves || options.onGameEvents)
|
|
3059
|
-
}).catch((error) => {
|
|
3060
|
-
console.error("Failed to set up room subscription:", error);
|
|
3061
|
-
});
|
|
3062
|
-
}
|
|
3063
|
-
let called = false;
|
|
3064
|
-
return () => {
|
|
3065
|
-
if (called) return;
|
|
3066
|
-
called = true;
|
|
3067
|
-
subscriptionIds.forEach((sub) => {
|
|
3068
|
-
const bucket = this.subscriptions[sub.type];
|
|
3069
|
-
const callbacks = bucket && bucket[roomId] || [];
|
|
3070
|
-
const index = callbacks.indexOf(sub.callback);
|
|
3071
|
-
if (index > -1) callbacks.splice(index, 1);
|
|
3072
|
-
});
|
|
3073
|
-
const hasNoCallbacks = (this.subscriptions.data[roomId]?.length ?? 0) === 0 && (this.subscriptions.messages[roomId]?.length ?? 0) === 0 && (this.subscriptions.gameEvents[roomId]?.length ?? 0) === 0;
|
|
3074
|
-
if (hasNoCallbacks) {
|
|
3075
|
-
this.rpcClient.call("H5_ROOM_UNSUBSCRIBE" /* H5_ROOM_UNSUBSCRIBE */, {
|
|
3076
|
-
roomId
|
|
3077
|
-
}).catch((error) => {
|
|
3078
|
-
console.error("Failed to clean up room subscription:", error);
|
|
3079
|
-
});
|
|
3080
|
-
}
|
|
3081
|
-
};
|
|
3082
|
-
}
|
|
3083
|
-
};
|
|
3084
|
-
|
|
3085
|
-
// src/RemoteHost.ts
|
|
3086
|
-
var getCdnBaseUrl = () => {
|
|
3087
|
-
return "https://venus-static-01293ak.web.app/";
|
|
3088
|
-
};
|
|
3089
|
-
var RemoteHost = class {
|
|
3090
|
-
constructor(venusApi) {
|
|
3091
|
-
__publicField(this, "ads");
|
|
3092
|
-
__publicField(this, "analytics");
|
|
3093
|
-
__publicField(this, "deviceCache");
|
|
3094
|
-
__publicField(this, "appStorage");
|
|
3095
|
-
__publicField(this, "globalStorage");
|
|
3096
|
-
__publicField(this, "avatar3d");
|
|
3097
|
-
__publicField(this, "navigation");
|
|
3098
|
-
__publicField(this, "notifications");
|
|
3099
|
-
__publicField(this, "popups");
|
|
3100
|
-
__publicField(this, "profile");
|
|
3101
|
-
__publicField(this, "cdn");
|
|
3102
|
-
__publicField(this, "time");
|
|
3103
|
-
__publicField(this, "post");
|
|
3104
|
-
__publicField(this, "ai");
|
|
3105
|
-
__publicField(this, "haptics");
|
|
3106
|
-
__publicField(this, "features");
|
|
3107
|
-
__publicField(this, "lifecycle");
|
|
3108
|
-
__publicField(this, "simulation");
|
|
3109
|
-
__publicField(this, "rooms");
|
|
3110
|
-
__publicField(this, "logging");
|
|
3111
|
-
__publicField(this, "iap");
|
|
3112
|
-
__publicField(this, "preloader");
|
|
3113
|
-
__publicField(this, "venusApi");
|
|
3114
|
-
__publicField(this, "rpcClient");
|
|
3115
|
-
__publicField(this, "_isInitialized", false);
|
|
3116
|
-
this.venusApi = venusApi;
|
|
3117
|
-
const rpcClient = new RpcClient();
|
|
3118
|
-
this.rpcClient = rpcClient;
|
|
3119
|
-
this.ads = new RpcAdsApi(rpcClient);
|
|
3120
|
-
this.analytics = new RpcAnalyticsApi(rpcClient);
|
|
3121
|
-
this.deviceCache = new RpcStorageApi(rpcClient, {
|
|
3122
|
-
clear: "H5_DEVICE_CACHE_CLEAR" /* DEVICE_CACHE_CLEAR */,
|
|
3123
|
-
getItem: "H5_DEVICE_CACHE_GET_ITEM" /* DEVICE_CACHE_GET_ITEM */,
|
|
3124
|
-
getKey: "H5_DEVICE_CACHE_KEY" /* DEVICE_CACHE_KEY */,
|
|
3125
|
-
length: "H5_DEVICE_CACHE_LENGTH" /* DEVICE_CACHE_LENGTH */,
|
|
3126
|
-
removeItem: "H5_DEVICE_CACHE_REMOVE_ITEM" /* DEVICE_CACHE_REMOVE_ITEM */,
|
|
3127
|
-
setItem: "H5_DEVICE_CACHE_SET_ITEM" /* DEVICE_CACHE_SET_ITEM */
|
|
3128
|
-
});
|
|
3129
|
-
this.appStorage = new RpcStorageApi(rpcClient, {
|
|
3130
|
-
clear: "H5_APP_STORAGE_CLEAR" /* APP_STORAGE_CLEAR */,
|
|
3131
|
-
getItem: "H5_APP_STORAGE_GET_ITEM" /* APP_STORAGE_GET_ITEM */,
|
|
3132
|
-
getKey: "H5_APP_STORAGE_KEY" /* APP_STORAGE_KEY */,
|
|
3133
|
-
length: "H5_APP_STORAGE_LENGTH" /* APP_STORAGE_LENGTH */,
|
|
3134
|
-
removeItem: "H5_APP_STORAGE_REMOVE_ITEM" /* APP_STORAGE_REMOVE_ITEM */,
|
|
3135
|
-
setItem: "H5_APP_STORAGE_SET_ITEM" /* APP_STORAGE_SET_ITEM */,
|
|
3136
|
-
getAllItems: "H5_APP_STORAGE_GET_ALL_ITEMS" /* APP_STORAGE_GET_ALL_ITEMS */,
|
|
3137
|
-
setMultipleItems: "H5_APP_STORAGE_SET_ITEM" /* APP_STORAGE_SET_ITEM */,
|
|
3138
|
-
removeMultipleItems: "H5_APP_STORAGE_REMOVE_ITEM" /* APP_STORAGE_REMOVE_ITEM */
|
|
3139
|
-
});
|
|
3140
|
-
this.globalStorage = new RpcStorageApi(rpcClient, {
|
|
3141
|
-
clear: "H5_GLOBAL_STORAGE_CLEAR" /* GLOBAL_STORAGE_CLEAR */,
|
|
3142
|
-
getItem: "H5_GLOBAL_STORAGE_GET_ITEM" /* GLOBAL_STORAGE_GET_ITEM */,
|
|
3143
|
-
getKey: "H5_GLOBAL_STORAGE_KEY" /* GLOBAL_STORAGE_KEY */,
|
|
3144
|
-
length: "H5_GLOBAL_STORAGE_LENGTH" /* GLOBAL_STORAGE_LENGTH */,
|
|
3145
|
-
removeItem: "H5_GLOBAL_STORAGE_REMOVE_ITEM" /* GLOBAL_STORAGE_REMOVE_ITEM */,
|
|
3146
|
-
setItem: "H5_GLOBAL_STORAGE_SET_ITEM" /* GLOBAL_STORAGE_SET_ITEM */,
|
|
3147
|
-
getAllItems: "H5_GLOBAL_STORAGE_GET_ALL_ITEMS" /* GLOBAL_STORAGE_GET_ALL_ITEMS */,
|
|
3148
|
-
setMultipleItems: "H5_GLOBAL_STORAGE_SET_MULTIPLE_ITEMS" /* GLOBAL_STORAGE_SET_MULTIPLE_ITEMS */,
|
|
3149
|
-
removeMultipleItems: "H5_GLOBAL_STORAGE_REMOVE_MULTIPLE_ITEMS" /* GLOBAL_STORAGE_REMOVE_MULTIPLE_ITEMS */
|
|
3150
|
-
});
|
|
3151
|
-
this.avatar3d = new RpcAvatarApi(rpcClient, venusApi);
|
|
3152
|
-
this.navigation = new RpcNavigationApi(rpcClient, venusApi);
|
|
3153
|
-
this.notifications = new RpcNotificationsApi(rpcClient);
|
|
3154
|
-
this.popups = new RpcPopupsApi(rpcClient);
|
|
3155
|
-
this.profile = new HostProfileApi();
|
|
3156
|
-
this.cdn = new HostCdnApi(getCdnBaseUrl());
|
|
3157
|
-
this.time = new HostTimeApi(rpcClient);
|
|
3158
|
-
this.post = new RpcPostApi(rpcClient);
|
|
3159
|
-
this.ai = new RpcAiApi(rpcClient);
|
|
3160
|
-
this.haptics = new RpcHapticsApi(rpcClient);
|
|
3161
|
-
this.features = new RpcFeaturesApi(rpcClient);
|
|
3162
|
-
this.lifecycle = new RpcLifecycleApi(rpcClient);
|
|
3163
|
-
this.simulation = new RpcSimulationApi(rpcClient);
|
|
3164
|
-
this.rooms = new RpcRoomsApi(rpcClient);
|
|
3165
|
-
this.logging = new RpcLoggingApi(this, rpcClient);
|
|
3166
|
-
this.iap = new RpcIapApi(rpcClient);
|
|
3167
|
-
this.preloader = new RpcPreloaderApi(rpcClient);
|
|
3168
|
-
venusApi.isMock = () => false;
|
|
3169
|
-
this.venusApi.sharedAssets = new RpcSharedAssetsApi(rpcClient, venusApi);
|
|
3170
|
-
initializeRoomsApi(this.venusApi, this);
|
|
3171
|
-
console.log("[Venus SDK] Remote host created");
|
|
3172
|
-
}
|
|
3173
|
-
get isInitialized() {
|
|
3174
|
-
return this._isInitialized;
|
|
3175
|
-
}
|
|
3176
|
-
async initialize(options = {}) {
|
|
3177
|
-
this.log("Initializing Remote Host...");
|
|
3178
|
-
const transport = new VenusTransport();
|
|
3179
|
-
transport.start();
|
|
3180
|
-
this.rpcClient.start(transport);
|
|
3181
|
-
const roomsApi = this.rooms;
|
|
3182
|
-
roomsApi.setupNotifications(transport);
|
|
3183
|
-
try {
|
|
3184
|
-
this.log("Trying to initialize using NEW method...");
|
|
3185
|
-
transport.instanceId = await this.initNew();
|
|
3186
|
-
} catch (error) {
|
|
3187
|
-
this.log(`Failed to initialize using NEW method: ${error}`);
|
|
3188
|
-
this.log(`Trying to initialize using OLD method...`);
|
|
3189
|
-
transport.instanceId = await this.initOld(transport);
|
|
3190
|
-
}
|
|
3191
|
-
this.log(`Remote Host Initialized with id: ${transport.instanceId}`);
|
|
3192
|
-
this._isInitialized = true;
|
|
3193
|
-
this.venusApi._bootstrap.apiInjected = true;
|
|
3194
|
-
this.venusApi._bootstrap.venus = window.venus;
|
|
3195
|
-
await this.rpcClient.call("READY" /* READY */, {});
|
|
3196
|
-
}
|
|
3197
|
-
registerIFrame(transport) {
|
|
3198
|
-
return new Promise((resolve, reject) => {
|
|
3199
|
-
this.log("Registering IFrame...");
|
|
3200
|
-
const location = window.location;
|
|
3201
|
-
const pathName = location.pathname;
|
|
3202
|
-
const tokens = pathName.split("/");
|
|
3203
|
-
const appId = tokens[2];
|
|
3204
|
-
console.log("[Venus SDK] App ID ", appId);
|
|
3205
|
-
const registrationMessage = {
|
|
3206
|
-
type: "H5_IFRAME_REGISTER",
|
|
3207
|
-
instanceId: appId,
|
|
3208
|
-
direction: "H5_TO_APP",
|
|
3209
|
-
timestamp: Date.now()
|
|
3210
|
-
};
|
|
3211
|
-
const subscription = transport.onVenusMessage((message) => {
|
|
3212
|
-
if (message.type == "INJECT_VENUS_API_SCRIPT") {
|
|
3213
|
-
const scriptContent = message.data?.script;
|
|
3214
|
-
if (!scriptContent) {
|
|
3215
|
-
throw new Error("Failed to inject venus api, no script found.");
|
|
3216
|
-
}
|
|
3217
|
-
const script = document.createElement("script");
|
|
3218
|
-
script.type = "text/javascript";
|
|
3219
|
-
script.textContent = scriptContent;
|
|
3220
|
-
document.head.appendChild(script);
|
|
3221
|
-
setTimeout(() => {
|
|
3222
|
-
if (window.venus) {
|
|
3223
|
-
subscription.unsubscribe();
|
|
3224
|
-
resolve(window.venus?._config?.instanceId);
|
|
3225
|
-
}
|
|
3226
|
-
}, 100);
|
|
3227
|
-
}
|
|
3228
|
-
});
|
|
3229
|
-
transport.sendVenusMessage(registrationMessage);
|
|
3230
|
-
setTimeout(() => {
|
|
3231
|
-
subscription.unsubscribe();
|
|
3232
|
-
reject();
|
|
3233
|
-
}, 1e3);
|
|
3234
|
-
});
|
|
3235
|
-
}
|
|
3236
|
-
async initNew() {
|
|
3237
|
-
const response = await this.rpcClient.call(
|
|
3238
|
-
"INITIALIZE_SDK" /* INIT_SDK */,
|
|
3239
|
-
{},
|
|
3240
|
-
1e3
|
|
3241
|
-
);
|
|
3242
|
-
if (response.profile) {
|
|
3243
|
-
const profile = response.profile;
|
|
3244
|
-
const sanitizedProfile = {
|
|
3245
|
-
id: profile.id,
|
|
3246
|
-
username: profile.username,
|
|
3247
|
-
avatarUrl: profile.avatarUrl ?? null,
|
|
3248
|
-
isAnonymous: Boolean(profile.isAnonymous)
|
|
3249
|
-
};
|
|
3250
|
-
if (typeof window !== "undefined") {
|
|
3251
|
-
const globalWindow = window;
|
|
3252
|
-
const venus = globalWindow.venus || (globalWindow.venus = {});
|
|
3253
|
-
venus.profile = sanitizedProfile;
|
|
3254
|
-
if (venus._config) {
|
|
3255
|
-
venus._config.profile = sanitizedProfile;
|
|
3256
|
-
}
|
|
3257
|
-
if (venus.config) {
|
|
3258
|
-
venus.config.profile = sanitizedProfile;
|
|
3259
|
-
}
|
|
3260
|
-
}
|
|
3261
|
-
}
|
|
3262
|
-
return response.instanceId;
|
|
3263
|
-
}
|
|
3264
|
-
async initOld(transport) {
|
|
3265
|
-
const isInIframe = window.self !== window.top;
|
|
3266
|
-
const hasReactNativeWebView = typeof window.ReactNativeWebView !== "undefined";
|
|
3267
|
-
if (hasReactNativeWebView) {
|
|
3268
|
-
return this.useInjectedId();
|
|
3269
|
-
} else if (isInIframe) {
|
|
3270
|
-
return await this.registerIFrame(transport);
|
|
3271
|
-
} else {
|
|
3272
|
-
throw new Error("Failed to initialize. Unknown Error");
|
|
3273
|
-
}
|
|
3274
|
-
}
|
|
3275
|
-
useInjectedId() {
|
|
3276
|
-
const instanceId = window.venus?._config?.instanceId || window._venusInitState?.poolId;
|
|
3277
|
-
this.log(`On mobile, using injected instanceId: ${instanceId}`);
|
|
3278
|
-
if (!instanceId) {
|
|
3279
|
-
throw new Error("Expected injected instanceId on mobile");
|
|
3280
|
-
}
|
|
3281
|
-
return instanceId;
|
|
3282
|
-
}
|
|
3283
|
-
log(message) {
|
|
3284
|
-
console.log(`[Venus SDK] [Remote Host] ${message}`);
|
|
3285
|
-
}
|
|
3286
|
-
};
|
|
3287
|
-
|
|
3288
|
-
// src/Host.ts
|
|
3289
|
-
function createHost(venusApi, isMock) {
|
|
3290
|
-
if (isMock) {
|
|
3291
|
-
console.log("[Venus SDK] Creating Local Host");
|
|
3292
|
-
return new MockHost(venusApi);
|
|
3293
|
-
} else {
|
|
3294
|
-
console.log("[Venus SDK] Creating Remote Host");
|
|
3295
|
-
return new RemoteHost(venusApi);
|
|
3296
|
-
}
|
|
3297
|
-
}
|
|
3298
|
-
|
|
3299
1958
|
// src/venus-api/index.js
|
|
3300
1959
|
init_rooms();
|
|
3301
1960
|
var HapticStyle = {
|
|
@@ -3479,6 +2138,7 @@ var VenusAPI2 = class {
|
|
|
3479
2138
|
}
|
|
3480
2139
|
};
|
|
3481
2140
|
this._detectHostedEnvironment();
|
|
2141
|
+
this.launchParams = {};
|
|
3482
2142
|
this.config = createProxiedObject.call(this, "config", {
|
|
3483
2143
|
locale: "en-US",
|
|
3484
2144
|
languageCode: "en",
|
|
@@ -3602,6 +2262,7 @@ var VenusAPI2 = class {
|
|
|
3602
2262
|
initializePopups(this, host);
|
|
3603
2263
|
initializeAnalytics(this, host);
|
|
3604
2264
|
initializeIap(this, host);
|
|
2265
|
+
initializeLeaderboard(this, host);
|
|
3605
2266
|
initializeLocalNotifications(this, host);
|
|
3606
2267
|
initializePreloader(this, host);
|
|
3607
2268
|
initializeTime(this, host);
|
|
@@ -3619,6 +2280,7 @@ var VenusAPI2 = class {
|
|
|
3619
2280
|
initializePost(this, host);
|
|
3620
2281
|
initializeAi(this, host);
|
|
3621
2282
|
initializeSimulation(this, host);
|
|
2283
|
+
initializeSocial(this, host);
|
|
3622
2284
|
initializeAssetLoader(this, createProxiedMethod);
|
|
3623
2285
|
}
|
|
3624
2286
|
// Generate deterministic instance ID based on current page URL
|
|
@@ -3681,95 +2343,23 @@ var VenusAPI2 = class {
|
|
|
3681
2343
|
//---------------------------------------
|
|
3682
2344
|
// PUBLIC API METHODS
|
|
3683
2345
|
//---------------------------------------
|
|
3684
|
-
async initializeAsync(options
|
|
2346
|
+
async initializeAsync(options) {
|
|
3685
2347
|
if (this._shared.initialized) {
|
|
3686
2348
|
return Promise.resolve(true);
|
|
3687
2349
|
}
|
|
3688
2350
|
if (this._shared.initPromise) {
|
|
3689
2351
|
return this._shared.initPromise;
|
|
3690
2352
|
}
|
|
3691
|
-
this._shared.initPromise = new Promise(async (resolve) => {
|
|
2353
|
+
this._shared.initPromise = new Promise(async (resolve, reject) => {
|
|
3692
2354
|
try {
|
|
3693
|
-
|
|
3694
|
-
|
|
3695
|
-
"hardDisableMock",
|
|
3696
|
-
"mock",
|
|
3697
|
-
"helpText",
|
|
3698
|
-
"forceRemoteCdn",
|
|
3699
|
-
"usePreloader"
|
|
3700
|
-
];
|
|
3701
|
-
const supportedMockParams = [
|
|
3702
|
-
"initDelay",
|
|
3703
|
-
"isMobile",
|
|
3704
|
-
"isWeb",
|
|
3705
|
-
"locale",
|
|
3706
|
-
"rooms",
|
|
3707
|
-
"craftingConfig",
|
|
3708
|
-
"onShowContext",
|
|
3709
|
-
"onHideContext"
|
|
3710
|
-
];
|
|
3711
|
-
Object.keys(options).forEach((param) => {
|
|
3712
|
-
if (!supportedRootParams.includes(param)) {
|
|
3713
|
-
this.log(`Unsupported parameter: ${param}`);
|
|
3714
|
-
}
|
|
3715
|
-
});
|
|
3716
|
-
if (options.mockData && typeof options.mockData === "object") {
|
|
3717
|
-
console.warn(
|
|
3718
|
-
"[Venus Mock] mockData is deprecated, use options.mock instead"
|
|
3719
|
-
);
|
|
3720
|
-
options.mock = { ...options.mock, ...options.mockData };
|
|
3721
|
-
}
|
|
3722
|
-
if (options.mock && typeof options.mock === "object") {
|
|
3723
|
-
Object.keys(options.mock).forEach((param) => {
|
|
3724
|
-
if (!supportedMockParams.includes(param)) {
|
|
3725
|
-
this.log(`Unsupported mock parameter: ${param}`);
|
|
3726
|
-
}
|
|
3727
|
-
});
|
|
3728
|
-
}
|
|
3729
|
-
if (options.helpText && typeof options.helpText === "string") {
|
|
3730
|
-
this._mock.helpText = options.helpText;
|
|
3731
|
-
}
|
|
3732
|
-
if (typeof options.forceRemoteCdn === "boolean") {
|
|
3733
|
-
this._mock.forceRemoteCdn = options.forceRemoteCdn;
|
|
3734
|
-
console.log(
|
|
3735
|
-
"[Venus Mock] Force remote CDN mode:",
|
|
3736
|
-
options.forceRemoteCdn
|
|
3737
|
-
);
|
|
3738
|
-
}
|
|
3739
|
-
}
|
|
3740
|
-
await this.host.initialize(options);
|
|
2355
|
+
const result = await this.host.initialize(options);
|
|
2356
|
+
this._shared.initialized = true;
|
|
3741
2357
|
if (!options.usePreloader) {
|
|
3742
|
-
|
|
3743
|
-
}
|
|
3744
|
-
if (this._bootstrap.isInsideHostedEnvironment) {
|
|
3745
|
-
this._shared.initialized = true;
|
|
3746
|
-
resolve(true);
|
|
3747
|
-
return;
|
|
2358
|
+
this.host.preloader.hideLoadScreen();
|
|
3748
2359
|
}
|
|
3749
|
-
|
|
3750
|
-
this.log(`Using mock initialization delay: ${mockDelay}ms`);
|
|
3751
|
-
setTimeout(async () => {
|
|
3752
|
-
this._shared.initialized = true;
|
|
3753
|
-
this._initializeMockMode();
|
|
3754
|
-
resolve(true);
|
|
3755
|
-
}, mockDelay);
|
|
2360
|
+
resolve(result);
|
|
3756
2361
|
} catch (err) {
|
|
3757
|
-
|
|
3758
|
-
"[Venus Bootstrap] Initialization error, falling back to mock mode",
|
|
3759
|
-
err
|
|
3760
|
-
);
|
|
3761
|
-
if (options.hardDisableMock) {
|
|
3762
|
-
console.warn(
|
|
3763
|
-
"[Venus Bootstrap] hardDisableMock is true, not using mock."
|
|
3764
|
-
);
|
|
3765
|
-
resolve(false);
|
|
3766
|
-
return;
|
|
3767
|
-
}
|
|
3768
|
-
this._initializeMockMode();
|
|
3769
|
-
setTimeout(async () => {
|
|
3770
|
-
this._shared.initialized = true;
|
|
3771
|
-
resolve(true);
|
|
3772
|
-
}, 100);
|
|
2362
|
+
reject(err);
|
|
3773
2363
|
}
|
|
3774
2364
|
});
|
|
3775
2365
|
return this._shared.initPromise;
|