npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

janus-gateway-client

v0.0.67

Published

Janus Gateway Client

Downloads

27

Readme

janus-gateway-client

Logic related to signaling and negotiation between frontend and nodejs backend. Using this package you can establish connection with nodejs server which in turn making use of janus-gateway-node.
Package based upon video about scaling janus-gateway.
This package is used inside react-janus-videoroom.

Getting Started

yarn add janus-gateway-client 

alt text

Usage

import { JanusClient } from 'janus-gateway-client';
import ReconnectingWebSocket from 'reconnecting-websocket';

...

const client = new JanusClient({
    onPublisher: this.onPublisher,
    onSubscriber: this.onSubscriber,
    onError: (error) => console.error(error),
    user_id,
    server,
    logger: this.logger,
    WebSocket: ReconnectingWebSocket,
    subscriberRtcConfiguration: rtcConfiguration,
    publisherRtcConfiguration: rtcConfiguration,
    transactionTimeout: 15000,
    keepAliveInterval: 10000
});

this.client.initialize()
.then(() => (

    this.client.getRooms()

))
.then(({ load }) => {

    const rooms = load; //use one of the rooms objects to retrieve room id and join specific room
    
    this.connected = true;

});

Options

server

string | required

server running janus-gateway-node.

const server = "wss://yoururl.com";

onSubscriber

(subscriber:JanusSubscriber) => void | required

this function will notify user when new participant joined room in which user currently publishing media.

const onSubscriber = async (subscriber) => {
		
    subscriber.addEventListener("terminated", this.onSubscriberTerminated(subscriber));

    subscriber.addEventListener("leaving", this.onSubscriberLeaving(subscriber));

    subscriber.addEventListener("disconnected", this.onSubscriberLeaving(subscriber));
    
    try {

        await subscriber.initialize();
        
        if (this.props.onParticipantJoined) {
            this.props.onParticipantJoined(subscriber);
        }

        const subscribers = this.getSubscribers();
        
        if (this.nParticipants!==subscribers.length) {
            this.nParticipants = subscribers.length;
            this.onParticipantsAmountChange();
        }

        this.forceUpdate();
        
    } catch(error) {
        
        this.props.onError(error);

    }
    
}

onPublisher

(publisher:JanusPublisher) => void | required

called after publisher succesfully joined room.

const onPublisher = async (publisher) => {

    publisher.addEventListener("terminated", this.onPublisherTerminated(publisher));

    publisher.addEventListener("disconnected", this.onPublisherDisconnected(publisher));
    
    if (this.props.onConnected) {
        this.props.onConnected(publisher);
    }

    this.forceUpdate();

}

WebSocket

any | required

websocket instance.

transactionTimeout

number | required

time interval before incomplete transaction will throw timeout error.

keepAliveInterval

number | required

keepalive time interval for user.

user_id

user_id | required

unique user identifier.

onError

(error:any) => void | required

in case error occurred this. function will be invoked to notify user about error.

logger

Logger | required

customize logging

interface Logger {
	enable: () => void,
	disable: () => void,
	success: (...args:any[]) => void,
	info: (...args:any[]) => void,
	error: (error:any) => void,
	json: (...args:any[]) => void,
	tag: (tag:string, type:`success` | `info` | `error`) => (...args:any[]) => void
}

subscriberRtcConfiguration

any | optional

publisherRtcConfiguration

any | optional

Instance methods

initialize

() => Promise<JanusPublisher[]>

establish connection with the server.

...
await this.client.initialize();

terminate

() => Promise<void>

terminate connection with server, perform cleanup actions.

...
await this.client.terminate();

replaceVideoTrack

(cameraDeviceId:string) => Promise<void>

replace current video source.

...
await this.client.replaceVideoTrack(this.props.cameraId);

join

(room_id:string, mediaConstraints?: MediaStreamConstraints) => Promise<void>

join specific room as a publisher and subscribe to all available participants feeds.

...
await this.client.join(room_id, mediaConstraints);

leave

() => Promise<void>

leave room in which user currently resides.

...
await this.client.leave();

DEMO

https://github.com/IG-88-2/janus-gateway-videoroom-demo

link

Contributing

Please consider to help by providing feedback on how this project can be improved or what is missing to make it useful for community. Thank you!

Authors

  • Anatoly Strashkevich

License

This project is licensed under the MIT License - see the LICENSE.md file for details