liuyu 5 years ago
parent
commit
f9bc3f7f57
6 changed files with 105 additions and 7 deletions
  1. 5 3
      app/controller/.room.js
  2. 64 0
      app/controller/room.js
  3. 4 1
      app/model/room.js
  4. 2 0
      app/router.js
  5. 26 0
      app/service/room.js
  6. 4 3
      package.json

+ 5 - 3
app/controller/.room.js

@@ -1,6 +1,6 @@
 module.exports = {
   create: {
-    requestBody: ["title","name", "type", "filedir", "url", "anchorid","username","status","content","starttime","endtime","adverts","isadvert"],
+    requestBody: ["title","name", "type", "filedir", "url", "anchorid","username","status","content","starttime","endtime","adverts","isadvert","stream_id","ishis"],
   },
   destroy: {
     params: ["!id"],
@@ -8,7 +8,7 @@ module.exports = {
   },
   update: {
     params: ["!id"],
-    requestBody: ["title","name", "type", "filedir", "url", "anchorid","username","status","content","starttime","endtime","adverts","isadvert"],
+    requestBody: ["title","name", "type", "filedir", "url", "anchorid","username","status","content","starttime","endtime","adverts","isadvert","stream_id","ishis"],
   },
   show: {
     parameters: {
@@ -27,7 +27,9 @@ module.exports = {
         status: "status",
         anchorid: "anchorid",
         starttime: "starttime",
-        endtime: "endtime"
+        endtime: "endtime",
+        stream_id: "stream_id",
+        ishis: "ishis"
       },
     },
     service: "query",

+ 64 - 0
app/controller/room.js

@@ -4,6 +4,7 @@ const _ = require('lodash');
 const meta = require('./.room.js');
 const Controller = require('egg').Controller;
 const { CrudController } = require('naf-framework-mongoose/lib/controller');
+const tencentcloud = require('tencentcloud-sdk-nodejs');
 
 class RoomController extends Controller {
   constructor(ctx) {
@@ -20,6 +21,69 @@ class RoomController extends Controller {
     const data = await this.service.query(this.ctx.query);
     this.ctx.ok({ ...data });
   }
+
+  async startrecord() {
+    const data = await this.service.startrecord(this.ctx.request.body);
+    this.ctx.ok({ ...data });
+  }
+
+  async starttranscode() {
+    // 调用录制接口
+    // 取得公共参数头
+    const SecretId = 'AKIDCAtWu3GhY9VbQzJgfOq4QVJq8AxWi3Sa';
+    const SecretKey = '3sRknnwoOhlY4JH2Wjf6VeYCdnhKr88z';
+    // 导入对应产品模块的client models。
+    const TrtcClient = tencentcloud.trtc.v20190722.Client;
+    const models = tencentcloud.trtc.v20190722.Models;
+
+    const Credential = tencentcloud.common.Credential;
+    const ClientProfile = tencentcloud.common.ClientProfile;
+    const HttpProfile = tencentcloud.common.HttpProfile;
+
+    const cred = new Credential(SecretId, SecretKey);
+    const httpProfile = new HttpProfile();
+    httpProfile.endpoint = 'trtc.tencentcloudapi.com';
+    const clientProfile = new ClientProfile();
+    clientProfile.httpProfile = httpProfile;
+    const client = new TrtcClient(cred, 'ap-shanghai', clientProfile);
+
+    const req = new models.StartMCUMixTranscodeRequest();
+
+    const params = {};
+    params.SdkAppId = this.app.config.sdkappid;
+    params.RoomId = this.ctx.query.roomname;
+    const OutputParams_ = {};
+    OutputParams_.StreamId = this.app.config.sdkappid + '_' + this.ctx.query.roomid + '_mix';
+    OutputParams_.PureAudioStream = 0;
+    OutputParams_.RecordId = this.app.config.sdkappid + '_' + this.ctx.query.roomid;
+    OutputParams_.RecordAudioOnly = 0;
+    params.OutputParams = OutputParams_;
+    const EncodeParams_ = {};
+    EncodeParams_.VideoWidth = 1280;
+    EncodeParams_.VideoHeight = 720;
+    EncodeParams_.VideoBitrate = 1560;
+    EncodeParams_.VideoFramerate = 15;
+    EncodeParams_.VideoGop = 2;
+    EncodeParams_.BackgroundColor = 0;
+    EncodeParams_.AudioSampleRate = 48000;
+    EncodeParams_.AudioBitrate = 64;
+    EncodeParams_.AudioChannels = 2;
+    params.EncodeParams = EncodeParams_;
+    const LayoutParams_ = {};
+    LayoutParams_.Template = 2;
+    LayoutParams_.MainVideoUserId = 'main_pc';
+    LayoutParams_.MainVideoStreamType = 1;
+    params.LayoutParams = LayoutParams_;
+    req.from_json_string(JSON.stringify(params));
+    client.StartMCUMixTranscode(req, function(errMsg, response) {
+      if (errMsg) {
+        console.log(errMsg);
+        return;
+      }
+      console.log(response.to_json_string());
+    });
+    this.ctx.ok({ });
+  }
 }
 
 module.exports = CrudController(RoomController, meta);

+ 4 - 1
app/model/room.js

@@ -14,7 +14,10 @@ const RoomSchema = {
   title: { type: String, required: false, maxLength: 200 }, // 标题
   type: { type: String, required: false, maxLength: 64 }, // 类型0、直播1、会议
   filedir: { type: String, required: false, maxLength: 200 }, // 封面图片
-  url: { type: String, required: false, maxLength: 200 }, // 房间地址
+  url: { type: String, required: false, maxLength: 200 }, // 视频地址
+  stream_id: { type: String, required: false }, // 视频回放文件id
+  ishis: { type: String, required: false, maxLength: 64, default: '0' }, // 状态0、正常1、历史
+  requestId: { type: String, required: false }, // 请求id
   content: { type: String, required: false }, // 直播简介
   anchorid: { type: String, required: false, maxLength: 200 }, // 主播id
   username: { type: String, required: false, maxLength: 200 }, // 主播名称

+ 2 - 0
app/router.js

@@ -19,9 +19,11 @@ module.exports = app => {
   router.post('role', '/api/onlive/role/update/:id', controller.role.update);
 
   // 房间表设置路由
+  router.get('/api/onlive/room/starttranscode', controller.room.starttranscode);
   router.get('/api/onlive/room/roomname', controller.room.findroomname);
   router.resources('room', '/api/onlive/room', controller.room); // index、create、show、destroy
   router.post('room', '/api/onlive/room/update/:id', controller.room.update);
+  router.post('/api/onlive/room/startrecord', controller.room.startrecord);
 
   // 聊天表设置路由
   router.resources('chat', '/api/onlive/chat', controller.chat); // index、create、show、destroy

+ 26 - 0
app/service/room.js

@@ -51,6 +51,32 @@ class RoomService extends CrudService {
     }
     return { data, total };
   }
+
+  // 接收录播地址
+  async startrecord(data) {
+    // 接收录播参数
+    const { stream_id } = data;
+    const arr = stream_id.split('_');
+    const id = arr[1];
+    console.log('id--->' + id);
+    const res = await this.model.findById(id);
+    if (res) {
+      res.stream_id = stream_id;
+      res.url = data.video_url;
+      res.ishis = '1';
+      await res.save();
+    }
+    return res;
+  }
+
+  async updaterequid(id, requestid) {
+    const res = await this.model.findById(id);
+    if (res) {
+      res.requestId = requestid;
+      await res.save();
+    }
+    return res;
+  }
 }
 
 module.exports = RoomService;

+ 4 - 3
package.json

@@ -8,21 +8,22 @@
   },
   "dependencies": {
     "egg": "^2.23.0",
+    "egg-naf-amqp": "0.0.13",
     "egg-redis": "^2.4.0",
     "egg-scripts": "^2.11.0",
+    "egg-view-nunjucks": "^2.2.0",
     "jsonwebtoken": "^8.5.1",
     "lodash": "^4.17.15",
     "moment": "^2.24.0",
-    "egg-view-nunjucks": "^2.2.0",
     "naf-framework-mongoose": "^0.6.11",
+    "raml2html": "^6.1.0",
     "silly-datetime": "^0.1.2",
     "string-random": "^0.1.3",
+    "tencentcloud-sdk-nodejs": "^3.0.199",
     "tls-sig-api-v2": "^1.0.0",
     "url-join": "^4.0.1",
-    "raml2html": "^6.1.0",
     "uuid": "^3.3.3",
     "xlsx": "^0.15.1",
-    "egg-naf-amqp": "0.0.13",
     "xmlreader": "^0.2.3"
   },
   "devDependencies": {