-
-
Notifications
You must be signed in to change notification settings - Fork 77
Home
JanusClient is a flutter library/package for building scalable and performant WebRTC applications using Janus - General purpose WebRTC server as its backend technology. Since this library doesn't implement its own platform-specific APIs for the WebRTC stack and we don't believe in re-inventing the wheels again, it relies on flutter_webrtc for the entire WebRTC stack for various platforms.
This library can be seen as an improved version of janus.js the only difference is janus.js uses callbacks for every operation, whereas this library uses Future(Promise in javascript). Now let's look at all the building blocks of the flutter_janus_client application step by step.
This is the primary class in which we can specify various optional behavioral properties of the library including the required ones.
JanusClient janus= JanusClient(
transport, // required
iceServers,
refreshInterval = 50,
apiSecret,
isUnifiedPlan = true,
token,
stringIds = false,
usePlanB = false,
pollingInterval,
loggerName = "JanusClient",
maxEvent = 10,
loggerLevel = Level.ALL,
withCredentials = false
)
as we can see above JanusClient
requires transport since we make no assumption of what kind of transport you would like to use that's why we let you decide.
similar to janus.js flutter_janus_client supports two kinds of transport that are as follows:-
We prefer to use WebSocketJanusTransport
as it is faster, so in this guide, we will use that only.
WebSocketJanusTransport ws = WebSocketJanusTransport(url: 'ws://0.0.0.0:8188');
JanusClient janus = JanusClient(
withCredentials: true,
isUnifiedPlan: true,
stringIds: false,
apiSecret: "SecureIt",
transport: ws
);
At this point, we have JanusClient
instance ready to communicate with our janus server, but before we can actually do something on Janus server we need to create a new session later on which we will create a plugin handle so the whole relationship can be described as follows:-
JanusClient => JanusSession => JanusPlugin
.
It's worth mentioning that we can have multiple sessions on janus instance and similarly we can have multiple plugin handles on Session instance.
It is a simple class with simple functionality and that is to hold one or more plugin handles that actually communicate with Janus plugins.
JanusSession session = await janus.createSession();
JanusVideoCallPlugin videoCallPlugin = await session.attach<JanusVideoCallPlugin>();
It is the superclass of all Janus plugins, it implements core features and functionalities like send
,sendData
, createOffer
, createAnswer
etc. In this guide, we will not discuss each and every implementor class like JanusAudioBridgePlugin,JanusSipPlugin, etc. examples in the repository are quite informative in itself.
since the most important part of Janus application are plugins so most of the interaction with the Janus server happens through JanusPlugin methods
Now let's look at some important methods and properties of JanusPlugin which are quite extensively used in a JanusClient
application.
-
send({dynamic data, RTCSessionDescription? jsep}) → Future This method is crucial for communicating with Janus Server's APIs it takes in data and optionally jsep for negotiating with webrtc peers
-
sendData(String message) → Future Send a text message on the existing text room using a data channel with the same label as specified during the initDataChannel() method call.
-
initializeMediaDevices({bool? useDisplayMediaDevices = false, Map<String, dynamic>? mediaConstraints}) → Future<MediaStream?> the method that generates MediaStream from your device camera that will be automatically added to the peer connection instance internally used by the Janus client.
-
initDataChannel({RTCDataChannelInit? rtcDataChannelInit}) → Future this method Initializes the data channel on the handle's internal peer connection object. It is mainly used for Janus TextRoom but can be used for other plugins with data channel support
-
handleRemoteJsep(RTCSessionDescription? data) → Future It allows you to set Remote Description on internal peer connection, Received from janus server.
data ↔ Stream<RTCDataChannelMessage>?
remoteTrack ↔ Stream<RemoteTrack>?
typedMessages ↔ Stream<TypedEvent<JanusEvent>>?
webRTCHandle ↔ JanusWebRTCHandle?
onData ↔ Stream<RTCDataChannelState>?
That's it, folks! We hope this guide helped you understand the core idea of this library and would help you write your next WebRTC application