0.0.67 • Published 3 years ago

janus-gateway-client v0.0.67

Weekly downloads
143
License
-
Repository
github
Last release
3 years ago

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

0.0.67

3 years ago

0.0.65

4 years ago

0.0.66

4 years ago

0.0.64

4 years ago

0.0.63

4 years ago

0.0.62

4 years ago

0.0.61

4 years ago

0.0.59

4 years ago

0.0.58

4 years ago

0.0.6

4 years ago

0.0.57

4 years ago

0.0.55

4 years ago

0.0.54

4 years ago

0.0.53

4 years ago

0.0.51

4 years ago

0.0.5

4 years ago

0.0.43

4 years ago

0.0.41

4 years ago

0.0.42

4 years ago

0.0.4

4 years ago

0.0.39

4 years ago

0.0.38

4 years ago

0.0.37

4 years ago

0.0.36

4 years ago

0.0.35

4 years ago

0.0.34

4 years ago

0.0.33

4 years ago

0.0.32

4 years ago

0.0.31

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago

0.0.0

4 years ago