Skip to content

Commit

Permalink
server done
Browse files Browse the repository at this point in the history
  • Loading branch information
plutoless committed Mar 17, 2019
1 parent 6f33b35 commit 13994c8
Show file tree
Hide file tree
Showing 8 changed files with 542 additions and 2 deletions.
9 changes: 8 additions & 1 deletion Agora-Cloud-Recording-Nodejs/.vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceFolder}/recordtest.js",
"program": "${workspaceFolder}/record/recordtest.js",
"console": "integratedTerminal"
},
{
"type": "node",
"request": "launch",
"name": "Launch Server",
"program": "${workspaceFolder}/server/app.js",
"console": "integratedTerminal"
},
{
Expand Down
6 changes: 5 additions & 1 deletion Agora-Cloud-Recording-Nodejs/record/AgoraCloudRecord.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ class AgoraCloudRecord extends EventEmitter {
this.subscribeEvents()
}

GetRecordingId() {
return this.sdk.GetRecordingId();
}

StartCloudRecording(appid, cname, token, uid, recordConfig, storageConfig) {
if(!appid) {
throw new Error('appid is mandatory')
Expand All @@ -19,7 +23,7 @@ class AgoraCloudRecord extends EventEmitter {

token = token || ""
uid = parseInt(uid)
if(isNaN(uid) && uid < 0) {
if(isNaN(uid) && uid <= 0) {
throw new Error('invalid uid')
}

Expand Down
8 changes: 8 additions & 0 deletions Agora-Cloud-Recording-Nodejs/record/src/recorder_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ void RecorderManager::Init(Local<Object> exports)

Nan::SetPrototypeMethod(tpl, "StartCloudRecording", StartCloudRecording);
Nan::SetPrototypeMethod(tpl, "StopCloudRecording", StopCloudRecording);
Nan::SetPrototypeMethod(tpl, "GetRecordingId", GetRecordingId);
Nan::SetPrototypeMethod(tpl, "onEvent", onEvent);
Nan::SetPrototypeMethod(tpl, "Release", Release);

Expand Down Expand Up @@ -186,6 +187,13 @@ void RecorderManager::Release(const Nan::FunctionCallbackInfo<v8::Value> &args)
napi_set_int_result(args, true);
}

void RecorderManager::GetRecordingId(const Nan::FunctionCallbackInfo<v8::Value> &args)
{
RecorderManager *instance = ObjectWrap::Unwrap<RecorderManager>(args.Holder());
RecordingId recording_id = instance->controller_->GetRecordingId();
napi_set_string_result(args, recording_id);
}

void RecorderManager::StartCloudRecording(const Nan::FunctionCallbackInfo<v8::Value> &args)
{
do
Expand Down
1 change: 1 addition & 0 deletions Agora-Cloud-Recording-Nodejs/record/src/recorder_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class RecorderManager : public Nan::ObjectWrap,
static void Release(
const Nan::FunctionCallbackInfo<v8::Value> &args);
static void onEvent(const Nan::FunctionCallbackInfo<v8::Value> &args);
static void GetRecordingId(const Nan::FunctionCallbackInfo<v8::Value> &args);

void OnRecordingConnecting(RecordingId recording_id);
void OnRecordingStarted(RecordingId recording_id);
Expand Down
52 changes: 52 additions & 0 deletions Agora-Cloud-Recording-Nodejs/server/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
const express = require('express')
const app = express()
const port = 3000
const RecordManager = require('./recordManager')
const bodyParser = require('body-parser')

app.use(bodyParser.json());

app.post('/recorder/v1/start', (req, res, next) => {
let { body } = req;
let { appid, channel, key, uid } = body;
if (!appid) {
throw new Error("appid is mandatory");
}
if (!channel) {
throw new Error("channel is mandatory");
}

RecordManager.start(key, appid, channel, uid).then(recorder => {
//start recorder success
res.status(200).json({
success: true,
sid: recorder.sid
});
}).catch((e) => {
//start recorder failed
next(e);
});
})

app.post('/recorder/v1/stop', (req, res, next) => {
let { body } = req;
let { sid } = body;
if (!sid) {
throw new Error("sid is mandatory");
}

RecordManager.stop(sid);
res.status(200).json({
success: true
});
})

app.use( (err, req, res, next) => {
console.error(err.stack)
res.status(500).json({
success: false,
err: err.message || 'generic error'
})
})

app.listen(port)
Loading

0 comments on commit 13994c8

Please sign in to comment.