Modern typescript client for janus-gateway.
npm install janus-gateway-tsdxjanus-gateway-tsdx 
================
Modern typescript client for janus gateway. Based on websockets.
The original client can be found here https://janus.conf.meetecho.com/docs/rest.html.
This library is a rewrite of janus-gateway-js in typescript.
Also, this library is possible to be used with react-native.
In this case we need to create some shim classes and pass them to Client constructor, see Client.
bluebird Promise library.websocket dependency.webrtcsupport dependency.yarn add janus-gateway-tsdx
Just run yarn build
* Client
* Connection
* Session
* Plugin
* WebsocketConnection
Currently, the project has implemented: audio-bridge, video-streaming, and video-room.
If you require a plugin that is not implemented then you need to write it on your own.
* AudioBridgePlugin
* StreamingPlugin
* VideoRoomPlugin
Media devices shim:
``typescript
import {MediaDevices} from 'janus-gateway-tsdx';
import {mediaDevices} from 'react-native-webrtc';
class MediaDevicesReactNativeShim implements MediaDevices {
getUserMedia = (constraints) => {
return Promise.resolve(mediaDevices.getUserMedia(constraints));
};
}
export default MediaDevicesReactNativeShim
`
WebRTC shim:
`typescript
import {RTCIceCandidate, RTCPeerConnection, RTCSessionDescription} from 'react-native-webrtc';
import {WebRTC} from 'janus-gateway-tsdx';
class WebRTCReactNativeShim implements WebRTC {
newRTCPeerConnection = (config, _): RTCPeerConnection => {
return new RTCPeerConnection(config);
};
newRTCSessionDescription = (jsep: RTCSessionDescription): RTCSessionDescription => {
return new RTCSessionDescription(jsep);
};
newRTCIceCandidate = (candidate: RTCIceCandidate): RTCIceCandidate => {
return new RTCIceCandidate(candidate);
};
}
export default WebRTCReactNativeShim
`
Then use it:
`typescript`
import Client from '../../client/client';
let client = new Client(this.address, this.clientOptions, new MediaDevicesReactNativeShim(), new WebRTCReactNativeShim);
For simplicity lets write an EchoTest plugin that does
only audio.
`typescript
import Promise from 'bluebird';
import Plugin from '../client/plugin';
import MediaPlugin from './base/media-plugin';
class EchoTest extends MediaPlugin {
static NAME = 'janus.plugin.echotest';
audio(state: boolean): Promise
return Promise.try(() => this.getUserMedia({ audio: true, video: false }))
.then(stream => {
this.createPeerConnection();
stream.getTracks().forEach(track => this.addTrack(track, stream));
})
.then(() => this.createOffer({}))
.then(jsep => {
let message = { body: { audio: state }, jsep };
return this.sendWithTransaction(message);
})
.then(response => {
let jsep = response.get('jsep');
if (jsep) {
this.setRemoteSDP(jsep);
return jsep;
}
});
}
}
Plugin.register(EchoTest.NAME, EchoTest);
export default EchoTest;
`
Then we can use it
`typescript``
let janus = new Janus.Client(config.url, config);
janus.createConnection('client')
.then(connection => connection.createSession())
.then(session => session.attachPlugin(EchoTest.NAME))
.then(echoTestPlugin => echoTestPlugin.audio(true))