trtc-electron-sdk 10.3.8-beta.9 → 10.3.112-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -31,7 +31,8 @@ const TrtcRender = function () {
31
31
  lastImageRotation: 0,
32
32
  lastIsNeedRotate: true,
33
33
  firstFrameRender: false,
34
- event: new EventEmitter()
34
+ event: new EventEmitter(),
35
+ fallbackCb: null,
35
36
  };
36
37
  that.getView = function () {
37
38
  return that.view;
@@ -40,15 +41,16 @@ const TrtcRender = function () {
40
41
  that.setContentMode = function (mode) {
41
42
  that.contentMode = mode;
42
43
  };
43
- that.bind = function (view) {
44
- initCanvas(view, that.mirrorView, view.clientWidth, view.clientHeight, that.initRotation, true, console.warn);
44
+ that.bind = function (view, fallbackCb) {
45
+ that.fallbackCb = fallbackCb;
46
+ initCanvas(view, that.mirrorView, view.clientWidth, view.clientHeight, that.initRotation, true, console.warn, true);
45
47
  };
46
48
  that.unbind = function () {
47
49
  try {
48
50
  gl.getExtension('WEBGL_lose_context').loseContext();
49
51
  }
50
52
  catch (err) {
51
- console.warn('trtc:', err);
53
+ console.warn(err);
52
54
  }
53
55
  program = undefined;
54
56
  positionLocation = undefined;
@@ -69,7 +71,7 @@ const TrtcRender = function () {
69
71
  that.view && that.view.removeChild(that.container);
70
72
  }
71
73
  catch (e) {
72
- console.warn('trtc:', e);
74
+ console.warn(e);
73
75
  }
74
76
  that.canvas = undefined;
75
77
  that.container = undefined;
@@ -83,7 +85,7 @@ const TrtcRender = function () {
83
85
  };
84
86
  that.renderImage = function (image) {
85
87
  if (!gl) {
86
- console.log('trtc:no gl');
88
+ console.log('!gl');
87
89
  return;
88
90
  }
89
91
  if (image.width != that.initWidth
@@ -93,8 +95,8 @@ const TrtcRender = function () {
93
95
  const view = that.view;
94
96
  that.unbind();
95
97
  initCanvas(view, image.mirror, image.width, image.height, image.rotation, image.isNeedRotate, e => {
96
- console.error(`trtc:init canvas ${image.width}*${image.height} rotation ${image.rotation} failed. ${e}`);
97
- });
98
+ console.error(`init canvas ${image.width}*${image.height} rotation ${image.rotation} failed. ${e}`);
99
+ }, false);
98
100
  }
99
101
  gl.bindBuffer(gl.ARRAY_BUFFER, texCoordBuffer);
100
102
  const xWidth = image.width + image.left + image.right;
@@ -158,9 +160,9 @@ const TrtcRender = function () {
158
160
  right,
159
161
  bottom,
160
162
  rotation: rotation,
161
- yplane: imageData.yUint8Array,
162
- uplane: imageData.uUint8Array,
163
- vplane: imageData.vUint8Array,
163
+ yplane: new Uint8Array(imageData.yUint8Array),
164
+ uplane: new Uint8Array(imageData.uUint8Array),
165
+ vplane: new Uint8Array(imageData.vUint8Array),
164
166
  isNeedRotate
165
167
  });
166
168
  const now32 = (Date.now() & 0xffffffff) >>> 0;
@@ -175,7 +177,7 @@ const TrtcRender = function () {
175
177
  if (config.getDebugMode()) {
176
178
  e = gl.getError();
177
179
  if (e != gl.NO_ERROR) {
178
- console.log('trtc:upload y plane ', width, height, yplane.byteLength, ' error', e);
180
+ console.log('upload y plane ', width, height, yplane.byteLength, ' error', e);
179
181
  }
180
182
  }
181
183
  gl.activeTexture(gl.TEXTURE1);
@@ -184,7 +186,7 @@ const TrtcRender = function () {
184
186
  if (config.getDebugMode()) {
185
187
  e = gl.getError();
186
188
  if (e != gl.NO_ERROR) {
187
- console.log('trtc:upload u plane ', width, height, uplane.byteLength, ' error', e);
189
+ console.log('upload u plane ', width, height, uplane.byteLength, ' error', e);
188
190
  }
189
191
  }
190
192
  gl.activeTexture(gl.TEXTURE2);
@@ -194,7 +196,7 @@ const TrtcRender = function () {
194
196
  if (config.getDebugMode()) {
195
197
  e = gl.getError();
196
198
  if (e != gl.NO_ERROR) {
197
- console.log('trtc:upload v plane ', width, height, vplane.byteLength, ' error', e);
199
+ console.log('upload v plane ', width, height, vplane.byteLength, ' error', e);
198
200
  }
199
201
  }
200
202
  }
@@ -239,7 +241,7 @@ const TrtcRender = function () {
239
241
  + ' b=y+2.017*u;'
240
242
  + ' gl_FragColor=vec4(r,g,b,1.0);'
241
243
  + '}';
242
- function initCanvas(view, mirror, width, height, rotation, isNeedRotate, onFailure) {
244
+ function initCanvas(view, mirror, width, height, rotation, isNeedRotate, onFailure, isBind) {
243
245
  that.clientWidth = view.clientWidth;
244
246
  that.clientHeight = view.clientHeight;
245
247
  that.view = view;
@@ -252,6 +254,11 @@ const TrtcRender = function () {
252
254
  that.container.style.alignItems = 'center';
253
255
  that.view.appendChild(that.container);
254
256
  that.canvas = document.createElement('canvas');
257
+ that.canvas.addEventListener('webglcontextlost', function (e) {
258
+ if (!isBind && that.fallbackCb) {
259
+ that.fallbackCb();
260
+ }
261
+ }, { once: true });
255
262
  if (isNeedKeepWidthAndHeight(rotation, isNeedRotate)) {
256
263
  that.canvas.width = width;
257
264
  that.canvas.height = height;
@@ -273,7 +280,7 @@ const TrtcRender = function () {
273
280
  }) || that.canvas.getContext('experimental-webgl');
274
281
  }
275
282
  catch (e) {
276
- console.log('trtc:', e);
283
+ console.log(e);
277
284
  }
278
285
  if (!gl) {
279
286
  gl = undefined;
@@ -361,9 +368,9 @@ const TrtcRender = function () {
361
368
  }
362
369
  }
363
370
  catch (e) {
364
- console.log(`trtc:updateCanvas error ${that.canvas}`);
365
- console.log('trtc:', that);
366
- console.error('trtc:', e);
371
+ console.log(`updateCanvas error ${that.canvas}`);
372
+ console.log(that);
373
+ console.error(e);
367
374
  return false;
368
375
  }
369
376
  return true;
@@ -51,10 +51,10 @@
51
51
  function error(msg) {
52
52
  if (topWindow.console) {
53
53
  if (topWindow.console.error) {
54
- topWindow.console.error('trtc:', msg);
54
+ topWindow.console.error(msg);
55
55
  }
56
56
  else if (topWindow.console.log) {
57
- topWindow.console.log('trtc:', msg);
57
+ topWindow.console.log(msg);
58
58
  }
59
59
  }
60
60
  }
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const EventEmitter = require('events').EventEmitter;
4
4
  const isEqual = require('lodash.isequal');
5
- const { calcCanvasStyle } = require('../util');
5
+ const { isNeedKeepWidthAndHeight } = require('../util');
6
6
  /* contentMode
7
7
  * - 0: Cropped mode. Uniformly scale the video until it fills the visible boundaries (cropped). One dimension of the video may have clipped contents.
8
8
  * - 1: Fit mode. Uniformly scale the video until one of its dimension fits the boundary (zoomed to fit). Areas that are not filled due to the disparity
@@ -21,6 +21,33 @@ class RGBRenderer {
21
21
  getView() {
22
22
  return this.element;
23
23
  }
24
+ _calcZoom(vertical = false, contentMode = 0, width, height, clientWidth, clientHeight) {
25
+ let localRatio = clientWidth / clientHeight;
26
+ let tempRatio = width / height;
27
+ if (isNaN(localRatio) || isNaN(tempRatio)) {
28
+ return 1;
29
+ }
30
+ if (!contentMode) {
31
+ if (vertical) {
32
+ return localRatio > tempRatio ?
33
+ clientHeight / height : clientWidth / width;
34
+ }
35
+ else {
36
+ return localRatio < tempRatio ?
37
+ clientHeight / height : clientWidth / width;
38
+ }
39
+ }
40
+ else {
41
+ if (vertical) {
42
+ return localRatio < tempRatio ?
43
+ clientHeight / height : clientWidth / width;
44
+ }
45
+ else {
46
+ return localRatio > tempRatio ?
47
+ clientHeight / height : clientWidth / width;
48
+ }
49
+ }
50
+ }
24
51
  bind(element) {
25
52
  this.element = element;
26
53
  let container = document.createElement('div');
@@ -46,64 +73,64 @@ class RGBRenderer {
46
73
  refreshCanvas() {
47
74
  }
48
75
  updateCanvas(options = {
49
- contentWidth: 0,
50
- contentHeight: 0,
76
+ width: 0,
77
+ height: 0,
51
78
  rotation: 0,
52
79
  mirrorView: false,
53
80
  contentMode: 0,
54
- containerWidth: 0,
55
- containerHeight: 0,
81
+ clientWidth: 0,
82
+ clientHeight: 0,
56
83
  isNeedRotate: true
57
84
  }) {
58
85
  if (isEqual(this.cacheCanvasOpts, options)) {
59
86
  return;
60
87
  }
61
88
  this.cacheCanvasOpts = Object.assign({}, options);
62
- const { width, height, transform } = calcCanvasStyle(options);
63
- this.canvas.width = width;
64
- this.canvas.height = height;
65
- this.canvas.style.transform = transform;
89
+ if ([0, 90, 180, 270].indexOf(options.rotation) === -1) {
90
+ throw new Error('Invalid value for rotation. Only support 0, 90, 180, 270');
91
+ }
92
+ const isKeepWidthHeight = isNeedKeepWidthAndHeight(options.rotation, options.isNeedRotate);
93
+ if (isKeepWidthHeight) {
94
+ this.canvas.width = options.width;
95
+ this.canvas.height = options.height;
96
+ }
97
+ else {
98
+ this.canvas.height = options.width;
99
+ this.canvas.width = options.height;
100
+ }
101
+ this.canvas.style.zoom = this._calcZoom(!isKeepWidthHeight, options.contentMode, options.width, options.height, options.clientWidth, options.clientHeight);
102
+ if (options.mirrorView) {
103
+ this.canvas.style.transform = 'rotateY(180deg)';
104
+ }
66
105
  }
67
106
  drawFrame(imageData) {
68
107
  if (!this.ready) {
69
108
  this.ready = true;
70
109
  this.event.emit('ready');
71
110
  }
72
- try {
73
- let mirror = false;
74
- let contentWidth = imageData.width;
75
- let contentHeight = imageData.height;
76
- const isNeedRotate = imageData.isNeedRotate;
77
- let left = 0;
78
- let top = 0;
79
- let right = 0;
80
- let bottom = 0;
81
- let rotation = imageData.rotation;
82
- let ts = imageData.timestamp;
83
- let width = contentWidth + left + right;
84
- let height = contentHeight + top + bottom;
85
- this.updateCanvas({
86
- contentWidth: width,
87
- contentHeight: height,
88
- rotation,
89
- mirrorView: mirror,
90
- contentMode: this.contentMode,
91
- containerWidth: this.container.clientWidth,
92
- containerHeight: this.container.clientHeight,
93
- isNeedRotate
94
- });
95
- let newImage = new ImageData(new Uint8ClampedArray(imageData.data.buffer || imageData.data), width, height);
96
- const tempCanvas = document.createElement('canvas');
97
- tempCanvas.width = imageData.width;
98
- tempCanvas.height = imageData.height;
99
- const tempCtx = tempCanvas.getContext('2d');
100
- tempCtx.putImageData(newImage, 0, 0);
101
- let ctx = this.canvas.getContext("2d");
102
- ctx.drawImage(tempCanvas, 0, 0);
103
- }
104
- catch (error) {
105
- console.error('trtc:RGBRenderer.drawFrame error:', error);
106
- }
111
+ let mirror = 0;
112
+ let contentWidth = imageData.width;
113
+ let contentHeight = imageData.height;
114
+ const isNeedRotate = imageData.isNeedRotate;
115
+ let left = 0;
116
+ let top = 0;
117
+ let right = 0;
118
+ let bottom = 0;
119
+ let rotation = imageData.rotation;
120
+ let ts = imageData.timestamp;
121
+ let width = contentWidth + left + right;
122
+ let height = contentHeight + top + bottom;
123
+ this.updateCanvas({
124
+ width, height, rotation,
125
+ mirrorView: mirror,
126
+ contentMode: this.contentMode,
127
+ clientWidth: this.container.clientWidth,
128
+ clientHeight: this.container.clientHeight,
129
+ isNeedRotate
130
+ });
131
+ let ctx = this.canvas.getContext("2d");
132
+ let tmpimage = new ImageData(imageData.data, width, height);
133
+ ctx.putImageData(tmpimage, 0, 0);
107
134
  }
108
135
  setContentMode(mode = 0) {
109
136
  this.contentMode = mode;
@@ -4,7 +4,7 @@ const EventEmitter = require('events').EventEmitter;
4
4
  const isEqual = require('lodash.isequal');
5
5
  const YUVBuffer = require('yuv-buffer');
6
6
  const YUVCanvas = require('yuv-canvas');
7
- const { calcCanvasStyle } = require('../util');
7
+ const { isNeedKeepWidthAndHeight } = require('../util');
8
8
  /* contentMode
9
9
  * - 0: Cropped mode. Uniformly scale the video until it fills the visible boundaries (cropped).
10
10
  * One dimension of the video may have clipped contents.
@@ -25,6 +25,33 @@ class Renderer {
25
25
  getView() {
26
26
  return this.element;
27
27
  }
28
+ _calcZoom(vertical = false, contentMode = 0, width, height, clientWidth, clientHeight) {
29
+ const localRatio = clientWidth / clientHeight;
30
+ const tempRatio = width / height;
31
+ if (isNaN(localRatio) || isNaN(tempRatio)) {
32
+ return 1;
33
+ }
34
+ if (!contentMode) {
35
+ if (vertical) {
36
+ return localRatio > tempRatio
37
+ ? clientHeight / height : clientWidth / width;
38
+ }
39
+ else {
40
+ return localRatio < tempRatio
41
+ ? clientHeight / height : clientWidth / width;
42
+ }
43
+ }
44
+ else {
45
+ if (vertical) {
46
+ return localRatio < tempRatio
47
+ ? clientHeight / height : clientWidth / width;
48
+ }
49
+ else {
50
+ return localRatio > tempRatio
51
+ ? clientHeight / height : clientWidth / width;
52
+ }
53
+ }
54
+ }
28
55
  bind(element) {
29
56
  this.element = element;
30
57
  const container = document.createElement('div');
@@ -51,23 +78,35 @@ class Renderer {
51
78
  refreshCanvas() {
52
79
  }
53
80
  updateCanvas(options = {
54
- contentWidth: 0,
55
- contentHeight: 0,
81
+ width: 0,
82
+ height: 0,
56
83
  rotation: 0,
57
84
  mirrorView: false,
58
85
  contentMode: 0,
59
- containerWidth: 0,
60
- containerHeight: 0,
86
+ clientWidth: 0,
87
+ clientHeight: 0,
61
88
  isNeedRotate: true
62
89
  }) {
63
90
  if (isEqual(this.cacheCanvasOpts, options)) {
64
91
  return;
65
92
  }
66
93
  this.cacheCanvasOpts = Object.assign({}, options);
67
- const { width, height, transform } = calcCanvasStyle(options);
68
- this.canvas.width = width;
69
- this.canvas.height = height;
70
- this.canvas.style.transform = transform;
94
+ if ([0, 90, 180, 270].indexOf(options.rotation) === -1) {
95
+ throw new Error('Invalid value for rotation. Only support 0, 90, 180, 270');
96
+ }
97
+ const isKeepWidthHeight = isNeedKeepWidthAndHeight(options.rotation, options.isNeedRotate);
98
+ if (isNeedKeepWidthAndHeight(options.rotation, options.isNeedRotate)) {
99
+ this.canvas.width = options.width;
100
+ this.canvas.height = options.height;
101
+ }
102
+ else {
103
+ this.canvas.height = options.width;
104
+ this.canvas.width = options.height;
105
+ }
106
+ this.canvas.style.zoom = this._calcZoom(!isKeepWidthHeight, options.contentMode, options.width, options.height, options.clientWidth, options.clientHeight);
107
+ if (options.mirrorView) {
108
+ this.canvas.style.transform = 'rotateY(180deg)';
109
+ }
71
110
  }
72
111
  _adjustImageData(imageData) {
73
112
  const { width, height, yUint8Array, uUint8Array, vUint8Array } = imageData;
@@ -112,7 +151,7 @@ class Renderer {
112
151
  this.event.emit('ready');
113
152
  }
114
153
  imageData = this._adjustImageData(imageData);
115
- const mirror = false;
154
+ const mirror = 0;
116
155
  const contentWidth = imageData.width;
117
156
  const contentHeight = imageData.height;
118
157
  const left = 0;
@@ -125,13 +164,11 @@ class Renderer {
125
164
  const width = contentWidth + left + right;
126
165
  const height = contentHeight + top + bottom;
127
166
  this.updateCanvas({
128
- contentWidth: width,
129
- contentHeight: height,
130
- rotation,
167
+ width, height, rotation,
131
168
  mirrorView: mirror,
132
169
  contentMode: this.contentMode,
133
- containerWidth: this.container.clientWidth,
134
- containerHeight: this.container.clientHeight,
170
+ clientWidth: this.container.clientWidth,
171
+ clientHeight: this.container.clientHeight,
135
172
  isNeedRotate
136
173
  });
137
174
  const format = YUVBuffer.format({
@@ -2,7 +2,7 @@
2
2
  import { EventEmitter } from 'events';
3
3
  export interface IRenderer {
4
4
  event: EventEmitter;
5
- bind(element: Element): void;
5
+ bind(element: Element, fallbackCb?: () => void): void;
6
6
  unbind(): void;
7
7
  drawFrame(imageData: {
8
8
  header: any;
@@ -18,7 +18,7 @@ declare class GlRenderer implements IRenderer {
18
18
  self: any;
19
19
  event: EventEmitter;
20
20
  constructor();
21
- bind(element: Element): void;
21
+ bind(element: Element, fallbackCb?: () => void): void;
22
22
  unbind(): void;
23
23
  drawFrame(imageData: {
24
24
  header: any;
@@ -50,9 +50,5 @@ declare const _default: {
50
50
  GlRenderer: typeof GlRenderer;
51
51
  SoftwareRenderer: any;
52
52
  RGBRenderer: any;
53
- I420VideoRenderer: any;
54
- BGRAVideoRenderer: any;
55
- RGBAVideoRenderer: any;
56
- Canvas3DRGBARenderer: any;
57
53
  };
58
54
  export default _default;
@@ -9,18 +9,14 @@ const GlRenderer_1 = __importDefault(require("./GlRenderer"));
9
9
  const SoftwareRenderer_1 = __importDefault(require("./SoftwareRenderer"));
10
10
  // @ts-ignore
11
11
  const RGBRenderer_1 = __importDefault(require("./RGBRenderer"));
12
- const I420VideoRenderer_1 = __importDefault(require("./I420VideoRenderer"));
13
- const BGRAVideoRenderer_1 = __importDefault(require("./BGRAVideoRenderer"));
14
- const RGBAVideoRenderer_1 = __importDefault(require("./RGBAVideoRenderer"));
15
- const Canvas3DRGBARenderer_1 = __importDefault(require("./Canvas3DRGBARenderer"));
16
12
  class GlRenderer {
17
13
  constructor() {
18
14
  // @ts-ignore
19
15
  this.self = GlRenderer_1.default.apply(this);
20
16
  this.event = this.self.event;
21
17
  }
22
- bind(element) {
23
- return this.self.bind(element);
18
+ bind(element, fallbackCb) {
19
+ return this.self.bind(element, fallbackCb);
24
20
  }
25
21
  unbind() {
26
22
  return this.self.unbind();
@@ -55,9 +51,5 @@ exports.default = {
55
51
  CustomRenderer,
56
52
  GlRenderer,
57
53
  SoftwareRenderer: SoftwareRenderer_1.default,
58
- RGBRenderer: RGBRenderer_1.default,
59
- I420VideoRenderer: I420VideoRenderer_1.default,
60
- BGRAVideoRenderer: BGRAVideoRenderer_1.default,
61
- RGBAVideoRenderer: RGBAVideoRenderer_1.default,
62
- Canvas3DRGBARenderer: Canvas3DRGBARenderer_1.default,
54
+ RGBRenderer: RGBRenderer_1.default
63
55
  };
@@ -1,5 +1,3 @@
1
- /// <reference types="node" />
2
- import { TRTCVideoStreamType } from "../trtc_define";
3
1
  /**
4
2
  * 配置对象, 可用来打开 debug 模式
5
3
  *
@@ -17,30 +15,4 @@ export declare class Config {
17
15
  getDebugMode(): boolean;
18
16
  }
19
17
  export declare function isNeedKeepWidthAndHeight(rotation: number, isNeedRotate: boolean): boolean;
20
- export declare function calcScaleRate(vertical: boolean, contentMode: number, contentWidth: number, contentHeight: number, containerWidth: number, containerHeight: number): number;
21
- export declare function calcCanvasStyle(options?: {
22
- contentWidth: number;
23
- contentHeight: number;
24
- rotation: number;
25
- mirrorView: boolean;
26
- contentMode: number;
27
- containerWidth: number;
28
- containerHeight: number;
29
- isNeedRotate: boolean;
30
- }): {
31
- [x: string]: any;
32
- };
33
- export declare function calcVideoStyle(options?: {
34
- contentWidth: number;
35
- contentHeight: number;
36
- rotation: number;
37
- mirrorView: boolean;
38
- contentMode: number;
39
- containerWidth: number;
40
- containerHeight: number;
41
- isNeedRotate: boolean;
42
- }): {
43
- [x: string]: any;
44
- };
45
18
  export declare const config: Config;
46
- export declare function allocBuffer(length: number, userId?: string, streamType?: TRTCVideoStreamType): Buffer;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.allocBuffer = exports.config = exports.calcVideoStyle = exports.calcCanvasStyle = exports.calcScaleRate = exports.isNeedKeepWidthAndHeight = exports.Config = void 0;
3
+ exports.config = exports.isNeedKeepWidthAndHeight = exports.Config = void 0;
4
4
  /**
5
5
  * 配置对象, 可用来打开 debug 模式
6
6
  *
@@ -28,110 +28,4 @@ function isNeedKeepWidthAndHeight(rotation, isNeedRotate) {
28
28
  return rotation === 0 || rotation === 180 || !isNeedRotate;
29
29
  }
30
30
  exports.isNeedKeepWidthAndHeight = isNeedKeepWidthAndHeight;
31
- function calcScaleRate(vertical = false, contentMode = 0, contentWidth, contentHeight, containerWidth, containerHeight) {
32
- const containerRatio = containerWidth / containerHeight;
33
- const contentRatio = contentWidth / contentHeight;
34
- if (isNaN(containerRatio) || isNaN(contentRatio)) {
35
- return 1;
36
- }
37
- if (!contentMode) {
38
- if (vertical) {
39
- return containerRatio > contentRatio
40
- ? containerHeight / contentHeight : containerWidth / contentWidth;
41
- }
42
- else {
43
- return containerRatio < contentRatio
44
- ? containerHeight / contentHeight : containerWidth / contentWidth;
45
- }
46
- }
47
- else {
48
- if (vertical) {
49
- return containerRatio < contentRatio
50
- ? containerHeight / contentHeight : containerWidth / contentWidth;
51
- }
52
- else {
53
- return containerRatio > contentRatio
54
- ? containerHeight / contentHeight : containerWidth / contentWidth;
55
- }
56
- }
57
- }
58
- exports.calcScaleRate = calcScaleRate;
59
- function calcCanvasStyle(options = {
60
- contentWidth: 0,
61
- contentHeight: 0,
62
- rotation: 0,
63
- mirrorView: false,
64
- contentMode: 0,
65
- containerWidth: 0,
66
- containerHeight: 0,
67
- isNeedRotate: true
68
- }) {
69
- if ([0, 90, 180, 270].indexOf(options.rotation) === -1) {
70
- throw new Error('Invalid value for rotation. Only support 0, 90, 180, 270');
71
- }
72
- const style = {
73
- width: 0,
74
- height: 0,
75
- transform: ''
76
- };
77
- const isKeepWidthHeight = isNeedKeepWidthAndHeight(options.rotation, options.isNeedRotate);
78
- if (isNeedKeepWidthAndHeight(options.rotation, options.isNeedRotate)) {
79
- style.width = options.contentWidth;
80
- style.height = options.contentHeight;
81
- }
82
- else {
83
- style.height = options.contentWidth;
84
- style.width = options.contentHeight;
85
- }
86
- const scale = calcScaleRate(!isKeepWidthHeight, options.contentMode, style.width, style.height, options.containerWidth, options.containerHeight);
87
- style.transform = `scale(${scale})`;
88
- if (options.mirrorView) {
89
- style.transform = `${style.transform} rotateY(180deg)`;
90
- }
91
- return style;
92
- }
93
- exports.calcCanvasStyle = calcCanvasStyle;
94
- function calcVideoStyle(options = {
95
- contentWidth: 0,
96
- contentHeight: 0,
97
- rotation: 0,
98
- mirrorView: false,
99
- contentMode: 0,
100
- containerWidth: 0,
101
- containerHeight: 0,
102
- isNeedRotate: true
103
- }) {
104
- if ([0, 90, 180, 270].indexOf(options.rotation) === -1) {
105
- throw new Error('Invalid value for rotation. Only support 0, 90, 180, 270');
106
- }
107
- let width = 0;
108
- let height = 0;
109
- const isKeepWidthHeight = isNeedKeepWidthAndHeight(options.rotation, options.isNeedRotate);
110
- if (isNeedKeepWidthAndHeight(options.rotation, options.isNeedRotate)) {
111
- width = options.contentWidth;
112
- height = options.contentHeight;
113
- }
114
- else {
115
- height = options.contentWidth;
116
- width = options.contentHeight;
117
- }
118
- const scale = calcScaleRate(!isKeepWidthHeight, options.contentMode, width, height, options.containerWidth, options.containerHeight);
119
- const style = {
120
- width: `${width * scale}px`,
121
- height: `${height * scale}px`,
122
- };
123
- if (options.mirrorView) {
124
- style.transform = 'rotateY(180deg)';
125
- }
126
- return style;
127
- }
128
- exports.calcVideoStyle = calcVideoStyle;
129
31
  exports.config = new Config();
130
- function allocBuffer(length, userId, streamType) {
131
- console.debug('trtc:alloc buffer:', length, userId, streamType);
132
- if (length >= 1) {
133
- return Buffer.alloc(length);
134
- }
135
- return null;
136
- }
137
- exports.allocBuffer = allocBuffer;