RTCall.js — A library for Browser-to-Browser audio-only calling
HOME © Muaz Khan . @WebRTCWeb . Github . Latest issues . What's New?
Feedback
How to make audio-only calls using RTCall?
// https://www.webrtc-experiment.com/RTCall.js
var call = new RTCall();
// "onincomingcall" fires each time if someone calls you
call.onincomingcall = function(caller) {
call.receive(caller.receiverid);
};
// "oncustomer" is fired only for admin
// you can set admin like this:
// call.admin = true;
call.oncustomer = function(customer) {
call.call(customer.callerid);
};
// "onstream" returns you remote media stream
call.onstream = function(e) {
// e.stream ---- remote media stream object
// e.callerid ---- id of the remote person
audio = e.audio;
audio.play(); // "e.audio" object is paused by default
document.documentElement.appendChild(audio);
};
// initializing "RTCall" object
call.init();
// customers can call "admin" using his caller-id
call.call('admin-caller-id');
How to use custom signaling channel?
By default, RTCall is using WebSockets for signaling. You can use socket.io, WebSync or services like firebase, pubnub, pusher etc.
call.openSignalingChannel = function(config) {
var SIGNALING_SERVER = 'https://socketio-over-nodejs2.herokuapp.com:443/';
var channel = config.channel || this.channel;
var sender = Math.round(Math.random() * 60535) + 5000;
io.connect(SIGNALING_SERVER).emit('new-channel', {
channel: channel,
sender : sender
});
var socket = io.connect(SIGNALING_SERVER + channel);
socket.channel = channel;
socket.on('connect', function () {
if (config.callback) config.callback(socket);
});
socket.send = function (message) {
socket.emit('message', {
sender: sender,
data : message
});
};
socket.on('message', config.onmessage);
};
Or Firebase:
call.openSignalingChannel = function (config) {
var channel = config.channel || this.channel;
var socket = new Firebase('https://webrtc.firebaseIO.com/' + channel);
socket.on('child_added', function (snap) {
var data = snap.val();
config.onmessage(data);
// we want socket.io behavior;
// that's why data is removed from firebase servers
// as soon as it is received
// data.userid != userid &&
if (data.userid != userid) snap.ref().remove();
});
// must override "send"
socket.send = function (data) {
socket.push(data);
};
config.callback(socket);
};