Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(project): cleanup environments #2007

Merged
merged 1 commit into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions config/CN/.env.development
Original file line number Diff line number Diff line change
@@ -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
Expand Down
7 changes: 0 additions & 7 deletions config/CN/.env.production
Original file line number Diff line number Diff line change
@@ -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
Expand Down
7 changes: 0 additions & 7 deletions config/SG/.env.development
Original file line number Diff line number Diff line change
@@ -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
Expand Down
7 changes: 0 additions & 7 deletions config/SG/.env.production
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions desktop/main-app/src/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 4 additions & 8 deletions desktop/main-app/src/window-manager/window-main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,23 +68,19 @@ export class WindowMain extends AbstractWindow<false> {
}

private setupDOMReady(): void {
const domReady$ = new Val<Electron.Event | null>(null);
const domReady$ = new Val<{ AGORA_APP_ID: string } | null>(null);
const preloaded$ = new Val<IpcMainEvent | null>(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 => {
Expand Down
2 changes: 1 addition & 1 deletion desktop/main-app/src/window-manager/window-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
20 changes: 0 additions & 20 deletions desktop/renderer-app/src/constants/process.ts
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
18 changes: 14 additions & 4 deletions desktop/renderer-app/src/tasks/init-flat-services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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,
});
Expand All @@ -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 () => {
Expand Down Expand Up @@ -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: {
Expand Down
7 changes: 0 additions & 7 deletions desktop/renderer-app/typings/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
6 changes: 0 additions & 6 deletions docs/env/README-zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` |
Expand All @@ -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
6 changes: 0 additions & 6 deletions docs/env/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` |
Expand All @@ -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
10 changes: 6 additions & 4 deletions packages/flat-pages/src/LoginPage/WeChatLogin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand All @@ -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,
)}`;
}
8 changes: 6 additions & 2 deletions packages/flat-pages/src/LoginPage/agoraLogin.ts
Original file line number Diff line number Diff line change
@@ -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();
Expand All @@ -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`;
}
8 changes: 6 additions & 2 deletions packages/flat-pages/src/LoginPage/githubLogin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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}`;
}
8 changes: 6 additions & 2 deletions packages/flat-pages/src/LoginPage/googleLogin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}`;
}
24 changes: 0 additions & 24 deletions packages/flat-pages/src/constants/process.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
10 changes: 0 additions & 10 deletions packages/flat-pages/src/typings/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
8 changes: 7 additions & 1 deletion packages/flat-stores/src/classroom-replay-store/history.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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
Expand Down
Loading