Random things of a random world

Sami's Page

  • Join Us on Facebook!
  • Follow Us on Twitter!
  • LinkedIn
  • Subcribe to Our RSS Feed

Quick Audiobridge Room Thing in JavaScript for Janus Gateway

If you need to use Janus Gateway with janus-gateway-js, here's a simple example since the docs on the page are wrong:

import * as Janus from 'janus-gateway-js';

const janus = new Janus.Client('ws://localhost:8188', { keepalive: true, apisecret: 'secret' });
const connection = await janus.createConnection();
const session = await connection.createSession();
const plugin = await session.attachPlugin('janus.plugin.audiobridge');
plugin.on('message', (message) => { console.log("msg: ", message); }); // For debugging
plugin.on('pc:track:remote', (message) => { /* handle incoming audio, stream is in message.streams[0] */ });
const resp = await plugin.join('test', { display: "Name" quality: 3, token: 'token' });
const stream = await plugin.getUserMedia({ audio: true, video: false });
const response = await plugin.offerStream(stream);

That should get you started. The pc:track:remote I had to dig from tests since I didn't see it anywhere really mentioned and the offerStream() wasn't in the docs, they used some methods that didn't even exist. Will have to report these and get them fixed.

Note that I'm using string IDs for rooms, if you use numbers then the type has to be a number, not a string, in join or you'll get exceptions.

Add comment