verto 1.6.14 - jquery.verto.js Our Modifications - jquery.verto.js
1  1 
2/* 2/*
3 * Verto HTML5/Javascript Telephony Signaling and Control Protocol Stack for FreeSWITCH 3 * Verto HTML5/Javascript Telephony Signaling and Control Protocol Stack for FreeSWITCH
4 * Copyright (C) 2005-2014, Anthony Minessale II <anthm@freeswitch.org> 4 * Copyright (C) 2005-2014, Anthony Minessale II <anthm@freeswitch.org>
5 * 5 *
6 * Version: MPL 1.1 6 * Version: MPL 1.1
7 * 7 *
8 * The contents of this file are subject to the Mozilla Public License Version 8 * The contents of this file are subject to the Mozilla Public License Version
9 * 1.1 (the "License"); you may not use this file except in compliance with 9 * 1.1 (the "License"); you may not use this file except in compliance with
10 * the License. You may obtain a copy of the License at 10 * the License. You may obtain a copy of the License at
11 * http://www.mozilla.org/MPL/ 11 * http://www.mozilla.org/MPL/
12 * 12 *
13 * Software distributed under the License is distributed on an "AS IS" basis, 13 * Software distributed under the License is distributed on an "AS IS" basis,
14 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 14 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
15 * for the specific language governing rights and limitations under the 15 * for the specific language governing rights and limitations under the
16 * License. 16 * License.
17 * 17 *
18 * The Original Code is Verto HTML5/Javascript Telephony Signaling and Control Protocol Stack for FreeSWITCH 18 * The Original Code is Verto HTML5/Javascript Telephony Signaling and Control Protocol Stack for FreeSWITCH
19 * 19 *
20 * The Initial Developer of the Original Code is 20 * The Initial Developer of the Original Code is
21 * Anthony Minessale II <anthm@freeswitch.org> 21 * Anthony Minessale II <anthm@freeswitch.org>
22 * Portions created by the Initial Developer are Copyright (C) 22 * Portions created by the Initial Developer are Copyright (C)
23 * the Initial Developer. All Rights Reserved. 23 * the Initial Developer. All Rights Reserved.
24 * 24 *
25 * Contributor(s): 25 * Contributor(s):
26 * 26 *
27 * Anthony Minessale II <anthm@freeswitch.org> 27 * Anthony Minessale II <anthm@freeswitch.org>
  28 *
  29 *   - Our Modifications: https://meeting.gomeet.com/lib/verto/jquery.verto.js.modifications.html
28 * 30 *
29 * jquery.verto.js - Main interface 31 * jquery.verto.js - Main interface
30 * 32 *
31 */  33 */ 
32  34 
33(function($) { 35(function($) {
34    var sources = []; 36    var sources = [];
35  37 
36    var generateGUID = (typeof(window.crypto) !== 'undefined' && typeof(window.crypto.getRandomValues) !== 'undefined') ? 38    var generateGUID = (typeof(window.crypto) !== 'undefined' && typeof(window.crypto.getRandomValues) !== 'undefined') ?
37    function() { 39    function() {
38        // If we have a cryptographically secure PRNG, use that 40        // If we have a cryptographically secure PRNG, use that
39        // http://stackoverflow.com/questions/6906916/collisions-when-generating-uuids-in-javascript 41        // http://stackoverflow.com/questions/6906916/collisions-when-generating-uuids-in-javascript
40        var buf = new Uint16Array(8); 42        var buf = new Uint16Array(8);
41        window.crypto.getRandomValues(buf); 43        window.crypto.getRandomValues(buf);
42        var S4 = function(num) { 44        var S4 = function(num) {
43            var ret = num.toString(16); 45            var ret = num.toString(16);
44            while (ret.length < 4) { 46            while (ret.length < 4) {
45                ret = "0" + ret; 47                ret = "0" + ret;
46            } 48            }
47            return ret; 49            return ret;
48        }; 50        };
49        return (S4(buf[0]) + S4(buf[1]) + "-" + S4(buf[2]) + "-" + S4(buf[3]) + "-" + S4(buf[4]) + "-" + S4(buf[5]) + S4(buf[6]) + S4(buf[7])); 51        return (S4(buf[0]) + S4(buf[1]) + "-" + S4(buf[2]) + "-" + S4(buf[3]) + "-" + S4(buf[4]) + "-" + S4(buf[5]) + S4(buf[6]) + S4(buf[7]));
50    } 52    }
51  53 
52    : 54    :
53  55 
54    function() { 56    function() {
55        // Otherwise, just use Math.random 57        // Otherwise, just use Math.random
56        // http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/2117523#2117523 58        // http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/2117523#2117523
57        return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { 59        return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
58            var r = Math.random() * 16 | 0, 60            var r = Math.random() * 16 | 0,
59            v = c == 'x' ? r : (r & 0x3 | 0x8); 61            v = c == 'x' ? r : (r & 0x3 | 0x8);
60            return v.toString(16); 62            return v.toString(16);
61        }); 63        });
62    }; 64    };
63  65 
64    /// MASTER OBJ 66    /// MASTER OBJ
65    $.verto = function(options, callbacks) { 67    $.verto = function(options, callbacks) {
66        var verto = this; 68        var verto = this;
67  69 
68        $.verto.saved.push(verto); 70        $.verto.saved.push(verto);
69  71 
70        verto.options = $.extend({ 72        verto.options = $.extend({
71            login: null, 73            login: null,
72            passwd: null, 74            passwd: null,
73            socketUrl: null, 75            socketUrl: null,
74            tag: null, 76            tag: null,
75        localTag: null, 77        localTag: null,
76            videoParams: {}, 78            videoParams: {},
77            audioParams: {}, 79            audioParams: {},
78        loginParams: {}, 80        loginParams: {},
79        deviceParams: {onResCheck: null}, 81        deviceParams: {onResCheck: null},
80        userVariables: {}, 82        userVariables: {},
81            iceServers: false, 83            iceServers: false,
82            ringSleep: 6000, 84            ringSleep: 6000,
83      sessid: null, 85      sessid: null,
84      useStream: null 86      useStream: null
85        }, options); 87        }, options);
86  88 
87    if (verto.options.deviceParams.useCamera) { 89    if (verto.options.deviceParams.useCamera) {
88        $.FSRTC.getValidRes(verto.options.deviceParams.useCamera, verto.options.deviceParams.onResCheck); 90        $.FSRTC.getValidRes(verto.options.deviceParams.useCamera, verto.options.deviceParams.onResCheck);
89    } 91    }
90  92 
91    if (!verto.options.deviceParams.useMic) { 93    if (!verto.options.deviceParams.useMic) {
92        verto.options.deviceParams.useMic = "any"; 94        verto.options.deviceParams.useMic = "any";
93    } 95    }
94  96 
95    if (!verto.options.deviceParams.useSpeak) { 97    if (!verto.options.deviceParams.useSpeak) {
96        verto.options.deviceParams.useSpeak = "any"; 98        verto.options.deviceParams.useSpeak = "any";
97    } 99    }
98  100 
99    if (verto.options.sessid) { 101    if (verto.options.sessid) {
100        verto.sessid = verto.options.sessid; 102        verto.sessid = verto.options.sessid;
101    } else { 103    } else {
102            verto.sessid = localStorage.getItem("verto_session_uuid") || generateGUID(); 104            verto.sessid = localStorage.getItem("verto_session_uuid") || generateGUID();
103        localStorage.setItem("verto_session_uuid", verto.sessid); 105        localStorage.setItem("verto_session_uuid", verto.sessid);
104    } 106    }
105  107 
106        verto.dialogs = {}; 108        verto.dialogs = {};
107        verto.callbacks = callbacks || {}; 109        verto.callbacks = callbacks || {};
108        verto.eventSUBS = {}; 110        verto.eventSUBS = {};
109  111 
110        verto.rpcClient = new $.JsonRpcClient({ 112        verto.rpcClient = new $.JsonRpcClient({
111            login: verto.options.login, 113            login: verto.options.login,
112            passwd: verto.options.passwd, 114            passwd: verto.options.passwd,
113            socketUrl: verto.options.socketUrl, 115            socketUrl: verto.options.socketUrl,
114            wsFallbackURL: verto.options.wsFallbackURL, 116            wsFallbackURL: verto.options.wsFallbackURL,
115            turnServer: verto.options.turnServer, 117            turnServer: verto.options.turnServer,
116        loginParams: verto.options.loginParams, 118        loginParams: verto.options.loginParams,
117        userVariables: verto.options.userVariables, 119        userVariables: verto.options.userVariables,
118            sessid: verto.sessid, 120            sessid: verto.sessid,
119            onmessage: function(e) { 121            onmessage: function(e) {
120                return verto.handleMessage(e.eventData); 122                return verto.handleMessage(e.eventData);
121            }, 123            },
122            onWSConnect: function(o) { 124            onWSConnect: function(o) {
123                o.call('login', {}); 125                o.call('login', {});
124            }, 126            },
125            onWSLogin: function(success) { 127            onWSLogin: function(success) {
126                if (verto.callbacks.onWSLogin) { 128                if (verto.callbacks.onWSLogin) {
127                    verto.callbacks.onWSLogin(verto, success); 129                    verto.callbacks.onWSLogin(verto, success);
128                } 130                }
129            }, 131            },
130            onWSClose: function(success) { 132            onWSClose: function(success) {
131                if (verto.callbacks.onWSClose) { 133                if (verto.callbacks.onWSClose) {
132                    verto.callbacks.onWSClose(verto, success); 134                    verto.callbacks.onWSClose(verto, success);
133                } 135                }
134                verto.purge(); 136                verto.purge();
135            } 137            }
136        }); 138        });
137  139 
138        var tag = verto.options.tag; 140        var tag = verto.options.tag;
139        if (typeof(tag) === "function") { 141        if (typeof(tag) === "function") {
140          tag = tag(); 142          tag = tag();
141        } 143        }
142  144 
143        if (verto.options.ringFile && verto.options.tag) { 145        if (verto.options.ringFile && verto.options.tag) {
144            verto.ringer = $("#" + tag); 146            verto.ringer = $("#" + tag);
145        } 147        }
146  148 
147        verto.rpcClient.call('login', {}); 149        verto.rpcClient.call('login', {});
148  150 
149    }; 151    };
150  152 
151  153 
152    $.verto.prototype.deviceParams = function(obj) { 154    $.verto.prototype.deviceParams = function(obj) {
153        var verto = this; 155        var verto = this;
154  156 
155    for (var i in obj) { 157    for (var i in obj) {
156            verto.options.deviceParams[i] = obj[i]; 158            verto.options.deviceParams[i] = obj[i];
157    } 159    }
158  160 
159    if (obj.useCamera) { 161    if (obj.useCamera) {
160        $.FSRTC.getValidRes(verto.options.deviceParams.useCamera, obj ? obj.onResCheck : undefined); 162        $.FSRTC.getValidRes(verto.options.deviceParams.useCamera, obj ? obj.onResCheck : undefined);
161    } 163    }
162    }; 164    };
163  165 
164    $.verto.prototype.videoParams = function(obj) { 166    $.verto.prototype.videoParams = function(obj) {
165        var verto = this; 167        var verto = this;
166  168 
167    for (var i in obj) { 169    for (var i in obj) {
168            verto.options.videoParams[i] = obj[i]; 170            verto.options.videoParams[i] = obj[i];
169    } 171    }
170    }; 172    };
171  173 
172    $.verto.prototype.iceServers = function(obj) { 174    $.verto.prototype.iceServers = function(obj) {
173        var verto = this; 175        var verto = this;
174        verto.options.iceServers = obj; 176        verto.options.iceServers = obj;
175    }; 177    };
176  178 
177    $.verto.prototype.loginData = function(params) { 179    $.verto.prototype.loginData = function(params) {
178    var verto = this; 180    var verto = this;
179        verto.options.login = params.login; 181        verto.options.login = params.login;
180        verto.options.passwd = params.passwd; 182        verto.options.passwd = params.passwd;
181        verto.rpcClient.loginData(params); 183        verto.rpcClient.loginData(params);
182    }; 184    };
183  185 
184    $.verto.prototype.logout = function(msg) { 186    $.verto.prototype.logout = function(msg) {
185        var verto = this; 187        var verto = this;
186        verto.rpcClient.closeSocket(); 188        verto.rpcClient.closeSocket();
187        if (verto.callbacks.onWSClose) { 189        if (verto.callbacks.onWSClose) {
188            verto.callbacks.onWSClose(verto, false); 190            verto.callbacks.onWSClose(verto, false);
189        } 191        }
190        verto.purge(); 192        verto.purge();
191    }; 193    };
192  194 
193    $.verto.prototype.login = function(msg) { 195    $.verto.prototype.login = function(msg) {
194        var verto = this; 196        var verto = this;
195        verto.logout(); 197        verto.logout();
196        verto.rpcClient.call('login', {}); 198        verto.rpcClient.call('login', {});
197    }; 199    };
198  200 
199    $.verto.prototype.message = function(msg) { 201    $.verto.prototype.message = function(msg) {
200        var verto = this; 202        var verto = this;
201        var err = 0; 203        var err = 0;
202  204 
203        if (!msg.to) { 205        if (!msg.to) {
204            console.error("Missing To"); 206            console.error("Missing To");
205            err++; 207            err++;
206        } 208        }
207  209 
208        if (!msg.body) { 210        if (!msg.body) {
209            console.error("Missing Body"); 211            console.error("Missing Body");
210            err++; 212            err++;
211        } 213        }
212  214 
213        if (err) { 215        if (err) {
214            return false; 216            return false;
215        } 217        }
216  218 
217        verto.sendMethod("verto.info", { 219        verto.sendMethod("verto.info", {
218            msg: msg 220            msg: msg
219        }); 221        });
220  222 
221        return true; 223        return true;
222    }; 224    };
223  225 
224    $.verto.prototype.processReply = function(method, success, e) { 226    $.verto.prototype.processReply = function(method, success, e) {
225        var verto = this; 227        var verto = this;
226        var i; 228        var i;
227  229 
228        //console.log("Response: " + method, success, e); 230        //console.log("Response: " + method, success, e);
229  231 
230        switch (method) { 232        switch (method) {
231        case "verto.subscribe": 233        case "verto.subscribe":
232            for (i in e.unauthorizedChannels) { 234            for (i in e.unauthorizedChannels) {
233                drop_bad(verto, e.unauthorizedChannels[i]); 235                drop_bad(verto, e.unauthorizedChannels[i]);
234            } 236            }
235            for (i in e.subscribedChannels) { 237            for (i in e.subscribedChannels) {
236                mark_ready(verto, e.subscribedChannels[i]); 238                mark_ready(verto, e.subscribedChannels[i]);
237            } 239            }
238  240 
239            break; 241            break;
240        case "verto.unsubscribe": 242        case "verto.unsubscribe":
241            //console.error(e); 243            //console.error(e);
242            break; 244            break;
243        } 245        }
244    }; 246    };
245  247 
246    $.verto.prototype.sendMethod = function(method, params) { 248    $.verto.prototype.sendMethod = function(method, params) {
247        var verto = this; 249        var verto = this;
248  250 
249        verto.rpcClient.call(method, params, 251        verto.rpcClient.call(method, params,
250  252 
251        function(e) { 253        function(e) {
252            /* Success */  254            /* Success */ 
253            verto.processReply(method, true, e); 255            verto.processReply(method, true, e);
254        }, 256        },
255  257 
256        function(e) { 258        function(e) {
257            /* Error */  259            /* Error */ 
258            verto.processReply(method, false, e); 260            verto.processReply(method, false, e);
259        }); 261        });
260    }; 262    };
261  263 
262    function do_sub(verto, channel, obj) { 264    function do_sub(verto, channel, obj) {
263  265 
264    } 266    }
265  267 
266    function drop_bad(verto, channel) { 268    function drop_bad(verto, channel) {
267        console.error("drop unauthorized channel: " + channel); 269        console.error("drop unauthorized channel: " + channel);
268        delete verto.eventSUBS[channel]; 270        delete verto.eventSUBS[channel];
269    } 271    }
270  272 
271    function mark_ready(verto, channel) { 273    function mark_ready(verto, channel) {
272        for (var j in verto.eventSUBS[channel]) { 274        for (var j in verto.eventSUBS[channel]) {
273            verto.eventSUBS[channel][j].ready = true; 275            verto.eventSUBS[channel][j].ready = true;
274            console.log("subscribed to channel: " + channel); 276            console.log("subscribed to channel: " + channel);
275            if (verto.eventSUBS[channel][j].readyHandler) { 277            if (verto.eventSUBS[channel][j].readyHandler) {
276                verto.eventSUBS[channel][j].readyHandler(verto, channel); 278                verto.eventSUBS[channel][j].readyHandler(verto, channel);
277            } 279            }
278        } 280        }
279    } 281    }
280  282 
281    var SERNO = 1; 283    var SERNO = 1;
282  284 
283    function do_subscribe(verto, channel, subChannels, sparams) { 285    function do_subscribe(verto, channel, subChannels, sparams) {
284        var params = sparams || {}; 286        var params = sparams || {};
285  287 
286        var local = params.local; 288        var local = params.local;
287  289 
288        var obj = { 290        var obj = {
289            eventChannel: channel, 291            eventChannel: channel,
290            userData: params.userData, 292            userData: params.userData,
291            handler: params.handler, 293            handler: params.handler,
292            ready: false, 294            ready: false,
293            readyHandler: params.readyHandler, 295            readyHandler: params.readyHandler,
294            serno: SERNO++ 296            serno: SERNO++
295        }; 297        };
296  298 
297        var isnew = false; 299        var isnew = false;
298  300 
299        if (!verto.eventSUBS[channel]) { 301        if (!verto.eventSUBS[channel]) {
300            verto.eventSUBS[channel] = []; 302            verto.eventSUBS[channel] = [];
301            subChannels.push(channel); 303            subChannels.push(channel);
302            isnew = true; 304            isnew = true;
303        } 305        }
304  306 
305        verto.eventSUBS[channel].push(obj); 307        verto.eventSUBS[channel].push(obj);
306  308 
307        if (local) { 309        if (local) {
308            obj.ready = true; 310            obj.ready = true;
309            obj.local = true; 311            obj.local = true;
310        } 312        }
311  313 
312        if (!isnew && verto.eventSUBS[channel][0].ready) { 314        if (!isnew && verto.eventSUBS[channel][0].ready) {
313            obj.ready = true; 315            obj.ready = true;
314            if (obj.readyHandler) { 316            if (obj.readyHandler) {
315                obj.readyHandler(verto, channel); 317                obj.readyHandler(verto, channel);
316            } 318            }
317        } 319        }
318  320 
319        return { 321        return {
320            serno: obj.serno, 322            serno: obj.serno,
321            eventChannel: channel 323            eventChannel: channel
322        }; 324        };
323  325 
324    } 326    }
325  327 
326    $.verto.prototype.subscribe = function(channel, sparams) { 328    $.verto.prototype.subscribe = function(channel, sparams) {
327        var verto = this; 329        var verto = this;
328        var r = []; 330        var r = [];
329        var subChannels = []; 331        var subChannels = [];
330        var params = sparams || {}; 332        var params = sparams || {};
331  333 
332        if (typeof(channel) === "string") { 334        if (typeof(channel) === "string") {
333            r.push(do_subscribe(verto, channel, subChannels, params)); 335            r.push(do_subscribe(verto, channel, subChannels, params));
334        } else { 336        } else {
335            for (var i in channel) { 337            for (var i in channel) {
336                r.push(do_subscribe(verto, channel, subChannels, params)); 338                r.push(do_subscribe(verto, channel, subChannels, params));
337            } 339            }
338        } 340        }
339  341 
340        if (subChannels.length) { 342        if (subChannels.length) {
341            verto.sendMethod("verto.subscribe", { 343            verto.sendMethod("verto.subscribe", {
342                eventChannel: subChannels.length == 1 ? subChannels[0] : subChannels, 344                eventChannel: subChannels.length == 1 ? subChannels[0] : subChannels,
343                subParams: params.subParams 345                subParams: params.subParams
344            }); 346            });
345        } 347        }
346  348 
347        return r; 349        return r;
348    }; 350    };
349  351 
350    $.verto.prototype.unsubscribe = function(handle) { 352    $.verto.prototype.unsubscribe = function(handle) {
351        var verto = this; 353        var verto = this;
352        var i; 354        var i;
353  355 
354        if (!handle) { 356        if (!handle) {
355            for (i in verto.eventSUBS) { 357            for (i in verto.eventSUBS) {
356                if (verto.eventSUBS[i]) { 358                if (verto.eventSUBS[i]) {
357                    verto.unsubscribe(verto.eventSUBS[i]); 359                    verto.unsubscribe(verto.eventSUBS[i]);
358                } 360                }
359            } 361            }
360        } else { 362        } else {
361            var unsubChannels = {}; 363            var unsubChannels = {};
362            var sendChannels = []; 364            var sendChannels = [];
363            var channel; 365            var channel;
364  366 
365            if (typeof(handle) == "string") { 367            if (typeof(handle) == "string") {
366                delete verto.eventSUBS[handle]; 368                delete verto.eventSUBS[handle];
367                unsubChannels[handle]++; 369                unsubChannels[handle]++;
368            } else { 370            } else {
369                for (i in handle) { 371                for (i in handle) {
370                    if (typeof(handle[i]) == "string") { 372                    if (typeof(handle[i]) == "string") {
371                        channel = handle[i]; 373                        channel = handle[i];
372                        delete verto.eventSUBS[channel]; 374                        delete verto.eventSUBS[channel];
373                        unsubChannels[channel]++; 375                        unsubChannels[channel]++;
374                    } else { 376                    } else {
375                        var repl = []; 377                        var repl = [];
376                        channel = handle[i].eventChannel; 378                        channel = handle[i].eventChannel;
377  379 
378                        for (var j in verto.eventSUBS[channel]) { 380                        for (var j in verto.eventSUBS[channel]) {
379                            if (verto.eventSUBS[channel][j].serno == handle[i].serno) {} else { 381                            if (verto.eventSUBS[channel][j].serno == handle[i].serno) {} else {
380                                repl.push(verto.eventSUBS[channel][j]); 382                                repl.push(verto.eventSUBS[channel][j]);
381                            } 383                            }
382                        } 384                        }
383  385 
384                        verto.eventSUBS[channel] = repl; 386                        verto.eventSUBS[channel] = repl;
385  387 
386                        if (verto.eventSUBS[channel].length === 0) { 388                        if (verto.eventSUBS[channel].length === 0) {
387                            delete verto.eventSUBS[channel]; 389                            delete verto.eventSUBS[channel];
388                            unsubChannels[channel]++; 390                            unsubChannels[channel]++;
389                        } 391                        }
390                    } 392                    }
391                } 393                }
392            } 394            }
393  395 
394            for (var u in unsubChannels) { 396            for (var u in unsubChannels) {
395                console.log("Sending Unsubscribe for: ", u); 397                console.log("Sending Unsubscribe for: ", u);
396                sendChannels.push(u); 398                sendChannels.push(u);
397            } 399            }
398  400 
399            if (sendChannels.length) { 401            if (sendChannels.length) {
400                verto.sendMethod("verto.unsubscribe", { 402                verto.sendMethod("verto.unsubscribe", {
401                    eventChannel: sendChannels.length == 1 ? sendChannels[0] : sendChannels 403                    eventChannel: sendChannels.length == 1 ? sendChannels[0] : sendChannels
402                }); 404                });
403            } 405            }
404        } 406        }
405    }; 407    };
406  408 
407    $.verto.prototype.broadcast = function(channel, params) { 409    $.verto.prototype.broadcast = function(channel, params) {
408        var verto = this; 410        var verto = this;
409        var msg = { 411        var msg = {
410            eventChannel: channel, 412            eventChannel: channel,
411            data: {} 413            data: {}
412        }; 414        };
413        for (var i in params) { 415        for (var i in params) {
414            msg.data[i] = params[i]; 416            msg.data[i] = params[i];
415        } 417        }
416        verto.sendMethod("verto.broadcast", msg); 418        verto.sendMethod("verto.broadcast", msg);
417    }; 419    };
418  420 
419    $.verto.prototype.purge = function(callID) { 421    $.verto.prototype.purge = function(callID) {
420        var verto = this; 422        var verto = this;
421        var x = 0; 423        var x = 0;
422        var i; 424        var i;
423  425 
424        for (i in verto.dialogs) { 426        for (i in verto.dialogs) {
425            if (!x) { 427            if (!x) {
426                console.log("purging dialogs"); 428                console.log("purging dialogs");
427            } 429            }
428            x++; 430            x++;
429            verto.dialogs[i].setState($.verto.enum.state.purge); 431            verto.dialogs[i].setState($.verto.enum.state.purge);
430        } 432        }
431  433 
432        for (i in verto.eventSUBS) { 434        for (i in verto.eventSUBS) {
433            if (verto.eventSUBS[i]) { 435            if (verto.eventSUBS[i]) {
434                console.log("purging subscription: " + i); 436                console.log("purging subscription: " + i);
435                delete verto.eventSUBS[i]; 437                delete verto.eventSUBS[i];
436            } 438            }
437        } 439        }
438    }; 440    };
439  441 
440    $.verto.prototype.hangup = function(callID) { 442    $.verto.prototype.hangup = function(callID) {
441        var verto = this; 443        var verto = this;
442        if (callID) { 444        if (callID) {
443            var dialog = verto.dialogs[callID]; 445            var dialog = verto.dialogs[callID];
444  446 
445            if (dialog) { 447            if (dialog) {
446                dialog.hangup(); 448                dialog.hangup();
447            } 449            }
448        } else { 450        } else {
449            for (var i in verto.dialogs) { 451            for (var i in verto.dialogs) {
450                verto.dialogs[i].hangup(); 452                verto.dialogs[i].hangup();
451            } 453            }
452        } 454        }
453    }; 455    };
454  456 
455    $.verto.prototype.newCall = function(args, callbacks) { 457    $.verto.prototype.newCall = function(args, callbacks) {
456        var verto = this; 458        var verto = this;
457  459 
458        if (!verto.rpcClient.socketReady()) { 460        if (!verto.rpcClient.socketReady()) {
459            console.error("Not Connected..."); 461            console.error("Not Connected...");
460            return; 462            return;
461        } 463        }
462  464 
463        if (args["useCamera"]) { 465        if (args["useCamera"]) {
464            verto.options.deviceParams["useCamera"] = args["useCamera"]; 466            verto.options.deviceParams["useCamera"] = args["useCamera"];
465            verto.options.deviceParams["useCameraLabel"] = args["useCameraLabel"]; 467            verto.options.deviceParams["useCameraLabel"] = args["useCameraLabel"];
466        } 468        }
467  469 
468        var dialog = new $.verto.dialog($.verto.enum.direction.outbound, this, args); 470        var dialog = new $.verto.dialog($.verto.enum.direction.outbound, this, args);
469  471 
470        if (callbacks) { 472        if (callbacks) {
471            dialog.callbacks = callbacks; 473            dialog.callbacks = callbacks;
472        } 474        }
473  475 
474        dialog.invite(); 476        dialog.invite();
475  477 
476        return dialog; 478        return dialog;
477    }; 479    };
478  480 
479    $.verto.prototype.handleMessage = function(data) { 481    $.verto.prototype.handleMessage = function(data) {
480        var verto = this; 482        var verto = this;
481  483 
482        if (!(data && data.method)) { 484        if (!(data && data.method)) {
483            console.error("Invalid Data", data); 485            console.error("Invalid Data", data);
484            return; 486            return;
485        } 487        }
486  488 
487        if (data.params.callID) { 489        if (data.params.callID) {
488            var dialog = verto.dialogs[data.params.callID]; 490            var dialog = verto.dialogs[data.params.callID];
489          491         
490        if (data.method === "verto.attach" && dialog) { 492        if (data.method === "verto.attach" && dialog) {
491        delete dialog.verto.dialogs[dialog.callID]; 493        delete dialog.verto.dialogs[dialog.callID];
492        dialog.rtc.stop(); 494        dialog.rtc.stop();
493        dialog = null; 495        dialog = null;
494        } 496        }
495  497 
496            if (dialog) { 498            if (dialog) {
497  499 
498                switch (data.method) { 500                switch (data.method) {
499                case 'verto.bye': 501                case 'verto.bye':
500                    dialog.hangup(data.params); 502                    dialog.hangup(data.params);
501                    break; 503                    break;
502                case 'verto.answer': 504                case 'verto.answer':
503                    dialog.handleAnswer(data.params); 505                    dialog.handleAnswer(data.params);
504                    break; 506                    break;
505                case 'verto.media': 507                case 'verto.media':
506                    dialog.handleMedia(data.params); 508                    dialog.handleMedia(data.params);
507                    break; 509                    break;
508                case 'verto.display': 510                case 'verto.display':
509                    dialog.handleDisplay(data.params); 511                    dialog.handleDisplay(data.params);
510                    break; 512                    break;
511                case 'verto.info': 513                case 'verto.info':
512                    dialog.handleInfo(data.params); 514                    dialog.handleInfo(data.params);
513                    break; 515                    break;
514                default: 516                default:
515                    console.debug("INVALID METHOD OR NON-EXISTANT CALL REFERENCE IGNORED", dialog, data.method); 517                    console.debug("INVALID METHOD OR NON-EXISTANT CALL REFERENCE IGNORED", dialog, data.method);
516                    break; 518                    break;
517                } 519                }
518            } else { 520            } else {
519  521 
520                switch (data.method) { 522                switch (data.method) {
521                case 'verto.attach': 523                case 'verto.attach':
522                    data.params.attach = true; 524                    data.params.attach = true;
523  525 
524                    if (data.params.sdp && data.params.sdp.indexOf("m=video") > 0) { 526                    if (data.params.sdp && data.params.sdp.indexOf("m=video") > 0) {
525                        data.params.useVideo = true; 527                        data.params.useVideo = true;
526                    } 528                    }
527  529 
528                    if (data.params.sdp && data.params.sdp.indexOf("stereo=1") > 0) { 530                    if (data.params.sdp && data.params.sdp.indexOf("stereo=1") > 0) {
529                        data.params.useStereo = true; 531                        data.params.useStereo = true;
530                    } 532                    }
531  533 
532                    dialog = new $.verto.dialog($.verto.enum.direction.inbound, verto, data.params); 534                    dialog = new $.verto.dialog($.verto.enum.direction.inbound, verto, data.params);
533                    dialog.setState($.verto.enum.state.recovering); 535                    dialog.setState($.verto.enum.state.recovering);
534  536 
535                    break; 537                    break;
536                case 'verto.invite': 538                case 'verto.invite':
537  539 
538                    if (data.params.sdp && data.params.sdp.indexOf("m=video") > 0) { 540                    if (data.params.sdp && data.params.sdp.indexOf("m=video") > 0) {
539                        data.params.wantVideo = true; 541                        data.params.wantVideo = true;
540                    } 542                    }
541  543 
542                    if (data.params.sdp && data.params.sdp.indexOf("stereo=1") > 0) { 544                    if (data.params.sdp && data.params.sdp.indexOf("stereo=1") > 0) {
543                        data.params.useStereo = true; 545                        data.params.useStereo = true;
544                    } 546                    }
545  547 
546                    dialog = new $.verto.dialog($.verto.enum.direction.inbound, verto, data.params); 548                    dialog = new $.verto.dialog($.verto.enum.direction.inbound, verto, data.params);
547                    break; 549                    break;
548                default: 550                default:
549                    console.debug("INVALID METHOD OR NON-EXISTANT CALL REFERENCE IGNORED"); 551                    console.debug("INVALID METHOD OR NON-EXISTANT CALL REFERENCE IGNORED");
550                    break; 552                    break;
551                } 553                }
552            } 554            }
553  555 
554            return { 556            return {
555                method: data.method 557                method: data.method
556            }; 558            };
557        } else { 559        } else {
558            switch (data.method) { 560            switch (data.method) {
559            case 'verto.punt': 561            case 'verto.punt':
560                verto.purge(); 562                verto.purge();
561        verto.logout(); 563        verto.logout();
562        break; 564        break;
563            case 'verto.event': 565            case 'verto.event':
564                var list = null; 566                var list = null;
565                var key = null; 567                var key = null;
566  568 
567                if (data.params) { 569                if (data.params) {
568                    key = data.params.eventChannel; 570                    key = data.params.eventChannel;
569                } 571                }
570  572 
571                if (key) { 573                if (key) {
572                    list = verto.eventSUBS[key]; 574                    list = verto.eventSUBS[key];
573  575 
574                    if (!list) { 576                    if (!list) {
575                        list = verto.eventSUBS[key.split(".")[0]]; 577                        list = verto.eventSUBS[key.split(".")[0]];
576                    } 578                    }
577                } 579                }
578  580 
579                if (!list && key && key === verto.sessid) { 581                if (!list && key && key === verto.sessid) {
580                    if (verto.callbacks.onMessage) { 582                    if (verto.callbacks.onMessage) {
581                        verto.callbacks.onMessage(verto, null, $.verto.enum.message.pvtEvent, data.params); 583                        verto.callbacks.onMessage(verto, null, $.verto.enum.message.pvtEvent, data.params);
582                    } 584                    }
583                } else if (!list && key && verto.dialogs[key]) { 585                } else if (!list && key && verto.dialogs[key]) {
584                    verto.dialogs[key].sendMessage($.verto.enum.message.pvtEvent, data.params); 586                    verto.dialogs[key].sendMessage($.verto.enum.message.pvtEvent, data.params);
585                } else if (!list) { 587                } else if (!list) {
586                    if (!key) { 588                    if (!key) {
587                        key = "UNDEFINED"; 589                        key = "UNDEFINED";
588                    } 590                    }
589                    console.error("UNSUBBED or invalid EVENT " + key + " IGNORED"); 591                    console.error("UNSUBBED or invalid EVENT " + key + " IGNORED");
590                } else { 592                } else {
591                    for (var i in list) { 593                    for (var i in list) {
592                        var sub = list[i]; 594                        var sub = list[i];
593  595 
594                        if (!sub || !sub.ready) { 596                        if (!sub || !sub.ready) {
595                            console.error("invalid EVENT for " + key + " IGNORED"); 597                            console.error("invalid EVENT for " + key + " IGNORED");
596                        } else if (sub.handler) { 598                        } else if (sub.handler) {
597                            sub.handler(verto, data.params, sub.userData); 599                            sub.handler(verto, data.params, sub.userData);
598                        } else if (verto.callbacks.onEvent) { 600                        } else if (verto.callbacks.onEvent) {
599                            verto.callbacks.onEvent(verto, data.params, sub.userData); 601                            verto.callbacks.onEvent(verto, data.params, sub.userData);
600                        } else { 602                        } else {
601                            console.log("EVENT:", data.params); 603                            console.log("EVENT:", data.params);
602                        } 604                        }
603                    } 605                    }
604                } 606                }
605  607 
606                break; 608                break;
607  609 
608            case "verto.info": 610            case "verto.info":
609                if (verto.callbacks.onMessage) { 611                if (verto.callbacks.onMessage) {
610                    verto.callbacks.onMessage(verto, null, $.verto.enum.message.info, data.params.msg); 612                    verto.callbacks.onMessage(verto, null, $.verto.enum.message.info, data.params.msg);
611                } 613                }
612                //console.error(data); 614                //console.error(data);
613                console.debug("MESSAGE from: " + data.params.msg.from, data.params.msg.body); 615                console.debug("MESSAGE from: " + data.params.msg.from, data.params.msg.body);
614  616 
615                break; 617                break;
616  618 
617            case 'verto.clientReady': 619            case 'verto.clientReady':
618                if (verto.callbacks.onMessage) { 620                if (verto.callbacks.onMessage) {
619                    verto.callbacks.onMessage(verto, null, $.verto.enum.message.clientReady, data.params); 621                    verto.callbacks.onMessage(verto, null, $.verto.enum.message.clientReady, data.params);
620                } 622                }
621                console.debug("CLIENT READY", data.params); 623                console.debug("CLIENT READY", data.params);
622                break; 624                break;
623  625 
624            default: 626            default:
625                console.error("INVALID METHOD OR NON-EXISTANT CALL REFERENCE IGNORED", data.method); 627                console.error("INVALID METHOD OR NON-EXISTANT CALL REFERENCE IGNORED", data.method);
626                break; 628                break;
627            } 629            }
628        } 630        }
629    }; 631    };
630  632 
631    var del_array = function(array, name) { 633    var del_array = function(array, name) {
632        var r = []; 634        var r = [];
633        var len = array.length; 635        var len = array.length;
634  636 
635        for (var i = 0; i < len; i++) { 637        for (var i = 0; i < len; i++) {
636            if (array[i] != name) { 638            if (array[i] != name) {
637                r.push(array[i]); 639                r.push(array[i]);
638            } 640            }
639        } 641        }
640  642 
641        return r; 643        return r;
642    }; 644    };
643  645 
644    var hashArray = function() { 646    var hashArray = function() {
645        var vha = this; 647        var vha = this;
646  648 
647        var hash = {}; 649        var hash = {};
648        var array = []; 650        var array = [];
649  651 
650        vha.reorder = function(a) { 652        vha.reorder = function(a) {
651            array = a; 653            array = a;
652            var h = hash; 654            var h = hash;
653            hash = {}; 655            hash = {};
654  656 
655            var len = array.length; 657            var len = array.length;
656  658 
657            for (var i = 0; i < len; i++) { 659            for (var i = 0; i < len; i++) {
658                var key = array[i]; 660                var key = array[i];
659                if (h[key]) { 661                if (h[key]) {
660                    hash[key] = h[key]; 662                    hash[key] = h[key];
661                    delete h[key]; 663                    delete h[key];
662                } 664                }
663            } 665            }
664            h = undefined; 666            h = undefined;
665        }; 667        };
666  668 
667        vha.clear = function() { 669        vha.clear = function() {
668            hash = undefined; 670            hash = undefined;
669            array = undefined; 671            array = undefined;
670            hash = {}; 672            hash = {};
671            array = []; 673            array = [];
672        }; 674        };
673  675 
674        vha.add = function(name, val, insertAt) { 676        vha.add = function(name, val, insertAt) {
675            var redraw = false; 677            var redraw = false;
676  678 
677            if (!hash[name]) { 679            if (!hash[name]) {
678                if (insertAt === undefined || insertAt < 0 || insertAt >= array.length) { 680                if (insertAt === undefined || insertAt < 0 || insertAt >= array.length) {
679                    array.push(name); 681                    array.push(name);
680                } else { 682                } else {
681                    var x = 0; 683                    var x = 0;
682                    var n = []; 684                    var n = [];
683                    var len = array.length; 685                    var len = array.length;
684  686 
685                    for (var i = 0; i < len; i++) { 687                    for (var i = 0; i < len; i++) {
686                        if (x++==insertAt) { 688                        if (x++==insertAt) {
687                            n.push(name); 689                            n.push(name);
688                        } 690                        }
689                        n.push(array[i]); 691                        n.push(array[i]);
690                    } 692                    }
691  693 
692                    array = undefined; 694                    array = undefined;
693                    array = n; 695                    array = n;
694                    n = undefined; 696                    n = undefined;
695                    redraw = true; 697                    redraw = true;
696                } 698                }
697            } 699            }
698  700 
699            hash[name] = val; 701            hash[name] = val;
700  702 
701            return redraw; 703            return redraw;
702        }; 704        };
703  705 
704        vha.del = function(name) { 706        vha.del = function(name) {
705            var r = false; 707            var r = false;
706  708 
707            if (hash[name]) { 709            if (hash[name]) {
708                array = del_array(array, name); 710                array = del_array(array, name);
709                delete hash[name]; 711                delete hash[name];
710                r = true; 712                r = true;
711            } else { 713            } else {
712                console.error("can't del nonexistant key " + name); 714                console.error("can't del nonexistant key " + name);
713            } 715            }
714  716 
715            return r; 717            return r;
716        }; 718        };
717  719 
718        vha.get = function(name) { 720        vha.get = function(name) {
719            return hash[name]; 721            return hash[name];
720        }; 722        };
721  723 
722        vha.order = function() { 724        vha.order = function() {
723            return array; 725            return array;
724        }; 726        };
725  727 
726        vha.hash = function() { 728        vha.hash = function() {
727            return hash; 729            return hash;
728        }; 730        };
729  731 
730        vha.indexOf = function(name) { 732        vha.indexOf = function(name) {
731            var len = array.length; 733            var len = array.length;
732  734 
733            for (var i = 0; i < len; i++) { 735            for (var i = 0; i < len; i++) {
734                if (array[i] == name) { 736                if (array[i] == name) {
735                    return i; 737                    return i;
736                } 738                }
737            } 739            }
738        }; 740        };
739  741 
740        vha.arrayLen = function() { 742        vha.arrayLen = function() {
741            return array.length; 743            return array.length;
742        }; 744        };
743  745 
744        vha.asArray = function() { 746        vha.asArray = function() {
745            var r = []; 747            var r = [];
746  748 
747            var len = array.length; 749            var len = array.length;
748  750 
749            for (var i = 0; i < len; i++) { 751            for (var i = 0; i < len; i++) {
750                var key = array[i]; 752                var key = array[i];
751                r.push(hash[key]); 753                r.push(hash[key]);
752            } 754            }
753  755 
754            return r; 756            return r;
755        }; 757        };
756  758 
757        vha.each = function(cb) { 759        vha.each = function(cb) {
758            var len = array.length; 760            var len = array.length;
759  761 
760            for (var i = 0; i < len; i++) { 762            for (var i = 0; i < len; i++) {
761                cb(array[i], hash[array[i]]); 763                cb(array[i], hash[array[i]]);
762            } 764            }
763        }; 765        };
764  766 
765        vha.dump = function(html) { 767        vha.dump = function(html) {
766            var str = ""; 768            var str = "";
767  769 
768            vha.each(function(name, val) { 770            vha.each(function(name, val) {
769                str += "name: " + name + " val: " + JSON.stringify(val) + (html ? "<br>" : "\n"); 771                str += "name: " + name + " val: " + JSON.stringify(val) + (html ? "<br>" : "\n");
770            }); 772            });
771  773 
772            return str; 774            return str;
773        }; 775        };
774  776 
775    }; 777    };
776  778 
777    $.verto.liveArray = function(verto, context, name, config) { 779    $.verto.liveArray = function(verto, context, name, config) {
778        var la = this; 780        var la = this;
779        var lastSerno = 0; 781        var lastSerno = 0;
780        var binding = null; 782        var binding = null;
781        var user_obj = config.userObj; 783        var user_obj = config.userObj;
782        var local = false; 784        var local = false;
783  785 
784        // Inherit methods of hashArray 786        // Inherit methods of hashArray
785        hashArray.call(la); 787        hashArray.call(la);
786  788 
787        // Save the hashArray add, del, reorder, clear methods so we can make our own. 789        // Save the hashArray add, del, reorder, clear methods so we can make our own.
788        la._add = la.add; 790        la._add = la.add;
789        la._del = la.del; 791        la._del = la.del;
790        la._reorder = la.reorder; 792        la._reorder = la.reorder;
791        la._clear = la.clear; 793        la._clear = la.clear;
792  794 
793        la.context = context; 795        la.context = context;
794        la.name = name; 796        la.name = name;
795        la.user_obj = user_obj; 797        la.user_obj = user_obj;
796  798 
797        la.verto = verto; 799        la.verto = verto;
798        la.broadcast = function(channel, obj) { 800        la.broadcast = function(channel, obj) {
799            verto.broadcast(channel, obj); 801            verto.broadcast(channel, obj);
800        }; 802        };
801        la.errs = 0; 803        la.errs = 0;
802  804 
803        la.clear = function() { 805        la.clear = function() {
804            la._clear(); 806            la._clear();
805            lastSerno = 0; 807            lastSerno = 0;
806  808 
807            if (la.onChange) { 809            if (la.onChange) {
808                la.onChange(la, { 810                la.onChange(la, {
809                    action: "clear"  811                    action: "clear" 
810                }); 812                });
811            } 813            }
812        }; 814        };
813  815 
814        la.checkSerno = function(serno) { 816        la.checkSerno = function(serno) {
815            if (serno < 0) { 817            if (serno < 0) {
816                return true; 818                return true;
817            } 819            }
818  820 
819            if (lastSerno > 0 && serno != (lastSerno + 1)) { 821            if (lastSerno > 0 && serno != (lastSerno + 1)) {
820                if (la.onErr) { 822                if (la.onErr) {
821                    la.onErr(la, { 823                    la.onErr(la, {
822                        lastSerno: lastSerno, 824                        lastSerno: lastSerno,
823                        serno: serno 825                        serno: serno
824                    }); 826                    });
825                } 827                }
826                la.errs++; 828                la.errs++;
827                console.debug(la.errs); 829                console.debug(la.errs);
828                if (la.errs < 3) { 830                if (la.errs < 3) {
829                    la.bootstrap(la.user_obj); 831                    la.bootstrap(la.user_obj);
830                } 832                }
831                return false; 833                return false;
832            } else { 834            } else {
833                lastSerno = serno; 835                lastSerno = serno;
834                return true; 836                return true;
835            } 837            }
836        }; 838        };
837  839 
838        la.reorder = function(serno, a) { 840        la.reorder = function(serno, a) {
839            if (la.checkSerno(serno)) { 841            if (la.checkSerno(serno)) {
840                la._reorder(a); 842                la._reorder(a);
841                if (la.onChange) { 843                if (la.onChange) {
842                    la.onChange(la, { 844                    la.onChange(la, {
843                        serno: serno, 845                        serno: serno,
844                        action: "reorder"  846                        action: "reorder" 
845                    }); 847                    });
846                } 848                }
847            } 849            }
848        }; 850        };
849  851 
850        la.init = function(serno, val, key, index) { 852        la.init = function(serno, val, key, index) {
851            if (key === null || key === undefined) { 853            if (key === null || key === undefined) {
852                key = serno; 854                key = serno;
853            } 855            }
854            if (la.checkSerno(serno)) { 856            if (la.checkSerno(serno)) {
855                if (la.onChange) { 857                if (la.onChange) {
856                    la.onChange(la, { 858                    la.onChange(la, {
857                        serno: serno, 859                        serno: serno,
858                        action: "init", 860                        action: "init",
859                        index: index, 861                        index: index,
860                        key: key, 862                        key: key,
861                        data: val 863                        data: val
862                    }); 864                    });
863                } 865                }
864            } 866            }
865        }; 867        };
866  868 
867        la.bootObj = function(serno, val) { 869        la.bootObj = function(serno, val) {
868            if (la.checkSerno(serno)) { 870            if (la.checkSerno(serno)) {
869  871 
870                //la.clear(); 872                //la.clear();
871                for (var i in val) { 873                for (var i in val) {
872                    la._add(val[i][0], val[i][1]); 874                    la._add(val[i][0], val[i][1]);
873                } 875                }
874  876 
875                if (la.onChange) { 877                if (la.onChange) {
876                    la.onChange(la, { 878                    la.onChange(la, {
877                        serno: serno, 879                        serno: serno,
878                        action: "bootObj", 880                        action: "bootObj",
879                        data: val, 881                        data: val,
880                        redraw: true 882                        redraw: true
881                    }); 883                    });
882                } 884                }
883            } 885            }
884        }; 886        };
885  887 
886        // @param serno  La is the serial number for la particular request. 888        // @param serno  La is the serial number for la particular request.
887        // @param key    If looking at it as a hash table, la represents the key in the hashArray object where you want to store the val object. 889        // @param key    If looking at it as a hash table, la represents the key in the hashArray object where you want to store the val object.
888        // @param index  If looking at it as an array, la represents the position in the array where you want to store the val object. 890        // @param index  If looking at it as an array, la represents the position in the array where you want to store the val object.
889        // @param val    La is the object you want to store at the key or index location in the hash table / array. 891        // @param val    La is the object you want to store at the key or index location in the hash table / array.
890        la.add = function(serno, val, key, index) { 892        la.add = function(serno, val, key, index) {
891            if (key === null || key === undefined) { 893            if (key === null || key === undefined) {
892                key = serno; 894                key = serno;
893            } 895            }
894            if (la.checkSerno(serno)) { 896            if (la.checkSerno(serno)) {
895                var redraw = la._add(key, val, index); 897                var redraw = la._add(key, val, index);
896                if (la.onChange) { 898                if (la.onChange) {
897                    la.onChange(la, { 899                    la.onChange(la, {
898                        serno: serno, 900                        serno: serno,
899                        action: "add", 901                        action: "add",
900                        index: index, 902                        index: index,
901                        key: key, 903                        key: key,
902                        data: val, 904                        data: val,
903                        redraw: redraw 905                        redraw: redraw
904                    }); 906                    });
905                } 907                }
906            } 908            }
907        }; 909        };
908  910 
909        la.modify = function(serno, val, key, index) { 911        la.modify = function(serno, val, key, index) {
910            if (key === null || key === undefined) { 912            if (key === null || key === undefined) {
911                key = serno; 913                key = serno;
912            } 914            }
913            if (la.checkSerno(serno)) { 915            if (la.checkSerno(serno)) {
914                la._add(key, val, index); 916                la._add(key, val, index);
915                if (la.onChange) { 917                if (la.onChange) {
916                    la.onChange(la, { 918                    la.onChange(la, {
917                        serno: serno, 919                        serno: serno,
918                        action: "modify", 920                        action: "modify",
919                        key: key, 921                        key: key,
920                        data: val, 922                        data: val,
921                        index: index 923                        index: index
922                    }); 924                    });
923                } 925                }
924            } 926            }
925        }; 927        };
926  928 
927        la.del = function(serno, key, index) { 929        la.del = function(serno, key, index) {
928            if (key === null || key === undefined) { 930            if (key === null || key === undefined) {
929                key = serno; 931                key = serno;
930            } 932            }
931            if (la.checkSerno(serno)) { 933            if (la.checkSerno(serno)) {
932                if (index === null || index < 0 || index === undefined) { 934                if (index === null || index < 0 || index === undefined) {
933                    index = la.indexOf(key); 935                    index = la.indexOf(key);
934                } 936                }
935                var ok = la._del(key); 937                var ok = la._del(key);
936  938 
937                if (ok && la.onChange) { 939                if (ok && la.onChange) {
938                    la.onChange(la, { 940                    la.onChange(la, {
939                        serno: serno, 941                        serno: serno,
940                        action: "del", 942                        action: "del",
941                        key: key, 943                        key: key,
942                        index: index 944                        index: index
943                    }); 945                    });
944                } 946                }
945            } 947            }
946        }; 948        };
947  949 
948        var eventHandler = function(v, e, la) { 950        var eventHandler = function(v, e, la) {
949            var packet = e.data; 951            var packet = e.data;
950  952 
951            //console.error("READ:", packet); 953            //console.error("READ:", packet);
952  954 
953            if (packet.name != la.name) { 955            if (packet.name != la.name) {
954                return; 956                return;
955            } 957            }
956  958 
957            switch (packet.action) { 959            switch (packet.action) {
958  960 
959            case "init": 961            case "init":
960                la.init(packet.wireSerno, packet.data, packet.hashKey, packet.arrIndex); 962                la.init(packet.wireSerno, packet.data, packet.hashKey, packet.arrIndex);
961                break; 963                break;
962  964 
963            case "bootObj": 965            case "bootObj":
964                la.bootObj(packet.wireSerno, packet.data); 966                la.bootObj(packet.wireSerno, packet.data);
965                break; 967                break;
966            case "add": 968            case "add":
967                la.add(packet.wireSerno, packet.data, packet.hashKey, packet.arrIndex); 969                la.add(packet.wireSerno, packet.data, packet.hashKey, packet.arrIndex);
968                break; 970                break;
969  971 
970            case "modify": 972            case "modify":
971                if (! (packet.arrIndex || packet.hashKey)) { 973                if (! (packet.arrIndex || packet.hashKey)) {
972                    console.error("Invalid Packet", packet); 974                    console.error("Invalid Packet", packet);
973                } else { 975                } else {
974                    la.modify(packet.wireSerno, packet.data, packet.hashKey, packet.arrIndex); 976                    la.modify(packet.wireSerno, packet.data, packet.hashKey, packet.arrIndex);
975                } 977                }
976                break; 978                break;
977            case "del": 979            case "del":
978                if (! (packet.arrIndex || packet.hashKey)) { 980                if (! (packet.arrIndex || packet.hashKey)) {
979                    console.error("Invalid Packet", packet); 981                    console.error("Invalid Packet", packet);
980                } else { 982                } else {
981                    la.del(packet.wireSerno, packet.hashKey, packet.arrIndex); 983                    la.del(packet.wireSerno, packet.hashKey, packet.arrIndex);
982                } 984                }
983                break; 985                break;
984  986 
985            case "clear": 987            case "clear":
986                la.clear(); 988                la.clear();
987                break; 989                break;
988  990 
989            case "reorder": 991            case "reorder":
990                la.reorder(packet.wireSerno, packet.order); 992                la.reorder(packet.wireSerno, packet.order);
991                break; 993                break;
992  994 
993            default: 995            default:
994                if (la.checkSerno(packet.wireSerno)) { 996                if (la.checkSerno(packet.wireSerno)) {
995                    if (la.onChange) { 997                    if (la.onChange) {
996                        la.onChange(la, { 998                        la.onChange(la, {
997                            serno: packet.wireSerno, 999                            serno: packet.wireSerno,
998                            action: packet.action, 1000                            action: packet.action,
999                            data: packet.data 1001                            data: packet.data
1000                        }); 1002                        });
1001                    } 1003                    }
1002                } 1004                }
1003                break; 1005                break;
1004            } 1006            }
1005        }; 1007        };
1006  1008 
1007        if (la.context) { 1009        if (la.context) {
1008            binding = la.verto.subscribe(la.context, { 1010            binding = la.verto.subscribe(la.context, {
1009                handler: eventHandler, 1011                handler: eventHandler,
1010                userData: la, 1012                userData: la,
1011                subParams: config.subParams 1013                subParams: config.subParams
1012            }); 1014            });
1013        } 1015        }
1014  1016 
1015        la.destroy = function() { 1017        la.destroy = function() {
1016            la._clear(); 1018            la._clear();
1017            la.verto.unsubscribe(binding); 1019            la.verto.unsubscribe(binding);
1018        }; 1020        };
1019  1021 
1020        la.sendCommand = function(cmd, obj) { 1022        la.sendCommand = function(cmd, obj) {
1021            var self = la; 1023            var self = la;
1022            self.broadcast(self.context, { 1024            self.broadcast(self.context, {
1023                liveArray: { 1025                liveArray: {
1024                    command: cmd, 1026                    command: cmd,
1025                    context: self.context, 1027                    context: self.context,
1026                    name: self.name, 1028                    name: self.name,
1027                    obj: obj 1029                    obj: obj
1028                } 1030                }
1029            }); 1031            });
1030        }; 1032        };
1031  1033 
1032        la.bootstrap = function(obj) { 1034        la.bootstrap = function(obj) {
1033            var self = la; 1035            var self = la;
1034            la.sendCommand("bootstrap", obj); 1036            la.sendCommand("bootstrap", obj);
1035            //self.heartbeat(); 1037            //self.heartbeat();
1036        }; 1038        };
1037  1039 
1038        la.changepage = function(obj) { 1040        la.changepage = function(obj) {
1039            var self = la; 1041            var self = la;
1040            self.clear(); 1042            self.clear();
1041            self.broadcast(self.context, { 1043            self.broadcast(self.context, {
1042                liveArray: { 1044                liveArray: {
1043                    command: "changepage", 1045                    command: "changepage",
1044                    context: la.context, 1046                    context: la.context,
1045                    name: la.name, 1047                    name: la.name,
1046                    obj: obj 1048                    obj: obj
1047                } 1049                }
1048            }); 1050            });
1049        }; 1051        };
1050  1052 
1051        la.heartbeat = function(obj) { 1053        la.heartbeat = function(obj) {
1052            var self = la; 1054            var self = la;
1053  1055 
1054            var callback = function() { 1056            var callback = function() {
1055                self.heartbeat.call(self, obj); 1057                self.heartbeat.call(self, obj);
1056            }; 1058            };
1057            self.broadcast(self.context, { 1059            self.broadcast(self.context, {
1058                liveArray: { 1060                liveArray: {
1059                    command: "heartbeat", 1061                    command: "heartbeat",
1060                    context: self.context, 1062                    context: self.context,
1061                    name: self.name, 1063                    name: self.name,
1062                    obj: obj 1064                    obj: obj
1063                } 1065                }
1064            }); 1066            });
1065            self.hb_pid = setTimeout(callback, 30000); 1067            self.hb_pid = setTimeout(callback, 30000);
1066        }; 1068        };
1067  1069 
1068        la.bootstrap(la.user_obj); 1070        la.bootstrap(la.user_obj);
1069    }; 1071    };
1070  1072 
1071    $.verto.liveTable = function(verto, context, name, jq, config) { 1073    $.verto.liveTable = function(verto, context, name, jq, config) {
1072        var dt; 1074        var dt;
1073        var la = new $.verto.liveArray(verto, context, name, { 1075        var la = new $.verto.liveArray(verto, context, name, {
1074            subParams: config.subParams 1076            subParams: config.subParams
1075        }); 1077        });
1076        var lt = this; 1078        var lt = this;
1077  1079 
1078        lt.liveArray = la; 1080        lt.liveArray = la;
1079        lt.dataTable = dt; 1081        lt.dataTable = dt;
1080        lt.verto = verto; 1082        lt.verto = verto;
1081  1083 
1082        lt.destroy = function() { 1084        lt.destroy = function() {
1083            if (dt) { 1085            if (dt) {
1084                dt.fnDestroy(); 1086                dt.fnDestroy();
1085            } 1087            }
1086            if (la) { 1088            if (la) {
1087                la.destroy(); 1089                la.destroy();
1088            } 1090            }
1089  1091 
1090            dt = null; 1092            dt = null;
1091            la = null; 1093            la = null;
1092        }; 1094        };
1093  1095 
1094        la.onErr = function(obj, args) { 1096        la.onErr = function(obj, args) {
1095            console.error("Error: ", obj, args); 1097            console.error("Error: ", obj, args);
1096        }; 1098        };
1097  1099 
1098    /* back compat so jsonstatus can always be enabled */  1100    /* back compat so jsonstatus can always be enabled */ 
1099    function genRow(data) { 1101    function genRow(data) {
1100        if (typeof(data[4]) === "string" && data[4].indexOf("{") > -1) { 1102        if (typeof(data[4]) === "string" && data[4].indexOf("{") > -1) {
1101        var tmp = $.parseJSON(data[4]); 1103        var tmp = $.parseJSON(data[4]);
1102        data[4] = tmp.oldStatus; 1104        data[4] = tmp.oldStatus;
1103        data[5] = null; 1105        data[5] = null;
1104        } 1106        }
1105        return data; 1107        return data;
1106    } 1108    }
1107  1109 
1108    function genArray(obj) { 1110    function genArray(obj) {
1109        var data = obj.asArray(); 1111        var data = obj.asArray();
1110  1112 
1111            for (var i in data) { 1113            for (var i in data) {
1112        data[i] = genRow(data[i]); 1114        data[i] = genRow(data[i]);
1113        } 1115        }
1114  1116 
1115        return data; 1117        return data;
1116    } 1118    }
1117  1119 
1118  1120 
1119        la.onChange = function(obj, args) { 1121        la.onChange = function(obj, args) {
1120            var index = 0; 1122            var index = 0;
1121            var iserr = 0; 1123            var iserr = 0;
1122  1124 
1123            if (!dt) { 1125            if (!dt) {
1124                if (!config.aoColumns) { 1126                if (!config.aoColumns) {
1125                    if (args.action != "init") { 1127                    if (args.action != "init") {
1126                        return; 1128                        return;
1127                    } 1129                    }
1128  1130 
1129                    config.aoColumns = []; 1131                    config.aoColumns = [];
1130  1132 
1131                    for (var i in args.data) { 1133                    for (var i in args.data) {
1132                        config.aoColumns.push({ 1134                        config.aoColumns.push({
1133                            "sTitle": args.data[i] 1135                            "sTitle": args.data[i]
1134                        }); 1136                        });
1135                    } 1137                    }
1136                } 1138                }
1137  1139 
1138                dt = jq.dataTable(config); 1140                dt = jq.dataTable(config);
1139            } 1141            }
1140  1142 
1141            if (dt && (args.action == "del" || args.action == "modify")) { 1143            if (dt && (args.action == "del" || args.action == "modify")) {
1142                index = args.index; 1144                index = args.index;
1143  1145 
1144                if (index === undefined && args.key) { 1146                if (index === undefined && args.key) {
1145                    index = la.indexOf(args.key); 1147                    index = la.indexOf(args.key);
1146                } 1148                }
1147  1149 
1148                if (index === undefined) { 1150                if (index === undefined) {
1149                    console.error("INVALID PACKET Missing INDEX\n", args); 1151                    console.error("INVALID PACKET Missing INDEX\n", args);
1150                    return; 1152                    return;
1151                } 1153                }
1152            } 1154            }
1153  1155 
1154            if (config.onChange) { 1156            if (config.onChange) {
1155                config.onChange(obj, args); 1157                config.onChange(obj, args);
1156            } 1158            }
1157  1159 
1158            try { 1160            try {
1159                switch (args.action) { 1161                switch (args.action) {
1160                case "bootObj": 1162                case "bootObj":
1161                    if (!args.data) { 1163                    if (!args.data) {
1162                        console.error("missing data"); 1164                        console.error("missing data");
1163                        return; 1165                        return;
1164                    } 1166                    }
1165                    dt.fnClearTable(); 1167                    dt.fnClearTable();
1166                    dt.fnAddData(genArray(obj)); 1168                    dt.fnAddData(genArray(obj));
1167                    dt.fnAdjustColumnSizing(); 1169                    dt.fnAdjustColumnSizing();
1168                    break; 1170                    break;
1169                case "add": 1171                case "add":
1170                    if (!args.data) { 1172                    if (!args.data) {
1171                        console.error("missing data"); 1173                        console.error("missing data");
1172                        return; 1174                        return;
1173                    } 1175                    }
1174                    if (args.redraw > -1) { 1176                    if (args.redraw > -1) {
1175                        // specific position, more costly 1177                        // specific position, more costly
1176                        dt.fnClearTable(); 1178                        dt.fnClearTable();
1177                        dt.fnAddData(genArray(obj)); 1179                        dt.fnAddData(genArray(obj));
1178                    } else { 1180                    } else {
1179                        dt.fnAddData(genRow(args.data)); 1181                        dt.fnAddData(genRow(args.data));
1180                    } 1182                    }
1181                    dt.fnAdjustColumnSizing(); 1183                    dt.fnAdjustColumnSizing();
1182                    break; 1184                    break;
1183                case "modify": 1185                case "modify":
1184                    if (!args.data) { 1186                    if (!args.data) {
1185                        return; 1187                        return;
1186                    } 1188                    }
1187                    //console.debug(args, index); 1189                    //console.debug(args, index);
1188                    dt.fnUpdate(genRow(args.data), index); 1190                    dt.fnUpdate(genRow(args.data), index);
1189                    dt.fnAdjustColumnSizing(); 1191                    dt.fnAdjustColumnSizing();
1190                    break; 1192                    break;
1191                case "del": 1193                case "del":
1192                    dt.fnDeleteRow(index); 1194                    dt.fnDeleteRow(index);
1193                    dt.fnAdjustColumnSizing(); 1195                    dt.fnAdjustColumnSizing();
1194                    break; 1196                    break;
1195                case "clear": 1197                case "clear":
1196                    dt.fnClearTable(); 1198                    dt.fnClearTable();
1197                    break; 1199                    break;
1198                case "reorder": 1200                case "reorder":
1199                    // specific position, more costly 1201                    // specific position, more costly
1200                    dt.fnClearTable(); 1202                    dt.fnClearTable();
1201                    dt.fnAddData(genArray(obj)); 1203                    dt.fnAddData(genArray(obj));
1202                    break; 1204                    break;
1203                case "hide": 1205                case "hide":
1204                    jq.hide(); 1206                    jq.hide();
1205                    break; 1207                    break;
1206  1208 
1207                case "show": 1209                case "show":
1208                    jq.show(); 1210                    jq.show();
1209                    break; 1211                    break;
1210  1212 
1211                } 1213                }
1212            } catch(err) { 1214            } catch(err) {
1213                console.error("ERROR: " + err); 1215                console.error("ERROR: " + err);
1214                iserr++; 1216                iserr++;
1215            } 1217            }
1216  1218 
1217            if (iserr) { 1219            if (iserr) {
1218                obj.errs++; 1220                obj.errs++;
1219                if (obj.errs < 3) { 1221                if (obj.errs < 3) {
1220                    obj.bootstrap(obj.user_obj); 1222                    obj.bootstrap(obj.user_obj);
1221                } 1223                }
1222            } else { 1224            } else {
1223                obj.errs = 0; 1225                obj.errs = 0;
1224            } 1226            }
1225  1227 
1226        }; 1228        };
1227  1229 
1228        la.onChange(la, { 1230        la.onChange(la, {
1229            action: "init"  1231            action: "init" 
1230        }); 1232        });
1231  1233 
1232    }; 1234    };
1233  1235 
1234    var CONFMAN_SERNO = 1; 1236    var CONFMAN_SERNO = 1;
1235  1237 
1236    /* 1238    /*
1237        Conference Manager without jQuery table. 1239        Conference Manager without jQuery table.
1238     */  1240     */ 
1239  1241 
1240    $.verto.conf = function(verto, params) { 1242    $.verto.conf = function(verto, params) {
1241        var conf = this; 1243        var conf = this;
1242  1244 
1243        conf.params = $.extend({ 1245        conf.params = $.extend({
1244            dialog: null, 1246            dialog: null,
1245            hasVid: false, 1247            hasVid: false,
1246            laData: null, 1248            laData: null,
1247            onBroadcast: null, 1249            onBroadcast: null,
1248            onLaChange: null, 1250            onLaChange: null,
1249            onLaRow: null 1251            onLaRow: null
1250        }, params); 1252        }, params);
1251  1253 
1252        conf.verto = verto; 1254        conf.verto = verto;
1253        conf.serno = CONFMAN_SERNO++; 1255        conf.serno = CONFMAN_SERNO++;
1254  1256 
1255        createMainModeratorMethods(); 1257        createMainModeratorMethods();
1256  1258 
1257        verto.subscribe(conf.params.laData.modChannel, { 1259        verto.subscribe(conf.params.laData.modChannel, {
1258            handler: function(v, e) { 1260            handler: function(v, e) {
1259                if (conf.params.onBroadcast) { 1261                if (conf.params.onBroadcast) {
1260                    conf.params.onBroadcast(verto, conf, e.data); 1262                    conf.params.onBroadcast(verto, conf, e.data);
1261                } 1263                }
1262            } 1264            }
1263        }); 1265        });
1264  1266 
1265        verto.subscribe(conf.params.laData.infoChannel, { 1267        verto.subscribe(conf.params.laData.infoChannel, {
1266            handler: function(v, e) { 1268            handler: function(v, e) {
1267                if (typeof(conf.params.infoCallback) === "function") { 1269                if (typeof(conf.params.infoCallback) === "function") {
1268                    conf.params.infoCallback(v,e); 1270                    conf.params.infoCallback(v,e);
1269                } 1271                }
1270            } 1272            }
1271        }); 1273        });
1272  1274 
1273        verto.subscribe(conf.params.laData.chatChannel, { 1275        verto.subscribe(conf.params.laData.chatChannel, {
1274            handler: function(v, e) { 1276            handler: function(v, e) {
1275                if (typeof(conf.params.chatCallback) === "function") { 1277                if (typeof(conf.params.chatCallback) === "function") {
1276                    conf.params.chatCallback(v,e); 1278                    conf.params.chatCallback(v,e);
1277                } 1279                }
1278            } 1280            }
1279        }); 1281        });
1280    }; 1282    };
1281  1283 
1282    $.verto.conf.prototype.modCommand = function(cmd, id, value) { 1284    $.verto.conf.prototype.modCommand = function(cmd, id, value) {
1283        var conf = this; 1285        var conf = this;
1284  1286 
1285        conf.verto.rpcClient.call("verto.broadcast", { 1287        conf.verto.rpcClient.call("verto.broadcast", {
1286            "eventChannel": conf.params.laData.modChannel, 1288            "eventChannel": conf.params.laData.modChannel,
1287            "data": { 1289            "data": {
1288                "application": "conf-control", 1290                "application": "conf-control",
1289                "command": cmd, 1291                "command": cmd,
1290                "id": id, 1292                "id": id,
1291                "value": value 1293                "value": value
1292            } 1294            }
1293        }); 1295        });
1294    }; 1296    };
1295  1297 
1296    $.verto.conf.prototype.destroy = function() { 1298    $.verto.conf.prototype.destroy = function() {
1297        var conf = this; 1299        var conf = this;
1298  1300 
1299        conf.destroyed = true; 1301        conf.destroyed = true;
1300        conf.params.onBroadcast(conf.verto, conf, 'destroy'); 1302        conf.params.onBroadcast(conf.verto, conf, 'destroy');
1301  1303 
1302        if (conf.params.laData.modChannel) { 1304        if (conf.params.laData.modChannel) {
1303            conf.verto.unsubscribe(conf.params.laData.modChannel); 1305            conf.verto.unsubscribe(conf.params.laData.modChannel);
1304        } 1306        }
1305  1307 
1306        if (conf.params.laData.chatChannel) { 1308        if (conf.params.laData.chatChannel) {
1307            conf.verto.unsubscribe(conf.params.laData.chatChannel); 1309            conf.verto.unsubscribe(conf.params.laData.chatChannel);
1308        } 1310        }
1309  1311 
1310        if (conf.params.laData.infoChannel) { 1312        if (conf.params.laData.infoChannel) {
1311            conf.verto.unsubscribe(conf.params.laData.infoChannel); 1313            conf.verto.unsubscribe(conf.params.laData.infoChannel);
1312        } 1314        }
1313    }; 1315    };
1314  1316 
1315    function createMainModeratorMethods() { 1317    function createMainModeratorMethods() {
1316        $.verto.conf.prototype.listVideoLayouts = function() { 1318        $.verto.conf.prototype.listVideoLayouts = function() {
1317            this.modCommand("list-videoLayouts", null, null); 1319            this.modCommand("list-videoLayouts", null, null);
1318        }; 1320        };
1319  1321 
1320        $.verto.conf.prototype.play = function(file) { 1322        $.verto.conf.prototype.play = function(file) {
1321            this.modCommand("play", null, file); 1323            this.modCommand("play", null, file);
1322        }; 1324        };
1323  1325 
1324        $.verto.conf.prototype.stop = function() { 1326        $.verto.conf.prototype.stop = function() {
1325            this.modCommand("stop", null, "all"); 1327            this.modCommand("stop", null, "all");
1326        }; 1328        };
1327  1329 
1328        $.verto.conf.prototype.deaf = function(memberID) { 1330        $.verto.conf.prototype.deaf = function(memberID) {
1329            this.modCommand("deaf", parseInt(memberID)); 1331            this.modCommand("deaf", parseInt(memberID));
1330        }; 1332        };
1331  1333 
1332        $.verto.conf.prototype.undeaf = function(memberID) { 1334        $.verto.conf.prototype.undeaf = function(memberID) {
1333            this.modCommand("undeaf", parseInt(memberID)); 1335            this.modCommand("undeaf", parseInt(memberID));
1334        }; 1336        };
1335  1337 
1336        $.verto.conf.prototype.record = function(file) { 1338        $.verto.conf.prototype.record = function(file) {
1337            this.modCommand("recording", null, ["start", file]); 1339            this.modCommand("recording", null, ["start", file]);
1338        }; 1340        };
1339  1341 
1340        $.verto.conf.prototype.stopRecord = function() { 1342        $.verto.conf.prototype.stopRecord = function() {
1341            this.modCommand("recording", null, ["stop", "all"]); 1343            this.modCommand("recording", null, ["stop", "all"]);
1342        }; 1344        };
1343  1345 
1344        $.verto.conf.prototype.snapshot = function(file) { 1346        $.verto.conf.prototype.snapshot = function(file) {
1345            if (!this.params.hasVid) { 1347            if (!this.params.hasVid) {
1346                throw 'Conference has no video'; 1348                throw 'Conference has no video';
1347            } 1349            }
1348            this.modCommand("vid-write-png", null, file); 1350            this.modCommand("vid-write-png", null, file);
1349        }; 1351        };
1350  1352 
1351        $.verto.conf.prototype.setVideoLayout = function(layout, canvasID) { 1353        $.verto.conf.prototype.setVideoLayout = function(layout, canvasID) {
1352            if (!this.params.hasVid) { 1354            if (!this.params.hasVid) {
1353                throw 'Conference has no video'; 1355                throw 'Conference has no video';
1354            } 1356            }
1355        if (canvasID) { 1357        if (canvasID) {
1356        this.modCommand("vid-layout", null, [layout, canvasID]); 1358        this.modCommand("vid-layout", null, [layout, canvasID]);
1357        } else { 1359        } else {
1358        this.modCommand("vid-layout", null, layout); 1360        this.modCommand("vid-layout", null, layout);
1359        } 1361        }
1360        }; 1362        };
1361  1363 
1362        $.verto.conf.prototype.kick = function(memberID) { 1364        $.verto.conf.prototype.kick = function(memberID) {
1363            this.modCommand("kick", parseInt(memberID)); 1365            this.modCommand("kick", parseInt(memberID));
1364        }; 1366        };
1365  1367 
1366        $.verto.conf.prototype.muteMic = function(memberID) { 1368        $.verto.conf.prototype.muteMic = function(memberID) {
1367            this.modCommand("tmute", parseInt(memberID)); 1369            this.modCommand("tmute", parseInt(memberID));
1368        }; 1370        };
1369  1371 
1370        $.verto.conf.prototype.muteVideo = function(memberID) { 1372        $.verto.conf.prototype.muteVideo = function(memberID) {
1371            if (!this.params.hasVid) { 1373            if (!this.params.hasVid) {
1372                throw 'Conference has no video'; 1374                throw 'Conference has no video';
1373            } 1375            }
1374            this.modCommand("tvmute", parseInt(memberID)); 1376            this.modCommand("tvmute", parseInt(memberID));
1375        }; 1377        };
1376  1378 
1377        $.verto.conf.prototype.presenter = function(memberID) { 1379        $.verto.conf.prototype.presenter = function(memberID) {
1378            if (!this.params.hasVid) { 1380            if (!this.params.hasVid) {
1379                throw 'Conference has no video'; 1381                throw 'Conference has no video';
1380            } 1382            }
1381            this.modCommand("vid-res-id", parseInt(memberID), "presenter"); 1383            this.modCommand("vid-res-id", parseInt(memberID), "presenter");
1382        }; 1384        };
1383  1385 
1384        $.verto.conf.prototype.videoFloor = function(memberID) { 1386        $.verto.conf.prototype.videoFloor = function(memberID) {
1385            if (!this.params.hasVid) { 1387            if (!this.params.hasVid) {
1386                throw 'Conference has no video'; 1388                throw 'Conference has no video';
1387            } 1389            }
1388            this.modCommand("vid-floor", parseInt(memberID), "force"); 1390            this.modCommand("vid-floor", parseInt(memberID), "force");
1389        }; 1391        };
1390  1392 
1391        $.verto.conf.prototype.banner = function(memberID, text) { 1393        $.verto.conf.prototype.banner = function(memberID, text) {
1392            if (!this.params.hasVid) { 1394            if (!this.params.hasVid) {
1393                throw 'Conference has no video'; 1395                throw 'Conference has no video';
1394            } 1396            }
1395            this.modCommand("vid-banner", parseInt(memberID), escape(text)); 1397            this.modCommand("vid-banner", parseInt(memberID), escape(text));
1396        }; 1398        };
1397  1399 
1398        $.verto.conf.prototype.volumeDown = function(memberID) { 1400        $.verto.conf.prototype.volumeDown = function(memberID) {
1399            this.modCommand("volume_out", parseInt(memberID), "down"); 1401            this.modCommand("volume_out", parseInt(memberID), "down");
1400        }; 1402        };
1401  1403 
1402        $.verto.conf.prototype.volumeUp = function(memberID) { 1404        $.verto.conf.prototype.volumeUp = function(memberID) {
1403            this.modCommand("volume_out", parseInt(memberID), "up"); 1405            this.modCommand("volume_out", parseInt(memberID), "up");
1404        }; 1406        };
1405  1407 
1406        $.verto.conf.prototype.gainDown = function(memberID) { 1408        $.verto.conf.prototype.gainDown = function(memberID) {
1407            this.modCommand("volume_in", parseInt(memberID), "down"); 1409            this.modCommand("volume_in", parseInt(memberID), "down");
1408        }; 1410        };
1409  1411 
1410        $.verto.conf.prototype.gainUp = function(memberID) { 1412        $.verto.conf.prototype.gainUp = function(memberID) {
1411            this.modCommand("volume_in", parseInt(memberID), "up"); 1413            this.modCommand("volume_in", parseInt(memberID), "up");
1412        }; 1414        };
1413  1415 
1414        $.verto.conf.prototype.transfer = function(memberID, exten) { 1416        $.verto.conf.prototype.transfer = function(memberID, exten) {
1415            this.modCommand("transfer", parseInt(memberID), exten); 1417            this.modCommand("transfer", parseInt(memberID), exten);
1416        }; 1418        };
1417  1419 
1418        $.verto.conf.prototype.sendChat = function(message, type) { 1420        $.verto.conf.prototype.sendChat = function(message, type) {
1419            var conf = this; 1421            var conf = this;
1420            conf.verto.rpcClient.call("verto.broadcast", { 1422            conf.verto.rpcClient.call("verto.broadcast", {
1421                "eventChannel": conf.params.laData.chatChannel, 1423                "eventChannel": conf.params.laData.chatChannel,
1422                "data": { 1424                "data": {
1423                    "action": "send", 1425                    "action": "send",
1424                    "message": message, 1426                    "message": message,
1425                    "type": type 1427                    "type": type
1426                } 1428                }
1427            }); 1429            });
1428        }; 1430        };
1429              1431             
1430    } 1432    }
1431  1433 
1432    $.verto.modfuncs = {}; 1434    $.verto.modfuncs = {};
1433  1435 
1434    $.verto.confMan = function(verto, params) { 1436    $.verto.confMan = function(verto, params) {
1435        var confMan = this; 1437        var confMan = this;
1436  1438 
1437        confMan.params = $.extend({ 1439        confMan.params = $.extend({
1438            tableID: null, 1440            tableID: null,
1439            statusID: null, 1441            statusID: null,
1440            mainModID: null, 1442            mainModID: null,
1441            dialog: null, 1443            dialog: null,
1442            hasVid: false, 1444            hasVid: false,
1443            laData: null, 1445            laData: null,
1444            onBroadcast: null, 1446            onBroadcast: null,
1445            onLaChange: null, 1447            onLaChange: null,
1446            onLaRow: null 1448            onLaRow: null
1447        }, params); 1449        }, params);
1448  1450 
1449        confMan.verto = verto; 1451        confMan.verto = verto;
1450        confMan.serno = CONFMAN_SERNO++; 1452        confMan.serno = CONFMAN_SERNO++;
1451    confMan.canvasCount = confMan.params.laData.canvasCount; 1453    confMan.canvasCount = confMan.params.laData.canvasCount;
1452      1454     
1453        function genMainMod(jq) { 1455        function genMainMod(jq) {
1454            var play_id = "play_" + confMan.serno; 1456            var play_id = "play_" + confMan.serno;
1455            var stop_id = "stop_" + confMan.serno; 1457            var stop_id = "stop_" + confMan.serno;
1456            var recording_id = "recording_" + confMan.serno; 1458            var recording_id = "recording_" + confMan.serno;
1457            var snapshot_id = "snapshot_" + confMan.serno; 1459            var snapshot_id = "snapshot_" + confMan.serno;
1458            var rec_stop_id = "recording_stop" + confMan.serno; 1460            var rec_stop_id = "recording_stop" + confMan.serno;
1459            var div_id = "confman_" + confMan.serno; 1461            var div_id = "confman_" + confMan.serno;
1460  1462 
1461            var html =  "<div id='" + div_id + "'><br>" + 1463            var html =  "<div id='" + div_id + "'><br>" +
1462        "<button class='ctlbtn' id='" + play_id + "'>Play</button>" + 1464        "<button class='ctlbtn' id='" + play_id + "'>Play</button>" +
1463        "<button class='ctlbtn' id='" + stop_id + "'>Stop</button>" + 1465        "<button class='ctlbtn' id='" + stop_id + "'>Stop</button>" +
1464        "<button class='ctlbtn' id='" + recording_id + "'>Record</button>" + 1466        "<button class='ctlbtn' id='" + recording_id + "'>Record</button>" +
1465        "<button class='ctlbtn' id='" + rec_stop_id + "'>Record Stop</button>" + 1467        "<button class='ctlbtn' id='" + rec_stop_id + "'>Record Stop</button>" +
1466        (confMan.params.hasVid ? "<button class='ctlbtn' id='" + snapshot_id + "'>PNG Snapshot</button>" : "") + 1468        (confMan.params.hasVid ? "<button class='ctlbtn' id='" + snapshot_id + "'>PNG Snapshot</button>" : "") +
1467        "<br><br></div>"; 1469        "<br><br></div>";
1468  1470 
1469            jq.html(html); 1471            jq.html(html);
1470  1472 
1471        $.verto.modfuncs.change_video_layout = function(id, canvas_id) {          1473        $.verto.modfuncs.change_video_layout = function(id, canvas_id) {         
1472        var val = $("#" + id + " option:selected").text(); 1474        var val = $("#" + id + " option:selected").text();
1473        if (val !== "none") { 1475        if (val !== "none") {
1474                    confMan.modCommand("vid-layout", null, [val, canvas_id]); 1476                    confMan.modCommand("vid-layout", null, [val, canvas_id]);
1475        } 1477        }
1476        }; 1478        };
1477  1479 
1478        if (confMan.params.hasVid) { 1480        if (confMan.params.hasVid) {
1479        for (var j = 0; j < confMan.canvasCount; j++) { 1481        for (var j = 0; j < confMan.canvasCount; j++) {
1480            var vlayout_id = "confman_vid_layout_" + j + "_" + confMan.serno; 1482            var vlayout_id = "confman_vid_layout_" + j + "_" + confMan.serno;
1481            var vlselect_id = "confman_vl_select_" + j + "_" + confMan.serno; 1483            var vlselect_id = "confman_vl_select_" + j + "_" + confMan.serno;
1482          1484         
1483  1485 
1484            var vlhtml =  "<div id='" + vlayout_id + "'><br>" + 1486            var vlhtml =  "<div id='" + vlayout_id + "'><br>" +
1485            "<b>Video Layout Canvas " + (j+1) +   1487            "<b>Video Layout Canvas " + (j+1) +  
1486            "</b> <select onChange='$.verto.modfuncs.change_video_layout(\"" + vlayout_id + "\", \"" + (j+1) + "\")' id='" + vlselect_id + "'></select> " + 1488            "</b> <select onChange='$.verto.modfuncs.change_video_layout(\"" + vlayout_id + "\", \"" + (j+1) + "\")' id='" + vlselect_id + "'></select> " +
1487            "<br><br></div>"; 1489            "<br><br></div>";
1488            jq.append(vlhtml); 1490            jq.append(vlhtml);
1489        } 1491        }
1490  1492 
1491        $("#" + snapshot_id).click(function() { 1493        $("#" + snapshot_id).click(function() {
1492                    var file = prompt("Please enter file name", ""); 1494                    var file = prompt("Please enter file name", "");
1493            if (file) { 1495            if (file) {
1494            confMan.modCommand("vid-write-png", null, file); 1496            confMan.modCommand("vid-write-png", null, file);
1495            } 1497            }
1496        }); 1498        });
1497        } 1499        }
1498  1500 
1499            $("#" + play_id).click(function() { 1501            $("#" + play_id).click(function() {
1500                var file = prompt("Please enter file name", ""); 1502                var file = prompt("Please enter file name", "");
1501        if (file) { 1503        if (file) {
1502                    confMan.modCommand("play", null, file); 1504                    confMan.modCommand("play", null, file);
1503        } 1505        }
1504            }); 1506            });
1505  1507 
1506            $("#" + stop_id).click(function() { 1508            $("#" + stop_id).click(function() {
1507                confMan.modCommand("stop", null, "all"); 1509                confMan.modCommand("stop", null, "all");
1508            }); 1510            });
1509  1511 
1510            $("#" + recording_id).click(function() { 1512            $("#" + recording_id).click(function() {
1511                var file = prompt("Please enter file name", ""); 1513                var file = prompt("Please enter file name", "");
1512        if (file) { 1514        if (file) {
1513                    confMan.modCommand("recording", null, ["start", file]); 1515                    confMan.modCommand("recording", null, ["start", file]);
1514        } 1516        }
1515            }); 1517            });
1516  1518 
1517            $("#" + rec_stop_id).click(function() { 1519            $("#" + rec_stop_id).click(function() {
1518                confMan.modCommand("recording", null, ["stop", "all"]); 1520                confMan.modCommand("recording", null, ["stop", "all"]);
1519            }); 1521            });
1520  1522 
1521        } 1523        }
1522  1524 
1523        function genControls(jq, rowid) { 1525        function genControls(jq, rowid) {
1524            var x = parseInt(rowid); 1526            var x = parseInt(rowid);
1525            var kick_id = "kick_" + x; 1527            var kick_id = "kick_" + x;
1526            var canvas_in_next_id = "canvas_in_next_" + x; 1528            var canvas_in_next_id = "canvas_in_next_" + x;
1527            var canvas_in_prev_id = "canvas_in_prev_" + x; 1529            var canvas_in_prev_id = "canvas_in_prev_" + x;
1528            var canvas_out_next_id = "canvas_out_next_" + x; 1530            var canvas_out_next_id = "canvas_out_next_" + x;
1529            var canvas_out_prev_id = "canvas_out_prev_" + x; 1531            var canvas_out_prev_id = "canvas_out_prev_" + x;
1530  1532 
1531            var canvas_in_set_id = "canvas_in_set_" + x; 1533            var canvas_in_set_id = "canvas_in_set_" + x;
1532            var canvas_out_set_id = "canvas_out_set_" + x; 1534            var canvas_out_set_id = "canvas_out_set_" + x;
1533  1535 
1534            var layer_set_id = "layer_set_" + x; 1536            var layer_set_id = "layer_set_" + x;
1535            var layer_next_id = "layer_next_" + x; 1537            var layer_next_id = "layer_next_" + x;
1536            var layer_prev_id = "layer_prev_" + x; 1538            var layer_prev_id = "layer_prev_" + x;
1537          1539         
1538            var tmute_id = "tmute_" + x; 1540            var tmute_id = "tmute_" + x;
1539            var tvmute_id = "tvmute_" + x; 1541            var tvmute_id = "tvmute_" + x;
1540            var vbanner_id = "vbanner_" + x; 1542            var vbanner_id = "vbanner_" + x;
1541            var tvpresenter_id = "tvpresenter_" + x; 1543            var tvpresenter_id = "tvpresenter_" + x;
1542            var tvfloor_id = "tvfloor_" + x; 1544            var tvfloor_id = "tvfloor_" + x;
1543            var box_id = "box_" + x; 1545            var box_id = "box_" + x;
1544            var gainup_id = "gain_in_up" + x; 1546            var gainup_id = "gain_in_up" + x;
1545            var gaindn_id = "gain_in_dn" + x; 1547            var gaindn_id = "gain_in_dn" + x;
1546            var volup_id = "vol_in_up" + x; 1548            var volup_id = "vol_in_up" + x;
1547            var voldn_id = "vol_in_dn" + x; 1549            var voldn_id = "vol_in_dn" + x;
1548            var transfer_id = "transfer" + x; 1550            var transfer_id = "transfer" + x;
1549          1551         
1550  1552 
1551            var html = "<div id='" + box_id + "'>"; 1553            var html = "<div id='" + box_id + "'>";
1552  1554 
1553        html += "<b>General Controls</b><hr noshade>"; 1555        html += "<b>General Controls</b><hr noshade>";
1554  1556 
1555            html += "<button class='ctlbtn' id='" + kick_id + "'>Kick</button>" + 1557            html += "<button class='ctlbtn' id='" + kick_id + "'>Kick</button>" +
1556                "<button class='ctlbtn' id='" + tmute_id + "'>Mute</button>" + 1558                "<button class='ctlbtn' id='" + tmute_id + "'>Mute</button>" +
1557                "<button class='ctlbtn' id='" + gainup_id + "'>Gain -</button>" + 1559                "<button class='ctlbtn' id='" + gainup_id + "'>Gain -</button>" +
1558                "<button class='ctlbtn' id='" + gaindn_id + "'>Gain +</button>" + 1560                "<button class='ctlbtn' id='" + gaindn_id + "'>Gain +</button>" +
1559                "<button class='ctlbtn' id='" + voldn_id + "'>Vol -</button>" + 1561                "<button class='ctlbtn' id='" + voldn_id + "'>Vol -</button>" +
1560                "<button class='ctlbtn' id='" + volup_id + "'>Vol +</button>" + 1562                "<button class='ctlbtn' id='" + volup_id + "'>Vol +</button>" +
1561                "<button class='ctlbtn' id='" + transfer_id + "'>Transfer</button>"; 1563                "<button class='ctlbtn' id='" + transfer_id + "'>Transfer</button>";
1562          1564         
1563        if (confMan.params.hasVid) { 1565        if (confMan.params.hasVid) {
1564        html += "<br><br><b>Video Controls</b><hr noshade>"; 1566        html += "<br><br><b>Video Controls</b><hr noshade>";
1565  1567 
1566  1568 
1567                html += "<button class='ctlbtn' id='" + tvmute_id + "'>VMute</button>" + 1569                html += "<button class='ctlbtn' id='" + tvmute_id + "'>VMute</button>" +
1568                    "<button class='ctlbtn' id='" + tvpresenter_id + "'>Presenter</button>" + 1570                    "<button class='ctlbtn' id='" + tvpresenter_id + "'>Presenter</button>" +
1569                    "<button class='ctlbtn' id='" + tvfloor_id + "'>Vid Floor</button>" + 1571                    "<button class='ctlbtn' id='" + tvfloor_id + "'>Vid Floor</button>" +
1570                    "<button class='ctlbtn' id='" + vbanner_id + "'>Banner</button>"; 1572                    "<button class='ctlbtn' id='" + vbanner_id + "'>Banner</button>";
1571  1573 
1572        if (confMan.canvasCount > 1) { 1574        if (confMan.canvasCount > 1) {
1573                    html += "<br><br><b>Canvas Controls</b><hr noshade>" + 1575                    html += "<br><br><b>Canvas Controls</b><hr noshade>" +
1574            "<button class='ctlbtn' id='" + canvas_in_set_id + "'>Set Input Canvas</button>" + 1576            "<button class='ctlbtn' id='" + canvas_in_set_id + "'>Set Input Canvas</button>" +
1575            "<button class='ctlbtn' id='" + canvas_in_prev_id + "'>Prev Input Canvas</button>" + 1577            "<button class='ctlbtn' id='" + canvas_in_prev_id + "'>Prev Input Canvas</button>" +
1576            "<button class='ctlbtn' id='" + canvas_in_next_id + "'>Next Input Canvas</button>" + 1578            "<button class='ctlbtn' id='" + canvas_in_next_id + "'>Next Input Canvas</button>" +
1577              1579             
1578            "<br>" + 1580            "<br>" +
1579              1581             
1580            "<button class='ctlbtn' id='" + canvas_out_set_id + "'>Set Watching Canvas</button>" + 1582            "<button class='ctlbtn' id='" + canvas_out_set_id + "'>Set Watching Canvas</button>" +
1581            "<button class='ctlbtn' id='" + canvas_out_prev_id + "'>Prev Watching Canvas</button>" + 1583            "<button class='ctlbtn' id='" + canvas_out_prev_id + "'>Prev Watching Canvas</button>" +
1582            "<button class='ctlbtn' id='" + canvas_out_next_id + "'>Next Watching Canvas</button>"; 1584            "<button class='ctlbtn' id='" + canvas_out_next_id + "'>Next Watching Canvas</button>";
1583        } 1585        }
1584          1586         
1585        html += "<br>" + 1587        html += "<br>" +
1586  1588 
1587                "<button class='ctlbtn' id='" + layer_set_id + "'>Set Layer</button>" + 1589                "<button class='ctlbtn' id='" + layer_set_id + "'>Set Layer</button>" +
1588                    "<button class='ctlbtn' id='" + layer_prev_id + "'>Prev Layer</button>" + 1590                    "<button class='ctlbtn' id='" + layer_prev_id + "'>Prev Layer</button>" +
1589                    "<button class='ctlbtn' id='" + layer_next_id + "'>Next Layer</button>" + 1591                    "<button class='ctlbtn' id='" + layer_next_id + "'>Next Layer</button>" +
1590  1592 
1591  1593 
1592  1594 
1593                    "</div>"; 1595                    "</div>";
1594            } 1596            }
1595  1597 
1596            jq.html(html); 1598            jq.html(html);
1597  1599 
1598  1600 
1599            if (!jq.data("mouse")) { 1601            if (!jq.data("mouse")) {
1600                $("#" + box_id).hide(); 1602                $("#" + box_id).hide();
1601            } 1603            }
1602  1604 
1603            jq.mouseover(function(e) { 1605            jq.mouseover(function(e) {
1604                jq.data({"mouse": true}); 1606                jq.data({"mouse": true});
1605                $("#" + box_id).show(); 1607                $("#" + box_id).show();
1606            }); 1608            });
1607  1609 
1608            jq.mouseout(function(e) { 1610            jq.mouseout(function(e) {
1609                jq.data({"mouse": false}); 1611                jq.data({"mouse": false});
1610                $("#" + box_id).hide(); 1612                $("#" + box_id).hide();
1611            }); 1613            });
1612  1614 
1613            $("#" + transfer_id).click(function() { 1615            $("#" + transfer_id).click(function() {
1614                var xten = prompt("Enter Extension"); 1616                var xten = prompt("Enter Extension");
1615        if (xten) { 1617        if (xten) {
1616                    confMan.modCommand("transfer", x, xten); 1618                    confMan.modCommand("transfer", x, xten);
1617        } 1619        }
1618            }); 1620            });
1619  1621 
1620            $("#" + kick_id).click(function() { 1622            $("#" + kick_id).click(function() {
1621                confMan.modCommand("kick", x); 1623                confMan.modCommand("kick", x);
1622            }); 1624            });
1623  1625 
1624  1626 
1625            $("#" + layer_set_id).click(function() { 1627            $("#" + layer_set_id).click(function() {
1626                var cid = prompt("Please enter layer ID", ""); 1628                var cid = prompt("Please enter layer ID", "");
1627        if (cid) { 1629        if (cid) {
1628                    confMan.modCommand("vid-layer", x, cid); 1630                    confMan.modCommand("vid-layer", x, cid);
1629        } 1631        }
1630            }); 1632            });
1631  1633 
1632            $("#" + layer_next_id).click(function() { 1634            $("#" + layer_next_id).click(function() {
1633                confMan.modCommand("vid-layer", x, "next"); 1635                confMan.modCommand("vid-layer", x, "next");
1634            }); 1636            });
1635            $("#" + layer_prev_id).click(function() { 1637            $("#" + layer_prev_id).click(function() {
1636                confMan.modCommand("vid-layer", x, "prev"); 1638                confMan.modCommand("vid-layer", x, "prev");
1637            }); 1639            });
1638  1640 
1639            $("#" + canvas_in_set_id).click(function() { 1641            $("#" + canvas_in_set_id).click(function() {
1640                var cid = prompt("Please enter canvas ID", ""); 1642                var cid = prompt("Please enter canvas ID", "");
1641        if (cid) { 1643        if (cid) {
1642                    confMan.modCommand("vid-canvas", x, cid); 1644                    confMan.modCommand("vid-canvas", x, cid);
1643        } 1645        }
1644            }); 1646            });
1645  1647 
1646            $("#" + canvas_out_set_id).click(function() { 1648            $("#" + canvas_out_set_id).click(function() {
1647                var cid = prompt("Please enter canvas ID", ""); 1649                var cid = prompt("Please enter canvas ID", "");
1648        if (cid) { 1650        if (cid) {
1649                    confMan.modCommand("vid-watching-canvas", x, cid); 1651                    confMan.modCommand("vid-watching-canvas", x, cid);
1650        } 1652        }
1651            }); 1653            });
1652  1654 
1653            $("#" + canvas_in_next_id).click(function() { 1655            $("#" + canvas_in_next_id).click(function() {
1654                confMan.modCommand("vid-canvas", x, "next"); 1656                confMan.modCommand("vid-canvas", x, "next");
1655            }); 1657            });
1656            $("#" + canvas_in_prev_id).click(function() { 1658            $("#" + canvas_in_prev_id).click(function() {
1657                confMan.modCommand("vid-canvas", x, "prev"); 1659                confMan.modCommand("vid-canvas", x, "prev");
1658            }); 1660            });
1659  1661 
1660  1662 
1661            $("#" + canvas_out_next_id).click(function() { 1663            $("#" + canvas_out_next_id).click(function() {
1662                confMan.modCommand("vid-watching-canvas", x, "next"); 1664                confMan.modCommand("vid-watching-canvas", x, "next");
1663            }); 1665            });
1664            $("#" + canvas_out_prev_id).click(function() { 1666            $("#" + canvas_out_prev_id).click(function() {
1665                confMan.modCommand("vid-watching-canvas", x, "prev"); 1667                confMan.modCommand("vid-watching-canvas", x, "prev");
1666            }); 1668            });
1667          1669         
1668            $("#" + tmute_id).click(function() { 1670            $("#" + tmute_id).click(function() {
1669                confMan.modCommand("tmute", x); 1671                confMan.modCommand("tmute", x);
1670            }); 1672            });
1671  1673 
1672        if (confMan.params.hasVid) { 1674        if (confMan.params.hasVid) {
1673        $("#" + tvmute_id).click(function() { 1675        $("#" + tvmute_id).click(function() {
1674                    confMan.modCommand("tvmute", x); 1676                    confMan.modCommand("tvmute", x);
1675        }); 1677        });
1676        $("#" + tvpresenter_id).click(function() { 1678        $("#" + tvpresenter_id).click(function() {
1677                    confMan.modCommand("vid-res-id", x, "presenter"); 1679                    confMan.modCommand("vid-res-id", x, "presenter");
1678        }); 1680        });
1679        $("#" + tvfloor_id).click(function() { 1681        $("#" + tvfloor_id).click(function() {
1680                    confMan.modCommand("vid-floor", x, "force"); 1682                    confMan.modCommand("vid-floor", x, "force");
1681        }); 1683        });
1682        $("#" + vbanner_id).click(function() { 1684        $("#" + vbanner_id).click(function() {
1683                    var text = prompt("Please enter text", ""); 1685                    var text = prompt("Please enter text", "");
1684            if (text) { 1686            if (text) {
1685            confMan.modCommand("vid-banner", x, escape(text)); 1687            confMan.modCommand("vid-banner", x, escape(text));
1686            } 1688            }
1687        }); 1689        });
1688        } 1690        }
1689  1691 
1690            $("#" + gainup_id).click(function() { 1692            $("#" + gainup_id).click(function() {
1691                confMan.modCommand("volume_in", x, "up"); 1693                confMan.modCommand("volume_in", x, "up");
1692            }); 1694            });
1693  1695 
1694            $("#" + gaindn_id).click(function() { 1696            $("#" + gaindn_id).click(function() {
1695                confMan.modCommand("volume_in", x, "down"); 1697                confMan.modCommand("volume_in", x, "down");
1696            }); 1698            });
1697  1699 
1698            $("#" + volup_id).click(function() { 1700            $("#" + volup_id).click(function() {
1699                confMan.modCommand("volume_out", x, "up"); 1701                confMan.modCommand("volume_out", x, "up");
1700            }); 1702            });
1701  1703 
1702            $("#" + voldn_id).click(function() { 1704            $("#" + voldn_id).click(function() {
1703                confMan.modCommand("volume_out", x, "down"); 1705                confMan.modCommand("volume_out", x, "down");
1704            }); 1706            });
1705  1707 
1706            return html; 1708            return html;
1707        } 1709        }
1708  1710 
1709        var atitle = ""; 1711        var atitle = "";
1710        var awidth = 0; 1712        var awidth = 0;
1711  1713 
1712        //$(".jsDataTable").width(confMan.params.hasVid ? "900px" : "800px"); 1714        //$(".jsDataTable").width(confMan.params.hasVid ? "900px" : "800px");
1713  1715 
1714        verto.subscribe(confMan.params.laData.infoChannel, { 1716        verto.subscribe(confMan.params.laData.infoChannel, {
1715            handler: function(v, e) { 1717            handler: function(v, e) {
1716                if (typeof(confMan.params.infoCallback) === "function") { 1718                if (typeof(confMan.params.infoCallback) === "function") {
1717                    confMan.params.infoCallback(v,e); 1719                    confMan.params.infoCallback(v,e);
1718                } 1720                }
1719            } 1721            }
1720        }); 1722        });
1721  1723 
1722    verto.subscribe(confMan.params.laData.chatChannel, { 1724    verto.subscribe(confMan.params.laData.chatChannel, {
1723        handler: function(v, e) { 1725        handler: function(v, e) {
1724        if (typeof(confMan.params.chatCallback) === "function") { 1726        if (typeof(confMan.params.chatCallback) === "function") {
1725            confMan.params.chatCallback(v,e); 1727            confMan.params.chatCallback(v,e);
1726        } 1728        }
1727        } 1729        }
1728    }); 1730    });
1729  1731 
1730        if (confMan.params.laData.role === "moderator") { 1732        if (confMan.params.laData.role === "moderator") {
1731            atitle = "Action"; 1733            atitle = "Action";
1732            awidth = 600; 1734            awidth = 600;
1733  1735 
1734            if (confMan.params.mainModID) { 1736            if (confMan.params.mainModID) {
1735                genMainMod($(confMan.params.mainModID)); 1737                genMainMod($(confMan.params.mainModID));
1736                $(confMan.params.displayID).html("Moderator Controls Ready<br><br>"); 1738                $(confMan.params.displayID).html("Moderator Controls Ready<br><br>");
1737            } else { 1739            } else {
1738                $(confMan.params.mainModID).html(""); 1740                $(confMan.params.mainModID).html("");
1739            } 1741            }
1740  1742 
1741            verto.subscribe(confMan.params.laData.modChannel, { 1743            verto.subscribe(confMan.params.laData.modChannel, {
1742                handler: function(v, e) { 1744                handler: function(v, e) {
1743                    //console.error("MODDATA:", e.data); 1745                    //console.error("MODDATA:", e.data);
1744                    if (confMan.params.onBroadcast) { 1746                    if (confMan.params.onBroadcast) {
1745                        confMan.params.onBroadcast(verto, confMan, e.data); 1747                        confMan.params.onBroadcast(verto, confMan, e.data);
1746                    } 1748                    }
1747  1749 
1748            if (e.data["conf-command"] === "list-videoLayouts") { 1750            if (e.data["conf-command"] === "list-videoLayouts") {
1749            for (var j = 0; j < confMan.canvasCount; j++) { 1751            for (var j = 0; j < confMan.canvasCount; j++) {
1750                var vlselect_id = "#confman_vl_select_" + j + "_" + confMan.serno; 1752                var vlselect_id = "#confman_vl_select_" + j + "_" + confMan.serno;
1751                var vlayout_id = "#confman_vid_layout_" + j + "_" + confMan.serno; 1753                var vlayout_id = "#confman_vid_layout_" + j + "_" + confMan.serno;
1752                  1754                 
1753                var x = 0; 1755                var x = 0;
1754                var options; 1756                var options;
1755                  1757                 
1756                $(vlselect_id).selectmenu({}); 1758                $(vlselect_id).selectmenu({});
1757                $(vlselect_id).selectmenu("enable"); 1759                $(vlselect_id).selectmenu("enable");
1758                $(vlselect_id).empty(); 1760                $(vlselect_id).empty();
1759                  1761                 
1760                $(vlselect_id).append(new Option("Choose a Layout", "none")); 1762                $(vlselect_id).append(new Option("Choose a Layout", "none"));
1761  1763 
1762                if (e.data.responseData) { 1764                if (e.data.responseData) {
1763                var rdata = []; 1765                var rdata = [];
1764  1766 
1765                for (var i in e.data.responseData) { 1767                for (var i in e.data.responseData) {
1766                    rdata.push(e.data.responseData[i].name); 1768                    rdata.push(e.data.responseData[i].name);
1767                } 1769                }
1768                  1770                 
1769                options = rdata.sort(function(a, b) { 1771                options = rdata.sort(function(a, b) {
1770                    var ga = a.substring(0, 6) == "group:" ? true : false; 1772                    var ga = a.substring(0, 6) == "group:" ? true : false;
1771                    var gb = b.substring(0, 6) == "group:" ? true : false; 1773                    var gb = b.substring(0, 6) == "group:" ? true : false;
1772                      1774                     
1773                    if ((ga || gb) && ga != gb) { 1775                    if ((ga || gb) && ga != gb) {
1774                    return ga ? -1 : 1; 1776                    return ga ? -1 : 1;
1775                    } 1777                    }
1776                      1778                     
1777                    return ( ( a == b ) ? 0 : ( ( a > b ) ? 1 : -1 ) ); 1779                    return ( ( a == b ) ? 0 : ( ( a > b ) ? 1 : -1 ) );
1778                }); 1780                });
1779  1781 
1780                for (var i in options) { 1782                for (var i in options) {
1781                    $(vlselect_id).append(new Option(options[i], options[i])); 1783                    $(vlselect_id).append(new Option(options[i], options[i]));
1782                    x++; 1784                    x++;
1783                } 1785                }
1784                } 1786                }
1785  1787 
1786                if (x) { 1788                if (x) {
1787                $(vlselect_id).selectmenu('refresh', true); 1789                $(vlselect_id).selectmenu('refresh', true);
1788                } else { 1790                } else {
1789                $(vlayout_id).hide(); 1791                $(vlayout_id).hide();
1790                } 1792                }
1791            } 1793            }
1792            } else { 1794            } else {
1793  1795 
1794            if (!confMan.destroyed && confMan.params.displayID) { 1796            if (!confMan.destroyed && confMan.params.displayID) {
1795                            $(confMan.params.displayID).html(e.data.response + "<br><br>"); 1797                            $(confMan.params.displayID).html(e.data.response + "<br><br>");
1796                            if (confMan.lastTimeout) { 1798                            if (confMan.lastTimeout) {
1797                clearTimeout(confMan.lastTimeout); 1799                clearTimeout(confMan.lastTimeout);
1798                confMan.lastTimeout = 0; 1800                confMan.lastTimeout = 0;
1799                            } 1801                            }
1800                            confMan.lastTimeout = setTimeout(function() { $(confMan.params.displayID).html(confMan.destroyed ? "" : "Moderator Controls Ready<br><br>");}, 4000); 1802                            confMan.lastTimeout = setTimeout(function() { $(confMan.params.displayID).html(confMan.destroyed ? "" : "Moderator Controls Ready<br><br>");}, 4000);
1801            } 1803            }
1802            } 1804            }
1803                } 1805                }
1804            }); 1806            });
1805  1807 
1806  1808 
1807        if (confMan.params.hasVid) { 1809        if (confMan.params.hasVid) {
1808        confMan.modCommand("list-videoLayouts", null, null); 1810        confMan.modCommand("list-videoLayouts", null, null);
1809        } 1811        }
1810        } 1812        }
1811  1813 
1812        var row_callback = null; 1814        var row_callback = null;
1813  1815 
1814        if (confMan.params.laData.role === "moderator") { 1816        if (confMan.params.laData.role === "moderator") {
1815            row_callback = function(nRow, aData, iDisplayIndex, iDisplayIndexFull) { 1817            row_callback = function(nRow, aData, iDisplayIndex, iDisplayIndexFull) {
1816                if (!aData[5]) { 1818                if (!aData[5]) {
1817                    var $row = $('td:eq(5)', nRow); 1819                    var $row = $('td:eq(5)', nRow);
1818                    genControls($row, aData); 1820                    genControls($row, aData);
1819  1821 
1820                    if (confMan.params.onLaRow) { 1822                    if (confMan.params.onLaRow) {
1821                        confMan.params.onLaRow(verto, confMan, $row, aData); 1823                        confMan.params.onLaRow(verto, confMan, $row, aData);
1822                    } 1824                    }
1823                } 1825                }
1824            }; 1826            };
1825        } 1827        }
1826  1828 
1827        confMan.lt = new $.verto.liveTable(verto, confMan.params.laData.laChannel, confMan.params.laData.laName, $(confMan.params.tableID), { 1829        confMan.lt = new $.verto.liveTable(verto, confMan.params.laData.laChannel, confMan.params.laData.laName, $(confMan.params.tableID), {
1828            subParams: { 1830            subParams: {
1829                callID: confMan.params.dialog ? confMan.params.dialog.callID : null 1831                callID: confMan.params.dialog ? confMan.params.dialog.callID : null
1830            }, 1832            },
1831  1833 
1832            "onChange": function(obj, args) { 1834            "onChange": function(obj, args) {
1833                $(confMan.params.statusID).text("Conference Members: " + " (" + obj.arrayLen() + " Total)"); 1835                $(confMan.params.statusID).text("Conference Members: " + " (" + obj.arrayLen() + " Total)");
1834                if (confMan.params.onLaChange) { 1836                if (confMan.params.onLaChange) {
1835                    confMan.params.onLaChange(verto, confMan, $.verto.enum.confEvent.laChange, obj, args); 1837                    confMan.params.onLaChange(verto, confMan, $.verto.enum.confEvent.laChange, obj, args);
1836                } 1838                }
1837            }, 1839            },
1838  1840 
1839            "aaData": [], 1841            "aaData": [],
1840            "aoColumns": [ 1842            "aoColumns": [
1841                { 1843                {
1842                    "sTitle": "ID", 1844                    "sTitle": "ID",
1843                    "sWidth": "50"  1845                    "sWidth": "50" 
1844                }, 1846                },
1845                { 1847                {
1846                    "sTitle": "Number", 1848                    "sTitle": "Number",
1847            "sWidth": "250"  1849            "sWidth": "250" 
1848                }, 1850                },
1849                { 1851                {
1850                    "sTitle": "Name", 1852                    "sTitle": "Name",
1851            "sWidth": "250"  1853            "sWidth": "250" 
1852                }, 1854                },
1853                { 1855                {
1854                    "sTitle": "Codec", 1856                    "sTitle": "Codec",
1855                    "sWidth": "100"  1857                    "sWidth": "100" 
1856                }, 1858                },
1857                { 1859                {
1858                    "sTitle": "Status", 1860                    "sTitle": "Status",
1859                    "sWidth": confMan.params.hasVid ? "200px" : "150px"  1861                    "sWidth": confMan.params.hasVid ? "200px" : "150px" 
1860                }, 1862                },
1861                { 1863                {
1862                    "sTitle": atitle, 1864                    "sTitle": atitle,
1863                    "sWidth": awidth, 1865                    "sWidth": awidth,
1864                } 1866                }
1865            ], 1867            ],
1866            "bAutoWidth": true, 1868            "bAutoWidth": true,
1867            "bDestroy": true, 1869            "bDestroy": true,
1868            "bSort": false, 1870            "bSort": false,
1869            "bInfo": false, 1871            "bInfo": false,
1870            "bFilter": false, 1872            "bFilter": false,
1871            "bLengthChange": false, 1873            "bLengthChange": false,
1872            "bPaginate": false, 1874            "bPaginate": false,
1873            "iDisplayLength": 1400, 1875            "iDisplayLength": 1400,
1874  1876 
1875            "oLanguage": { 1877            "oLanguage": {
1876                "sEmptyTable": "The Conference is Empty....."  1878                "sEmptyTable": "The Conference is Empty....." 
1877            }, 1879            },
1878  1880 
1879            "fnRowCallback": row_callback 1881            "fnRowCallback": row_callback
1880  1882 
1881        }); 1883        });
1882    }; 1884    };
1883  1885 
1884    $.verto.confMan.prototype.modCommand = function(cmd, id, value) { 1886    $.verto.confMan.prototype.modCommand = function(cmd, id, value) {
1885        var confMan = this; 1887        var confMan = this;
1886  1888 
1887        confMan.verto.rpcClient.call("verto.broadcast", { 1889        confMan.verto.rpcClient.call("verto.broadcast", {
1888            "eventChannel": confMan.params.laData.modChannel, 1890            "eventChannel": confMan.params.laData.modChannel,
1889            "data": { 1891            "data": {
1890        "application": "conf-control", 1892        "application": "conf-control",
1891        "command": cmd, 1893        "command": cmd,
1892        "id": id, 1894        "id": id,
1893        "value": value 1895        "value": value
1894            } 1896            }
1895    }); 1897    });
1896    }; 1898    };
1897  1899 
1898    $.verto.confMan.prototype.sendChat = function(message, type) { 1900    $.verto.confMan.prototype.sendChat = function(message, type) {
1899        var confMan = this; 1901        var confMan = this;
1900        confMan.verto.rpcClient.call("verto.broadcast", { 1902        confMan.verto.rpcClient.call("verto.broadcast", {
1901            "eventChannel": confMan.params.laData.chatChannel, 1903            "eventChannel": confMan.params.laData.chatChannel,
1902            "data": { 1904            "data": {
1903        "action": "send", 1905        "action": "send",
1904        "message": message, 1906        "message": message,
1905        "type": type 1907        "type": type
1906            } 1908            }
1907    }); 1909    });
1908    }; 1910    };
1909  1911 
1910  1912 
1911    $.verto.confMan.prototype.destroy = function() { 1913    $.verto.confMan.prototype.destroy = function() {
1912        var confMan = this; 1914        var confMan = this;
1913  1915 
1914        confMan.destroyed = true; 1916        confMan.destroyed = true;
1915  1917 
1916        if (confMan.lt) { 1918        if (confMan.lt) {
1917            confMan.lt.destroy(); 1919            confMan.lt.destroy();
1918        } 1920        }
1919  1921 
1920        if (confMan.params.laData.chatChannel) { 1922        if (confMan.params.laData.chatChannel) {
1921            confMan.verto.unsubscribe(confMan.params.laData.chatChannel); 1923            confMan.verto.unsubscribe(confMan.params.laData.chatChannel);
1922        } 1924        }
1923  1925 
1924        if (confMan.params.laData.modChannel) { 1926        if (confMan.params.laData.modChannel) {
1925            confMan.verto.unsubscribe(confMan.params.laData.modChannel); 1927            confMan.verto.unsubscribe(confMan.params.laData.modChannel);
1926        } 1928        }
1927  1929 
1928        if (confMan.params.mainModID) { 1930        if (confMan.params.mainModID) {
1929            $(confMan.params.mainModID).html(""); 1931            $(confMan.params.mainModID).html("");
1930        } 1932        }
1931    }; 1933    };
1932  1934 
1933    $.verto.dialog = function(direction, verto, params) { 1935    $.verto.dialog = function(direction, verto, params) {
1934        var dialog = this; 1936        var dialog = this;
1935  1937 
1936        dialog.params = $.extend({ 1938        dialog.params = $.extend({
1937            useVideo: verto.options.useVideo, 1939            useVideo: verto.options.useVideo,
1938            useStereo: verto.options.useStereo, 1940            useStereo: verto.options.useStereo,
1939        screenShare: false, 1941        screenShare: false,
1940        useCamera: false, 1942        useCamera: false,
1941        useMic: verto.options.deviceParams.useMic, 1943        useMic: verto.options.deviceParams.useMic,
1942        useMicLabel: verto.options.deviceParams.useMicLabel, 1944        useMicLabel: verto.options.deviceParams.useMicLabel,
1943        useSpeak: verto.options.deviceParams.useSpeak, 1945        useSpeak: verto.options.deviceParams.useSpeak,
1944            tag: verto.options.tag, 1946            tag: verto.options.tag,
1945            localTag: verto.options.localTag, 1947            localTag: verto.options.localTag,
  1948            audioHackTag: verto.options.audioHackTag,
1946            login: verto.options.login, 1949            login: verto.options.login,
1947      videoParams: verto.options.videoParams, 1950      videoParams: verto.options.videoParams,
1948      useStream: verto.options.useStream, 1951      useStream: verto.options.useStream,
1949        }, params); 1952        }, params);
1950      1953     
1951  1954 
1952    if (!dialog.params.screenShare) { 1955    if (!dialog.params.screenShare) {
1953        dialog.params.useCamera = verto.options.deviceParams.useCamera; 1956        dialog.params.useCamera = verto.options.deviceParams.useCamera;
1954        dialog.params.useCameraLabel = verto.options.deviceParams.useCameraLabel; 1957        dialog.params.useCameraLabel = verto.options.deviceParams.useCameraLabel;
1955    } 1958    }
1956  1959 
1957        dialog.verto = verto; 1960        dialog.verto = verto;
1958        dialog.direction = direction; 1961        dialog.direction = direction;
1959        dialog.lastState = null; 1962        dialog.lastState = null;
1960        dialog.state = dialog.lastState = $.verto.enum.state.new; 1963        dialog.state = dialog.lastState = $.verto.enum.state.new;
1961        dialog.callbacks = verto.callbacks; 1964        dialog.callbacks = verto.callbacks;
1962        dialog.answered = false; 1965        dialog.answered = false;
1963        dialog.attach = params.attach || false; 1966        dialog.attach = params.attach || false;
1964    dialog.screenShare = params.screenShare || false; 1967    dialog.screenShare = params.screenShare || false;
1965    dialog.useCamera = dialog.params.useCamera; 1968    dialog.useCamera = dialog.params.useCamera;
1966    dialog.useCameraLabel = dialog.params.useCameraLabel; 1969    dialog.useCameraLabel = dialog.params.useCameraLabel;
1967    dialog.useMic = dialog.params.useMic; 1970    dialog.useMic = dialog.params.useMic;
1968    dialog.useMicLabel = dialog.params.useMicLabel; 1971    dialog.useMicLabel = dialog.params.useMicLabel;
1969    dialog.useSpeak = dialog.params.useSpeak; 1972    dialog.useSpeak = dialog.params.useSpeak;
  1973        dialog.acceptUDP = params.acceptUDP;
  1974        dialog.outgoingBandwidth = params.outgoingBandwidth; //ANYAM-6843
  1975        dialog.vendMaxQuant = params.vendMaxQuant;
1970      1976     
1971        if (dialog.params.callID) { 1977        if (dialog.params.callID) {
1972            dialog.callID = dialog.params.callID; 1978            dialog.callID = dialog.params.callID;
1973        } else { 1979        } else {
1974            dialog.callID = dialog.params.callID = generateGUID(); 1980            dialog.callID = dialog.params.callID = generateGUID();
1975        } 1981        }
1976  1982 
1977    if (typeof(dialog.params.tag) === "function") { 1983    if (typeof(dialog.params.tag) === "function") {
1978        dialog.params.tag = dialog.params.tag(); 1984        dialog.params.tag = dialog.params.tag();
1979    } 1985    }
1980      1986     
1981        if (dialog.params.tag) { 1987        if (dialog.params.tag) {
1982            dialog.audioStream = document.getElementById(dialog.params.tag); 1988            dialog.audioStream = document.getElementById(dialog.params.tag);
1983  1989 
1984            if (dialog.params.useVideo) { 1990            if (dialog.params.useVideo) {
1985                dialog.videoStream = dialog.audioStream; 1991                dialog.videoStream = dialog.audioStream;
1986            } 1992            }
1987        } //else conjure one TBD 1993        } //else conjure one TBD
1988  1994 
  1995        //ANYAM-10634
  1996        if (dialog.params.audioHackTag) {
  1997            dialog.audioHack = document.getElementById(dialog.params.audioHackTag);
  1998        }
  1999 
1989        if (dialog.params.localTag) { 2000        if (dialog.params.localTag) {
1990        dialog.localVideo = document.getElementById(dialog.params.localTag); 2001        dialog.localVideo = document.getElementById(dialog.params.localTag);
1991    } 2002    }
1992  2003 
1993        dialog.verto.dialogs[dialog.callID] = dialog; 2004        dialog.verto.dialogs[dialog.callID] = dialog;
1994  2005 
1995        var RTCcallbacks = {}; 2006        var RTCcallbacks = {};
1996  2007 
1997        if (dialog.direction == $.verto.enum.direction.inbound) { 2008        if (dialog.direction == $.verto.enum.direction.inbound) {
1998            if (dialog.params.display_direction === "outbound") { 2009            if (dialog.params.display_direction === "outbound") {
1999                dialog.params.remote_caller_id_name = dialog.params.caller_id_name; 2010                dialog.params.remote_caller_id_name = dialog.params.caller_id_name;
2000                dialog.params.remote_caller_id_number = dialog.params.caller_id_number; 2011                dialog.params.remote_caller_id_number = dialog.params.caller_id_number;
2001            } else { 2012            } else {
2002                dialog.params.remote_caller_id_name = dialog.params.callee_id_name; 2013                dialog.params.remote_caller_id_name = dialog.params.callee_id_name;
2003                dialog.params.remote_caller_id_number = dialog.params.callee_id_number; 2014                dialog.params.remote_caller_id_number = dialog.params.callee_id_number;
2004            } 2015            }
2005  2016 
2006            if (!dialog.params.remote_caller_id_name) { 2017            if (!dialog.params.remote_caller_id_name) {
2007                dialog.params.remote_caller_id_name = "Nobody"; 2018                dialog.params.remote_caller_id_name = "Nobody";
2008            } 2019            }
2009  2020 
2010            if (!dialog.params.remote_caller_id_number) { 2021            if (!dialog.params.remote_caller_id_number) {
2011                dialog.params.remote_caller_id_number = "UNKNOWN"; 2022                dialog.params.remote_caller_id_number = "UNKNOWN";
2012            } 2023            }
2013  2024 
2014            RTCcallbacks.onMessage = function(rtc, msg) { 2025            RTCcallbacks.onMessage = function(rtc, msg) {
2015                console.debug(msg); 2026                console.debug(msg);
2016            }; 2027            };
2017  2028 
2018            RTCcallbacks.onAnswerSDP = function(rtc, sdp) { 2029            RTCcallbacks.onAnswerSDP = function(rtc, sdp) {
2019                console.error("answer sdp", sdp); 2030                console.error("answer sdp", sdp);
2020            }; 2031            };
2021        } else { 2032        } else {
2022            dialog.params.remote_caller_id_name = "Outbound Call"; 2033            dialog.params.remote_caller_id_name = "Outbound Call";
2023            dialog.params.remote_caller_id_number = dialog.params.destination_number; 2034            dialog.params.remote_caller_id_number = dialog.params.destination_number;
2024        } 2035        }
2025  2036 
2026        RTCcallbacks.onICESDP = function(rtc) { 2037        RTCcallbacks.onICESDP = function(rtc) {
2027            console.log("RECV " + rtc.type + " SDP", rtc.mediaData.SDP); 2038            console.log("RECV " + rtc.type + " SDP", rtc.mediaData.SDP);
2028  2039 
2029        if (dialog.state == $.verto.enum.state.requesting || dialog.state == $.verto.enum.state.answering || dialog.state == $.verto.enum.state.active) { 2040        if (dialog.state == $.verto.enum.state.requesting || dialog.state == $.verto.enum.state.answering || dialog.state == $.verto.enum.state.active) {
2030        location.reload(); 2041        location.reload();
2031        return; 2042        return;
2032        } 2043        }
2033  2044 
2034            if (rtc.type == "offer") { 2045            if (rtc.type == "offer") {
2035        if (dialog.state == $.verto.enum.state.active) { 2046        if (dialog.state == $.verto.enum.state.active) {
2036                    dialog.setState($.verto.enum.state.requesting); 2047                    dialog.setState($.verto.enum.state.requesting);
2037            dialog.sendMethod("verto.attach", { 2048            dialog.sendMethod("verto.attach", {
2038            sdp: rtc.mediaData.SDP 2049            sdp: rtc.mediaData.SDP
2039                    }); 2050                    });
2040        } else { 2051        } else {
2041                    dialog.setState($.verto.enum.state.requesting); 2052                    dialog.setState($.verto.enum.state.requesting);
2042              2053             
2043                    dialog.sendMethod("verto.invite", { 2054                    dialog.sendMethod("verto.invite", {
2044            sdp: rtc.mediaData.SDP 2055            sdp: rtc.mediaData.SDP
2045                    }); 2056                    });
2046        } 2057        }
2047            } else { //answer 2058            } else { //answer
2048                dialog.setState($.verto.enum.state.answering); 2059                dialog.setState($.verto.enum.state.answering);
2049  2060 
2050                dialog.sendMethod(dialog.attach ? "verto.attach" : "verto.answer", { 2061                dialog.sendMethod(dialog.attach ? "verto.attach" : "verto.answer", {
2051                    sdp: dialog.rtc.mediaData.SDP 2062                    sdp: dialog.rtc.mediaData.SDP
2052                }); 2063                });
2053            } 2064            }
2054        }; 2065        };
2055  2066 
2056        RTCcallbacks.onICE = function(rtc) { 2067        RTCcallbacks.onICE = function(rtc) {
2057            //console.log("cand", rtc.mediaData.candidate); 2068            //console.log("cand", rtc.mediaData.candidate);
2058            if (rtc.type == "offer") { 2069            if (rtc.type == "offer") {
2059                console.log("offer", rtc.mediaData.candidate); 2070                console.log("offer", rtc.mediaData.candidate);
2060                return; 2071                return;
2061            } 2072            }
2062        }; 2073        };
2063  2074 
2064        RTCcallbacks.onStream = function(rtc, stream) { 2075        RTCcallbacks.onStream = function(rtc, stream) {
2065            if (dialog.callbacks.permissionCallback && 2076            if (dialog.callbacks.permissionCallback &&
2066                typeof dialog.callbacks.permissionCallback.onGranted === 'function') { 2077                typeof dialog.callbacks.permissionCallback.onGranted === 'function') {
2067                dialog.callbacks.permissionCallback.onGranted(stream); 2078                dialog.callbacks.permissionCallback.onGranted(stream);
2068            } 2079            }
2069            else if (dialog.verto.options.permissionCallback && 2080            else if (dialog.verto.options.permissionCallback &&
2070                typeof dialog.verto.options.permissionCallback.onGranted === 'function'){ 2081                typeof dialog.verto.options.permissionCallback.onGranted === 'function'){
2071                dialog.verto.options.permissionCallback.onGranted(stream); 2082                dialog.verto.options.permissionCallback.onGranted(stream);
2072            } 2083            }
2073            console.log("stream started"); 2084            console.log("stream started");
2074        }; 2085        };
2075  2086 
2076        RTCcallbacks.onRemoteStream = function(rtc, stream) { 2087        RTCcallbacks.onRemoteStream = function(rtc, stream) {
2077          if (typeof dialog.callbacks.onRemoteStream === 'function') { 2088          if (typeof dialog.callbacks.onRemoteStream === 'function') {
  2089            console.log('!!! onRemoteStream 1');
2078            dialog.callbacks.onRemoteStream(stream, dialog); 2090            dialog.callbacks.onRemoteStream(stream, dialog);
2079          } 2091          }
2080          console.log("remote stream started"); 2092          console.log("remote stream started");
2081        }; 2093        };
2082  2094 
2083        RTCcallbacks.onError = function(e) { 2095        RTCcallbacks.onError = function(rtc, e) {
2084            if (dialog.callbacks.permissionCallback && 2096            if (dialog.callbacks.permissionCallback &&
2085                typeof dialog.callbacks.permissionCallback.onDenied === 'function') { 2097                typeof dialog.callbacks.permissionCallback.onDenied === 'function') {
2086                dialog.callbacks.permissionCallback.onDenied();  2098                dialog.callbacks.permissionCallback.onDenied(rtc, e); //ANYAM 
2087            } 2099            }
2088            else if (dialog.verto.options.permissionCallback && 2100            else if (dialog.verto.options.permissionCallback &&
2089                typeof dialog.verto.options.permissionCallback.onDenied === 'function'){ 2101                typeof dialog.verto.options.permissionCallback.onDenied === 'function'){
2090                dialog.verto.options.permissionCallback.onDenied();  2102                dialog.verto.options.permissionCallback.onDenied(rtc, e); //ANYAM-12729 
2091            } 2103            }
  2104 
  2105            //ANYAM
  2106            if (dialog.verto.callbacks.onReportError) {
  2107                dialog.verto.callbacks.onReportError(e);
  2108            }
  2109 
2092            console.error("ERROR:", e); 2110            console.error("ERROR:", e);
2093            dialog.hangup({cause: "Device or Permission Error"}); 2111            dialog.hangup({cause: "Device or Permission Error"});
2094        }; 2112        };
2095  2113 
2096        dialog.rtc = new $.FSRTC({ 2114        dialog.rtc = new $.FSRTC({
2097            callbacks: RTCcallbacks, 2115            callbacks: RTCcallbacks,
2098        localVideo: dialog.screenShare ? null : dialog.localVideo, 2116        localVideo: dialog.screenShare ? null : dialog.localVideo,
2099            useVideo: dialog.params.useVideo ? dialog.videoStream : null, 2117            useVideo: dialog.params.useVideo ? dialog.videoStream : null,
2100            useAudio: dialog.audioStream, 2118            useAudio: dialog.audioStream,
  2119            useAudioHack: dialog.audioHack,
2101            useStereo: dialog.params.useStereo, 2120            useStereo: dialog.params.useStereo,
2102            videoParams: dialog.params.videoParams, 2121            videoParams: dialog.params.videoParams,
2103            audioParams: verto.options.audioParams, 2122            audioParams: verto.options.audioParams,
2104            iceServers: verto.options.iceServers, 2123            iceServers: verto.options.iceServers,
2105            screenShare: dialog.screenShare, 2124            screenShare: dialog.screenShare,
2106            useCamera: dialog.useCamera, 2125            useCamera: dialog.useCamera,
2107            useCameraLabel: dialog.useCameraLabel, 2126            useCameraLabel: dialog.useCameraLabel,
2108            useMic: dialog.useMic, 2127            useMic: dialog.useMic,
2109            useMicLabel: dialog.useMicLabel, 2128            useMicLabel: dialog.useMicLabel,
2110            useSpeak: dialog.useSpeak, 2129            useSpeak: dialog.useSpeak,
2111      turnServer: verto.options.turnServer, 2130            turnServer: verto.options.turnServer,
2112      useStream: dialog.params.useStream  2131            useStream: dialog.params.useStream, 
  2132            acceptUDP: dialog.acceptUDP,
  2133            outgoingBandwidth: dialog.outgoingBandwidth, //ANYAM-6843
  2134            vendMaxQuant: dialog.vendMaxQuant,
  2135            userVariables: params.userVariables
2113        }); 2136        });
2114  2137 
2115        dialog.rtc.verto = dialog.verto; 2138        dialog.rtc.verto = dialog.verto;
2116  2139 
2117        if (dialog.direction == $.verto.enum.direction.inbound) { 2140        if (dialog.direction == $.verto.enum.direction.inbound) {
2118            if (dialog.attach) { 2141            if (dialog.attach) {
2119                dialog.answer(); 2142                dialog.answer();
2120            } else { 2143            } else {
2121                dialog.ring(); 2144                dialog.ring();
2122            } 2145            }
2123        } 2146        }
2124    }; 2147    };
2125  2148 
2126    $.verto.dialog.prototype.invite = function() { 2149    $.verto.dialog.prototype.invite = function() {
2127        var dialog = this; 2150        var dialog = this;
2128        dialog.rtc.call(); 2151        dialog.rtc.call();
2129    }; 2152    };
2130  2153 
2131    $.verto.dialog.prototype.sendMethod = function(method, obj) { 2154    $.verto.dialog.prototype.sendMethod = function(method, obj) {
2132        var dialog = this; 2155        var dialog = this;
2133        obj.dialogParams = {}; 2156        obj.dialogParams = {};
2134  2157 
2135        for (var i in dialog.params) { 2158        for (var i in dialog.params) {
2136        if (i == "sdp" && method != "verto.invite" && method != "verto.attach") { 2159        if (i == "sdp" && method != "verto.invite" && method != "verto.attach") {
2137                continue; 2160                continue;
2138        } 2161        }
2139          2162         
2140        if ((obj.noDialogParams && i != "callID")) { 2163        if ((obj.noDialogParams && i != "callID")) {
2141        continue; 2164        continue;
2142        } 2165        }
2143  2166 
2144        obj.dialogParams[i] = dialog.params[i]; 2167        obj.dialogParams[i] = dialog.params[i];
2145        } 2168        }
2146      2169     
2147    delete obj.noDialogParams; 2170    delete obj.noDialogParams;
2148  2171 
2149        dialog.verto.rpcClient.call(method, obj, 2172        dialog.verto.rpcClient.call(method, obj,
2150  2173 
2151        function(e) { 2174        function(e) {
2152            /* Success */  2175            /* Success */ 
2153            dialog.processReply(method, true, e); 2176            dialog.processReply(method, true, e);
2154        }, 2177        },
2155  2178 
2156        function(e) { 2179        function(e) {
2157            /* Error */  2180            /* Error */ 
2158            dialog.processReply(method, false, e); 2181            dialog.processReply(method, false, e);
2159        }); 2182        });
2160    }; 2183    };
2161  2184 
2162    function checkStateChange(oldS, newS) { 2185    function checkStateChange(oldS, newS) {
2163  2186 
2164        if (newS == $.verto.enum.state.purge || $.verto.enum.states[oldS.name][newS.name]) { 2187        if (newS == $.verto.enum.state.purge || $.verto.enum.states[oldS.name][newS.name]) {
2165            return true; 2188            return true;
2166        } 2189        }
2167  2190 
2168        return false; 2191        return false;
2169    } 2192    }
2170  2193 
2171  2194 
2172    // Attach audio output device to video element using device/sink ID.                                                                                           2195    // Attach audio output device to video element using device/sink ID.                                                                                          
2173    function find_name(id) { 2196    function find_name(id) {
2174    for (var i in $.verto.audioOutDevices) { 2197    for (var i in $.verto.audioOutDevices) {
2175        var source = $.verto.audioOutDevices[i]; 2198        var source = $.verto.audioOutDevices[i];
2176        if (source.id === id) { 2199        if (source.id === id) {
2177        return(source.label); 2200        return(source.label);
2178        } 2201        }
2179    } 2202    }
2180  2203 
2181    return id; 2204    return id;
2182    } 2205    }
2183  2206 
2184    $.verto.dialog.prototype.setAudioPlaybackDevice = function(sinkId, callback, arg) { 2207    $.verto.dialog.prototype.setAudioPlaybackDevice = function(sinkId, callback, arg) {
2185    var dialog = this; 2208    var dialog = this;
2186    var element = dialog.audioStream; 2209    var element = dialog.audioStream;
2187  2210 
2188    if (typeof element.sinkId !== 'undefined') { 2211    if (typeof element.sinkId !== 'undefined') {
2189        var devname = find_name(sinkId); 2212        var devname = find_name(sinkId);
2190        console.info("Dialog: " + dialog.callID + " Setting speaker:", element, devname); 2213        console.info("Dialog: " + dialog.callID + " Setting speaker:", element, devname);
2191  2214 
2192        element.setSinkId(sinkId) 2215        element.setSinkId(sinkId)
2193        .then(function() { 2216        .then(function() {
2194            console.log("Dialog: " + dialog.callID + ' Success, audio output device attached: ' + sinkId); 2217            console.log("Dialog: " + dialog.callID + ' Success, audio output device attached: ' + sinkId);
2195            if (callback) { 2218            if (callback) {
2196            callback(true, devname, arg); 2219            callback(true, devname, arg);
2197            } 2220            }
2198        }) 2221        })
2199        .catch(function(error) { 2222        .catch(function(error) {
2200            var errorMessage = error; 2223            var errorMessage = error;
2201            if (error.name === 'SecurityError') { 2224            if (error.name === 'SecurityError') {
2202            errorMessage = "Dialog: " + dialog.callID + ' You need to use HTTPS for selecting audio output ' + 2225            errorMessage = "Dialog: " + dialog.callID + ' You need to use HTTPS for selecting audio output ' +
2203                'device: ' + error; 2226                'device: ' + error;
2204            } 2227            }
2205            if (callback) { 2228            if (callback) {
2206            callback(false, null, arg); 2229            callback(false, null, arg);
2207            } 2230            }
2208            console.error(errorMessage); 2231            console.error(errorMessage);
2209        }); 2232        });
2210    } else { 2233    } else {
2211        console.warn("Dialog: " + dialog.callID + ' Browser does not support output device selection.'); 2234        console.warn("Dialog: " + dialog.callID + ' Browser does not support output device selection.');
2212        if (callback) { 2235        if (callback) {
2213        callback(false, null, arg); 2236        callback(false, null, arg);
2214        } 2237        }
2215    } 2238    }
2216    } 2239    }
2217  2240 
2218    $.verto.dialog.prototype.setState = function(state) { 2241    $.verto.dialog.prototype.setState = function(state) {
2219        var dialog = this; 2242        var dialog = this;
2220  2243 
2221        if (dialog.state == $.verto.enum.state.ringing) { 2244        if (dialog.state == $.verto.enum.state.ringing) {
2222            dialog.stopRinging(); 2245            dialog.stopRinging();
2223        } 2246        }
2224  2247 
2225        if (dialog.state == state || !checkStateChange(dialog.state, state)) { 2248        if (dialog.state == state || !checkStateChange(dialog.state, state)) {
2226            console.error("Dialog " + dialog.callID + ": INVALID state change from " + dialog.state.name + " to " + state.name); 2249            console.error("Dialog " + dialog.callID + ": INVALID state change from " + dialog.state.name + " to " + state.name);
2227            dialog.hangup(); 2250            dialog.hangup();
2228            return false; 2251            return false;
2229        } 2252        }
2230  2253 
2231        console.log("Dialog " + dialog.callID + ": state change from " + dialog.state.name + " to " + state.name); 2254        console.log("Dialog " + dialog.callID + ": state change from " + dialog.state.name + " to " + state.name);
2232  2255 
2233        dialog.lastState = dialog.state; 2256        dialog.lastState = dialog.state;
2234        dialog.state = state; 2257        dialog.state = state;
2235  2258 
  2259        //ANYAM-12203
  2260        if (!dialog.causeCode) {
  2261            dialog.causeCode = 16;
  2262        }
  2263 
  2264        if (!dialog.cause) {
  2265            dialog.cause = "NORMAL CLEARING";
  2266        }
  2267 
2236        if (dialog.callbacks.onDialogState) { 2268        if (dialog.callbacks.onDialogState) {
2237            dialog.callbacks.onDialogState(this); 2269            dialog.callbacks.onDialogState(this);
2238        } 2270        }
2239  2271 
2240        switch (dialog.state) { 2272        switch (dialog.state) {
2241  2273 
2242        case $.verto.enum.state.early: 2274        case $.verto.enum.state.early:
2243        case $.verto.enum.state.active: 2275        case $.verto.enum.state.active:
2244  2276 
2245        var speaker = dialog.useSpeak; 2277        var speaker = dialog.useSpeak;
2246        console.info("Using Speaker: ", speaker); 2278        console.info("Using Speaker: ", speaker);
2247  2279 
2248        if (speaker && speaker !== "any" && speaker !== "none") { 2280        if (speaker && speaker !== "any" && speaker !== "none") {
2249        setTimeout(function() { 2281        setTimeout(function() {
2250            dialog.setAudioPlaybackDevice(speaker); 2282            dialog.setAudioPlaybackDevice(speaker);
2251        }, 500); 2283        }, 500);
2252        } 2284        }
2253  2285 
2254        break; 2286        break;
2255  2287 
2256        case $.verto.enum.state.trying: 2288        case $.verto.enum.state.trying:
2257            setTimeout(function() { 2289            setTimeout(function() {
2258                if (dialog.state == $.verto.enum.state.trying) { 2290                if (dialog.state == $.verto.enum.state.trying) {
2259                    dialog.setState($.verto.enum.state.hangup); 2291                    dialog.setState($.verto.enum.state.hangup);
2260                } 2292                }
2261            }, 30000); 2293            }, 30000);
2262            break; 2294            break;
2263        case $.verto.enum.state.purge: 2295        case $.verto.enum.state.purge:
2264            dialog.setState($.verto.enum.state.destroy); 2296            dialog.setState($.verto.enum.state.destroy);
2265            break; 2297            break;
2266        case $.verto.enum.state.hangup: 2298        case $.verto.enum.state.hangup:
2267  2299 
2268            if (dialog.lastState.val > $.verto.enum.state.requesting.val && dialog.lastState.val < $.verto.enum.state.hangup.val) { 2300            if (dialog.lastState.val > $.verto.enum.state.requesting.val && dialog.lastState.val < $.verto.enum.state.hangup.val) {
2269                dialog.sendMethod("verto.bye", {}); 2301                dialog.sendMethod("verto.bye", {});
2270            } 2302            }
2271  2303 
2272            dialog.setState($.verto.enum.state.destroy); 2304            dialog.setState($.verto.enum.state.destroy);
2273            break; 2305            break;
2274        case $.verto.enum.state.destroy: 2306        case $.verto.enum.state.destroy:
2275  2307 
2276            if (typeof(dialog.verto.options.tag) === "function") { 2308            if (typeof(dialog.verto.options.tag) === "function") {
2277              $('#' + dialog.params.tag).remove(); 2309              $('#' + dialog.params.tag).remove();
2278            } 2310            }
2279  2311 
2280            delete dialog.verto.dialogs[dialog.callID]; 2312            delete dialog.verto.dialogs[dialog.callID];
2281        if (dialog.params.screenShare) { 2313        if (dialog.params.screenShare) {
2282        dialog.rtc.stopPeer(); 2314        dialog.rtc.stopPeer();
2283        } else { 2315        } else {
2284        dialog.rtc.stop(); 2316        dialog.rtc.stop();
2285        } 2317        }
2286            break; 2318            break;
2287        } 2319        }
2288  2320 
2289        return true; 2321        return true;
2290    }; 2322    };
2291  2323 
2292    $.verto.dialog.prototype.processReply = function(method, success, e) { 2324    $.verto.dialog.prototype.processReply = function(method, success, e) {
2293        var dialog = this; 2325        var dialog = this;
2294  2326 
2295        //console.log("Response: " + method + " State:" + dialog.state.name, success, e); 2327        //console.log("Response: " + method + " State:" + dialog.state.name, success, e);
2296  2328 
2297        switch (method) { 2329        switch (method) {
2298  2330 
2299        case "verto.answer": 2331        case "verto.answer":
2300        case "verto.attach": 2332        case "verto.attach":
2301            if (success) { 2333            if (success) {
2302                dialog.setState($.verto.enum.state.active); 2334                dialog.setState($.verto.enum.state.active);
2303            } else { 2335            } else {
2304                dialog.hangup(); 2336                dialog.hangup();
2305            } 2337            }
2306            break; 2338            break;
2307        case "verto.invite": 2339        case "verto.invite":
2308            if (success) { 2340            if (success) {
2309                dialog.setState($.verto.enum.state.trying); 2341                dialog.setState($.verto.enum.state.trying);
2310            } else { 2342            } else {
2311                dialog.setState($.verto.enum.state.destroy); 2343                dialog.setState($.verto.enum.state.destroy);
2312            } 2344            }
2313            break; 2345            break;
2314  2346 
2315        case "verto.bye": 2347        case "verto.bye":
2316            dialog.hangup(); 2348            dialog.hangup();
2317            break; 2349            break;
2318  2350 
2319        case "verto.modify": 2351        case "verto.modify":
2320            if (e.holdState) { 2352            if (e.holdState) {
2321                if (e.holdState == "held") { 2353                if (e.holdState == "held") {
2322                    if (dialog.state != $.verto.enum.state.held) { 2354                    if (dialog.state != $.verto.enum.state.held) {
2323                        dialog.setState($.verto.enum.state.held); 2355                        dialog.setState($.verto.enum.state.held);
2324                    } 2356                    }
2325                } else if (e.holdState == "active") { 2357                } else if (e.holdState == "active") {
2326                    if (dialog.state != $.verto.enum.state.active) { 2358                    if (dialog.state != $.verto.enum.state.active) {
2327                        dialog.setState($.verto.enum.state.active); 2359                        dialog.setState($.verto.enum.state.active);
2328                    } 2360                    }
2329                } 2361                }
2330            } 2362            }
2331  2363 
2332            if (success) {} 2364            if (success) {}
2333  2365 
2334            break; 2366            break;
2335  2367 
2336        default: 2368        default:
2337            break; 2369            break;
2338        } 2370        }
2339  2371 
2340    }; 2372    };
2341  2373 
2342    $.verto.dialog.prototype.hangup = function(params) { 2374    $.verto.dialog.prototype.hangup = function(params) {
2343        var dialog = this; 2375        var dialog = this;
2344  2376 
2345        if (params) { 2377        if (params) {
2346            if (params.causeCode) { 2378            if (params.causeCode) {
2347        dialog.causeCode = params.causeCode; 2379        dialog.causeCode = params.causeCode;
2348            } 2380            }
2349  2381 
2350            if (params.cause) { 2382            if (params.cause) {
2351        dialog.cause = params.cause; 2383        dialog.cause = params.cause;
2352            } 2384            }
2353        } 2385        }
2354  2386 
2355    if (!dialog.cause && !dialog.causeCode) { 2387    if (!dialog.cause && !dialog.causeCode) {
2356        dialog.cause = "NORMAL_CLEARING"; 2388        dialog.cause = "NORMAL_CLEARING";
2357    } 2389    }
2358  2390 
2359        if (dialog.state.val >= $.verto.enum.state.new.val && dialog.state.val < $.verto.enum.state.hangup.val) { 2391        if (dialog.state.val >= $.verto.enum.state.new.val && dialog.state.val < $.verto.enum.state.hangup.val) {
2360            dialog.setState($.verto.enum.state.hangup); 2392            dialog.setState($.verto.enum.state.hangup);
2361        } else if (dialog.state.val < $.verto.enum.state.destroy) { 2393        } else if (dialog.state.val < $.verto.enum.state.destroy) {
2362            dialog.setState($.verto.enum.state.destroy); 2394            dialog.setState($.verto.enum.state.destroy);
2363        } 2395        }
2364    }; 2396    };
2365  2397 
2366    $.verto.dialog.prototype.stopRinging = function() { 2398    $.verto.dialog.prototype.stopRinging = function() {
2367        var dialog = this; 2399        var dialog = this;
2368        if (dialog.verto.ringer) { 2400        if (dialog.verto.ringer) {
2369            dialog.verto.ringer.stop(); 2401            dialog.verto.ringer.stop();
2370        } 2402        }
2371    }; 2403    };
2372  2404 
2373    $.verto.dialog.prototype.indicateRing = function() { 2405    $.verto.dialog.prototype.indicateRing = function() {
2374        var dialog = this; 2406        var dialog = this;
2375  2407 
2376        if (dialog.verto.ringer) { 2408        if (dialog.verto.ringer) {
2377            dialog.verto.ringer.attr("src", dialog.verto.options.ringFile)[0].play(); 2409            dialog.verto.ringer.attr("src", dialog.verto.options.ringFile)[0].play();
2378  2410 
2379            setTimeout(function() { 2411            setTimeout(function() {
2380                dialog.stopRinging(); 2412                dialog.stopRinging();
2381                if (dialog.state == $.verto.enum.state.ringing) { 2413                if (dialog.state == $.verto.enum.state.ringing) {
2382                    dialog.indicateRing(); 2414                    dialog.indicateRing();
2383                } 2415                }
2384            }, 2416            },
2385            dialog.verto.options.ringSleep); 2417            dialog.verto.options.ringSleep);
2386        } 2418        }
2387    }; 2419    };
2388  2420 
2389    $.verto.dialog.prototype.ring = function() { 2421    $.verto.dialog.prototype.ring = function() {
2390        var dialog = this; 2422        var dialog = this;
2391  2423 
2392        dialog.setState($.verto.enum.state.ringing); 2424        dialog.setState($.verto.enum.state.ringing);
2393        dialog.indicateRing(); 2425        dialog.indicateRing();
2394    }; 2426    };
2395  2427 
2396    $.verto.dialog.prototype.useVideo = function(on) { 2428    $.verto.dialog.prototype.useVideo = function(on) {
2397        var dialog = this; 2429        var dialog = this;
2398  2430 
2399        dialog.params.useVideo = on; 2431        dialog.params.useVideo = on;
2400  2432 
2401        if (on) { 2433        if (on) {
2402            dialog.videoStream = dialog.audioStream; 2434            dialog.videoStream = dialog.audioStream;
2403        } else { 2435        } else {
2404            dialog.videoStream = null; 2436            dialog.videoStream = null;
2405        } 2437        }
2406  2438 
2407        dialog.rtc.useVideo(dialog.videoStream, dialog.localVideo); 2439        dialog.rtc.useVideo(dialog.videoStream, dialog.localVideo);
2408  2440 
2409    }; 2441    };
2410  2442 
2411    $.verto.dialog.prototype.setMute = function(what) { 2443    $.verto.dialog.prototype.setMute = function(what) {
2412    var dialog = this; 2444    var dialog = this;
2413    return dialog.rtc.setMute(what); 2445    return dialog.rtc.setMute(what);
2414    }; 2446    };
2415  2447 
2416    $.verto.dialog.prototype.getMute = function() { 2448    $.verto.dialog.prototype.getMute = function() {
2417    var dialog = this;   2449    var dialog = this;  
2418    return dialog.rtc.getMute(); 2450    return dialog.rtc.getMute();
2419    }; 2451    };
2420  2452 
2421    $.verto.dialog.prototype.setVideoMute = function(what) { 2453    $.verto.dialog.prototype.setVideoMute = function(what) {
2422    var dialog = this; 2454    var dialog = this;
2423    return dialog.rtc.setVideoMute(what); 2455    return dialog.rtc.setVideoMute(what);
2424    }; 2456    };
2425  2457 
2426    $.verto.dialog.prototype.getVideoMute = function() { 2458    $.verto.dialog.prototype.getVideoMute = function() {
2427    var dialog = this;   2459    var dialog = this;  
2428    return dialog.rtc.getVideoMute(); 2460    return dialog.rtc.getVideoMute();
2429    }; 2461    };
2430  2462 
2431    $.verto.dialog.prototype.useStereo = function(on) { 2463    $.verto.dialog.prototype.useStereo = function(on) {
2432        var dialog = this; 2464        var dialog = this;
2433  2465 
2434        dialog.params.useStereo = on; 2466        dialog.params.useStereo = on;
2435        dialog.rtc.useStereo(on); 2467        dialog.rtc.useStereo(on);
2436    }; 2468    };
2437  2469 
2438    $.verto.dialog.prototype.dtmf = function(digits) { 2470    $.verto.dialog.prototype.dtmf = function(digits) {
2439        var dialog = this; 2471        var dialog = this;
2440        if (digits) { 2472        if (digits) {
2441            dialog.sendMethod("verto.info", { 2473            dialog.sendMethod("verto.info", {
2442                dtmf: digits 2474                dtmf: digits
2443            }); 2475            });
2444        } 2476        }
2445    }; 2477    };
2446  2478 
2447    $.verto.dialog.prototype.rtt = function(obj) { 2479    $.verto.dialog.prototype.rtt = function(obj) {
2448        var dialog = this; 2480        var dialog = this;
2449    var pobj = {}; 2481    var pobj = {};
2450  2482 
2451    if (!obj) { 2483    if (!obj) {
2452        return false; 2484        return false;
2453    } 2485    }
2454  2486 
2455    pobj.code = obj.code; 2487    pobj.code = obj.code;
2456    pobj.chars = obj.chars; 2488    pobj.chars = obj.chars;
2457  2489 
2458  2490 
2459        if (pobj.chars || pobj.code) { 2491        if (pobj.chars || pobj.code) {
2460            dialog.sendMethod("verto.info", { 2492            dialog.sendMethod("verto.info", {
2461                txt: obj, 2493                txt: obj,
2462        noDialogParams: true 2494        noDialogParams: true
2463            }); 2495            });
2464        } 2496        }
2465    }; 2497    };
2466  2498 
2467    $.verto.dialog.prototype.transfer = function(dest, params) { 2499    $.verto.dialog.prototype.transfer = function(dest, params) {
2468        var dialog = this; 2500        var dialog = this;
2469        if (dest) { 2501        if (dest) {
2470            dialog.sendMethod("verto.modify", { 2502            dialog.sendMethod("verto.modify", {
2471                action: "transfer", 2503                action: "transfer",
2472                destination: dest, 2504                destination: dest,
2473                params: params 2505                params: params
2474            }); 2506            });
2475        } 2507        }
2476    }; 2508    };
2477  2509 
2478    $.verto.dialog.prototype.replace = function(replaceCallID, params) { 2510    $.verto.dialog.prototype.replace = function(replaceCallID, params) {
2479        var dialog = this; 2511        var dialog = this;
2480        if (replaceCallID) { 2512        if (replaceCallID) {
2481            dialog.sendMethod("verto.modify", { 2513            dialog.sendMethod("verto.modify", {
2482                action: "replace", 2514                action: "replace",
2483                replaceCallID: replaceCallID, 2515                replaceCallID: replaceCallID,
2484                params: params 2516                params: params
2485            }); 2517            });
2486        } 2518        }
2487    }; 2519    };
2488  2520 
2489    $.verto.dialog.prototype.hold = function(params) { 2521    $.verto.dialog.prototype.hold = function(params) {
2490        var dialog = this; 2522        var dialog = this;
2491  2523 
2492        dialog.sendMethod("verto.modify", { 2524        dialog.sendMethod("verto.modify", {
2493            action: "hold", 2525            action: "hold",
2494            params: params 2526            params: params
2495        }); 2527        });
2496    }; 2528    };
2497  2529 
2498    $.verto.dialog.prototype.unhold = function(params) { 2530    $.verto.dialog.prototype.unhold = function(params) {
2499        var dialog = this; 2531        var dialog = this;
2500  2532 
2501        dialog.sendMethod("verto.modify", { 2533        dialog.sendMethod("verto.modify", {
2502            action: "unhold", 2534            action: "unhold",
2503            params: params 2535            params: params
2504        }); 2536        });
2505    }; 2537    };
2506  2538 
2507    $.verto.dialog.prototype.toggleHold = function(params) { 2539    $.verto.dialog.prototype.toggleHold = function(params) {
2508        var dialog = this; 2540        var dialog = this;
2509  2541 
2510        dialog.sendMethod("verto.modify", { 2542        dialog.sendMethod("verto.modify", {
2511            action: "toggleHold", 2543            action: "toggleHold",
2512            params: params 2544            params: params
2513        }); 2545        });
2514    }; 2546    };
2515  2547 
2516    $.verto.dialog.prototype.message = function(msg) { 2548    $.verto.dialog.prototype.message = function(msg) {
2517        var dialog = this; 2549        var dialog = this;
2518        var err = 0; 2550        var err = 0;
2519  2551 
2520        msg.from = dialog.params.login; 2552        msg.from = dialog.params.login;
2521  2553 
2522        if (!msg.to) { 2554        if (!msg.to) {
2523            console.error("Missing To"); 2555            console.error("Missing To");
2524            err++; 2556            err++;
2525        } 2557        }
2526  2558 
2527        if (!msg.body) { 2559        if (!msg.body) {
2528            console.error("Missing Body"); 2560            console.error("Missing Body");
2529            err++; 2561            err++;
2530        } 2562        }
2531  2563 
2532        if (err) { 2564        if (err) {
2533            return false; 2565            return false;
2534        } 2566        }
2535  2567 
2536        dialog.sendMethod("verto.info", { 2568        dialog.sendMethod("verto.info", {
2537            msg: msg 2569            msg: msg
2538        }); 2570        });
2539  2571 
2540        return true; 2572        return true;
2541    }; 2573    };
2542  2574 
2543    $.verto.dialog.prototype.answer = function(params) { 2575    $.verto.dialog.prototype.answer = function(params) {
2544        var dialog = this; 2576        var dialog = this;
2545      2577     
2546        if (!dialog.answered) { 2578        if (!dialog.answered) {
2547        if (!params) { 2579        if (!params) {
2548        params = {}; 2580        params = {};
2549        } 2581        }
2550  2582 
2551        params.sdp = dialog.params.sdp; 2583        params.sdp = dialog.params.sdp;
2552  2584 
2553            if (params) { 2585            if (params) {
2554                if (params.useVideo) { 2586                if (params.useVideo) {
2555                    dialog.useVideo(true); 2587                    dialog.useVideo(true);
2556                } 2588                }
2557        dialog.params.callee_id_name = params.callee_id_name; 2589        dialog.params.callee_id_name = params.callee_id_name;
2558        dialog.params.callee_id_number = params.callee_id_number; 2590        dialog.params.callee_id_number = params.callee_id_number;
2559  2591 
2560        if (params.useCamera) { 2592        if (params.useCamera) {
2561            dialog.useCamera = params.useCamera; 2593            dialog.useCamera = params.useCamera;
2562            dialog.useCameraLabel = params.useCameraLabel; 2594            dialog.useCameraLabel = params.useCameraLabel;
2563        } 2595        }
2564  2596 
2565        if (params.useMic) { 2597        if (params.useMic) {
2566            dialog.useMic = params.useMic; 2598            dialog.useMic = params.useMic;
2567            dialog.useMic = params.useMicLabel; 2599            dialog.useMic = params.useMicLabel;
2568        } 2600        }
2569  2601 
2570        if (params.useSpeak) { 2602        if (params.useSpeak) {
2571            dialog.useSpeak = params.useSpeak; 2603            dialog.useSpeak = params.useSpeak;
2572        } 2604        }
2573            } 2605            }
2574          2606         
2575            dialog.rtc.createAnswer(params); 2607            dialog.rtc.createAnswer(params);
2576            dialog.answered = true; 2608            dialog.answered = true;
2577        } 2609        }
2578    }; 2610    };
2579  2611 
2580    $.verto.dialog.prototype.handleAnswer = function(params) { 2612    $.verto.dialog.prototype.handleAnswer = function(params) {
2581        var dialog = this; 2613        var dialog = this;
2582  2614 
2583        dialog.gotAnswer = true; 2615        dialog.gotAnswer = true;
2584  2616 
2585        if (dialog.state.val >= $.verto.enum.state.active.val) { 2617        if (dialog.state.val >= $.verto.enum.state.active.val) {
2586            return; 2618            return;
2587        } 2619        }
2588  2620 
2589        if (dialog.state.val >= $.verto.enum.state.early.val) { 2621        if (dialog.state.val >= $.verto.enum.state.early.val) {
2590            dialog.setState($.verto.enum.state.active); 2622            dialog.setState($.verto.enum.state.active);
2591        } else { 2623        } else {
2592            if (dialog.gotEarly) { 2624            if (dialog.gotEarly) {
2593                console.log("Dialog " + dialog.callID + " Got answer while still establishing early media, delaying..."); 2625                console.log("Dialog " + dialog.callID + " Got answer while still establishing early media, delaying...");
2594            } else { 2626            } else {
2595                console.log("Dialog " + dialog.callID + " Answering Channel"); 2627                console.log("Dialog " + dialog.callID + " Answering Channel");
2596                dialog.rtc.answer(params.sdp, function() { 2628                dialog.rtc.answer(params.sdp, function() {
2597                    dialog.setState($.verto.enum.state.active); 2629                    dialog.setState($.verto.enum.state.active);
2598                }, function(e) { 2630                }, function(e) {
2599                    console.error(e); 2631                    console.error(e);
2600                    dialog.hangup(); 2632                    dialog.hangup();
2601                }); 2633                });
2602                console.log("Dialog " + dialog.callID + "ANSWER SDP", params.sdp); 2634                console.log("Dialog " + dialog.callID + "ANSWER SDP", params.sdp);
2603            } 2635            }
2604        } 2636        }
2605  2637 
2606  2638 
2607    }; 2639    };
2608  2640 
2609    $.verto.dialog.prototype.cidString = function(enc) { 2641    $.verto.dialog.prototype.cidString = function(enc) {
2610        var dialog = this; 2642        var dialog = this;
2611        var party = dialog.params.remote_caller_id_name + (enc ? " &lt;" : " <") + dialog.params.remote_caller_id_number + (enc ? "&gt;" : ">"); 2643        var party = dialog.params.remote_caller_id_name + (enc ? " &lt;" : " <") + dialog.params.remote_caller_id_number + (enc ? "&gt;" : ">");
2612        return party; 2644        return party;
2613    }; 2645    };
2614  2646 
2615    $.verto.dialog.prototype.sendMessage = function(msg, params) { 2647    $.verto.dialog.prototype.sendMessage = function(msg, params) {
2616        var dialog = this; 2648        var dialog = this;
2617  2649 
2618        if (dialog.callbacks.onMessage) { 2650        if (dialog.callbacks.onMessage) {
2619            dialog.callbacks.onMessage(dialog.verto, dialog, msg, params); 2651            dialog.callbacks.onMessage(dialog.verto, dialog, msg, params);
2620        } 2652        }
2621    }; 2653    };
2622  2654 
2623    $.verto.dialog.prototype.handleInfo = function(params) { 2655    $.verto.dialog.prototype.handleInfo = function(params) {
2624        var dialog = this; 2656        var dialog = this;
2625  2657 
2626        dialog.sendMessage($.verto.enum.message.info, params); 2658        dialog.sendMessage($.verto.enum.message.info, params);
2627  2659 
2628    }; 2660    };
2629  2661 
2630    $.verto.dialog.prototype.handleDisplay = function(params) { 2662    $.verto.dialog.prototype.handleDisplay = function(params) {
2631        var dialog = this; 2663        var dialog = this;
2632  2664 
2633        if (params.display_name) { 2665        if (params.display_name) {
2634            dialog.params.remote_caller_id_name = params.display_name; 2666            dialog.params.remote_caller_id_name = params.display_name;
2635        } 2667        }
2636        if (params.display_number) { 2668        if (params.display_number) {
2637            dialog.params.remote_caller_id_number = params.display_number; 2669            dialog.params.remote_caller_id_number = params.display_number;
2638        } 2670        }
2639  2671 
2640        dialog.sendMessage($.verto.enum.message.display, {}); 2672        dialog.sendMessage($.verto.enum.message.display, {});
2641    }; 2673    };
2642  2674 
2643    $.verto.dialog.prototype.handleMedia = function(params) { 2675    $.verto.dialog.prototype.handleMedia = function(params) {
2644        var dialog = this; 2676        var dialog = this;
2645  2677 
2646        if (dialog.state.val >= $.verto.enum.state.early.val) { 2678        if (dialog.state.val >= $.verto.enum.state.early.val) {
2647            return; 2679            return;
2648        } 2680        }
2649  2681 
2650        dialog.gotEarly = true; 2682        dialog.gotEarly = true;
2651  2683 
2652        dialog.rtc.answer(params.sdp, function() { 2684        dialog.rtc.answer(params.sdp, function() {
2653            console.log("Dialog " + dialog.callID + "Establishing early media"); 2685            console.log("Dialog " + dialog.callID + "Establishing early media");
2654            dialog.setState($.verto.enum.state.early); 2686            dialog.setState($.verto.enum.state.early);
2655  2687 
2656            if (dialog.gotAnswer) { 2688            if (dialog.gotAnswer) {
2657                console.log("Dialog " + dialog.callID + "Answering Channel"); 2689                console.log("Dialog " + dialog.callID + "Answering Channel");
2658                dialog.setState($.verto.enum.state.active); 2690                dialog.setState($.verto.enum.state.active);
2659            } 2691            }
2660        }, function(e) { 2692        }, function(e) {
2661            console.error(e); 2693            console.error(e);
2662            dialog.hangup(); 2694            dialog.hangup();
2663        }); 2695        });
2664        console.log("Dialog " + dialog.callID + "EARLY SDP", params.sdp); 2696        console.log("Dialog " + dialog.callID + "EARLY SDP", params.sdp);
2665    }; 2697    };
2666  2698 
2667    $.verto.ENUM = function(s) { 2699    $.verto.ENUM = function(s) {
2668        var i = 0, 2700        var i = 0,
2669        o = {}; 2701        o = {};
2670        s.split(" ").map(function(x) { 2702        s.split(" ").map(function(x) {
2671            o[x] = { 2703            o[x] = {
2672                name: x, 2704                name: x,
2673                val: i++ 2705                val: i++
2674            }; 2706            };
2675        }); 2707        });
2676        return Object.freeze(o); 2708        return Object.freeze(o);
2677    }; 2709    };
2678  2710 
2679    $.verto.enum = {}; 2711    $.verto.enum = {};
2680  2712 
2681    $.verto.enum.states = Object.freeze({ 2713    $.verto.enum.states = Object.freeze({
2682        new: { 2714        new: {
2683            requesting: 1, 2715            requesting: 1,
2684            recovering: 1, 2716            recovering: 1,
2685            ringing: 1, 2717            ringing: 1,
2686            destroy: 1, 2718            destroy: 1,
2687            answering: 1, 2719            answering: 1,
2688        hangup: 1 2720        hangup: 1
2689        }, 2721        },
2690        requesting: { 2722        requesting: {
2691            trying: 1, 2723            trying: 1,
2692            hangup: 1, 2724            hangup: 1,
2693        active: 1 2725        active: 1
2694        }, 2726        },
2695        recovering: { 2727        recovering: {
2696            answering: 1, 2728            answering: 1,
2697            hangup: 1 2729            hangup: 1
2698        }, 2730        },
2699        trying: { 2731        trying: {
2700            active: 1, 2732            active: 1,
2701            early: 1, 2733            early: 1,
2702            hangup: 1 2734            hangup: 1
2703        }, 2735        },
2704        ringing: { 2736        ringing: {
2705            answering: 1, 2737            answering: 1,
2706            hangup: 1 2738            hangup: 1
2707        }, 2739        },
2708        answering: { 2740        answering: {
2709            active: 1, 2741            active: 1,
2710            hangup: 1 2742            hangup: 1
2711        }, 2743        },
2712        active: { 2744        active: {
2713            answering: 1, 2745            answering: 1,
2714            requesting: 1, 2746            requesting: 1,
2715            hangup: 1, 2747            hangup: 1,
2716            held: 1 2748            held: 1
2717        }, 2749        },
2718        held: { 2750        held: {
2719            hangup: 1, 2751            hangup: 1,
2720            active: 1 2752            active: 1
2721        }, 2753        },
2722        early: { 2754        early: {
2723            hangup: 1, 2755            hangup: 1,
2724            active: 1 2756            active: 1
2725        }, 2757        },
2726        hangup: { 2758        hangup: {
2727            destroy: 1 2759            destroy: 1
2728        }, 2760        },
2729        destroy: {}, 2761        destroy: {},
2730        purge: { 2762        purge: {
2731            destroy: 1 2763            destroy: 1
2732        } 2764        }
2733    }); 2765    });
2734  2766 
2735    $.verto.enum.state = $.verto.ENUM("new requesting trying recovering ringing answering early active held hangup destroy purge"); 2767    $.verto.enum.state = $.verto.ENUM("new requesting trying recovering ringing answering early active held hangup destroy purge");
2736    $.verto.enum.direction = $.verto.ENUM("inbound outbound"); 2768    $.verto.enum.direction = $.verto.ENUM("inbound outbound");
2737    $.verto.enum.message = $.verto.ENUM("display info pvtEvent clientReady"); 2769    $.verto.enum.message = $.verto.ENUM("display info pvtEvent clientReady");
2738  2770 
2739    $.verto.enum = Object.freeze($.verto.enum); 2771    $.verto.enum = Object.freeze($.verto.enum);
2740  2772 
2741    $.verto.saved = []; 2773    $.verto.saved = [];
2742      2774     
2743    $.verto.unloadJobs = []; 2775    $.verto.unloadJobs = [];
2744  2776 
2745    var unloadEventName = 'beforeunload';  2777    // Changed beforeunload to unload for ANYAM-4035 
  2778    var unloadEventName = 'unload';
2746    // Hacks for Mobile Safari 2779    // Hacks for Mobile Safari
2747    var iOS = ['iPad', 'iPhone', 'iPod'].indexOf(navigator.platform) >= 0; 2780    var iOS = ['iPad', 'iPhone', 'iPod'].indexOf(navigator.platform) >= 0;
2748    if (iOS) { 2781    if (iOS) {
2749      unloadEventName = 'pagehide'; 2782      unloadEventName = 'pagehide';
2750    } 2783    }
2751  2784 
2752    $(window).bind(unloadEventName, function() { 2785    $(window).bind(unloadEventName, function() {
2753        for (var f in $.verto.unloadJobs) { 2786        for (var f in $.verto.unloadJobs) {
2754          $.verto.unloadJobs[f](); 2787          $.verto.unloadJobs[f]();
2755        } 2788        }
2756  2789 
2757        if ($.verto.haltClosure) 2790        if ($.verto.haltClosure)
2758          return $.verto.haltClosure(); 2791          return $.verto.haltClosure();
2759  2792 
2760        for (var i in $.verto.saved) { 2793        for (var i in $.verto.saved) {
2761            var verto = $.verto.saved[i]; 2794            var verto = $.verto.saved[i];
2762            if (verto) { 2795            if (verto) {
  2796                verto.hangup(); //ANYAM
2763                verto.purge(); 2797                verto.purge();
2764                verto.logout(); 2798                verto.logout();
2765            } 2799            }
2766        } 2800        }
2767  2801 
2768        return $.verto.warnOnUnload; 2802        return $.verto.warnOnUnload;
2769    }); 2803    });
2770  2804 
2771    $.verto.videoDevices = []; 2805    $.verto.videoDevices = [];
2772    $.verto.audioInDevices = []; 2806    $.verto.audioInDevices = [];
2773    $.verto.audioOutDevices = []; 2807    $.verto.audioOutDevices = [];
2774  2808 
2775    var checkDevices = function(runtime) { 2809    var checkDevices = function(runtime) {
2776    console.info("enumerating devices"); 2810    console.info("enumerating devices");
2777    var aud_in = [], aud_out = [], vid = [];      2811    var aud_in = [], aud_out = [], vid = [];     
2778    var has_video = 0, has_audio = 0; 2812    var has_video = 0, has_audio = 0;
2779    var Xstream; 2813    var Xstream;
2780  2814 
2781    function gotDevices(deviceInfos) { 2815    function gotDevices(deviceInfos) {
2782          // Handles being called several times to update labels. Preserve values. 2816          // Handles being called several times to update labels. Preserve values.
2783        for (var i = 0; i !== deviceInfos.length; ++i) { 2817        for (var i = 0; i !== deviceInfos.length; ++i) {
2784        var deviceInfo = deviceInfos[i]; 2818        var deviceInfo = deviceInfos[i];
2785        var text = ""; 2819        var text = "";
2786  2820 
2787        console.log(deviceInfo); 2821        console.log(deviceInfo);
2788        console.log(deviceInfo.kind + ": " + deviceInfo.label + " id = " + deviceInfo.deviceId); 2822        console.log(deviceInfo.kind + ": " + deviceInfo.label + " id = " + deviceInfo.deviceId);
2789  2823 
2790        if (deviceInfo.kind === 'audioinput') { 2824        if (deviceInfo.kind === 'audioinput') {
2791            text = deviceInfo.label || 'microphone ' + (aud_in.length + 1); 2825            text = deviceInfo.label || 'microphone ' + (aud_in.length + 1);
2792            aud_in.push({id: deviceInfo.deviceId, kind: "audio_in", label: text}); 2826            aud_in.push({id: deviceInfo.deviceId, kind: "audio_in", label: text});
2793        } else if (deviceInfo.kind === 'audiooutput') { 2827        } else if (deviceInfo.kind === 'audiooutput') {
2794            text = deviceInfo.label || 'speaker ' + (aud_out.length + 1); 2828            text = deviceInfo.label || 'speaker ' + (aud_out.length + 1);
2795            aud_out.push({id: deviceInfo.deviceId, kind: "audio_out", label: text}); 2829            aud_out.push({id: deviceInfo.deviceId, kind: "audio_out", label: text});
2796        } else if (deviceInfo.kind === 'videoinput') { 2830        } else if (deviceInfo.kind === 'videoinput') {
2797            text = deviceInfo.label || 'camera ' + (vid.length + 1); 2831            text = deviceInfo.label || 'camera ' + (vid.length + 1);
2798            vid.push({id: deviceInfo.deviceId, kind: "video", label: text}); 2832            vid.push({id: deviceInfo.deviceId, kind: "video", label: text});
2799        } else { 2833        } else {
2800            console.log('Some other kind of source/device: ', deviceInfo); 2834            console.log('Some other kind of source/device: ', deviceInfo);
2801        } 2835        }
2802        } 2836        }
2803  2837 
2804  2838 
2805        $.verto.videoDevices = vid; 2839        $.verto.videoDevices = vid;
2806        $.verto.audioInDevices = aud_in; 2840        $.verto.audioInDevices = aud_in;
2807        $.verto.audioOutDevices = aud_out; 2841        $.verto.audioOutDevices = aud_out;
2808          2842         
2809        console.info("Audio IN Devices", $.verto.audioInDevices); 2843        console.info("Audio IN Devices", $.verto.audioInDevices);
2810        console.info("Audio Out Devices", $.verto.audioOutDevices); 2844        console.info("Audio Out Devices", $.verto.audioOutDevices);
2811        console.info("Video Devices", $.verto.videoDevices); 2845        console.info("Video Devices", $.verto.videoDevices);
2812  2846 
2813        if (Xstream) { 2847        if (Xstream) {
2814        Xstream.getTracks().forEach(function(track) {track.stop();}); 2848        Xstream.getTracks().forEach(function(track) {track.stop();});
2815        } 2849        }
2816  2850 
2817        if (runtime) { 2851        if (runtime) {
2818        runtime(true); 2852        runtime(true);
2819        } 2853        }
2820    } 2854    }
2821  2855 
2822  2856 
2823      2857     
2824  2858 
2825    function handleError(error) { 2859    function handleError(error) {
2826        console.log('device enumeration error: ', error); 2860        console.log('device enumeration error: ', error);
2827        if (runtime) runtime(false); 2861        if (runtime) runtime(false);
2828    } 2862    }
2829  2863 
2830  2864 
2831    function checkTypes(devs) { 2865    function checkTypes(devs) {
2832        for (var i = 0; i !== devs.length; ++i) { 2866        for (var i = 0; i !== devs.length; ++i) {
2833  2867 
2834        if (devs[i].kind === 'audioinput') { 2868        if (devs[i].kind === 'audioinput') {
2835            has_audio++; 2869            has_audio++;
2836        } else if (devs[i].kind === 'videoinput') { 2870        } else if (devs[i].kind === 'videoinput') {
2837            has_video++; 2871            has_video++;
2838        } 2872        }
2839        } 2873        }
2840        navigator.mediaDevices.getUserMedia({ audio: (has_audio > 0 ? true : false), video: (has_video > 0 ? true : false)}) 2874        navigator.mediaDevices.getUserMedia({ audio: (has_audio > 0 ? true : false), video: (has_video > 0 ? true : false)})
2841                .then(function(stream) { 2875                .then(function(stream) {
2842                        Xstream = stream; 2876                        Xstream = stream;
2843                        navigator.mediaDevices.enumerateDevices().then(gotDevices).catch(handleError); 2877                        navigator.mediaDevices.enumerateDevices().then(gotDevices).catch(handleError);
2844           }) 2878           })
2845           .catch(function(err) { 2879           .catch(function(err) {
2846                console.log("The following error occurred: " + err.name); 2880                console.log("The following error occurred: " + err.name);
2847          }); 2881          });
2848  2882 
2849    } 2883    }
2850  2884 
2851    navigator.mediaDevices.enumerateDevices().then(checkTypes).catch(handleError); 2885    navigator.mediaDevices.enumerateDevices().then(checkTypes).catch(handleError);
2852  2886 
2853  }; 2887  };
2854  2888 
2855    $.verto.refreshDevices = function(runtime) { 2889    $.verto.refreshDevices = function(runtime) {
2856    checkDevices(runtime); 2890    checkDevices(runtime);
2857    } 2891    }
2858  2892 
2859    $.verto.init = function(obj, runtime) { 2893    $.verto.init = function(obj, runtime) {
2860    if (!obj) { 2894    if (!obj) {
2861        obj = {}; 2895        obj = {};
2862    } 2896    }
2863  2897 
2864    if (!obj.skipPermCheck && !obj.skipDeviceCheck) { 2898    if (!obj.skipPermCheck && !obj.skipDeviceCheck) {
2865        $.FSRTC.checkPerms(function(status) { 2899        $.FSRTC.checkPerms(function(status) {
2866        checkDevices(runtime); 2900        checkDevices(runtime);
2867        }, true, true); 2901        }, true, true);
2868    } else if (obj.skipPermCheck && !obj.skipDeviceCheck) { 2902    } else if (obj.skipPermCheck && !obj.skipDeviceCheck) {
2869        checkDevices(runtime); 2903        checkDevices(runtime);
2870    } else if (!obj.skipPermCheck && obj.skipDeviceCheck) { 2904    } else if (!obj.skipPermCheck && obj.skipDeviceCheck) {
2871        $.FSRTC.checkPerms(function(status) { 2905        $.FSRTC.checkPerms(function(status) {
2872        runtime(status); 2906        runtime(status);
2873        }, true, true); 2907        }, true, true);
2874    } else { 2908    } else {
2875        runtime(null); 2909        runtime(null);
2876    } 2910    }
2877  2911 
2878    } 2912    }
2879  2913 
2880    $.verto.genUUID = function () { 2914    $.verto.genUUID = function () {
2881    return generateGUID(); 2915    return generateGUID();
2882    } 2916    }
2883  2917 
2884  2918 
2885})(jQuery); 2919})(jQuery);
2886  2920