setLocalStream

View as Markdown

setLocalStream

  • setLocalStream(stream): void

Replaces the current local media stream with the one specified as a parameter.

Parameters

stream
MediaStream

The media stream to use.

Returns

void

Example

Drawing and streaming the picture of a face:

1const canvas = document.createElement("canvas");
2const ctx = canvas.getContext("2d");
3
4// Set canvas size
5canvas.width = 400;
6canvas.height = 400;
7
8// Draw circle
9ctx.beginPath();
10ctx.arc(200, 200, 150, 0, 2 * Math.PI);
11ctx.fillStyle = "lightblue";
12ctx.fill();
13
14// Draw eyes
15ctx.beginPath();
16ctx.arc(150, 150, 30, 0, 2 * Math.PI);
17ctx.arc(250, 150, 30, 0, 2 * Math.PI);
18ctx.fillStyle = "black";
19ctx.fill();
20
21// Get the media stream
22const stream = canvas.captureStream(25); // 25 FPS
23
24// Stream the canvas
25await roomSession.setLocalStream(stream);