janus-videoroom-client-typescript
TypeScript icon, indicating that this package has built-in type declarations

1.0.11 • 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: 'no',
   secret: '****',
   pin: '****',
   audiocodec: 'opus',
   videocodec: 'vp8',
   record: false
}).then((result)=>{
    var roomId = result.room;
    ...
});

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-typescript

Weekly Downloads

4

Version

1.0.11

License

GPL-3.0

Unpacked Size

424 kB

Total Files

95

Last publish

Collaborators

  • lookapanda