Skip to content

Commit

Permalink
feat(api): add rebirth.init api
Browse files Browse the repository at this point in the history
1. If the init function is not called within 5 minutes, the task is considered to have failed
  • Loading branch information
BlackHole1 committed Mar 14, 2020
1 parent 2e272eb commit 81fed51
Show file tree
Hide file tree
Showing 12 changed files with 62 additions and 33 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,4 @@ typings/
.idea
/examples/*/rebirth_data/*
!/examples/*/rebirth_data/.gitkeep
.DS_Store
15 changes: 3 additions & 12 deletions README-zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ docker run -dit -P --name rebirth_alo7 -v `pwd`/rebirth_alo7/logs:/etc/www/logs
在网页加载完毕后,将会注入一些api,供网页使用

```javascript
// 初始化API (5分钟内如果没有调用,则认为任务失败),确保网页可以正常打开。
rebirth.init();

// 开始进行录制
rebirth.start();

Expand Down Expand Up @@ -109,18 +112,6 @@ module.exports = {
};
```

### 业务运用

> 以下是我们公司的运用场景
我们是一个在线教育的公司。在实际业务场景中有一个需求是把上课过程录制下来,并进行 `AI` 分析,生成本节课的精彩视频,供学生及老师查看。

因为我们的应用是 `Electron` 开发的,所以一开始我们使用的是在老师端启动一个屏幕录制,把上课过程录制下来,但是这样做有一个缺点,就是严重依赖了老师的电脑设备及网络带宽,导致我们公司在招聘老师的过程中,电脑性能也是一个非常重要的考察目标。

为了招聘到更多优秀的老师,避免因为非老师自身问题导致的没有招聘,所带来的影响。从而我们研发出 `Rebirth` 项目。

我们的做法是把上课页面完整的复制一份(这里称作 `replay`),同时在上课过程中,记录下学生和老师的动作行为(鼠标移动、鼠标点击、键盘打字、课件翻页、老师及学生摄像头的画面等),再根据这些动作行为数据,在 `replay` 里进行一次复现,在复现过程中由 `Rebirth` 进行录制。从而达到降低老师设备及网络带宽的要求,而且我们一节课可以为公司节省 **6~8** 元人民币的开销,因为之前屏幕录制使用的是第三方服务。

### 贡献者

感谢这些了不起的人:
Expand Down
18 changes: 3 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ docker run -dit -P --name rebirth_alo7 -v `pwd`/rebirth_alo7/logs:/etc/www/logs
After the webpage is loaded, some api will be injected for the webpage to use.

```javascript
// Initialize the API (if not called within 5 minutes, the task is considered to have failed) to ensure that the web page can be opened normally.
rebirth.init();

// start record
rebirth.start();

Expand Down Expand Up @@ -109,21 +112,6 @@ module.exports = {
};
```

### Use of business

> The following are the business scenarios of our company
ALO7 is an online education company that provides an Intelligent EFL Ecosystem.

One of ALO7 important product is ALO7 Online Tutoring-One-stop online tutoring solutions for schools and institutions.
During the online classes, we need to record the video of the class and analyze the quality of the class, meanwhile providing feedback for students and teachers.

Our platform is implemented by `Electron`, and the video is recorded from the tutor’s portal,which requires tutors’ high-performance PC and good internet service, plenty of experienced tutors can’t make it teach the class on our platform due to this issue.

This is how we optimized :

record all tutors’ control during the class (e.g., move the cursor, type, video, etc), then generate a video based on the data we collected, that’s why this project is named `Rebirth`. It not only makes more tutors to teach classes but save **6~8** CNY for each class (recording the class is based on the third-party service).

### Contributors

Thanks goes to these wonderful people:
Expand Down
23 changes: 23 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "rebirth",
"version": "1.0.0",
"description": "Record a web page on the server",
"main": "src/index.js",
"directories": {
"example": "examples"
},
"devDependencies": {},
"scripts": {
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s"
},
"repository": {
"type": "git",
"url": "git+https://github.com/alo7/rebirth.git"
},
"author": "",
"license": "MIT",
"bugs": {
"url": "https://github.com/alo7/rebirth/issues"
},
"homepage": "https://github.com/alo7/rebirth#readme"
}
13 changes: 12 additions & 1 deletion src/chrome-extension/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ const getRecordTasksAndStartTab = () => {
sendLog('open url', {
recordInfo: data
});

// If the init function is not called within 5 minutes, the task is considered to have failed
const initTimeoutId = setTimeout(() => {
sendLog('initTimeout');
actions.fail(id);
}, 1000 * 60 * 5);
tabs.setInitTimeoutId(id, initTimeoutId);
});
})
.catch(e => {
Expand All @@ -38,7 +45,7 @@ chrome.runtime.onConnect.addListener(port => {
const params = [ currentTabId, tabs.getMediaRecorder(currentTabId) ];

if ([ 'pause', 'resume', 'fail' ].includes(data.action)) {
return actions[data.action](...params);
return actions[data.action as 'pause' | 'resume' | 'fail'](...params);
}

if (data.action === 'start') {
Expand All @@ -58,5 +65,9 @@ chrome.runtime.onConnect.addListener(port => {
type: 'ready'
});
}

if (data.action === 'init') {
clearTimeout(tabs.getInitTimeoutId(currentTabId));
}
});
});
2 changes: 1 addition & 1 deletion src/chrome-extension/injected.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ interface MyWindow extends Window {

(window as MyWindow & typeof globalThis).rebirth = {} as rebirth;

[ 'pause', 'resume', 'fail' ].forEach((m) => {
[ 'init', 'pause', 'resume', 'fail' ].forEach(m => {
(window as MyWindow & typeof globalThis).rebirth[m] = () => {
const msg = {
'action': m,
Expand Down
2 changes: 1 addition & 1 deletion src/chrome-extension/lib/recording.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ const fail = (id: number): void => {
recordFail(id);
};

const actions: { [keys: string]: Function } = {
const actions: { [keys in 'start' | 'pause' | 'resume' | 'stop' | 'fail']: Function } = {
start,
pause,
resume,
Expand Down
14 changes: 14 additions & 0 deletions src/chrome-extension/lib/tabs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ class Tabs {
return (this.getTab(id) && this.getTab(id).fileName) ? this.getTab(id).fileName : 'fileName_is_null';
}

getInitTimeoutId (id: number) {
return (this.getTab(id) && this.getTab(id).initTimeoutId) ? this.getTab(id).initTimeoutId : 0;
}

createTab (id: number) {
this.tabs[id] = Object.create(null);
}
Expand Down Expand Up @@ -67,6 +71,16 @@ class Tabs {
this.tabs[id].fileName = makeID(8) + fileName;
}
}

setInitTimeoutId (id: number, timeoutId: number) {
if (this.getTab(id) === null) {
this.createTab(id);
}
if (timeoutId !== this.tabs[id].initTimeoutId) {
this.tabs[id].initTimeoutId = timeoutId;
}

}
}

const tabs = new Tabs();
Expand Down
1 change: 1 addition & 0 deletions src/chrome-extension/typing/background.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export type ITabs = {
mediaRecorder: MediaRecorder; // MediaRecorder Object
extraInfo: IRecursive; // Additional information to carry
fileName: string; // Record saved file name
initTimeoutId: number; // init timeout id
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/chrome-extension/typing/rebirth.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export type IAction = 'waiting' | 'start' | 'pause' | 'resume' | 'stop' | 'fail';
export type IAction = 'init' | 'waiting' | 'start' | 'pause' | 'resume' | 'stop' | 'fail';

export type IActionHelper = 'setExtraInfo' | 'ready';
2 changes: 1 addition & 1 deletion src/extensions_dist/background.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 81fed51

Please sign in to comment.