diff --git a/config/CN/.env.development b/config/CN/.env.development index dc5816f7018..9481432a6ea 100644 --- a/config/CN/.env.development +++ b/config/CN/.env.development @@ -1,10 +1,3 @@ -NETLESS_APP_IDENTIFIER=n9q1oBxDEeyuBMn1qc0iFw/fLgNSEvdwKjlig -AGORA_APP_ID=a185de0a777f4c159e302abcc0f03b64 -GITHUB_CLIENT_ID=9821657775fbc74773f1 -WECHAT_APP_ID=wx1133c2153a45e9b8 -AGORA_OAUTH_CLIENT_ID=flat-dev -GOOGLE_OAUTH_CLIENT_ID=273996094508-p97og69ojac5ja0khn1rvmi3tb7vgfgm.apps.googleusercontent.com - FLAT_SERVER_DOMAIN=flat-api-dev.whiteboard.agora.io UPDATE_DOMAIN=https://flat-storage.oss-cn-hangzhou.aliyuncs.com/versions FLAT_WEB_DOMAIN=flat-web-dev.whiteboard.agora.io diff --git a/config/CN/.env.production b/config/CN/.env.production index 6356199cb14..6a1ce4129ba 100644 --- a/config/CN/.env.production +++ b/config/CN/.env.production @@ -1,10 +1,3 @@ -NETLESS_APP_IDENTIFIER=cFjxAJjiEeuUQ0211QCRBw/mO9uJB_DiCIqug -AGORA_APP_ID=931b86d6781e49a2a255db4ce6e8e804 -GITHUB_CLIENT_ID=71a29285a437998bdfe0 -WECHAT_APP_ID=wx96d522d69d384cce -AGORA_OAUTH_CLIENT_ID=flat -GOOGLE_OAUTH_CLIENT_ID=273996094508-2rpraucen77a1o5dul5ftrua5k3og157.apps.googleusercontent.com - FLAT_SERVER_DOMAIN=flat-api.whiteboard.agora.io UPDATE_DOMAIN=https://flat-storage.oss-cn-hangzhou.aliyuncs.com/versions FLAT_WEB_DOMAIN=flat-web.whiteboard.agora.io diff --git a/config/SG/.env.development b/config/SG/.env.development index 0b844dbc66f..3df06b17b56 100644 --- a/config/SG/.env.development +++ b/config/SG/.env.development @@ -1,10 +1,3 @@ -NETLESS_APP_IDENTIFIER=n9q1oBxDEeyuBMn1qc0iFw/fLgNSEvdwKjlig -AGORA_APP_ID=a185de0a777f4c159e302abcc0f03b64 -GITHUB_CLIENT_ID=0ac608815326aead5db7 -WECHAT_APP_ID=wx1133c2153a45e9b8 -AGORA_OAUTH_CLIENT_ID=flat-dev -GOOGLE_OAUTH_CLIENT_ID=273996094508-p97og69ojac5ja0khn1rvmi3tb7vgfgm.apps.googleusercontent.com - FLAT_SERVER_DOMAIN=flat-api-dev-sg.whiteboard.agora.io UPDATE_DOMAIN=https://flat-storage.oss-cn-hangzhou.aliyuncs.com/versions FLAT_WEB_DOMAIN=flat-web-dev-sg.whiteboard.agora.io diff --git a/config/SG/.env.production b/config/SG/.env.production index cdf29bc1dec..cd8d4fa6473 100644 --- a/config/SG/.env.production +++ b/config/SG/.env.production @@ -1,10 +1,3 @@ -NETLESS_APP_IDENTIFIER=cFjxAJjiEeuUQ0211QCRBw/mO9uJB_DiCIqug -AGORA_APP_ID=931b86d6781e49a2a255db4ce6e8e804 -GITHUB_CLIENT_ID=da83d7e14217594fba46 -WECHAT_APP_ID=wx96d522d69d384cce -AGORA_OAUTH_CLIENT_ID=flat -GOOGLE_OAUTH_CLIENT_ID=273996094508-2rpraucen77a1o5dul5ftrua5k3og157.apps.googleusercontent.com - FLAT_SERVER_DOMAIN=flat-api-sg.whiteboard.agora.io UPDATE_DOMAIN=https://flat-storage.oss-cn-hangzhou.aliyuncs.com/versions FLAT_WEB_DOMAIN=flat-web.whiteboard.agora.io diff --git a/desktop/main-app/src/preload.ts b/desktop/main-app/src/preload.ts index 713e15df859..52200199d59 100644 --- a/desktop/main-app/src/preload.ts +++ b/desktop/main-app/src/preload.ts @@ -16,8 +16,8 @@ const { * this method will only be triggered on the main page * see: window-manager.ts */ -ipcRenderer.once("preload-dom-ready", () => { - agoraRTCElectronPreload(process.env.AGORA_APP_ID); +ipcRenderer.once("preload-dom-ready", (_event, args: { AGORA_APP_ID: string }) => { + agoraRTCElectronPreload(args.AGORA_APP_ID); }); // because DOMContentLoaded and DOMNodeInserted cannot be used, a new method is adopted to solve the problem of jQuery import failure diff --git a/desktop/main-app/src/window-manager/window-main/index.ts b/desktop/main-app/src/window-manager/window-main/index.ts index 03b172e5e04..020cfa7c087 100644 --- a/desktop/main-app/src/window-manager/window-main/index.ts +++ b/desktop/main-app/src/window-manager/window-main/index.ts @@ -68,23 +68,19 @@ export class WindowMain extends AbstractWindow { } private setupDOMReady(): void { - const domReady$ = new Val(null); + const domReady$ = new Val<{ AGORA_APP_ID: string } | null>(null); const preloaded$ = new Val(null); combine([domReady$, preloaded$]).subscribe(([domReady, event]) => { if (domReady && event) { if (!event.sender.isDestroyed()) { - event.sender.send("preload-dom-ready"); + event.sender.send("preload-dom-ready", domReady); } } }); - this._mainWindow$.subscribe(win => { - if (win) { - win.window.webContents.on("dom-ready", event => { - domReady$.setValue(event); - }); - } + ipcMain.on("init-agora-electron-sdk", (_event, args: { AGORA_APP_ID: string }) => { + domReady$.setValue(args); }); ipcMain.on("preload-loaded", (event: IpcMainEvent): void => { diff --git a/desktop/main-app/src/window-manager/window-manager.ts b/desktop/main-app/src/window-manager/window-manager.ts index 39ddd6aabb9..cbe060ad96d 100644 --- a/desktop/main-app/src/window-manager/window-manager.ts +++ b/desktop/main-app/src/window-manager/window-manager.ts @@ -29,7 +29,7 @@ export class WindowManager< } private interceptPortalNewWindow(customWindow: CustomWindow): void { - customWindow.window.webContents.on( + customWindow.window.webContents.addListener( "new-window", (event, _url, frameName, _disposition, options) => { if (!frameName.startsWith(constants.Portal)) { diff --git a/desktop/renderer-app/src/constants/process.ts b/desktop/renderer-app/src/constants/process.ts index 6689edf2086..4f108247c3f 100644 --- a/desktop/renderer-app/src/constants/process.ts +++ b/desktop/renderer-app/src/constants/process.ts @@ -1,25 +1,5 @@ export const NODE_ENV = process.env.NODE_ENV; -export const NETLESS = Object.freeze({ - APP_IDENTIFIER: process.env.NETLESS_APP_IDENTIFIER, -}); - -export const AGORA = Object.freeze({ - APP_ID: process.env.AGORA_APP_ID, -}); - -export const WECHAT = Object.freeze({ - APP_ID: process.env.WECHAT_APP_ID, -}); - -export const GITHUB = Object.freeze({ - CLIENT_ID: process.env.GITHUB_CLIENT_ID, -}); - -export const GOOGLE = Object.freeze({ - CLIENT_ID: process.env.GOOGLE_OAUTH_CLIENT_ID, -}); - export const FLAT_SERVER_DOMAIN = process.env.FLAT_SERVER_DOMAIN; export const FLAT_WEB_DOMAIN = process.env.FLAT_WEB_DOMAIN; diff --git a/desktop/renderer-app/src/tasks/init-flat-services.ts b/desktop/renderer-app/src/tasks/init-flat-services.ts index 00c6b1a56d2..d234005b21f 100644 --- a/desktop/renderer-app/src/tasks/init-flat-services.ts +++ b/desktop/renderer-app/src/tasks/init-flat-services.ts @@ -22,9 +22,19 @@ import { combine } from "value-enhancer"; import { runtime } from "../utils/runtime"; import { portalWindowManager } from "../utils/portal-window-manager"; -import { ipcAsyncByPreviewFileWindow } from "../utils/ipc"; +import { ipcAsyncByApp, ipcAsyncByPreviewFileWindow } from "../utils/ipc"; +import { globalStore } from "@netless/flat-stores"; export function initFlatServices(): void { + const config = globalStore.serverRegionConfig; + if (!config) { + throw new Error("Missing server region config"); + } + + // @ts-expect-error "init-agora-electron-sdk" is not a user defined event, + // it only aids to preload agora electron sdk + ipcAsyncByApp("init-agora-electron-sdk", { AGORA_APP_ID: config.agora.appId }); + const toaster = createToaster(); const flatI18n = FlatI18n.getInstance(); const flatServices = FlatServices.getInstance(); @@ -96,7 +106,7 @@ export function initFlatServices(): void { instance.setRTCEngine(rtcEngine); } else { instance = new AgoraRTCElectron({ - APP_ID: process.env.AGORA_APP_ID, + APP_ID: config.agora.appId, rtcEngine, isMac: runtime.isMac, }); @@ -109,7 +119,7 @@ export function initFlatServices(): void { flatServices.register("textChat", async () => { const { AgoraRTM } = await import("@netless/flat-service-provider-agora-rtm"); - return new AgoraRTM(process.env.AGORA_APP_ID); + return new AgoraRTM(config.agora.appId); }); flatServices.register("whiteboard", async () => { @@ -162,7 +172,7 @@ export function initFlatServices(): void { }); const service = new Fastboard({ - APP_ID: process.env.NETLESS_APP_IDENTIFIER, + APP_ID: config.whiteboard.appId, toaster, flatI18n, flatInfo: { diff --git a/desktop/renderer-app/typings/global.d.ts b/desktop/renderer-app/typings/global.d.ts index 75c89c70a7c..c6dc0d04506 100644 --- a/desktop/renderer-app/typings/global.d.ts +++ b/desktop/renderer-app/typings/global.d.ts @@ -14,14 +14,7 @@ declare module "*.mp3"; declare namespace NodeJS { interface ProcessEnv { NODE_ENV: "development" | "production"; - NETLESS_APP_IDENTIFIER: string; - AGORA_APP_ID: string; - - GITHUB_CLIENT_ID: string; - GOOGLE_OAUTH_CLIENT_ID: string; - - WECHAT_APP_ID: string; FLAT_SERVER_DOMAIN: string; FLAT_WEB_DOMAIN: string; diff --git a/docs/env/README-zh.md b/docs/env/README-zh.md index 2cc8089cb1a..6f6b11c54ea 100644 --- a/docs/env/README-zh.md +++ b/docs/env/README-zh.md @@ -2,10 +2,7 @@ | 变量名 | 描述 | 备注 | | ------------------------------------ | -------------------------------------------------- | ---------------------------------------------------------------- | -| NETLESS_APP_IDENTIFIER | 互动白板 Access Key | 见: [在 app 服务端生成 Token][netless-auth] | -| AGORA_APP_ID | Agora 声网 App ID | 用于 RTC 与 RTM。见: [校验用户权限][agora-app-id-auth] | | CLOUD_RECORDING_DEFAULT_AVATAR | Agora 云端录制用户默认背景图 URL | 见:[设置背景色或背景图][cloud-recording-background] | -| WECHAT_APP_ID | [微信开放平台][open-wechat] App ID | 见 `网站应用` 里 `AppID` | | FLAT_SERVER_DOMAIN | Flat Server 部署的域名地址 | 如: `flat-api.whiteboard.agora.io` | | UPDATE_DOMAIN | Flat 升级的 OSS 域名地址,用于存放新版与历史安装包 | 如: `https://flat-storage.oss-cn-hangzhou.aliyuncs.com/versions` | | SKIP_MAC_NOTARIZE | 是否跳过 Mac 公证步骤 | 值: `yes` 或者 `no` | @@ -14,9 +11,6 @@ | WINDOWS_CODE_SIGNING_CA_PATH | Windows 签名证书文件路径,可选,留空时不做签名 | 相对路径,相对于 `desktop/main-app` 目录 | | WINDOWS_CODE_SIGNING_CA_PASSWORD | Windows 签名证书密码,可选,留空时不做签名 | | -[open-wechat]: https://open.weixin.qq.com/ -[netless-auth]: https://docs.agora.io/cn/whiteboard/generate_whiteboard_token_at_app_server?platform=RESTful -[agora-app-id-auth]: https://docs.agora.io/cn/Agora%20Platform/token#a-name--appidause-an-app-id-for-authentication [cloud-recording]: https://docs.agora.io/cn/cloud-recording/cloud_recording_api_rest?platform=RESTful#storageConfig [cloud-recording-background]: https://docs.agora.io/cn/cloud-recording/cloud_recording_layout?platform=RESTful#background [electron-updater]: https://github.com/electron-userland/electron-builder/tree/master/packages/electron-updater diff --git a/docs/env/README.md b/docs/env/README.md index def67be2c95..d632950e7fc 100644 --- a/docs/env/README.md +++ b/docs/env/README.md @@ -2,10 +2,7 @@ | Variable | Description | Note | | ------------------------------------ | -------------------------------------------------------- | ----------------------------------------------------------------------------------- | -| NETLESS_APP_IDENTIFIER | Whiteboard Access Key | See [Projects and permissions][netless-auth] | -| AGORA_APP_ID | Agora App ID | For RTC and RTM. See [Use an App ID for authentication][agora-app-id-auth] | | CLOUD_RECORDING_DEFAULT_AVATAR | Agora Cloud Recording default user avatar URL | See: [Set the background color or background image][cloud-recording-background] | -| WECHAT_APP_ID | [Wechat Open Platform][open-wechat] App ID | | | FLAT_SERVER_DOMAIN | Flat Server deployed address | e.g. `flat-api.whiteboard.agora.io` | | UPDATE_DOMAIN | Flat upgrade OSS address for storing artifacts | e.g. `https://flat-storage.oss-cn-hangzhou.aliyuncs.com/versions` | | SKIP_MAC_NOTARIZE | Whether to skip the mac notarization step | value: `yes` or `no` | @@ -14,9 +11,6 @@ | WINDOWS_CODE_SIGNING_CA_PATH | Windows Code Signing CA file path. Skip if not provided | Relative to `desktop/main-app` | | WINDOWS_CODE_SIGNING_CA_PASSWORD | Windows Code Signing CA password. Skip if not provided | | -[open-wechat]: https://open.weixin.qq.com/ -[netless-auth]: https://docs.agora.io/en/whiteboard/generate_whiteboard_token_at_app_server?platform=RESTful -[agora-app-id-auth]: https://docs.agora.io/en/Agora%20Platform/token#a-name--appidause-an-app-id-for-authentication [cloud-recording]: https://docs.agora.io/en/cloud-recording/cloud_recording_api_rest?platform=RESTful#storageConfig [cloud-recording-background]: https://docs.agora.io/en/cloud-recording/cloud_recording_layout?platform=RESTful#background [electron-updater]: https://github.com/electron-userland/electron-builder/tree/master/packages/electron-updater diff --git a/packages/flat-pages/src/LoginPage/WeChatLogin.tsx b/packages/flat-pages/src/LoginPage/WeChatLogin.tsx index a6bfec83f97..f1bca150468 100644 --- a/packages/flat-pages/src/LoginPage/WeChatLogin.tsx +++ b/packages/flat-pages/src/LoginPage/WeChatLogin.tsx @@ -12,8 +12,8 @@ import { FLAT_SERVER_LOGIN, } from "@netless/flat-server-api"; import { errorTips } from "flat-components"; -import { WECHAT } from "../constants/process"; import { useSafePromise } from "../utils/hooks/lifecycle"; +import { globalStore } from "@netless/flat-stores"; export interface WeChatLoginProps { onLoginResult: (result: LoginProcessResult) => void; @@ -75,6 +75,10 @@ export function getQRCodeURL( authUUID: string, redirect_uri: string = FLAT_SERVER_LOGIN.WECHAT_CALLBACK, ): string { + const appId = globalStore.serverRegionConfig?.wechat.webAppId; + if (!appId) { + console.warn("missing server region config"); + } const redirectURL = encodeURIComponent(`${redirect_uri}`); const qrCodeStyle = ` .impowerBox .qrcode { @@ -95,9 +99,7 @@ export function getQRCodeURL( } `; - return `https://open.weixin.qq.com/connect/qrconnect?appid=${ - WECHAT.APP_ID - }&scope=snsapi_login&redirect_uri=${redirectURL}&state=${authUUID}&login_type=jssdk&self_redirect=true&style=black&href=data:text/css;base64,${window.btoa( + return `https://open.weixin.qq.com/connect/qrconnect?appid=${appId}&scope=snsapi_login&redirect_uri=${redirectURL}&state=${authUUID}&login_type=jssdk&self_redirect=true&style=black&href=data:text/css;base64,${window.btoa( qrCodeStyle, )}`; } diff --git a/packages/flat-pages/src/LoginPage/agoraLogin.ts b/packages/flat-pages/src/LoginPage/agoraLogin.ts index 43b4e5b49ad..24d27792ea3 100644 --- a/packages/flat-pages/src/LoginPage/agoraLogin.ts +++ b/packages/flat-pages/src/LoginPage/agoraLogin.ts @@ -1,8 +1,8 @@ import { v4 as uuidv4 } from "uuid"; import { LoginExecutor } from "./utils/disposer"; import { errorTips } from "flat-components"; +import { globalStore } from "@netless/flat-stores"; import { FLAT_SERVER_LOGIN, setAuthUUID } from "@netless/flat-server-api"; -import { AGORA_OAUTH } from "../constants/process"; export const agoraLogin: LoginExecutor = () => { const authUUID = uuidv4(); @@ -23,6 +23,10 @@ export const agoraLogin: LoginExecutor = () => { }; export function getAgoraURL(authUUID: string, redirect_uri: string): string { + const clientId = globalStore.serverRegionConfig?.agora.clientId; + if (!clientId) { + console.warn("missing server region config"); + } const redirectURL = encodeURIComponent(redirect_uri); - return `https://sso2.agora.io/api/v0/oauth/authorize?response_type=code&client_id=${AGORA_OAUTH.CLIENT_ID}&redirect_uri=${redirectURL}&scope=basic_info&state=${authUUID}&toPage=signup`; + return `https://sso2.agora.io/api/v0/oauth/authorize?response_type=code&client_id=${clientId}&redirect_uri=${redirectURL}&scope=basic_info&state=${authUUID}&toPage=signup`; } diff --git a/packages/flat-pages/src/LoginPage/githubLogin.ts b/packages/flat-pages/src/LoginPage/githubLogin.ts index cb4fc4cf301..214097d30f5 100644 --- a/packages/flat-pages/src/LoginPage/githubLogin.ts +++ b/packages/flat-pages/src/LoginPage/githubLogin.ts @@ -2,7 +2,7 @@ import { v4 as uuidv4 } from "uuid"; import { LoginExecutor } from "./utils/disposer"; import { errorTips } from "flat-components"; import { FLAT_SERVER_LOGIN, setAuthUUID, loginProcess } from "@netless/flat-server-api"; -import { GITHUB } from "../constants/process"; +import { globalStore } from "@netless/flat-stores"; export const githubLogin: LoginExecutor = (onSuccess, windowsBtn) => { let timer = NaN; @@ -46,6 +46,10 @@ export const githubLogin: LoginExecutor = (onSuccess, windowsBtn) => { }; export function getGithubURL(authUUID: string, redirect_uri: string): string { + const clientId = globalStore.serverRegionConfig?.github.clientId; + if (!clientId) { + console.warn("missing server region config"); + } const redirectURL = encodeURIComponent(redirect_uri); - return `https://github.com/login/oauth/authorize?client_id=${GITHUB.CLIENT_ID}&redirect_uri=${redirectURL}&state=${authUUID}`; + return `https://github.com/login/oauth/authorize?client_id=${clientId}&redirect_uri=${redirectURL}&state=${authUUID}`; } diff --git a/packages/flat-pages/src/LoginPage/googleLogin.ts b/packages/flat-pages/src/LoginPage/googleLogin.ts index fa8a98d69d9..4580d64915a 100644 --- a/packages/flat-pages/src/LoginPage/googleLogin.ts +++ b/packages/flat-pages/src/LoginPage/googleLogin.ts @@ -2,7 +2,7 @@ import { v4 as uuidv4 } from "uuid"; import { LoginExecutor } from "./utils/disposer"; import { errorTips } from "flat-components"; import { FLAT_SERVER_LOGIN, setAuthUUID, loginProcess } from "@netless/flat-server-api"; -import { GOOGLE } from "../constants/process"; +import { globalStore } from "@netless/flat-stores"; // @TODO: migrate to new google login api before 2023 // https://developers.google.com/identity/gsi/web @@ -48,7 +48,11 @@ export const googleLogin: LoginExecutor = (onSuccess, windowsBtn) => { }; export function getGoogleURL(authUUID: string, redirect_uri: string): string { + const clientId = globalStore.serverRegionConfig?.google.clientId; + if (!clientId) { + console.warn("missing server region config"); + } const scopes = ["openid", "https://www.googleapis.com/auth/userinfo.profile"]; const scope = encodeURIComponent(scopes.join(" ")); - return `https://accounts.google.com/o/oauth2/v2/auth?response_type=code&access_type=online&scope=${scope}&client_id=${GOOGLE.CLIENT_ID}&redirect_uri=${redirect_uri}&state=${authUUID}`; + return `https://accounts.google.com/o/oauth2/v2/auth?response_type=code&access_type=online&scope=${scope}&client_id=${clientId}&redirect_uri=${redirect_uri}&state=${authUUID}`; } diff --git a/packages/flat-pages/src/constants/process.ts b/packages/flat-pages/src/constants/process.ts index c467ea89fcc..fd012d9f256 100644 --- a/packages/flat-pages/src/constants/process.ts +++ b/packages/flat-pages/src/constants/process.ts @@ -1,29 +1,5 @@ export const NODE_ENV = process.env.NODE_ENV; -export const NETLESS = Object.freeze({ - APP_IDENTIFIER: process.env.NETLESS_APP_IDENTIFIER, -}); - -export const AGORA = Object.freeze({ - APP_ID: process.env.AGORA_APP_ID, -}); - -export const AGORA_OAUTH = Object.freeze({ - CLIENT_ID: process.env.AGORA_OAUTH_CLIENT_ID, -}); - -export const WECHAT = Object.freeze({ - APP_ID: process.env.WECHAT_APP_ID, -}); - -export const GITHUB = Object.freeze({ - CLIENT_ID: process.env.GITHUB_CLIENT_ID, -}); - -export const GOOGLE = Object.freeze({ - CLIENT_ID: process.env.GOOGLE_OAUTH_CLIENT_ID, -}); - export const FLAT_DOWNLOAD_URL = process.env.FLAT_DOWNLOAD_URL; export const PRIVACY_URL_CN = "https://flat.whiteboard.agora.io/privacy.html"; diff --git a/packages/flat-pages/src/typings/global.d.ts b/packages/flat-pages/src/typings/global.d.ts index 2f82726912d..560e4f8076f 100644 --- a/packages/flat-pages/src/typings/global.d.ts +++ b/packages/flat-pages/src/typings/global.d.ts @@ -5,16 +5,6 @@ declare namespace NodeJS { PROD: boolean; VERSION: string; - NETLESS_APP_IDENTIFIER: string; - - AGORA_APP_ID: string; - - AGORA_OAUTH_CLIENT_ID: string; - - GITHUB_CLIENT_ID: string; - GOOGLE_OAUTH_CLIENT_ID: string; - - WECHAT_APP_ID: string; FLAT_SERVER_DOMAIN: string; FLAT_WEB_DOMAIN: string; diff --git a/packages/flat-stores/src/classroom-replay-store/history.ts b/packages/flat-stores/src/classroom-replay-store/history.ts index 6311bd815e3..2ab7bcd30b5 100644 --- a/packages/flat-stores/src/classroom-replay-store/history.ts +++ b/packages/flat-stores/src/classroom-replay-store/history.ts @@ -1,6 +1,7 @@ import polly from "polly-js"; import { generateRTMToken } from "@netless/flat-server-api"; import { IServiceTextChatEventData } from "@netless/flat-services"; +import { globalStore } from "../global-store"; import { v4 } from "uuid"; export interface AgoraRTMQueryPayload { @@ -96,8 +97,13 @@ export class TextChatHistory { this.token = await generateRTMToken(); } + const appId = globalStore.serverRegionConfig?.agora.appId; + if (!appId) { + throw new Error("missing server region config"); + } + const response = await fetch( - `https://api.agora.io/dev/v2/project/${process.env.AGORA_APP_ID}/rtm/message/history/${action}`, + `https://api.agora.io/dev/v2/project/${appId}/rtm/message/history/${action}`, { method: "POST", // eslint-disable-next-line eqeqeq diff --git a/packages/flat-stores/src/classroom-replay-store/index.ts b/packages/flat-stores/src/classroom-replay-store/index.ts index 2ae6fed65fc..6bbd65a514e 100644 --- a/packages/flat-stores/src/classroom-replay-store/index.ts +++ b/packages/flat-stores/src/classroom-replay-store/index.ts @@ -91,8 +91,9 @@ export class ClassroomReplayStore { } public async loadRecording(recording: RoomRecording): Promise { - if (!process.env.NETLESS_APP_IDENTIFIER) { - throw new Error("Missing NETLESS_APP_IDENTIFIER"); + const config = globalStore.serverRegionConfig; + if (!config || !config.whiteboard.appId) { + throw new Error("missing server region config"); } if (!globalStore.whiteboardRoomUUID || !globalStore.whiteboardRoomToken) { @@ -121,7 +122,7 @@ export class ClassroomReplayStore { const fastboard = await replayFastboard({ sdkConfig: { - appIdentifier: process.env.NETLESS_APP_IDENTIFIER, + appIdentifier: config.whiteboard.appId, region: globalStore.region ?? "cn-hz", pptParams: { useServerWrap: true, diff --git a/web/flat-web/src/tasks/init-flat-services.ts b/web/flat-web/src/tasks/init-flat-services.ts index edc2aee67d0..7caa20592ae 100644 --- a/web/flat-web/src/tasks/init-flat-services.ts +++ b/web/flat-web/src/tasks/init-flat-services.ts @@ -16,8 +16,14 @@ import { message } from "antd"; import { generatePath } from "react-router-dom"; import { Remitter } from "remitter"; import { combine } from "value-enhancer"; +import { globalStore } from "@netless/flat-stores"; export function initFlatServices(): void { + const config = globalStore.serverRegionConfig; + if (config === null) { + throw new Error("server region config must be loaded"); + } + const toaster = createToaster(); const flatI18n = FlatI18n.getInstance(); @@ -43,12 +49,12 @@ export function initFlatServices(): void { flatServices.register("videoChat", async () => { const { AgoraRTCWeb } = await import("@netless/flat-service-provider-agora-rtc-web"); - return new AgoraRTCWeb({ APP_ID: process.env.AGORA_APP_ID }); + return new AgoraRTCWeb({ APP_ID: config.agora.appId }); }); flatServices.register("textChat", async () => { const { AgoraRTM } = await import("@netless/flat-service-provider-agora-rtm"); - return new AgoraRTM(process.env.AGORA_APP_ID); + return new AgoraRTM(config.agora.appId); }); flatServices.register("whiteboard", async () => { @@ -101,7 +107,7 @@ export function initFlatServices(): void { }); const service = new Fastboard({ - APP_ID: process.env.NETLESS_APP_IDENTIFIER, + APP_ID: config.whiteboard.appId, toaster, flatI18n, flatInfo: { diff --git a/web/flat-web/typings/global.d.ts b/web/flat-web/typings/global.d.ts index 14e32cccc66..384abb04aed 100644 --- a/web/flat-web/typings/global.d.ts +++ b/web/flat-web/typings/global.d.ts @@ -5,16 +5,6 @@ declare namespace NodeJS { PROD: boolean; VERSION: string; - NETLESS_APP_IDENTIFIER: string; - - AGORA_APP_ID: string; - - AGORA_OAUTH_CLIENT_ID: string; - - GITHUB_CLIENT_ID: string; - GOOGLE_OAUTH_CLIENT_ID: string; - - WECHAT_APP_ID: string; FLAT_SERVER_DOMAIN: string; FLAT_WEB_DOMAIN: string;