use 4 spaces indent to match the default of jslint

this is the first step of making the code follow the default jslint behaviour,
I also manually changed some { } to make it reasonable in addition to replacing tabs
This commit is contained in:
Seven Du 2014-11-11 23:33:03 +08:00
parent ab24bde262
commit eb3a27ccee
3 changed files with 908 additions and 929 deletions

View File

@ -64,8 +64,9 @@
var newLine = []; var newLine = [];
var index = 0; var index = 0;
for (var i = 0; i < elements.length; i++) { for (var i = 0; i < elements.length; i++) {
if (index === 3) // Format of media starts from the fourth. if (index === 3) { // Format of media starts from the fourth.
newLine[index++] = payload; // Put target payload to the first. newLine[index++] = payload; // Put target payload to the first.
}
if (elements[i] !== payload) newLine[index++] = elements[i]; if (elements[i] !== payload) newLine[index++] = elements[i];
} }
return newLine.join(' '); return newLine.join(' ');
@ -76,7 +77,7 @@
useVideo: null, useVideo: null,
useStereo: false, useStereo: false,
userData: null, userData: null,
iceServers: false, iceServers: false,
videoParams: {}, videoParams: {},
audioParams: {}, audioParams: {},
callbacks: { callbacks: {
@ -84,8 +85,7 @@
onICE: function() {}, onICE: function() {},
onOfferSDP: function() {} onOfferSDP: function() {}
} }
}, }, options);
options);
this.mediaData = { this.mediaData = {
SDP: null, SDP: null,
@ -163,9 +163,9 @@
function setCompat() { function setCompat() {
$.FSRTC.moz = !!navigator.mozGetUserMedia; $.FSRTC.moz = !!navigator.mozGetUserMedia;
//navigator.getUserMedia || (navigator.getUserMedia = navigator.mozGetUserMedia || navigator.webkitGetUserMedia || navigator.msGetUserMedia); //navigator.getUserMedia || (navigator.getUserMedia = navigator.mozGetUserMedia || navigator.webkitGetUserMedia || navigator.msGetUserMedia);
if (!navigator.getUserMedia) { if (!navigator.getUserMedia) {
navigator.getUserMedia = navigator.mozGetUserMedia || navigator.webkitGetUserMedia || navigator.msGetUserMedia; navigator.getUserMedia = navigator.mozGetUserMedia || navigator.webkitGetUserMedia || navigator.msGetUserMedia;
} }
} }
function checkCompat() { function checkCompat() {
@ -307,7 +307,7 @@
return onChannelError(self, e); return onChannelError(self, e);
}, },
constraints: self.constraints, constraints: self.constraints,
iceServers: self.options.iceServers, iceServers: self.options.iceServers,
offerSDP: { offerSDP: {
type: "offer", type: "offer",
sdp: self.remoteSDP sdp: self.remoteSDP
@ -324,9 +324,9 @@
getUserMedia({ getUserMedia({
constraints: { constraints: {
audio: { audio: {
mandatory: this.options.audioParams, mandatory: this.options.audioParams,
optional: [] optional: []
}, },
video: this.options.useVideo ? { video: this.options.useVideo ? {
mandatory: this.options.videoParams, mandatory: this.options.videoParams,
optional: [] optional: []
@ -371,7 +371,7 @@
return onChannelError(self, e); return onChannelError(self, e);
}, },
constraints: self.constraints, constraints: self.constraints,
iceServers: self.options.iceServers, iceServers: self.options.iceServers,
}); });
onStreamSuccess(self); onStreamSuccess(self);
@ -384,9 +384,9 @@
getUserMedia({ getUserMedia({
constraints: { constraints: {
audio: { audio: {
mandatory: this.options.audioParams, mandatory: this.options.audioParams,
optional: [] optional: []
}, },
video: this.options.useVideo ? { video: this.options.useVideo ? {
mandatory: this.options.videoParams, mandatory: this.options.videoParams,
optional: [] optional: []
@ -398,11 +398,11 @@
}); });
/* /*
navigator.getUserMedia({ navigator.getUserMedia({
video: this.options.useVideo, video: this.options.useVideo,
audio: true audio: true
}, onSuccess, onError); }, onSuccess, onError);
*/ */
}; };
@ -428,34 +428,34 @@
credential: 'homeo' credential: 'homeo'
}; };
var iceServers = null; var iceServers = null;
if (options.iceServers) { if (options.iceServers) {
var tmp = options.iceServers;; var tmp = options.iceServers;;
if (typeof(tmp) === "boolean") { if (typeof(tmp) === "boolean") {
tmp = null; tmp = null;
} }
if (tmp && typeof(tmp) !== "array") { if (tmp && typeof(tmp) !== "array") {
console.warn("iceServers must be an array, reverting to default ice servers"); console.warn("iceServers must be an array, reverting to default ice servers");
tmp = null; tmp = null;
} }
iceServers = { iceServers = {
iceServers: tmp || [STUN] iceServers: tmp || [STUN]
}; };
if (!moz && !tmp) { if (!moz && !tmp) {
if (parseInt(navigator.userAgent.match(/Chrom(e|ium)\/([0-9]+)\./)[2]) >= 28) TURN = { if (parseInt(navigator.userAgent.match(/Chrom(e|ium)\/([0-9]+)\./)[2]) >= 28) TURN = {
url: 'turn:turn.bistri.com:80', url: 'turn:turn.bistri.com:80',
credential: 'homeo', credential: 'homeo',
username: 'homeo' username: 'homeo'
}; };
iceServers.iceServers = [STUN]; iceServers.iceServers = [STUN];
} }
} }
var optional = { var optional = {
optional: [] optional: []
@ -488,30 +488,30 @@
options.onICESDP(peer.localDescription); options.onICESDP(peer.localDescription);
//x = 1; //x = 1;
/* /*
x = 1; x = 1;
peer.createOffer(function(sessionDescription) { peer.createOffer(function(sessionDescription) {
sessionDescription.sdp = serializeSdp(sessionDescription.sdp); sessionDescription.sdp = serializeSdp(sessionDescription.sdp);
peer.setLocalDescription(sessionDescription); peer.setLocalDescription(sessionDescription);
if (options.onICESDP) { if (options.onICESDP) {
options.onICESDP(sessionDescription); options.onICESDP(sessionDescription);
} }
}, onSdpError, constraints); }, onSdpError, constraints);
*/ */
} }
} else { } else {
if (!x && options.onICESDP) { if (!x && options.onICESDP) {
options.onICESDP(peer.localDescription); options.onICESDP(peer.localDescription);
//x = 1; //x = 1;
/* /*
x = 1; x = 1;
peer.createAnswer(function(sessionDescription) { peer.createAnswer(function(sessionDescription) {
sessionDescription.sdp = serializeSdp(sessionDescription.sdp); sessionDescription.sdp = serializeSdp(sessionDescription.sdp);
peer.setLocalDescription(sessionDescription); peer.setLocalDescription(sessionDescription);
if (options.onICESDP) { if (options.onICESDP) {
options.onICESDP(sessionDescription); options.onICESDP(sessionDescription);
} }
}, onSdpError, constraints); }, onSdpError, constraints);
*/ */
} }
} }
} }
@ -730,8 +730,8 @@
channel: channel, channel: channel,
sendData: function(message) { sendData: function(message) {
if (channel) { if (channel) {
channel.send(message); channel.send(message);
} }
}, },
stop: function() { stop: function() {
@ -770,8 +770,8 @@
//video.play(); //video.play();
} }
if (options.onsuccess) { if (options.onsuccess) {
options.onsuccess(stream); options.onsuccess(stream);
} }
media = stream; media = stream;
} }

File diff suppressed because it is too large Load Diff

View File

@ -73,10 +73,9 @@
tag: null, tag: null,
videoParams: {}, videoParams: {},
audioParams: {}, audioParams: {},
iceServers: false, iceServers: false,
ringSleep: 6000 ringSleep: 6000
}, }, options);
options);
verto.sessid = $.cookie('verto_session_uuid') || generateGUID(); verto.sessid = $.cookie('verto_session_uuid') || generateGUID();
$.cookie('verto_session_uuid', verto.sessid, { $.cookie('verto_session_uuid', verto.sessid, {
@ -84,9 +83,7 @@
}); });
verto.dialogs = {}; verto.dialogs = {};
verto.callbacks = callbacks || {}; verto.callbacks = callbacks || {};
verto.eventSUBS = {}; verto.eventSUBS = {};
verto.rpcClient = new $.JsonRpcClient({ verto.rpcClient = new $.JsonRpcClient({
@ -123,7 +120,6 @@
$.verto.prototype.iceServers = function(on) { $.verto.prototype.iceServers = function(on) {
var verto = this; var verto = this;
verto.options.iceServers = on; verto.options.iceServers = on;
}; };
@ -172,7 +168,7 @@
$.verto.prototype.processReply = function(method, success, e) { $.verto.prototype.processReply = function(method, success, e) {
var verto = this; var verto = this;
var i; var i;
//console.log("Response: " + method, success, e); //console.log("Response: " + method, success, e);
@ -228,7 +224,7 @@
} }
var SERNO = 1; var SERNO = 1;
function do_subscribe(verto, channel, subChannels, sparams) { function do_subscribe(verto, channel, subChannels, sparams) {
var params = sparams || {}; var params = sparams || {};
@ -298,7 +294,7 @@
$.verto.prototype.unsubscribe = function(handle) { $.verto.prototype.unsubscribe = function(handle) {
var verto = this; var verto = this;
var i; var i;
if (!handle) { if (!handle) {
for (i in verto.eventSUBS) { for (i in verto.eventSUBS) {
@ -309,7 +305,7 @@
} else { } else {
var unsubChannels = {}; var unsubChannels = {};
var sendChannels = []; var sendChannels = [];
var channel; var channel;
if (typeof(handle) == "string") { if (typeof(handle) == "string") {
delete verto.eventSUBS[handle]; delete verto.eventSUBS[handle];
@ -368,13 +364,13 @@
$.verto.prototype.purge = function(callID) { $.verto.prototype.purge = function(callID) {
var verto = this; var verto = this;
var x = 0; var x = 0;
var i; var i;
for (i in verto.dialogs) { for (i in verto.dialogs) {
if (!x) { if (!x) {
console.log("purging dialogs"); console.log("purging dialogs");
} }
x++; x++;
verto.dialogs[i].setState($.verto.enum.state.purge); verto.dialogs[i].setState($.verto.enum.state.purge);
} }
@ -423,10 +419,10 @@
$.verto.prototype.handleMessage = function(data) { $.verto.prototype.handleMessage = function(data) {
var verto = this; var verto = this;
if (!(data && data.method)) { if (!(data && data.method)) {
console.error("Invalid Data", data); console.error("Invalid Data", data);
return; return;
} }
if (data.params.callID) { if (data.params.callID) {
var dialog = verto.dialogs[data.params.callID]; var dialog = verto.dialogs[data.params.callID];
@ -467,10 +463,10 @@
data.params.useStereo = true; data.params.useStereo = true;
} }
dialog = new $.verto.dialog($.verto.enum.direction.inbound, verto, data.params); dialog = new $.verto.dialog($.verto.enum.direction.inbound, verto, data.params);
dialog.setState($.verto.enum.state.recovering); dialog.setState($.verto.enum.state.recovering);
break; break;
case 'verto.invite': case 'verto.invite':
if (data.params.sdp && data.params.sdp.indexOf("m=video") > 0) { if (data.params.sdp && data.params.sdp.indexOf("m=video") > 0) {
@ -510,10 +506,10 @@
} }
} }
if (!list && key && key === verto.sessid) { if (!list && key && key === verto.sessid) {
if (verto.callbacks.onMessage) { if (verto.callbacks.onMessage) {
verto.callbacks.onMessage(verto, null, $.verto.enum.message.pvtEvent, data.params); verto.callbacks.onMessage(verto, null, $.verto.enum.message.pvtEvent, data.params);
} }
} else if (!list && key && verto.dialogs[key]) { } else if (!list && key && verto.dialogs[key]) {
verto.dialogs[key].sendMessage($.verto.enum.message.pvtEvent, data.params); verto.dialogs[key].sendMessage($.verto.enum.message.pvtEvent, data.params);
} else if (!list) { } else if (!list) {
@ -944,21 +940,21 @@
la.verto.unsubscribe(binding); la.verto.unsubscribe(binding);
}; };
la.sendCommand = function(cmd, obj) { la.sendCommand = function(cmd, obj) {
var self = la; var self = la;
self.broadcast(self.context, { self.broadcast(self.context, {
liveArray: { liveArray: {
command: cmd, command: cmd,
context: self.context, context: self.context,
name: self.name, name: self.name,
obj: obj obj: obj
} }
}); });
}; };
la.bootstrap = function(obj) { la.bootstrap = function(obj) {
var self = la; var self = la;
la.sendCommand("bootstrap", obj); la.sendCommand("bootstrap", obj);
//self.heartbeat(); //self.heartbeat();
}; };
@ -1128,7 +1124,7 @@
} else { } else {
obj.errs = 0; obj.errs = 0;
} }
}; };
la.onChange(la, { la.onChange(la, {
@ -1138,211 +1134,205 @@
}; };
var CONFMAN_SERNO = 1; var CONFMAN_SERNO = 1;
$.verto.confMan = function(verto, params) { $.verto.confMan = function(verto, params) {
var confMan = this; var confMan = this;
conf conf
confMan.params = $.extend({ confMan.params = $.extend({
tableID: null, tableID: null,
statusID: null, statusID: null,
mainModID: null, mainModID: null,
dialog: null, dialog: null,
hasVid: false, hasVid: false,
laData: null, laData: null,
onBroadcast: null, onBroadcast: null,
onLaChange: null, onLaChange: null,
onLaRow: null onLaRow: null
}, }, params);
params);
confMan.verto = verto; confMan.verto = verto;
confMan.serno = CONFMAN_SERNO++; confMan.serno = CONFMAN_SERNO++;
function genMainMod(jq) { function genMainMod(jq) {
var play_id = "play_" + confMan.serno; var play_id = "play_" + confMan.serno;
var stop_id = "stop_" + confMan.serno; var stop_id = "stop_" + confMan.serno;
var recording_id = "recording_" + confMan.serno; var recording_id = "recording_" + confMan.serno;
var rec_stop_id = "recording_stop" + confMan.serno; var rec_stop_id = "recording_stop" + confMan.serno;
var div_id = "confman_" + confMan.serno; var div_id = "confman_" + confMan.serno;
var html = "<div id='" + div_id + "'><br>" + var html = "<div id='" + div_id + "'><br>" +
"<button class='ctlbtn' id='" + play_id + "'>Play</button>" + "<button class='ctlbtn' id='" + play_id + "'>Play</button>" +
"<button class='ctlbtn' id='" + stop_id + "'>Stop</button>" + "<button class='ctlbtn' id='" + stop_id + "'>Stop</button>" +
"<button class='ctlbtn' id='" + recording_id + "'>Record</button>" + "<button class='ctlbtn' id='" + recording_id + "'>Record</button>" +
"<button class='ctlbtn' id='" + rec_stop_id + "'>Record Stop</button>" "<button class='ctlbtn' id='" + rec_stop_id + "'>Record Stop</button>"
+ "<br><br></div>"; + "<br><br></div>";
jq.html(html); jq.html(html);
$("#" + play_id).click(function() { $("#" + play_id).click(function() {
var file = prompt("Please enter file name", ""); var file = prompt("Please enter file name", "");
confMan.modCommand("play", null, file); confMan.modCommand("play", null, file);
}); });
$("#" + stop_id).click(function() { $("#" + stop_id).click(function() {
confMan.modCommand("stop", null, "all"); confMan.modCommand("stop", null, "all");
}); });
$("#" + recording_id).click(function() { $("#" + recording_id).click(function() {
var file = prompt("Please enter file name", ""); var file = prompt("Please enter file name", "");
confMan.modCommand("recording", null, ["start", file]); confMan.modCommand("recording", null, ["start", file]);
}); });
$("#" + rec_stop_id).click(function() { $("#" + rec_stop_id).click(function() {
confMan.modCommand("recording", null, ["stop", "all"]); confMan.modCommand("recording", null, ["stop", "all"]);
}); });
} }
function genControls(jq, rowid) { function genControls(jq, rowid) {
var x = parseInt(rowid); var x = parseInt(rowid);
var kick_id = "kick_" + x; var kick_id = "kick_" + x;
var tmute_id = "tmute_" + x; var tmute_id = "tmute_" + x;
var box_id = "box_" + x; var box_id = "box_" + x;
var volup_id = "volume_in_up" + x; var volup_id = "volume_in_up" + x;
var voldn_id = "volume_in_dn" + x; var voldn_id = "volume_in_dn" + x;
var transfer_id = "transfer" + x; var transfer_id = "transfer" + x;
var html = "<div id='" + box_id + "'>" +
"<button class='ctlbtn' id='" + kick_id + "'>Kick</button>" +
"<button class='ctlbtn' id='" + tmute_id + "'>Mute</button>" +
"<button class='ctlbtn' id='" + voldn_id + "'>Vol -</button>" +
"<button class='ctlbtn' id='" + volup_id + "'>Vol +</button>" +
"<button class='ctlbtn' id='" + transfer_id + "'>Transfer</button>" +
"</div>"
;
jq.html(html);
if (!jq.data("mouse")) {
$("#" + box_id).hide();
}
jq.mouseover(function(e) {
jq.data({"mouse": true});
$("#" + box_id).show();
});
jq.mouseout(function(e) {
jq.data({"mouse": false});
$("#" + box_id).hide();
});
$("#" + transfer_id).click(function() {
var xten = prompt("Enter Extension");
confMan.modCommand("transfer", x, xten);
});
$("#" + kick_id).click(function() {
confMan.modCommand("kick", x);
});
$("#" + tmute_id).click(function() {
confMan.modCommand("tmute", x);
});
$("#" + volup_id).click(function() {
confMan.modCommand("volume_in", x, "up");
});
$("#" + voldn_id).click(function() {
confMan.modCommand("volume_in", x, "down");
});
return html;
}
var html = "<div id='" + box_id + "'>" +
"<button class='ctlbtn' id='" + kick_id + "'>Kick</button>" +
"<button class='ctlbtn' id='" + tmute_id + "'>Mute</button>" +
"<button class='ctlbtn' id='" + voldn_id + "'>Vol -</button>" +
"<button class='ctlbtn' id='" + volup_id + "'>Vol +</button>" +
"<button class='ctlbtn' id='" + transfer_id + "'>Transfer</button>" +
"</div>"
;
jq.html(html);
if (!jq.data("mouse")) {
$("#" + box_id).hide();
}
jq.mouseover(function(e) {
jq.data({"mouse": true});
$("#" + box_id).show();
});
jq.mouseout(function(e) {
jq.data({"mouse": false});
$("#" + box_id).hide();
});
$("#" + transfer_id).click(function() {
var xten = prompt("Enter Extension");
confMan.modCommand("transfer", x, xten);
});
$("#" + kick_id).click(function() {
confMan.modCommand("kick", x);
});
$("#" + tmute_id).click(function() {
confMan.modCommand("tmute", x);
});
$("#" + volup_id).click(function() {
confMan.modCommand("volume_in", x, "up");
});
$("#" + voldn_id).click(function() {
confMan.modCommand("volume_in", x, "down");
});
return html;
}
var atitle = "";
var awidth = 0;
var atitle = "";
var awidth = 0;
//$(".jsDataTable").width(confMan.params.hasVid ? "900px" : "800px"); //$(".jsDataTable").width(confMan.params.hasVid ? "900px" : "800px");
if (confMan.params.laData.role === "moderator") {
atitle = "Action";
awidth = 200;
if (confMan.params.mainModID) {
genMainMod($(confMan.params.mainModID));
$(confMan.params.displayID).html("Moderator Controls Ready<br><br>")
} else {
$(confMan.params.mainModID).html("");
}
verto.subscribe(confMan.params.laData.modChannel, { if (confMan.params.laData.role === "moderator") {
handler: function(v, e) { atitle = "Action";
console.error("MODDATA:", e.data); awidth = 200;
if (confMan.params.onBroadcast) {
confMan.params.onBroadcast(verto, confMan, e.data);
}
if (!confMan.destroyed && confMan.params.displayID) {
$(confMan.params.displayID).html(e.data.response + "<br><br>");
if (confMan.lastTimeout) {
clearTimeout(confMan.lastTimeout);
confMan.lastTimeout = 0;
}
confMan.lastTimeout = setTimeout(function() { $(confMan.params.displayID).html(confMan.destroyed ? "" : "Moderator Controls Ready<br><br>")}, 4000);
}
} if (confMan.params.mainModID) {
}); genMainMod($(confMan.params.mainModID));
$(confMan.params.displayID).html("Moderator Controls Ready<br><br>")
} } else {
$(confMan.params.mainModID).html("");
var row_callback = null; }
if (confMan.params.laData.role === "moderator") { verto.subscribe(confMan.params.laData.modChannel, {
row_callback = function(nRow, aData, iDisplayIndex, iDisplayIndexFull) { handler: function(v, e) {
if (!aData[5]) { console.error("MODDATA:", e.data);
var $row = $('td:eq(5)', nRow); if (confMan.params.onBroadcast) {
genControls($row, aData); confMan.params.onBroadcast(verto, confMan, e.data);
}
if (confMan.params.onLaRow) { if (!confMan.destroyed && confMan.params.displayID) {
confMan.params.onLaRow(verto, confMan, $row, aData); $(confMan.params.displayID).html(e.data.response + "<br><br>");
} if (confMan.lastTimeout) {
clearTimeout(confMan.lastTimeout);
confMan.lastTimeout = 0;
}
confMan.lastTimeout = setTimeout(function() { $(confMan.params.displayID).html(confMan.destroyed ? "" : "Moderator Controls Ready<br><br>")}, 4000);
}
}
});
}
var row_callback = null;
if (confMan.params.laData.role === "moderator") {
row_callback = function(nRow, aData, iDisplayIndex, iDisplayIndexFull) {
if (!aData[5]) {
var $row = $('td:eq(5)', nRow);
genControls($row, aData);
if (confMan.params.onLaRow) {
confMan.params.onLaRow(verto, confMan, $row, aData);
}
}
};
}
}
};
}
confMan.lt = new $.verto.liveTable(verto, confMan.params.laData.laChannel, confMan.params.laData.laName, $(confMan.params.tableID), { confMan.lt = new $.verto.liveTable(verto, confMan.params.laData.laChannel, confMan.params.laData.laName, $(confMan.params.tableID), {
subParams: { subParams: {
callID: confMan.params.dialog ? confMan.params.dialog.callID : null callID: confMan.params.dialog ? confMan.params.dialog.callID : null
}, },
"onChange": function(obj, args) { "onChange": function(obj, args) {
$(confMan.params.statusID).text("Conference Members: " + " (" + obj.arrayLen() + " Total)"); $(confMan.params.statusID).text("Conference Members: " + " (" + obj.arrayLen() + " Total)");
if (confMan.params.onLaChange) { if (confMan.params.onLaChange) {
confMan.params.onLaChange(verto, confMan, $.verto.enum.confEvent.laChange, obj, args); confMan.params.onLaChange(verto, confMan, $.verto.enum.confEvent.laChange, obj, args);
} }
}, },
"aaData": [], "aaData": [],
"aoColumns": [{ "aoColumns": [
"sTitle": "ID" {
}, "sTitle": "ID"
{ },
"sTitle": "Number" {
}, "sTitle": "Number"
{ },
"sTitle": "Name" {
}, "sTitle": "Name"
{ },
"sTitle": "Codec" {
}, "sTitle": "Codec"
{ },
"sTitle": "Status", {
"sWidth": confMan.params.hasVid ? "300px" : "150px" "sTitle": "Status",
}, "sWidth": confMan.params.hasVid ? "300px" : "150px"
{ },
"sTitle": atitle, {
"sWidth": awidth, "sTitle": atitle,
"sWidth": awidth,
}], }
],
"bAutoWidth": true, "bAutoWidth": true,
"bDestroy": true, "bDestroy": true,
"bSort": false, "bSort": false,
@ -1356,41 +1346,41 @@
"sEmptyTable": "The Conference is Empty....." "sEmptyTable": "The Conference is Empty....."
}, },
"fnRowCallback": row_callback "fnRowCallback": row_callback
}); });
} }
$.verto.confMan.prototype.modCommand = function(cmd, id, value) { $.verto.confMan.prototype.modCommand = function(cmd, id, value) {
var confMan = this; var confMan = this;
confMan.verto.sendMethod("verto.broadcast", { confMan.verto.sendMethod("verto.broadcast", {
"eventChannel": confMan.params.laData.modChannel, "eventChannel": confMan.params.laData.modChannel,
"data": { "data": {
"application": "conf-control", "application": "conf-control",
"command": cmd, "command": cmd,
"id": id, "id": id,
"value": value "value": value
} }
}); });
} }
$.verto.confMan.prototype.destroy = function() { $.verto.confMan.prototype.destroy = function() {
var confMan = this; var confMan = this;
confMan.destroyed = true; confMan.destroyed = true;
if (confMan.lt) { if (confMan.lt) {
confMan.lt.destroy(); confMan.lt.destroy();
} }
if (confMan.params.laData.modChannel) { if (confMan.params.laData.modChannel) {
confMan.verto.unsubscribe(confMan.params.laData.modChannel); confMan.verto.unsubscribe(confMan.params.laData.modChannel);
} }
if (confMan.params.mainModID) { if (confMan.params.mainModID) {
$(confMan.params.mainModID).html(""); $(confMan.params.mainModID).html("");
} }
} }
$.verto.dialog = function(direction, verto, params) { $.verto.dialog = function(direction, verto, params) {
@ -1400,9 +1390,8 @@
useVideo: verto.options.useVideo, useVideo: verto.options.useVideo,
useStereo: verto.options.useStereo, useStereo: verto.options.useStereo,
tag: verto.options.tag, tag: verto.options.tag,
login: verto.options.login login: verto.options.login
}, }, params);
params);
dialog.verto = verto; dialog.verto = verto;
dialog.direction = direction; dialog.direction = direction;
@ -1431,13 +1420,13 @@
var RTCcallbacks = {}; var RTCcallbacks = {};
if (dialog.direction == $.verto.enum.direction.inbound) { if (dialog.direction == $.verto.enum.direction.inbound) {
if (dialog.params.display_direction === "outbound") { if (dialog.params.display_direction === "outbound") {
dialog.params.remote_caller_id_name = dialog.params.caller_id_name; dialog.params.remote_caller_id_name = dialog.params.caller_id_name;
dialog.params.remote_caller_id_number = dialog.params.caller_id_number; dialog.params.remote_caller_id_number = dialog.params.caller_id_number;
} else { } else {
dialog.params.remote_caller_id_name = dialog.params.callee_id_name; dialog.params.remote_caller_id_name = dialog.params.callee_id_name;
dialog.params.remote_caller_id_number = dialog.params.callee_id_number; dialog.params.remote_caller_id_number = dialog.params.callee_id_number;
} }
if (!dialog.params.remote_caller_id_name) { if (!dialog.params.remote_caller_id_name) {
dialog.params.remote_caller_id_name = "Nobody"; dialog.params.remote_caller_id_name = "Nobody";
@ -1469,14 +1458,13 @@
dialog.sendMethod("verto.invite", { dialog.sendMethod("verto.invite", {
sdp: rtc.mediaData.SDP sdp: rtc.mediaData.SDP
}); });
} else { //answer } else { //answer
dialog.setState($.verto.enum.state.answering); dialog.setState($.verto.enum.state.answering);
dialog.sendMethod(dialog.attach ? "verto.attach" : "verto.answer", { dialog.sendMethod(dialog.attach ? "verto.attach" : "verto.answer", {
sdp: dialog.rtc.mediaData.SDP sdp: dialog.rtc.mediaData.SDP
}); });
} }
}; };
RTCcallbacks.onICE = function(rtc) { RTCcallbacks.onICE = function(rtc) {
@ -1485,7 +1473,6 @@
console.log("offer", rtc.mediaData.candidate); console.log("offer", rtc.mediaData.candidate);
return; return;
} }
}; };
RTCcallbacks.onError = function(e) { RTCcallbacks.onError = function(e) {
@ -1500,7 +1487,7 @@
useStereo: dialog.params.useStereo, useStereo: dialog.params.useStereo,
videoParams: verto.options.videoParams, videoParams: verto.options.videoParams,
audioParams: verto.options.audioParams, audioParams: verto.options.audioParams,
iceServers: verto.options.iceServers iceServers: verto.options.iceServers
}); });
dialog.rtc.verto = dialog.verto; dialog.rtc.verto = dialog.verto;
@ -1570,14 +1557,14 @@
dialog.lastState = dialog.state; dialog.lastState = dialog.state;
dialog.state = state; dialog.state = state;
if (!dialog.causeCode) {
dialog.causeCode = 16;
}
if (!dialog.cause) { if (!dialog.causeCode) {
dialog.cause = "NORMAL CLEARING"; dialog.causeCode = 16;
} }
if (!dialog.cause) {
dialog.cause = "NORMAL CLEARING";
}
if (dialog.callbacks.onDialogState) { if (dialog.callbacks.onDialogState) {
dialog.callbacks.onDialogState(this); dialog.callbacks.onDialogState(this);
@ -1585,12 +1572,12 @@
switch (dialog.state) { switch (dialog.state) {
case $.verto.enum.state.trying: case $.verto.enum.state.trying:
setTimeout(function() { setTimeout(function() {
if (dialog.state == $.verto.enum.state.trying) { if (dialog.state == $.verto.enum.state.trying) {
dialog.setState($.verto.enum.state.hangup); dialog.setState($.verto.enum.state.hangup);
} }
}, 30000); }, 30000);
break; break;
case $.verto.enum.state.purge: case $.verto.enum.state.purge:
dialog.setState($.verto.enum.state.destroy); dialog.setState($.verto.enum.state.destroy);
break; break;
@ -1603,7 +1590,7 @@
dialog.setState($.verto.enum.state.destroy); dialog.setState($.verto.enum.state.destroy);
break; break;
case $.verto.enum.state.destroy: case $.verto.enum.state.destroy:
delete dialog.verto.dialogs[dialog.callID]; delete dialog.verto.dialogs[dialog.callID];
dialog.rtc.stop(); dialog.rtc.stop();
break; break;
} }
@ -1664,15 +1651,15 @@
$.verto.dialog.prototype.hangup = function(params) { $.verto.dialog.prototype.hangup = function(params) {
var dialog = this; var dialog = this;
if (params) { if (params) {
if (params.causeCode) { if (params.causeCode) {
dialog.causeCode = params.causeCode; dialog.causeCode = params.causeCode;
} }
if (params.cause) { if (params.cause) {
dialog.cause = params.cause; dialog.cause = params.cause;
} }
} }
if (dialog.state.val > $.verto.enum.state.new.val && dialog.state.val < $.verto.enum.state.hangup.val) { if (dialog.state.val > $.verto.enum.state.new.val && dialog.state.val < $.verto.enum.state.hangup.val) {
dialog.setState($.verto.enum.state.hangup); dialog.setState($.verto.enum.state.hangup);
@ -1784,7 +1771,7 @@
var dialog = this; var dialog = this;
var err = 0; var err = 0;
msg.from = dialog.params.login; msg.from = dialog.params.login;
if (!msg.to) { if (!msg.to) {
console.error("Missing To"); console.error("Missing To");
@ -1815,8 +1802,8 @@
if (params.useVideo) { if (params.useVideo) {
dialog.useVideo(true); dialog.useVideo(true);
} }
dialog.params.callee_id_name = params.callee_id_name; dialog.params.callee_id_name = params.callee_id_name;
dialog.params.callee_id_number = params.callee_id_number; dialog.params.callee_id_number = params.callee_id_number;
} }
dialog.rtc.createAnswer(dialog.params.sdp); dialog.rtc.createAnswer(dialog.params.sdp);
dialog.answered = true; dialog.answered = true;
@ -1826,7 +1813,7 @@
$.verto.dialog.prototype.handleAnswer = function(params) { $.verto.dialog.prototype.handleAnswer = function(params) {
var dialog = this; var dialog = this;
dialog.gotAnswer = true; dialog.gotAnswer = true;
if (dialog.state.val >= $.verto.enum.state.active.val) { if (dialog.state.val >= $.verto.enum.state.active.val) {
return; return;
@ -1835,20 +1822,19 @@
if (dialog.state.val >= $.verto.enum.state.early.val) { if (dialog.state.val >= $.verto.enum.state.early.val) {
dialog.setState($.verto.enum.state.active); dialog.setState($.verto.enum.state.active);
} else { } else {
if (dialog.gotEarly) { if (dialog.gotEarly) {
console.log("Dialog " + dialog.callID + "Got answer while still establishing early media, delaying..."); console.log("Dialog " + dialog.callID + "Got answer while still establishing early media, delaying...");
} else { } else {
console.log("Dialog " + dialog.callID + "Answering Channel"); console.log("Dialog " + dialog.callID + "Answering Channel");
dialog.rtc.answer(params.sdp, function() { dialog.rtc.answer(params.sdp, function() {
dialog.setState($.verto.enum.state.active); dialog.setState($.verto.enum.state.active);
}, }, function(e) {
function(e) { console.error(e);
console.error(e); dialog.hangup();
dialog.hangup(); });
}); console.log("Dialog " + dialog.callID + "ANSWER SDP", params.sdp);
console.log("Dialog " + dialog.callID + "ANSWER SDP", params.sdp);
} }
} }
}; };
$.verto.dialog.prototype.cidString = function(enc) { $.verto.dialog.prototype.cidString = function(enc) {
@ -1891,18 +1877,17 @@
return; return;
} }
dialog.gotEarly = true; dialog.gotEarly = true;
dialog.rtc.answer(params.sdp, function() {
console.log("Dialog " + dialog.callID + "Establishing early media");
dialog.setState($.verto.enum.state.early);
if (dialog.gotAnswer) { dialog.rtc.answer(params.sdp, function() {
console.log("Dialog " + dialog.callID + "Answering Channel"); console.log("Dialog " + dialog.callID + "Establishing early media");
dialog.setState($.verto.enum.state.active); dialog.setState($.verto.enum.state.early);
}
}, if (dialog.gotAnswer) {
function(e) { console.log("Dialog " + dialog.callID + "Answering Channel");
dialog.setState($.verto.enum.state.active);
}
}, function(e) {
console.error(e); console.error(e);
dialog.hangup(); dialog.hangup();
}); });
@ -1926,7 +1911,7 @@
$.verto.enum.states = Object.freeze({ $.verto.enum.states = Object.freeze({
new: { new: {
requesting: 1, requesting: 1,
recovering: 1, recovering: 1,
ringing: 1, ringing: 1,
destroy: 1, destroy: 1,
answering: 1 answering: 1
@ -1953,8 +1938,8 @@
hangup: 1 hangup: 1
}, },
active: { active: {
answering: 1, answering: 1,
requesting: 1, requesting: 1,
hangup: 1, hangup: 1,
held: 1 held: 1
}, },