video-call-client v2.3.1
video-call-client
Javascript client for siosLIFE's Video Call server.
Usage
var VideoCallClient = require('video-call-client');Initializing the client
The first thing you need to do is create a client using VideoCallClient.
var videoCallClient = VideoCallClient(serverUrl, iceConfig, constraints);The iceConfig object is a
RTCConfiguration
object used to create the
RTCPeerConnection.
The constraints is a MediaStreamConstraints object passed to
getUserMedia.
Connecting to the server
As a normal user
You can connect to the Video Call server by using the login method of the video call client.
When the connection is established a connected event will be emitted to notify that the client is ready to start and receive calls.
videoCallClient.login({ user: ..., families: ... });
videoCallClient.on('connected', function() {
// let's see who's online
console.log(videoCallClient.users);
});The object passed to login will be sent to the Video Call server,
so more properties can be sent if needed.
As a userless machine
A machine can connect to the server to receive calls even if no users is logged in.
To do this, the machineLogin method can be used:
videoCallClient.machineLogin({ institutionId: ..., machineId: ... });
videoCallClient.on('connected', function() {
// Will now start receiving calls
});Like with login, a connected event will be emitted when the connection is established and the client is ready to receive calls.
A client logged as a machine user cannot start calls.
Starting calls
A call can be started with VideoCallClient's .startCall() method.
This method receives the target user's ID and returns an OutgoingCall object.
If the target user accepts the call, the OutgoingCall will emit an accepted event with a Call object.
If the call gets rejected, either by the user of if the user is unavailable, a rejected event will be emitted with the reason why the call was rejected.
var outgoingCall = videoCallClient.startCall(userId, institutionId);
outgoingCall.on('accepted', function(call) {
// your call was accepted
});
outgoingCall.on('rejected', function(reason) {
// too bad, you've been rejected
});Receiving calls
When someone calls you VideoCallClient will emit a call event.
This event's callback will receive an IncomingCall object to .accept() or .reject() the call.
The IncomingCall's .accept() method will return a Call object.
videoCallClient.on('call', function(incomingCall) {
// accept the call
var call = incomingCall.accept();
// or reject it
incomingCall.reject();
// but don't forget that the calling user can give up on you
incomingCall.on('end', function() {
// too late
});
});Ending calls
When a call is established, you can use the Call object to end the call.
It will also emit an end event if the other user ends the call on their side.
// lets end this
call.terminate();
// before someone else does
call.on('end', function() {
// bye bye
});Viewing online users
The VideoCallClient object has a users property.
This is an array of all the users that are online in the same room.
When a users joins or leaves the room, a user-joined and a user-left event will be emitted, respectively.
videoCallClient.users.forEach(function(user) {
console.log(user);
});
videoCallClient.on('user-joined', function(user) {
// new user
});
videoCallClient.on('user-left', function(user) {
// this one left the room
});A user only has a userId and a type.