janus-videoroom-client

4.2.1 • Public • Published

Conferencing with Janus WebRTC Gateway

Node.js client that implements a subset of the WebSocket interface of the Janus WebRTC Gateway.

Note: For now it supports the videoroom plugin only.

Setup janus client

var JanusClient = require('janus-videoroom-client').Janus;

Establish connection to the Janus WebSocket API

1. Create client

Without authentication

var client = new JanusClient({
    url: 'ws://localhost:8188'
});

Token based authentication

var client = new JanusClient({
    url: 'ws://localhost:8188',
    token: 'yourToken'
});

Static secret authentication

var client = new JanusClient({
    url: 'ws://localhost:8188',
    apiSecret: 'yourStaticSecret'
});

2. Register events connected, disconnected, error

client.onConnected(()=>{
    client.createSession().then((session)=>{
        ...
    }).catch((err)=>{
        ...
    })
});
client.onDisconnected(()=>{
    
});
client.onError((err)=>{
    
});

3. Call connect method

client.connect();

Create a new janus session

client.createSession().then((session)=>{
    ...
});

Create a new videoroom handle

client.createSession().then((session)=>{
    return session.videoRoom().createVideoRoomHandle();
}).then((videoRoomHandle)=>{
    ...
});

Get default videoroom handle

client.createSession().then((session)=>{
    return session.videoRoom().defaultHandle();
}).then((videoRoomHandle)=>{
    ...
});

Create a new videoroom

videoRoomHandle.create({
   publishers: 3,
   is_private: false,
   secret: '****',
   pin: '****',
   audiocodec: 'opus',
   videocodec: 'vp8',
   record: false
}).then((result)=>{
    var roomId = result.room;
    ...
});

Delete a videoroom

videoRoomHandle.destroy({
   room: roomId
}).then((result) => {
  ...
}).catch((err) => {
  ...
});

Publish media stream

session.videoRoom().publishFeed(room, offerSdp).then((publisherHandle)=>{
    var answerSdp = publisherHandle.getAnswer();
    ...
});
publisherHandle.trickle(candidate).then(()=>{
    ...
});

Subscribe to a media stream

session.videoRoom().listenFeed(room, feed).then((listenerHandle)=>{
    var offerSdp = listenerHandle.getOffer();
    ...
});
listenerHandle.trickle(candidate).then(()=>{
    ...
});
listenerHandle.setRemoteAnswer(answerSdp).then(()=>{
    ...
});

Get current published media streams

session.videoRoom().getFeeds(room).then((feeds)=>{
    for(let feed of feeds) {
        ...
    }
});

Run tests

npm test

Readme

Keywords

Package Sidebar

Install

npm i janus-videoroom-client

Weekly Downloads

43

Version

4.2.1

License

GPL-3.0

Unpacked Size

156 kB

Total Files

43

Last publish

Collaborators

  • sipwise