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.
var JanusClient = require('janus-videoroom-client').Janus;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'
});client.onConnected(()=>{
client.createSession().then((session)=>{
...
}).catch((err)=>{
...
})
});client.onDisconnected(()=>{
});client.onError((err)=>{
});client.connect();client.createSession().then((session)=>{
...
});client.createSession().then((session)=>{
return session.videoRoom().createVideoRoomHandle();
}).then((videoRoomHandle)=>{
...
});client.createSession().then((session)=>{
return session.videoRoom().defaultHandle();
}).then((videoRoomHandle)=>{
...
});videoRoomHandle.create({
publishers: 3,
is_private: 'no',
secret: '****',
pin: '****',
audiocodec: 'opus',
videocodec: 'vp8',
record: false
}).then((result)=>{
var roomId = result.room;
...
});session.videoRoom().publishFeed(room, offerSdp).then((publisherHandle)=>{
var answerSdp = publisherHandle.getAnswer();
...
});publisherHandle.trickle(candidate).then(()=>{
...
});session.videoRoom().listenFeed(room, feed).then((listenerHandle)=>{
var offerSdp = listenerHandle.getOffer();
...
});listenerHandle.trickle(candidate).then(()=>{
...
});listenerHandle.setRemoteAnswer(answerSdp).then(()=>{
...
});session.videoRoom().getFeeds(room).then((feeds)=>{
for(let feed of feeds) {
...
}
});npm test