trtc-electron-sdk 9.5.112-beta.1 → 9.5.112-beta.2

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,8 +41,9 @@ 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 {
@@ -94,7 +96,7 @@ const TrtcRender = function () {
94
96
  that.unbind();
95
97
  initCanvas(view, image.mirror, image.width, image.height, image.rotation, image.isNeedRotate, e => {
96
98
  console.error(`init canvas ${image.width}*${image.height} rotation ${image.rotation} failed. ${e}`);
97
- });
99
+ }, false);
98
100
  }
99
101
  gl.bindBuffer(gl.ARRAY_BUFFER, texCoordBuffer);
100
102
  const xWidth = image.width + image.left + image.right;
@@ -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;
@@ -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;
@@ -15,8 +15,8 @@ class GlRenderer {
15
15
  this.self = GlRenderer_1.default.apply(this);
16
16
  this.event = this.self.event;
17
17
  }
18
- bind(element) {
19
- return this.self.bind(element);
18
+ bind(element, fallbackCb) {
19
+ return this.self.bind(element, fallbackCb);
20
20
  }
21
21
  unbind() {
22
22
  return this.self.unbind();
package/liteav/trtc.js CHANGED
@@ -3357,7 +3357,14 @@ class TRTCCloud extends events_1.EventEmitter {
3357
3357
  renderer = new Render_1.default.GlRenderer();
3358
3358
  }
3359
3359
  view.innerHTML = ''; // 事先清空一下,避免画面叠加
3360
- renderer.bind(view);
3360
+ if (this.renderMode === 1) {
3361
+ renderer.bind(view, () => {
3362
+ this.setRenderMode(2);
3363
+ });
3364
+ }
3365
+ else {
3366
+ renderer.bind(view);
3367
+ }
3361
3368
  this.streams.set(String(key), renderer);
3362
3369
  if (key === this.getKey('local_video', trtc_define_1.TRTCVideoStreamType.TRTCVideoStreamTypeBig)) {
3363
3370
  // 只有本地视频, 才设置 local fill mode
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "trtc-electron-sdk",
3
- "version": "9.5.112-beta.1",
3
+ "version": "9.5.112-beta.2",
4
4
  "description": "trtc electron sdk",
5
5
  "main": "./liteav/trtc.js",
6
6
  "types": "./liteav/trtc.d.ts",