Skip to content

Commit

Permalink
feat(flat-rtm): add flat rtm service
Browse files Browse the repository at this point in the history
refactor(flat-server-api): mv flat server api to a package

refactor(flat-server-api): update deps

chore(flat-server-api): remove unused deps

refactor(flat-server-api): update entry

refactor(i18n): add i18next

refactor(flat-stores): mv stores to a package

refactor(flat-stores): mv stores to flat-stores

refactor(project): update to flat-stores

refactor(flat-rtm): update flat-rtm api

refactor(flat-stores): remove React

fix(flat-stores): correct imports

refactor(flat-rtm): fix rtm failing

chore(project): remove stores workspace

refactor(web): update rtm services config

refactor(web): replace errorTips with flat-components

refactor(flat-stores): update owner uuid from roomInfo

refactor(flat-server-api): replace session storage to local storage

session storage does not work under incognito mode

refactor(flat-rtc): ignore track enable

refactor(flat-stores): update device states on init

fix(flat-stores): cancel hand raising

refactor(flat-stores): add whiteboard debugging

refactor(classroom): listen to rtc events before joining room
  • Loading branch information
crimx committed Aug 22, 2022
1 parent 85db042 commit 3d3a721
Show file tree
Hide file tree
Showing 130 changed files with 2,322 additions and 3,278 deletions.
3 changes: 3 additions & 0 deletions .commitlintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ module.exports = {
"login",
"config",
"flat-rtc",
"flat-rtm",
"flat-server-api",
"flat-stores",
"pnpm",
"server",
],
Expand Down
1 change: 1 addition & 0 deletions .lintstagedrc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module.exports = {
"*.svg": "svgo",
"*.{ts,tsx}": ["eslint --cache --fix", "prettier --write"],
"*.{md,ts,tsx,js,css,less,json,yml,yaml,html,sh}": "cspell --no-progress --no-must-find-files",
};
1 change: 0 additions & 1 deletion desktop/main-app/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"baseUrl": ".",
"target": "es2017",
"module": "CommonJS",
"lib": ["es2017", "DOM"]
Expand Down
1 change: 0 additions & 1 deletion desktop/renderer-app/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"baseUrl": ".",
"lib": ["dom", "es2017"],
"module": "ESNext",
"jsx": "react",
Expand Down
8 changes: 8 additions & 0 deletions packages/flat-components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
"start": "start-storybook -p 6006 -s public --no-version-updates",
"build": "build-storybook -s public"
},
"peerDependencies": {
"@netless/flat-rtm": "workspace:*",
"@netless/flat-server-api": "workspace:*",
"flat-i18n": "workspace:*"
},
"dependencies": {
"@ant-design/icons": "^4.7.0",
"@netless/flat-rtc": "workspace:*",
Expand All @@ -38,6 +43,8 @@
},
"devDependencies": {
"@babel/core": "^7.17.7",
"@netless/flat-rtm": "workspace:*",
"@netless/flat-server-api": "workspace:*",
"@storybook/addon-actions": "~6.3.7",
"@storybook/addon-essentials": "~6.3.7",
"@storybook/addon-links": "~6.3.7",
Expand All @@ -58,6 +65,7 @@
"chance": "^1.1.8",
"css-loader": "^6.7.1",
"faker": "^5.5.3",
"flat-i18n": "workspace:*",
"less-loader": "^10.2.0",
"lodash-es": "^4.17.21",
"sass": "^1.49.9",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import React, { useEffect } from "react";
import { observer } from "mobx-react-lite";
import { useTranslation } from "react-i18next";
import { format } from "date-fns";
import { ChatMsg, ChatMsgType } from "../types";
import { ChatMsg } from "../types";

export interface ChatMessageProps {
/** current user uuid */
Expand All @@ -30,23 +30,23 @@ export const ChatMessage = observer<ChatMessageProps>(function ChatMessage({
}, []);

switch (message.type) {
case ChatMsgType.Notice: {
case "notice": {
return (
<div className="chat-message-line">
<div className="chat-message-notice">{message.value}</div>
<div className="chat-message-notice">{message.text}</div>
</div>
);
}
case ChatMsgType.BanText: {
case "ban": {
return (
<div className="chat-message-line">
<div className="chat-message-ban">
<span>{message.value ? t("banned") : t("unban")}</span>
<span>{message.status ? t("banned") : t("unban")}</span>
</div>
</div>
);
}
case ChatMsgType.UserGuide: {
case "user-guide": {
return (
<div className="chat-message-line">
<div className="chat-message-user-guide-bubble">
Expand Down Expand Up @@ -74,11 +74,11 @@ export const ChatMessage = observer<ChatMessageProps>(function ChatMessage({
const dateToday = format(new Date(), "yyyy-MM-dd");
const finalTimeString = dateString === dateToday ? timeString : fullTimeString;

if (userUUID === message.userUUID) {
if (userUUID === message.senderID) {
return (
<div className="chat-message-line is-reverse">
<div className="chat-message-bubble is-self">
<pre>{message.value}</pre>
<pre>{message.text}</pre>
</div>
<div className="chat-message-user">
<time
Expand All @@ -89,7 +89,7 @@ export const ChatMessage = observer<ChatMessageProps>(function ChatMessage({
{finalTimeString}
</time>
<span className="chat-message-user-name">
{messageUser?.name || message.userUUID}
{messageUser?.name || message.senderID}
</span>
<span className="chat-message-user-avatar">
<img alt="[avatar]" src={messageUser?.avatar} />
Expand All @@ -102,14 +102,14 @@ export const ChatMessage = observer<ChatMessageProps>(function ChatMessage({
return (
<div className="chat-message-line">
<div className="chat-message-bubble">
<pre>{message.value}</pre>
<pre>{message.text}</pre>
</div>
<div className="chat-message-user">
<span className="chat-message-user-avatar">
<img alt="[avatar]" src={messageUser?.avatar} />
</span>
<span className="chat-message-user-name">
{messageUser?.name || message.userUUID}
{messageUser?.name || message.senderID}
</span>
<time
className="chat-message-user-time"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export const ChatMessageList = observer<ChatMessageListProps>(function ChatMessa
{() => (
<ChatMessage
message={messages[index]}
messageUser={getUserByUUID(messages[index].userUUID)}
messageUser={getUserByUUID(messages[index].senderID)}
openCloudStorage={openCloudStorage}
userUUID={userUUID}
onMount={measure}
Expand Down
27 changes: 16 additions & 11 deletions packages/flat-components/src/components/ChatPanel/types.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
export enum ChatMsgType {
Notice = "Notice",
BanText = "BanText",
ChannelMessage = "ChannelMessage",
UserGuide = "UserGuide",
}

export type ChatMsg = {
import type { FlatRTMEventData } from "@netless/flat-rtm";

export type ChatMsgType = "notice" | "ban" | "room-message" | "user-guide";

export type ChatMsgRoomMessage = { type: "room-message" } & FlatRTMEventData["room-message"];

export type ChatMsgNotice = { type: "notice" } & FlatRTMEventData["notice"];

export type ChatMsgBan = { type: "ban" } & FlatRTMEventData["ban"];

export type ChatMsgUserGuide = {
type: "user-guide";
roomUUID: string;
uuid: string;
type: string;
value: string | boolean;
userUUID: string;
timestamp: number;
senderID: string;
};

export type ChatMsg = ChatMsgRoomMessage | ChatMsgNotice | ChatMsgBan | ChatMsgUserGuide;
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ export interface CloudStorageFileListFileNameProps {
fileMenus?: (
file: CloudStorageFile,
index: number,
) => Array<{ key: React.Key; name: React.ReactNode }> | void | undefined | null;
) =>
| Array<{ key: React.Key; name: React.ReactNode; className?: string }>
| void
| undefined
| null;
/** When file menu item clicked */
onItemMenuClick?: (fileUUID: string, menuKey: React.Key) => void;
/** When title is clicked */
Expand Down Expand Up @@ -62,8 +66,10 @@ export const CloudStorageFileListFileName = React.memo<CloudStorageFileListFileN
onItemMenuClick && onItemMenuClick(file.fileUUID, key)
}
>
{menuItems.map(({ key, name }) => (
<Menu.Item key={key}>{name}</Menu.Item>
{menuItems.map(({ key, name, className = "" }) => (
<Menu.Item key={key} className={className}>
{name}
</Menu.Item>
))}
</Menu>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@
padding: 9px 16px;
min-width: 164px;
}

.danger {
color: var(--danger);
}
}

.cloud-storage-file-list-title-span {
Expand Down
3 changes: 3 additions & 0 deletions packages/flat-components/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import "./theme/index.less";
export * from "./utils/room";
export * from "./utils/hooks";
export * from "./utils/errorTip";
export * from "./components/ChatPanel";
export * from "./components/ClassroomPage";
export * from "./components/CloudStorage";
Expand All @@ -26,3 +27,5 @@ export * from "./components/ClassroomPage/CloudRecordBtn";
export * from "./components/ClassroomPage/Timer";
export * from "./components/FlatIcons";
export * from "./components/SettingPage/AppearancePicker";

export { message } from "antd";
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { message } from "antd";
import { ServerRequestError } from "../../utils/error/server-request-error";
import { i18n } from "../../utils/i18n";
import { ServerRequestError } from "@netless/flat-server-api";
import { i18n } from "flat-i18n";

export const errorTips = (e: unknown): void => {
if (process.env.NODE_ENV === "development") {
Expand Down
4 changes: 4 additions & 0 deletions packages/flat-i18n/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules/
dist/
public/
*.js
15 changes: 14 additions & 1 deletion packages/flat-i18n/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,18 @@
"version": "0.1.0",
"private": true,
"license": "MIT",
"homepage": "https://github.com/netless-io/flat"
"homepage": "https://github.com/netless-io/flat",
"main": "src/index.ts",
"peerDependencies": {
"i18next": "21.x",
"react-i18next": "^11.15.7",
"react": ">= 16.8.0 || ^17"
},
"devDependencies": {
"i18next": "^21.6.14",
"prettier": "^2.3.0",
"react": "^17.0.2",
"react-i18next": "^11.15.7",
"typescript": "^4.6.2"
}
}
67 changes: 67 additions & 0 deletions packages/flat-i18n/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import i18next, { Resource } from "i18next";
import I18nextBrowserLanguageDetector from "i18next-browser-languagedetector";
import { initReactI18next } from "react-i18next";
import en from "../locales/en.json";
import zhCN from "../locales/zh-CN.json";

import varsCNen from "../vars/cn/en.json";
import varsCNzhCN from "../vars/cn/zh-CN.json";
import varsUSen from "../vars/us/en.json";
import varsUSzhCN from "../vars/us/zh-CN.json";

/**
* NOTE: to use this library, also install https://github.com/antfu/i18n-ally
* to edit translations. open a new vscode window at <path to renderer-app>.
*/

export let i18nLoaded = false;

export const i18n = i18next;

export const languages = ["en", "zh-CN"] as const;

export async function initI18n(): Promise<void> {
if (i18nLoaded) {
return;
}

const messages: Resource = {
en: { translation: en },
"zh-CN": { translation: zhCN },
};

const defaultVars: Record<string, Record<string, string>> = process.env.FLAT_REGION === "US"
? { en: varsUSen, "zh-CN": varsUSzhCN }
: { en: varsCNen, "zh-CN": varsCNzhCN };

const p = i18next
.use(I18nextBrowserLanguageDetector)
.use(initReactI18next)
.init({
resources: messages,
fallbackLng: "en",
supportedLngs: languages,
interpolation: {
escapeValue: false, // react already safes from xss
defaultVariables: defaultVars[i18next.language] || defaultVars.en,
},
});

const changeLang = (lang: string): void => {
document.querySelector("html")?.setAttribute("lang", lang);

const defaultVariables = defaultVars[lang] || defaultVars.en;
if (i18next.options.interpolation) {
i18next.options.interpolation.defaultVariables = defaultVariables;
} else {
i18next.options.interpolation = { defaultVariables };
}
};

changeLang(i18next.language);
i18next.on("languageChanged", changeLang);

await p;

i18nLoaded = true;
}
11 changes: 11 additions & 0 deletions packages/flat-i18n/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"declaration": true,
"declarationMap": true,
"sourceMap": true,
"composite": true,
"outDir": "./dist"
},
"include": ["src", "vars/**/*.json", "locales/**/*.json"]
}
4 changes: 4 additions & 0 deletions packages/flat-server-api/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules/
dist/
public/
*.js
19 changes: 19 additions & 0 deletions packages/flat-server-api/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "@netless/flat-server-api",
"version": "0.1.0",
"description": "Flat Server API",
"main": "src/index.ts",
"private": true,
"license": "MIT",
"scripts": {
"build": "tsc"
},
"peerDependencies": {
"axios": "0.x"
},
"devDependencies": {
"axios": "^0.26.1",
"prettier": "^2.3.0",
"typescript": "^4.6.2"
}
}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { FLAT_SERVER_DOMAIN } from "../../constants/process";

const FLAT_SERVER_PROTOCOL = `https://${FLAT_SERVER_DOMAIN}`;
const FLAT_SERVER_PROTOCOL = `https://${process.env.FLAT_SERVER_DOMAIN}`;

export const FLAT_SERVER_VERSIONS = {
V1: `${FLAT_SERVER_PROTOCOL}/v1`,
Expand All @@ -18,6 +16,14 @@ export const FLAT_SERVER_USER_BINDING = {
WECHAT_CALLBACK: `${FLAT_SERVER_VERSIONS.V1}/user/binding/platform/wechat/web`,
} as const;

export enum Region {
CN_HZ = "cn-hz",
US_SV = "us-sv",
SG = "sg",
IN_MUM = "in-mum",
GB_LON = "gb-lon",
}

export enum RoomType {
OneToOne = "OneToOne",
SmallClass = "SmallClass",
Expand Down
Loading

0 comments on commit 3d3a721

Please sign in to comment.