TRTCMediaMixingManager

TRTCMediaMixingManager

Local media mixing manager

Constructor

new TRTCMediaMixingManager()

Methods

bindPreviewArea(windowID, region)

Set preview parameters for mixed-stream video

Examples
// Display in HTML Element
import TRTCCloud from 'trtc-electron-sdk';

const trtcCloud = TRTCCloud.getTRTCShareInstance({
  isIPCMode: true
});

const mediaMixingManager = trtcCloud.getMediaMixingManager();

const windowID = 0; // Use Electron API BrowserWindow.getNativeWindowHandle()
const previewDOM = document.getElementById("preview-local-mixed-media-stream");
mediaMixingManager.bindPreviewArea(windowID, previewDOM);
// Display in a rectangle section
import TRTCCloud from 'trtc-electron-sdk';

const trtcCloud = TRTCCloud.getTRTCShareInstance({
  isIPCMode: true
});

const mediaMixingManager = trtcCloud.getMediaMixingManager();

const windowID = 0; // Use Electron API BrowserWindow.getNativeWindowHandle()
const previewDOM = document.getElementById("preview-local-mixed-media-stream");
const domRect = previewDOM.getBoundingClientRect();
const rect = {
  left: domRect.left * window.devicePixelRatio,
  right: domRect.right * window.devicePixelRatio,
  top: domRect.top * window.devicePixelRatio,
  bottom: domRect.bottom * window.devicePixelRatio
};

mediaMixingManager.bindPreviewArea(windowID, previewDOM);
Parameters:
Name Type Description
windowID Number | Uint8Array required

The window ID at the operating system level, which can be obtained with Electron API BrowserWindow.getNativeWindowHandle()

region HTMLElement | Rect | null required

The HTML element or Rectangle area to display local mixed-stream video

  • If you pass in an HTMLElement element, the SDK will display the local mixed-stream video within the HTMLElement element. It also supports clicking to select, moving, and scaling the media source, and supports triggering right-click menu events. The HTMLElement element must be a block element.
  • If you pass in a Rect display area, the SDK will display the local mixed-stream video within the area specified by Rect. It does not support clicking to select, moving, and scaling the media source, nor does it support triggering right-click menu events. You can implement these features on your web page yourself.
  • If you pass in null, the SDK will stop displaying the local mixed-stream video.

addMediaSource(mediaSource) → {Promise.<void>}

Add media source

Parameters:
Name Type Description
mediaSource TRTCMediaSource required

Media source data

Returns:
Type
Promise.<void>

removeMediaSource(mediaSource) → {Promise.<void>}

Remove media source

Parameters:
Name Type Description
mediaSource TRTCMediaSource required

Media source data

Returns:
Type
Promise.<void>

updateMediaSource(mediaSource) → {Promise.<void>}

Update media source

Parameters:
Name Type Description
mediaSource TRTCMediaSource required

Media source data

Returns:
Type
Promise.<void>

setCameraCaptureParam(cameraID, params)

Set camera capturing parameter

Parameters:
Name Type Description
cameraID string required

Camera device ID

params TRTCCameraCaptureParams required

Camera capturing parameters

setPhoneMirrorParam(phoneMirrorSourceId, param)

Set phone mirror parameter

Parameters:
Name Type Description
phoneMirrorSourceId string required

Phone mirror source ID

param TRTCPhoneMirrorParam required

Phone mirror parameter

setScreenCaptureProperty(screenOrWindowID, property)

Set screen/window capture property

Parameters:
Name Type Description
screenOrWindowID String required

Screen or window ID

property TRTCScreenCaptureProperty required

Capture proprety

startPublish() → {Promise.<void>}

Start publishing mixing video

Returns:
Type
Promise.<void>

stopPublish() → {Promise.<void>}

Stop publishing mixing video

Returns:
Type
Promise.<void>

updatePublishParams(params) → {Promise.<void>}

Update mixing video encoding parameter

Parameters:
Name Type Description
params TRTCMediaMixingEncParam required

Mixing video encoding parameter and background color.

Returns:
Type
Promise.<void>

setStreamLayout(layout)

Set stream layout

Examples
// Custom layout
import TRTCCloud, { TRTCStreamLayout, TRTCStreamLayoutMode, TRTCVideoFillMode } from 'trtc-electron-sdk';

const trtcCloud = TRTCCloud.getTRTCShareInstance({
  isIPCMode: true
});

const mediaMixingManager = trtcCloud.getMediaMixingManager();
if (mediaMixingManager) {
  const streamLayout: TRTCStreamLayout = {
    "layoutMode": TRTCStreamLayoutMode.Custom,
    "userList": [
      {
        "userId": "", // local userId
        "rect": {
          "left": 0,
          "top": 0,
          "right": 296,
          "bottom": 494
        },
        "fillMode": TRTCVideoFillMode.TRTCVideoFillMode_Fill, // Fill to strech the whole area
        "zOrder": 0
      },
      {
        "userId": "849014",
        "rect": {
          "left": 296,
          "top": 0,
          "right": 592,
          "bottom": 247
        },
        "fillMode": TRTCVideoFillMode.TRTCVideoFillMode_Fill,
        "zOrder": 1
      },
      {
        "userId": "p20",
        "rect": {
          "left": 296,
          "top": 247,
          "right": 592,
          "bottom": 494
        },
        "fillMode": TRTCVideoFillMode.TRTCVideoFillMode_Fill,
        "zOrder": 2
      }
    ]
  };
  mediaMixingManager.setStreamLayout(streamLayout);
}
// Clear custom layout and restore default layout
import TRTCCloud, { TRTCStreamLayout, TRTCStreamLayoutMode, TRTCVideoFillMode } from 'trtc-electron-sdk';

const trtcCloud = TRTCCloud.getTRTCShareInstance({
  isIPCMode: true
});

const mediaMixingManager = trtcCloud.getMediaMixingManager();
if (mediaMixingManager) {
  const streamLayout: TRTCStreamLayout = {
    "layoutMode": TRTCStreamLayoutMode.None
  };
  mediaMixingManager.setStreamLayout(streamLayout);
}
Parameters:
Name Type Description
layout TRTCStreamLayout required

Stream layout data

on(event, func)

Add event listener

Parameters:
Name Type Description
event TRTCMediaMixingEvent required

Event name

func function required

Event listener functon

off(event, func)

Remove event listener

Parameters:
Name Type Description
event TRTCMediaMixingEvent required

Event name

func function required

Event listener functon