Javascript client for siosLIFE Video Call server.
npm install video-call-client``js`
var VideoCallClient = require('video-call-client');
The first thing you need to do is create a client using VideoCallClient.
`js`
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.
#### 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.
`js
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:
`js
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.
A call can be started with VideoCallClient's .startCall() method.OutgoingCall
This method receives the target user's ID and returns an 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.
`js
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
});
`
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.
`js
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
});
});
`
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.
`js
// lets end this
call.terminate();
// before someone else does
call.on('end', function() {
// bye bye
});
`
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.
`js
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`.