Janus Gateway Node
npm install janus-gateway-node
yarn add janus-gateway-node
`
Summary - janus instances manager, receives messages from clients and dispatches them to correct janus instances (based on location of created room), sending back responses.
!alt text
Docker image herbert1947/janus-gateway-videoroom
`
docker pull herbert1947/janus-gateway-videoroom:latest
`
Usage
Follow this link to find information on how to use frontend part.
`
import { Janus } from 'janus-gateway-node';
...
const janus = new Janus();
await janus.initialize();
`
Options
$3
> () => Promise | optional
return necessary information for every available janus instance required
to establish connection. Example of launch instances script - https://github.com/IG-88-2/janus-gateway-videoroom-tests/blob/master/launchInstances.js
`
janus = new Janus({
generateInstances : async () : Promise => {
const instances = [];
const start_ws_port = 8188;
const start_admin_ws_port = 7188;
for(let i = 0; i < this.instancesAmount; i++) {
instances.push({
id : uuidv1(),
admin_key : uuidv1(),
server_name : instance_${i},
log_prefix : instance_${i}:,
docker_ip : 127.0.0.${1 + i},
ws_port : start_ws_port + i,
admin_ws_port : start_admin_ws_port + i,
stun_server : "stun.voip.eutelia.it",
nat_1_1_mapping : this.options.publicIp || 127.0.0.${1 + i},
stun_port : 3478,
debug_level : 5
});
}
await this.launchContainers(instances);
return instances.map(({
admin_key,
server_name,
ws_port,
docker_ip,
admin_ws_port,
log_prefix,
stun_server,
stun_port,
id,
debug_level
}) => {
return {
protocol: ws,
address: docker_ip,
port: ws_port,
adminPort: admin_ws_port,
adminKey: admin_key,
server_name
};
});
}
});
`
$3
> (instances:JanusInstance[]) => JanusInstance | optional
this function is called when room needs to be created, user can make a choice based on current
instance properties.
`
janus = new Janus({
selectInstance:(instances : JanusInstance[]) => {
let instance = instances[this.count];
if (!instance) {
this.count = 0;
instance = instances[this.count];
}
this.count += 1;
return instance;
}
});
`
$3
> (context:Context) => Promise | optional
update rooms data on change.
$3
> () => Promise | optional
retrieve rooms data on launch.
$3
> (error:any) => void | optional
in case error occurred this. function will be invoked to notify user about error.
$3
> any | optional
customize logging.
$3
> number | optional
keepalive timeout for user.
$3
> number | optional
synchronization interval for janus instances.
$3
> number | optional
amount of instances to spawn by default.
$3
> string | optional
this option will be passed as nat 1 1 mapping to janus.
$3
> any | optional
options for websocket server constructor.
`
const keys = {
key: fs.readFileSync("/keys/key.pem"),
cert: fs.readFileSync("/keys/cert.pem")
};
const serverOptions = {
key: keys.key,
cert: keys.cert
};
const server = https.createServer(serverOptions, app).listen(443);
janus = new Janus({
webSocketOptions:{
server
}
});
`
Instance methods
$3
> (message:{ type?:string, load:Data}) => Promise
`
const result = await janus.createRoom({
load: {
description: vp8 room,
bitrate: 512000,
bitrate_cap: false,
videocodec: "vp8"
}
});
``