extrn.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /**
  2. * 直播间男女端共用Manager
  3. */
  4. 'use strict';
  5. const F = require('../common/function');
  6. const C = require('../config');
  7. const _ = require('underscore');
  8. _.str = require('underscore.string');
  9. _.v = require('validator');
  10. const co = require('co');
  11. module.exports = function (app, commonManager) {
  12. let mgr_map = commonManager.mgr_map;
  13. let that = this;
  14. /**
  15. * 获取zego的accessToken
  16. */
  17. this.getZegoAccessToken = function* () {
  18. let res = yield mgr_map.curl.httpGet(C.java_host, C.java_port, '/zego/v1/getAccessToken', {}, null, 'utf8', 'http');
  19. if (!res.result) {
  20. F.throwErr("获取access_token为空");
  21. }
  22. let json = JSON.parse(res.data);
  23. if (json.code != 200 || F.isNull(json.data)) {
  24. return "";
  25. }
  26. return json.data.accessToken;
  27. };
  28. this.delZegoStream = function* (room_id, uid) {
  29. try {
  30. let stream_id = yield mgr_map.redis.getStreamId(uid);
  31. if (F.isNull(stream_id)) {
  32. return;
  33. }
  34. let stream_sid = yield mgr_map.redis.getStreamSvrId(uid);
  35. if (F.isNull(stream_sid)) {
  36. return;
  37. }
  38. let access_token = yield that.getZegoAccessToken();
  39. if (F.isNull(access_token)) {
  40. return;
  41. }
  42. let req = {
  43. "access_token": access_token,
  44. "version": 1,
  45. "seq": F.timestamp(),
  46. "room_id": room_id.toString(),
  47. "user_account": "1",
  48. "stream_id": stream_id,
  49. "stream_sid": ""
  50. };
  51. let res = yield mgr_map.curl.httpPostJson(C.zego_host, 443, '/cgi/delstream', req, null, 'utf8', 'https');
  52. F.addDebugLogs(["[ 即构接口 ]后台流删除接口", req, res]);
  53. } catch (e) {
  54. F.addErrLogs(["[ 即构接口 ]后台流删除接口异常", e.stack]);
  55. }
  56. };
  57. this.addZegoStream = function* (room_id, uid, appCode) {
  58. /*if ("10010128" == room_id || "10001950" == room_id) return;
  59. try {
  60. let stream_id = yield mgr_map.redis.getStreamId(uid);
  61. if (F.isNull(stream_id)) {
  62. return;
  63. }
  64. let stream_sid = yield mgr_map.redis.getStreamSvrId(uid);
  65. if (F.isNull(stream_sid)) {
  66. return;
  67. }
  68. let access_token = yield that.getZegoAccessToken();
  69. if (F.isNull(access_token)) {
  70. return;
  71. }
  72. if (!F.isNull(appCode) && 2 <= parseInt(appCode)) return;
  73. let req = {
  74. "access_token": access_token,
  75. "version": 1,
  76. "seq": F.timestamp(),
  77. "room_id": room_id.toString(),
  78. "user_account": uid.toString(),
  79. "stream_id": stream_id,
  80. "stream_sid": "",
  81. "extra_info": "" + F.timestamp(),
  82. "title": "svrpub"+F.timestamp()
  83. };
  84. let res = yield mgr_map.curl.httpPostJson(C.zego_host, 443, '/cgi/addstream', req, null, 'utf8', 'https');
  85. F.addDebugLogs(["[ 即构接口 ]后台流增加接口", req, res]);
  86. } catch (e) {
  87. F.addErrLogs(["[ 即构接口 ]后台流增加接口异常", e.stack]);
  88. }*/
  89. };
  90. };