The Voxbone WebRTC module enables you to create and hash your credentials into a token to be sent to Voxbone's auth server using voxbone.WebRTC.init(voxrtc_config). It essentials creates that voxrtc_config key
To install the Voxbone VoxSMS module and its dependencies, simply run the following command:
npm install voxbone-webrtc
-
Add the dependency to your application
var Voxbone = require('voxbone-webrtc');
-
Add your credentials
var voxrtc_username = 'your_webrtc_username'; var voxrtc_secret = 'your_webrtc_secret';
-
Create a new Voxbone object that will create the hash using the credentials & the expiring time (in seconds) as optional value (default is 300 seconds ~ 5 minutes)
var voxbone = new Voxbone({ voxrtcUsername: voxrtc_username, voxrtcSecret: voxrtc_secret, voxrtcExpiresInSeconds: 300 });
-
Send the voxrtc_config key to your front end using the voxbone.generate() function.
router.get('/', function(req, res) { voxrtc_config = voxbone.generate(); res.render('index', {}); });
/views/index.html demonstrates a sample application using the WebRTC library
-
In your view add the voxrtc_config key within the init() function to authenticate your browser
voxbone.WebRTC.init(#{voxrtc_config});
-
You can now configure how you want your call to be set using parameters in the init() function. eg:
function init(){ // Set the webrtc auth server url (url below it the default one) voxbone.WebRTC.authServerURL = "https://webrtc.voxbone.com/rest/authentication/createToken"; //If this is not set, a ping to each pop will be issued to determine which is the most optimal for the user //Default is to use the ping mechanism to determine the preferedPop. //voxbone.WebRTC.preferedPop = 'BE'; // set custom event handlers voxbone.WebRTC.customEventHandler = eventHandlers; //Set the caller-id, domain name gets automatically stripped off //Note that It must be a valid sip uri. //Default value is: [email protected] //voxbone.WebRTC.configuration.uri = "[email protected]"; //Add a display name //voxbone.WebRTC.configuration.display_name = ""; //Add an object or string in the X-Voxbone-Context SIP header //voxbone.WebRTC.context = "Here's a context string"; /** ** Authenticate your browser to enable it to make calls by sending the generate ** voxrtc_config (taken from your backend) to the Voxbone auth server. **/ voxbone.WebRTC.init(#{voxrtc_config}); }
More info in the Voxbone WebRTC Documentation