Skip to content

Repository files navigation

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

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

Establish connection to the Janus WebSocket API

1. Create client

Without authentication

varclient=newJanusClient({url: 'ws://localhost:8188'});

Token based authentication

varclient=newJanusClient({url: 'ws://localhost:8188',token: 'yourToken'});

Static secret authentication

varclient=newJanusClient({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)=>{returnsession.videoRoom().createVideoRoomHandle();}).then((videoRoomHandle)=>{
...
});

Get default videoroom handle

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

Create a new videoroom

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

Publish media stream

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

Subscribe to a media stream

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

Get current published media streams

session.videoRoom().getFeeds(room).then((feeds)=>{for(letfeedoffeeds){
...
}});

Run tests

npm test

About

javascript library to implement the websocket interface towards the janus server

Resources

Stars

0 stars

Watchers

4 watching

Forks

Releases

Packages

Contributors

Languages