123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183 |
- '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-beijing', 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 = this.ctx.query.shareid;
- LayoutParams_.MainVideoStreamType = 1;
- params.LayoutParams = LayoutParams_;
- console.log(params);
- console.log(JSON.stringify(params));
- 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({ });
- }
- async stoptranscode() {
- // 调用录制接口
- // 取得公共参数头
- 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-beijing', clientProfile);
- const req = new models.StopMCUMixTranscodeRequest();
- const params = {};
- params.SdkAppId = this.app.config.sdkappid;
- params.RoomId = this.ctx.query.roomname;
- req.from_json_string(JSON.stringify(params));
- client.StopMCUMixTranscode(req, function(errMsg, response) {
- if (errMsg) {
- console.log(errMsg);
- return;
- }
- console.log(response.to_json_string());
- });
- this.ctx.ok({ });
- }
- async deletefile() {
- // 调用录制接口
- // 取得公共参数头
- const SecretId = 'AKIDCAtWu3GhY9VbQzJgfOq4QVJq8AxWi3Sa';
- const SecretKey = '3sRknnwoOhlY4JH2Wjf6VeYCdnhKr88z';
- // 导入对应产品模块的client models。
- const VodClient = tencentcloud.vod.v20180717.Client;
- const models = tencentcloud.vod.v20180717.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 = 'vod.tencentcloudapi.com';
- const clientProfile = new ClientProfile();
- clientProfile.httpProfile = httpProfile;
- const client = new VodClient(cred, 'ap-beijing', clientProfile);
- const req = new models.DeleteMediaRequest();
- const params = { FileId: this.ctx.query.fileid };
- req.from_json_string(JSON.stringify(params));
- client.DeleteMedia(req, function(errMsg, response) {
- if (errMsg) {
- console.log(errMsg);
- return;
- }
- console.log(response.to_json_string());
- });
- this.ctx.ok({ });
- }
- async roomquest() {
- const data = await this.service.roomquest(this.ctx.request.body);
- this.ctx.ok({ data });
- }
- async updateanchor() {
- const data = await this.service.updateanchor(this.ctx.request.body);
- this.ctx.ok({ data });
- }
- async roomquestclose() {
- const data = await this.service.roomquestclose(this.ctx.request.body);
- this.ctx.ok({ data });
- }
- async updateshmai() {
- const data = await this.service.updateshmai(this.ctx.request.body);
- this.ctx.ok({ data });
- }
- async switchzjr() {
- const data = await this.service.switchzjr(this.ctx.request.body);
- this.ctx.ok({ data });
- }
- }
- module.exports = CrudController(RoomController, meta);
|