Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

clique-api-client-js

Package Overview
Dependencies
Maintainers
2
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

clique-api-client-js - npm Package Compare versions

Comparing version 1.0.4 to 2.0.2

certificate.crt

1

bower.json
{
"name": "clique-api-client-js",
"version": "2.0.1",
"homepage": "https://bitbucket.org/commcl/clique-api-client-js",

@@ -4,0 +5,0 @@ "authors": [

313

client.js
(function (global, factory) {
/*global define*/
if (typeof define === 'function' && define.amd) {
define(['sip.js/dist/sip.js', 'socket.io-client'], factory); // AMD
define(['./verto', 'socket.io-client'], factory); // AMD
} else if (typeof module === 'object' && module.exports) {
module.exports = factory(require('sip.js/dist/sip.js'), require('socket.io-client')); // commonjs
module.exports = factory(require('./verto'), require('socket.io-client')); // commonjs
} else {
global.clique_api = factory(global.SIP, global.io) // Browser
global.CliqueClient = factory(global.jQuery, global.io) // Browser
}
}(this, function(SIP, io) {
}(this, function($, io) {
function AjaxRequest(request) {

@@ -54,3 +54,4 @@ return new Promise(function(resolve, reject) {

var self = this;
if (typeof SIP === 'undefined') throw new Error("SIP.js is not available");
if (typeof $ === 'undefined') throw new Error("jQuery is not available");
if (typeof $.verto === 'undefined') throw new Error("Verto is not available");
if (typeof io === 'undefined') throw new Error("Socket.io is not available");

@@ -60,3 +61,2 @@

self.websocket_endpoint = options.websocket_endpoint;
self.turnServers = options.turnServers || [];
self.user_token = options.user_token;

@@ -70,2 +70,3 @@ self.event_handlers = options.event_handlers || {};

self.calls = {};
self.dialogs = {};
self.user_id = options.user_uuid;

@@ -190,18 +191,47 @@

return new Promise( function(resolve, reject) {
self.nodes[conference.node_domain] = new SIP.UA({
uri: self.user.sip_id + "@caw.me"
,password: self.user.sip_pwd
,wsServers: "wss://" + conference.node_domain + ":" + self.wss_port
,register: false
,rel100: SIP.C.supported.SUPPORTED
,traceSip: self.trace_sip
,iceCheckingTimeout: 3000
,turnServers: self.turnServers
});
var vertoCallbacks = {
onWSLogin: onWSLogin,
onWSClose: onWSClose,
onDialogState: onDialogState
};
self.nodes[conference.node_domain].on('connected', function(){ self.__trigger('connected'); });
self.nodes[conference.node_domain].on('disconnected', function(){ self.__trigger('disconnected') });
self.nodes[conference.node_domain] = new $.verto({
// The params...
socketUrl: "wss://" + conference.node_domain + ":" + self.wss_port,
login: self.user.sip_id,
passwd: self.user.sip_pwd,
iceServers: [{url:'stun:stun.l.google.com:19302'}],
tag: self._createAudioElement
}, vertoCallbacks);
function onWSLogin(verto, success) {
if (success) self.__trigger('connected');
success?resolve(self.nodes[conference.node_domain]):reject('Signaling connection failed');
};
resolve(self.nodes[conference.node_domain]);
});
function onWSClose(verto, success) {
self.__trigger('disconnected')
};
function onDialogState(d) {
switch (d.state.name) {
case "trying":
break;
case "answering":
self.__trigger('room_join', { conf_id: self.calls[d.callID], user: self.user })
break;
case "active":
break;
case "hangup":
self.__trigger('room_leave', { conf_id: self.calls[d.callID], message: "", error: d.cause });
break;
case "destroy":
// cleanup...
self.calls[conference.id] = undefined;
break;
}
};
}); // end of promise
});

@@ -247,16 +277,49 @@ }

self.nodes[node.domain_name] = new SIP.UA({
uri: self.user.sip_id + "@test.caw.me"
,password: self.user.sip_pwd
,wsServers: "wss://" + node.domain_name + ":" + self.wss_port
,register: false
,reliable: "required"
,traceSip: self.trace_sip
,iceCheckingTimeout: 3000
});
return new Promise( function(resolve, reject) {
var vertoCallbacks = {
onWSLogin: onWSLogin,
onWSClose: onWSClose,
onDialogState: onDialogState
};
self.nodes[node.domain_name].on('connected', function(){ self.__trigger('connected'); });
self.nodes[node.domain_name].on('disconnected', function(){ self.__trigger('disconnected') });
self.nodes[node.node_domain] = new $.verto({
// The params...
socketUrl: "wss://" + node.node_domain + ":" + self.wss_port,
login: self.user.sip_id,
passwd: self.user.sip_pwd,
iceServers: [{url:'stun:stun.l.google.com:19302'}],
tag: self._createAudioElement
}, vertoCallbacks);
function onWSLogin(verto, success) {
if (success) self.__trigger('connected');
success?resolve(self.nodes[node.node_domain]):reject('Signaling connection failed');
};
return self.nodes[node.domain_name];
function onWSClose(verto, success) {
self.__trigger('disconnected')
};
function onDialogState(d) {
switch (d.state.name) {
case "trying":
break;
case "answering":
self.__trigger('room_join', { conf_id: self.calls[d.callID], user: self.user })
break;
case "active":
break;
case "hangup":
self.__trigger('room_leave', { conf_id: self.calls[d.callID], message: "", error: d.cause });
break;
case "destroy":
// cleanup...
self.calls[conference.id] = undefined;
break;
}
};
}); // end of promise
});

@@ -319,15 +382,15 @@ });

CliqueClient.prototype.hangup = function(number) {
this.calls[number] && this.calls[number].terminate();
this.dialogs[number] && this.dialogs[number].hangup();
}
CliqueClient.prototype.closeRoom = function(conference_id) {
this.calls[conference_id] && this.calls[conference_id].terminate();
this.dialogs[conference_id] && this.dialogs[conference_id].hangup();
}
CliqueClient.prototype.localMute = function(conference_id) {
this.calls[conference_id] && this.calls[conference_id].mute();
this.dialogs[conference_id] && this.dialogs[conference_id].setMute("off");
}
CliqueClient.prototype.localUnmute = function(conference_id) {
this.calls[conference_id] && this.calls[conference_id].unmute();
this.dialogs[conference_id] && this.dialogs[conference_id].setMute("on");
}

@@ -372,62 +435,133 @@

CliqueClient.prototype._startConferenceCall = function(conference) {
CliqueClient.prototype.updateConfSettings = function(id, data) {
var self = this;
return self.initialized.then(function() {
return AjaxRequest({
url : self.api_endpoint + "/conferences/"+id+"/settings",
method: 'PUT',
dataType : "JSON",
bearer: self.user_token,
req_user: self.user.uuid,
data: data
})
}).then(function(data) {
if (!data.ok) throw data;
return data.settings;
}, function(err) {console.log(err)});
}
self.calls[conference.id] = self.nodes[conference.node_domain].invite("conference_" + conference.id, {
media: {
render: {remote: self._createAudioElement(conference.id)}
,constraints: {
audio: true,
video: false
}
}
});
CliqueClient.prototype.getConfSettings = function(id) {
var self = this;
return self.initialized.then(function() {
return AjaxRequest({
url : self.api_endpoint + "/conferences/"+id+"/settings",
method: 'GET',
dataType : "JSON",
bearer: self.user_token,
req_user: self.user.uuid
})
}).then(function(data) {
if (!data.ok) throw data;
return data.settings;
}, function(err) {console.log(err)});
}
self.conferences[conference.id] = conference;
CliqueClient.prototype.getConfInfo = function(id) {
var self = this;
return self.initialized.then(function() {
return AjaxRequest({
url : self.api_endpoint + "/conferences/"+id,
method: 'PUT',
dataType : "JSON",
bearer: self.user_token,
req_user: self.user.uuid
})
}).then(function(data) {
if (!data.ok) throw data;
return data.conference;
}, function(err) {console.log(err)});
}
self.calls[conference.id].on('accepted', function() {
self.__trigger('room_join', { conf_id: conference.id, user: self.user })
});
CliqueClient.prototype.updateConfInfo = function(id, data) {
var self = this;
return self.initialized.then(function() {
return AjaxRequest({
url : self.api_endpoint + "/conferences/"+id,
method: 'PUT',
dataType : "JSON",
bearer: self.user_token,
req_user: self.user.uuid,
data: data
})
}).then(function(data) {
if (!data.ok) throw data;
return data.conference;
}, function(err) {console.log(err)});
}
self.calls[conference.id].on('terminated', function(message, cause) {
var error;
if (!message && cause === SIP.C.causes.WEBRTC_ERROR) error = cause;
self.__trigger('room_leave', { conf_id: conference.id, message: message, error: error });
CliqueClient.prototype.confUserList = function(id) {
var self = this;
return self.initialized.then(function() {
return AjaxRequest({
url : self.api_endpoint + "/conferences/"+id+"/user-list-hash",
method: 'GET',
dataType : "JSON",
bearer: self.user_token,
req_user: self.user.uuid
})
}).then(function(data) {
if (!data.ok) throw data;
return data;
}, function(err) {console.log(err)});
}
//cleanup
self.calls[conference.id] = undefined;
var elem = document.getElementById(conference.id);
return elem.parentNode.removeChild(elem);
});
CliqueClient.prototype.searchConf = function() {
var self = this;
return self.initialized.then(function() {
return AjaxRequest({
url : self.api_endpoint + "/conferences",
method: 'GET',
dataType : "JSON",
bearer: self.user_token,
req_user: self.user.uuid
})
}).then(function(data) {
if (!data.ok) throw data;
return data.result;
}, function(err) {console.log(err)});
}
CliqueClient.prototype._startPhoneCall = function(ua, number, options) {
CliqueClient.prototype._startConferenceCall = function(conference) {
var self = this;
var headers = [];
if (options && options.source) headers.push('X-Clique-Source-Number: ' + options.source);
if (options && options.detect_live) headers.push('X-Clique-Live-Answer: true');
if (options && options.detect_beep) headers.push('X-Clique-Detect-Beep: true');
var dialog = self.nodes[conference.node_domain].newCall({destination_number:"conference_" + conference.id, caller_id_number:self.user.uuid});
self.calls[dialog.callID] = conference.id;
self.dialogs[conference.id] = dialog;
self.conferences[conference.id] = conference;
self.calls[number] = ua.invite(number, {
extraHeaders: headers,
media: {
render: {remote: self._createAudioElement(number)}
,constraints: {
audio: true,
video: false
}
}
});
}
self.calls[number].on('accepted', function() { self.__trigger('call_accepted', number) });
CliqueClient.prototype._startPhoneCall = function(ua, number, options) {
var self = this;
var vars = {};
self.calls[number].on('terminated', function(message, cause){
self.__trigger('call_ended', {number: number, cause: cause});
if (options && options.source) vars.Source_Number = options.source;
if (options && options.detect_live) vars.Live_Answer = true;
if (options && options.detect_beep) vars.Detect_Beep = true;
//cleanup
self.calls[number] = undefined;
var elem = document.getElementById(number);
return elem.parentNode.removeChild(elem);
});
var dialog = ua.newCall({destination_number:number, userVariables: vars, caller_id_number:self.user.uuid });
self.calls[dialog.callID] = number;
self.dialogs[number] = dialog;
}

@@ -491,8 +625,19 @@

CliqueClient.prototype._createAudioElement = function(id) {
function guid() {
function s4() {
return Math.floor((1 + Math.random()) * 0x10000)
.toString(16)
.substring(1);
}
return s4() + s4() + '-' + s4() + '-' + s4() + '-' +
s4() + '-' + s4() + s4() + s4();
}
var audioElement = document.createElement('audio');
if (id) audioElement.id = id;
if (!id) id = guid();
audioElement.id = id;
audioElement.autoplay = true;
audioElement.style.display = 'none';
document.body.appendChild(audioElement);
return audioElement;
return id;
}

@@ -499,0 +644,0 @@

{
"name": "clique-api-client-js",
"version": "1.0.4",
"version": "2.0.2",
"description": "Client side lib to work with clique platform",
"main": "client.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "node httpserver.js"
},
"dependencies": {
"sip.js": "~0.7.8",
"jquery": "^3.2.1",
"jquery-json": "^2.6.0",
"socket.io-client": "~1.4.5"

@@ -17,3 +18,6 @@ },

"license": "MIT",
"readme": "ERROR: No README data found!"
"readme": "ERROR: No README data found!",
"devDependencies": {
"mime": "^2.0.3"
}
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc