Library allows you to connect to the PulseVision platform and start streaming.
Note: This documentation is for v2.5.0 and above
Library is available as an npm package.
npm install @pulsevision/producer
yarn add @pulsevision/producer
pnpm add @pulsevision/producer
import {
BrowserUnsupportedError,
CredentialsInvalidError,
DeviceAccessDeniedError,
Producer,
RequestTimeoutError,
RuntimeError,
StreamSourceError,
} from '@pulsevision/producer';
let isLoading = false;
const producer = new Producer({
domain: 'https://app.pulsevision.io',
apiToken: 'YOUR-API-TOKEN',
roomName: 'user1',
meta: {
username: 'user1@example.com',
group: 'SOME GROUP NAME', // Optional parameter
restrictToMonitor: true, // Optional, true by default
},
debug: true,
});
producer.on('connect', ({ roomName }) => {
isLoading = false;
console.log('Connected to', roomName);
});
producer.on('disconnect', ({ roomName }) => {
console.log('Disconnected from', roomName);
});
producer.on('error', (error) => {
if (error instanceof BrowserUnsupportedError) {
console.log('Browser is not supported');
}
if (error instanceof DeviceAccessDeniedError) {
console.log('User denied access to media devices');
}
if (error instanceof StreamSourceError) {
console.log('Stream source error');
}
if (error instanceof RuntimeError) {
console.log('Runtime error');
}
});
// To start the stream
isLoading = true;
try {
await producer.connect();
} catch (error) {
isLoading = false;
if (error instanceof RequestTimeoutError) {
console.log('The server did not answer in time');
} else if (error instanceof CredentialsInvalidError) {
console.log('Credentials are invalid');
}
}
// To stop the stream; the same instance can connect again
await producer.disconnect();
// To release the instance for good
producer.destroy();
| Event | Data | When |
|---|---|---|
connect |
{ roomId, roomName } |
The stream is live. |
disconnect |
{ roomId, roomName } |
The room was left after disconnect() or the user stopped sharing. |
connectionLost |
{ roomId, roomName } |
The socket dropped without the client asking (network loss, server restart). Purely local: nothing is sent to the server. |
error |
PulseVisionError |
A capture, device or runtime problem. |
socketError |
Error |
An error reported by the socket. |
roomName in these payloads is the name the server knows, which is the name you passed
suffixed with a short random hash (user1_3kf9a). Each fresh connect() session
gets a new suffix; the name stays stable within that session, including reconnect emits.
After connectionLost the outcome depends on why the socket dropped:
| Reason | Capture | Socket | What to do |
|---|---|---|---|
| network drop, server restart | keeps running | reconnects by itself and the stream may resume | nothing; wait for connect |
| ping timeout, transport error | stops | closed, no reconnect | connect() starts a fresh session |
| server closes the socket | keeps running | closed, no reconnect | await disconnect(), then connect() |
A client disconnect() leaves the room without emitting connectionLost, and destroy()
releases the capture directly.
connect() asks for screen capture and starts streaming. It is safe to call twice: a
call while a connection is in flight returns the same promise, and a call while already
connected does nothing.await disconnect() stops the stream and leaves the room. The same instance can
connect again with a fresh room name and a new screen-capture click. After an SFU
restart, use this same disconnect/connect sequence to start a fresh session.destroy() is synchronous (void), terminal and idempotent. Capture, preview and
listeners stop immediately. If currently joined, it sends the existing exitRoom
event and closes the socket on the ACK or after 1 second; otherwise it closes
immediately. Call it on unmount; a later connect() rejects. A missing ACK cannot
keep local capture or the socket alive indefinitely.await connect(); the promise is where errors surface.A tab close or crash may prevent JavaScript from completing a graceful exit. The server keeps the room for its reconnect grace period, then removes it, so the stream can stay in the list for about two minutes. Explicit destroy() while the page is running sends exitRoom and does not wait for that grace period when the server ACKs.
All errors extend PulseVisionError. Connect/disconnect requests have a fixed 3 second deadline
and reject with RequestTimeoutError, which extends CredentialsInvalidError so that
existing instanceof CredentialsInvalidError checks keep working. A server error answer is
not wrapped: the promise rejects with the plain value the server sent, as in 2.4.0. For the
PulseVision API that is usually a string, such as 'No existing room', so
typeof error === 'string' and error === 'No existing room' still hold.
Previews and screenshots use ImageCapture where available, otherwise an inline video and canvas with the same pica resize and JPEG settings. The fallback video is released on disconnect/destroy.
The SDK asks for a full screen by default (meta.restrictToMonitor: true). Sharing a
window or a tab fails with StreamSourceError and leaves the room when the
browser reports the selected surface. Browsers that omit displaySurface
(e.g. Firefox) cannot enforce the restriction; it is only a picker hint there.
The browser always lets the user choose the source, and may ignore that hint.
Pass restrictToMonitor: false in meta to accept reported windows/tabs too.
While a producer is live the SDK uploads a JPEG preview of the captured screen:
POST {domain}/api/content/preview, as a multipart body with file,
roomName, roomId and resourceToken;POST {domain}/api/content with file and imageRequestKey
when the platform asks for one.The preview body contains your apiToken, so use an https domain.
When a requested screenshot cannot be taken, the SDK tells the server with a
fire-and-forget screenshotFailed event: { imageRequestKey, reason }. The
reason is one of not-sharing (no live stream), capture-ended (the shared
surface is gone), capture-muted (the browser paused the capture track),
capture-error or capture-error: <name> (the error class), upload-failed or
upload-failed: <name>, or upload-rejected: <status>. Only the error class
name is sent, never its message, so a URL, a token or an address in an error
text stays on the page; the reason is capped at 200 characters. Only requested
screenshots are reported; previews are not. This is server-facing: your local
error event and your code need no change, and servers that predate the event
ignore it.
import { useEffect, useRef, useState } from 'react';
import { Producer } from '@pulsevision/producer';
function App() {
const clientRef = useRef(null);
const [connected, setConnected] = useState(false);
useEffect(() => {
const producer = new Producer({
domain: 'https://app.pulsevision.io',
apiToken: 'YOUR-API-TOKEN',
roomName: 'user_test',
meta: {
username: 'username@example.com',
group: 'SOME GROUP NAME', // Optional parameter
restrictToMonitor: true, // Optional, true by default
},
debug: true,
});
producer.on('connect', () => {
setConnected(true);
});
producer.on('disconnect', () => {
setConnected(false);
});
producer.on('connectionLost', () => {
setConnected(false);
});
clientRef.current = producer;
return () => {
producer.destroy();
clientRef.current = null;
};
}, []);
return (
<>
{connected ? 'Connected' : 'Disconnected'}
>
);
}
<!doctype html>
<html lang="en">
<body>
<button id="connect">Connect</button>
<button id="disconnect">Disconnect</button>
<div id="status">Disconnected</div>
<script src="https://static.pulsevision.io/sdk/v2.5.0/pulsevision.umd.js"></script>
<script>
document.addEventListener('DOMContentLoaded', function () {
const client = new window.PulseVision.Producer({
domain: 'https://app.pulsevision.io',
apiToken: 'YOUR-API-TOKEN',
roomName: 'user_test',
meta: {
username: 'usernam@example.com',
group: 'SOME GROUP NAME', // Optional parameter
},
debug: true,
});
client.on('error', (data) => {
console.log('error', data);
});
client.on('disconnect', (data) => {
document.getElementById('status').innerHTML = 'Disconnected';
});
client.on('connectionLost', (data) => {
document.getElementById('status').innerHTML = 'Connection lost';
});
client.on('connect', (data) => {
document.getElementById('status').innerHTML = 'Connected';
});
document
.getElementById('connect')
.addEventListener('click', async () => {
try {
await client.connect();
console.log('producer connected');
} catch (error) {
console.log('producer error', error);
}
});
document
.getElementById('disconnect')
.addEventListener('click', async () => {
await client.disconnect();
console.log('producer disconnected');
});
window.addEventListener('beforeunload', () => {
client.destroy();
});
});
</script>
</body>
</html>
By default, iframes don't have access to the camera and microphone.
To allow access, you need to add allow="camera;microphone" attribute to the iframe tag.
If you use strict Permissions Policy, you need to add camera=() and microphone=() to the Permissions-Policy header.
If domains are different, add them to allowlist.
<!-- Same domain -->
<iframe src="https://example.com" allow="camera;microphone"></iframe>
<!-- Different domain -->
<iframe
src="https://example.com"
allow="
camera 'self' https://a.example.com https://b.example.com;
microphone 'self' https://a.example.com https://b.example.com
"
></iframe>
<!-- Any domain -->
<iframe src="http://example.net" allow="camera *;microphone *"></iframe>
More details about Permissions Policy: https://developer.mozilla.org/en-US/docs/Web/HTTP/Permissions_Policy
The bundled mediasoup-client 3.26.0 selects Chrome74 for Chromium 74–110, Chrome111 for Chromium 111+, Firefox120 for Firefox 120+, and Safari12 for WebKit 605+. React Native uses ReactNative106 and requires registered WebRTC globals. No handler was removed compared with 3.15.6, but detection now rejects Chromium below 74 and WebKit below 605 instead of attempting legacy fallbacks. Electron selects a handler from its Chromium version. Screen capture also requires browser support, a secure context, a user gesture and OS permission; handler detection alone does not establish capture support.