room.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. 'use strict';
  2. const _ = require('lodash');
  3. const meta = require('./.room.js');
  4. const Controller = require('egg').Controller;
  5. const { CrudController } = require('naf-framework-mongoose/lib/controller');
  6. const tencentcloud = require('tencentcloud-sdk-nodejs');
  7. class RoomController extends Controller {
  8. constructor(ctx) {
  9. super(ctx);
  10. this.service = this.ctx.service.room;
  11. }
  12. async findroomname() {
  13. const res = await this.service.findroomname(this.ctx.query);
  14. this.ctx.ok({ data: res });
  15. }
  16. async index() {
  17. const data = await this.service.query(this.ctx.query);
  18. this.ctx.ok({ ...data });
  19. }
  20. async startrecord() {
  21. const data = await this.service.startrecord(this.ctx.request.body);
  22. this.ctx.ok({ ...data });
  23. }
  24. async starttranscode() {
  25. // 调用录制接口
  26. // 取得公共参数头
  27. const SecretId = 'AKIDCAtWu3GhY9VbQzJgfOq4QVJq8AxWi3Sa';
  28. const SecretKey = '3sRknnwoOhlY4JH2Wjf6VeYCdnhKr88z';
  29. // 导入对应产品模块的client models。
  30. const TrtcClient = tencentcloud.trtc.v20190722.Client;
  31. const models = tencentcloud.trtc.v20190722.Models;
  32. const Credential = tencentcloud.common.Credential;
  33. const ClientProfile = tencentcloud.common.ClientProfile;
  34. const HttpProfile = tencentcloud.common.HttpProfile;
  35. const cred = new Credential(SecretId, SecretKey);
  36. const httpProfile = new HttpProfile();
  37. httpProfile.endpoint = 'trtc.tencentcloudapi.com';
  38. const clientProfile = new ClientProfile();
  39. clientProfile.httpProfile = httpProfile;
  40. const client = new TrtcClient(cred, 'ap-beijing', clientProfile);
  41. const req = new models.StartMCUMixTranscodeRequest();
  42. const params = {};
  43. params.SdkAppId = this.app.config.sdkappid;
  44. params.RoomId = this.ctx.query.roomname;
  45. const OutputParams_ = {};
  46. OutputParams_.StreamId = this.app.config.sdkappid + '_' + this.ctx.query.roomid + '_mix';
  47. OutputParams_.PureAudioStream = 0;
  48. OutputParams_.RecordId = this.app.config.sdkappid + '_' + this.ctx.query.roomid;
  49. OutputParams_.RecordAudioOnly = 0;
  50. params.OutputParams = OutputParams_;
  51. const EncodeParams_ = {};
  52. EncodeParams_.VideoWidth = 1280;
  53. EncodeParams_.VideoHeight = 720;
  54. EncodeParams_.VideoBitrate = 1560;
  55. EncodeParams_.VideoFramerate = 15;
  56. EncodeParams_.VideoGop = 2;
  57. EncodeParams_.BackgroundColor = 0;
  58. EncodeParams_.AudioSampleRate = 48000;
  59. EncodeParams_.AudioBitrate = 64;
  60. EncodeParams_.AudioChannels = 2;
  61. params.EncodeParams = EncodeParams_;
  62. const LayoutParams_ = {};
  63. LayoutParams_.Template = 2;
  64. LayoutParams_.MainVideoUserId = this.ctx.query.shareid;
  65. LayoutParams_.MainVideoStreamType = 1;
  66. params.LayoutParams = LayoutParams_;
  67. console.log(params);
  68. console.log(JSON.stringify(params));
  69. req.from_json_string(JSON.stringify(params));
  70. client.StartMCUMixTranscode(req, function(errMsg, response) {
  71. if (errMsg) {
  72. console.log(errMsg);
  73. return;
  74. }
  75. console.log(response.to_json_string());
  76. });
  77. this.ctx.ok({ });
  78. }
  79. async stoptranscode() {
  80. // 调用录制接口
  81. // 取得公共参数头
  82. const SecretId = 'AKIDCAtWu3GhY9VbQzJgfOq4QVJq8AxWi3Sa';
  83. const SecretKey = '3sRknnwoOhlY4JH2Wjf6VeYCdnhKr88z';
  84. // 导入对应产品模块的client models。
  85. const TrtcClient = tencentcloud.trtc.v20190722.Client;
  86. const models = tencentcloud.trtc.v20190722.Models;
  87. const Credential = tencentcloud.common.Credential;
  88. const ClientProfile = tencentcloud.common.ClientProfile;
  89. const HttpProfile = tencentcloud.common.HttpProfile;
  90. const cred = new Credential(SecretId, SecretKey);
  91. const httpProfile = new HttpProfile();
  92. httpProfile.endpoint = 'trtc.tencentcloudapi.com';
  93. const clientProfile = new ClientProfile();
  94. clientProfile.httpProfile = httpProfile;
  95. const client = new TrtcClient(cred, 'ap-beijing', clientProfile);
  96. const req = new models.StopMCUMixTranscodeRequest();
  97. const params = {};
  98. params.SdkAppId = this.app.config.sdkappid;
  99. params.RoomId = this.ctx.query.roomname;
  100. req.from_json_string(JSON.stringify(params));
  101. client.StopMCUMixTranscode(req, function(errMsg, response) {
  102. if (errMsg) {
  103. console.log(errMsg);
  104. return;
  105. }
  106. console.log(response.to_json_string());
  107. });
  108. this.ctx.ok({ });
  109. }
  110. async deletefile() {
  111. // 调用录制接口
  112. // 取得公共参数头
  113. const SecretId = 'AKIDCAtWu3GhY9VbQzJgfOq4QVJq8AxWi3Sa';
  114. const SecretKey = '3sRknnwoOhlY4JH2Wjf6VeYCdnhKr88z';
  115. // 导入对应产品模块的client models。
  116. const VodClient = tencentcloud.vod.v20180717.Client;
  117. const models = tencentcloud.vod.v20180717.Models;
  118. const Credential = tencentcloud.common.Credential;
  119. const ClientProfile = tencentcloud.common.ClientProfile;
  120. const HttpProfile = tencentcloud.common.HttpProfile;
  121. const cred = new Credential(SecretId, SecretKey);
  122. const httpProfile = new HttpProfile();
  123. httpProfile.endpoint = 'vod.tencentcloudapi.com';
  124. const clientProfile = new ClientProfile();
  125. clientProfile.httpProfile = httpProfile;
  126. const client = new VodClient(cred, 'ap-beijing', clientProfile);
  127. const req = new models.DeleteMediaRequest();
  128. const params = { FileId: this.ctx.query.fileid };
  129. req.from_json_string(JSON.stringify(params));
  130. client.DeleteMedia(req, function(errMsg, response) {
  131. if (errMsg) {
  132. console.log(errMsg);
  133. return;
  134. }
  135. console.log(response.to_json_string());
  136. });
  137. this.ctx.ok({ });
  138. }
  139. async roomquest() {
  140. const data = await this.service.roomquest(this.ctx.request.body);
  141. this.ctx.ok({ data });
  142. }
  143. async updateanchor() {
  144. const data = await this.service.updateanchor(this.ctx.request.body);
  145. this.ctx.ok({ data });
  146. }
  147. async roomquestclose() {
  148. const data = await this.service.roomquestclose(this.ctx.request.body);
  149. this.ctx.ok({ data });
  150. }
  151. async updateshmai() {
  152. const data = await this.service.updateshmai(this.ctx.request.body);
  153. this.ctx.ok({ data });
  154. }
  155. async switchzjr() {
  156. const data = await this.service.switchzjr(this.ctx.request.body);
  157. this.ctx.ok({ data });
  158. }
  159. }
  160. module.exports = CrudController(RoomController, meta);