1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- 'use strict';
- 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) {
- super(ctx);
- this.service = this.ctx.service.room;
- }
- async findroomname() {
- const res = await this.service.findroomname(this.ctx.query);
- this.ctx.ok({ data: res });
- }
- async index() {
- 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);
|