janus-client
Javascript web client for a WebRTC Janus server.
The js file comes from the official Janus repository while the typing one, index.d.ts
is tailored for the videoroom plugin.
Install
yarn add @nabla/janus-client
Usage
import Janus, { JSEP, PluginHanlde } from "@nabla/janus-client";
let session: Janus;
let localHandle: PluginHandle;
const opaqueId = "<OPAQUE_ID>";
Janus.init({
debug: true,
callback: () => {
session = new Janus({
server: serverUrl,
withCredentials: true,
success: () => {
session.attach({
plugin: "janus.plugin.videoroom",
opaqueId,
success: (pluginHandle) => {
localHandle = pluginHandle;
pluginHandle.send({
message: {
request: "join",
room: 1234,
ptype: "publisher",
display: "<USER_NAME>",
},
});
},
error: (err) => {
},
iceState: (state) => {
},
mediaState: (medium, on) => {
},
webrtcState: (on) => {
},
slowLink: () => {
},
onmessage: (msg, jsep) => {
const event = msg.videoroom;
if (event === "joined") {
if (msg.publishers) {
for (const p of msg.publishers) {
}
}
} else if (event === "event") {
if (msg.publishers) {
for (const p of msg.publishers) {
}
} else if (msg.leaving) {
} else if (msg.unpublished) {
}
} else if (event === "destroyed") {
}
if (jsep) {
localHandle.handleRemoteJsep({ jsep });
}
},
onlocalstream: (stream) => {
},
});
},
error: (err) => {
},
});
},
});