* The returned instance must have readyState <= 1, and if less than 1,
* react to onopen binding.
*/
- $.JsonRpcClient = function(options) {
- var self = this;
- this.options = $.extend({
- ajaxUrl : null,
- socketUrl : null, ///< The ws-url for default getSocket.
- onmessage : null, ///< Other onmessage-handler.
- login : null, /// auth login
- passwd : null, /// auth passwd
- sessid : null,
- getSocket : function(onmessage_cb) { return self._getSocket(onmessage_cb); }
- }, options);
-
- self.ws_cnt = 0;
-
- // Declare an instance version of the onmessage callback to wrap 'this'.
- this.wsOnMessage = function(event) { self._wsOnMessage(event); };
- };
-
- /// Holding the WebSocket on default getsocket.
- $.JsonRpcClient.prototype._ws_socket = null;
-
- /// Object <id>: { success_cb: cb, error_cb: cb }
- $.JsonRpcClient.prototype._ws_callbacks = {};
-
- /// The next JSON-RPC request id.
- $.JsonRpcClient.prototype._current_id = 1;
+ $.JsonRpcClient = function(options) {
+ var self = this;
+ this.options = $.extend({
+ ajaxUrl : null,
+ socketUrl : null, ///< The ws-url for default getSocket.
+ onmessage : null, ///< Other onmessage-handler.
+ login : null, /// auth login
+ passwd : null, /// auth passwd
+ sessid : null,
+ getSocket : function(onmessage_cb) { return self._getSocket(onmessage_cb); }
+ }, options);
+
+ self.ws_cnt = 0;
+
+ // Declare an instance version of the onmessage callback to wrap 'this'.
+ this.wsOnMessage = function(event) { self._wsOnMessage(event); };
+ };
- /**
- * @fn call
- * @memberof $.JsonRpcClient
- *
- * @param method The method to run on JSON-RPC server.
- * @param params The params; an array or object.
- * @param success_cb A callback for successful request.
- * @param error_cb A callback for error.
- */
- $.JsonRpcClient.prototype.call = function(method, params, success_cb, error_cb) {
+ /// Holding the WebSocket on default getsocket.
+ $.JsonRpcClient.prototype._ws_socket = null;
+
+ /// Object <id>: { success_cb: cb, error_cb: cb }
+ $.JsonRpcClient.prototype._ws_callbacks = {};
+
+ /// The next JSON-RPC request id.
+ $.JsonRpcClient.prototype._current_id = 1;
+
+ /**
+ * @fn call
+ * @memberof $.JsonRpcClient
+ *
+ * @param method The method to run on JSON-RPC server.
+ * @param params The params; an array or object.
+ * @param success_cb A callback for successful request.
+ * @param error_cb A callback for error.
+ */
+ $.JsonRpcClient.prototype.call = function(method, params, success_cb, error_cb) {
// Construct the JSON-RPC 2.0 request.
- if (!params) {
- params = {};
- }
-
- if (this.options.sessid) {
- params.sessid = this.options.sessid;
- }
+ if (!params) {
+ params = {};
+ }
- var request = {
- jsonrpc : '2.0',
- method : method,
- params : params,
- id : this._current_id++ // Increase the id counter to match request/response
- };
+ if (this.options.sessid) {
+ params.sessid = this.options.sessid;
+ }
- if (!success_cb) {
- success_cb = function(e){console.log("Success: ", e);};
- }
+ var request = {
+ jsonrpc : '2.0',
+ method : method,
+ params : params,
+ id : this._current_id++ // Increase the id counter to match request/response
+ };
- if (!error_cb) {
- error_cb = function(e){console.log("Error: ", e);};
- }
+ if (!success_cb) {
+ success_cb = function(e){console.log("Success: ", e);};
+ }
- // Try making a WebSocket call.
- var socket = this.options.getSocket(this.wsOnMessage);
- if (socket !== null) {
- this._wsCall(socket, request, success_cb, error_cb);
- return;
- }
+ if (!error_cb) {
+ error_cb = function(e){console.log("Error: ", e);};
+ }
- // No WebSocket, and no HTTP backend? This won't work.
- if (this.options.ajaxUrl === null) {
- throw "$.JsonRpcClient.call used with no websocket and no http endpoint.";
- }
+ // Try making a WebSocket call.
+ var socket = this.options.getSocket(this.wsOnMessage);
+ if (socket !== null) {
+ this._wsCall(socket, request, success_cb, error_cb);
+ return;
+ }
- $.ajax({
- type : 'POST',
- url : this.options.ajaxUrl,
- data : $.toJSON(request),
- dataType : 'json',
- cache : false,
+ // No WebSocket, and no HTTP backend? This won't work.
+ if (this.options.ajaxUrl === null) {
+ throw "$.JsonRpcClient.call used with no websocket and no http endpoint.";
+ }
- success : function(data) {
- if ('error' in data) error_cb(data.error, this);
- success_cb(data.result, this);
- },
+ $.ajax({
+ type : 'POST',
+ url : this.options.ajaxUrl,
+ data : $.toJSON(request),
+ dataType : 'json',
+ cache : false,
+
+ success : function(data) {
+ if ('error' in data) error_cb(data.error, this);
+ success_cb(data.result, this);
+ },
+
+ // JSON-RPC Server could return non-200 on error
+ error : function(jqXHR, textStatus, errorThrown) {
+ try {
+ var response = $.parseJSON(jqXHR.responseText);
+
+ if ('console' in window) console.log(response);
+
+ error_cb(response.error, this);
+ } catch (err) {
+ // Perhaps the responseText wasn't really a jsonrpc-error.
+ error_cb({ error: jqXHR.responseText }, this);
+ }
+ }
+ });
+ };
- // JSON-RPC Server could return non-200 on error
- error : function(jqXHR, textStatus, errorThrown) {
- try {
- var response = $.parseJSON(jqXHR.responseText);
- if ('console' in window) console.log(response);
- error_cb(response.error, this);
+ /**
+ * Notify sends a command to the server that won't need a response. In http, there is probably
+ * an empty response - that will be dropped, but in ws there should be no response at all.
+ *
+ * This is very similar to call, but has no id and no handling of callbacks.
+ *
+ * @fn notify
+ * @memberof $.JsonRpcClient
+ *
+ * @param method The method to run on JSON-RPC server.
+ * @param params The params; an array or object.
+ */
+ $.JsonRpcClient.prototype.notify = function(method, params) {
+ // Construct the JSON-RPC 2.0 request.
+
+ if (this.options.sessid) {
+ params.sessid = this.options.sessid;
}
- catch (err) {
- // Perhaps the responseText wasn't really a jsonrpc-error.
- error_cb({ error: jqXHR.responseText }, this);
+
+ var request = {
+ jsonrpc: '2.0',
+ method: method,
+ params: params
+ };
+
+ // Try making a WebSocket call.
+ var socket = this.options.getSocket(this.wsOnMessage);
+ if (socket !== null) {
+ this._wsCall(socket, request);
+ return;
}
- }
- });
- };
- /**
- * Notify sends a command to the server that won't need a response. In http, there is probably
- * an empty response - that will be dropped, but in ws there should be no response at all.
- *
- * This is very similar to call, but has no id and no handling of callbacks.
- *
- * @fn notify
- * @memberof $.JsonRpcClient
- *
- * @param method The method to run on JSON-RPC server.
- * @param params The params; an array or object.
- */
- $.JsonRpcClient.prototype.notify = function(method, params) {
- // Construct the JSON-RPC 2.0 request.
+ // No WebSocket, and no HTTP backend? This won't work.
+ if (this.options.ajaxUrl === null) {
+ throw "$.JsonRpcClient.notify used with no websocket and no http endpoint.";
+ }
- if (this.options.sessid) {
- params.sessid = this.options.sessid;
- }
+ $.ajax({
+ type : 'POST',
+ url : this.options.ajaxUrl,
+ data : $.toJSON(request),
+ dataType : 'json',
+ cache : false
+ });
+ };
- var request = {
- jsonrpc: '2.0',
- method: method,
- params: params
+ /**
+ * Make a batch-call by using a callback.
+ *
+ * The callback will get an object "batch" as only argument. On batch, you can call the methods
+ * "call" and "notify" just as if it was a normal $.JsonRpcClient object, and all calls will be
+ * sent as a batch call then the callback is done.
+ *
+ * @fn batch
+ * @memberof $.JsonRpcClient
+ *
+ * @param callback The main function which will get a batch handler to run call and notify on.
+ * @param all_done_cb A callback function to call after all results have been handled.
+ * @param error_cb A callback function to call if there is an error from the server.
+ * Note, that batch calls should always get an overall success, and the
+ * only error
+ */
+ $.JsonRpcClient.prototype.batch = function(callback, all_done_cb, error_cb) {
+ var batch = new $.JsonRpcClient._batchObject(this, all_done_cb, error_cb);
+ callback(batch);
+ batch._execute();
};
- // Try making a WebSocket call.
- var socket = this.options.getSocket(this.wsOnMessage);
- if (socket !== null) {
- this._wsCall(socket, request);
- return;
- }
+ /**
+ * The default getSocket handler.
+ *
+ * @param onmessage_cb The callback to be bound to onmessage events on the socket.
+ *
+ * @fn _getSocket
+ * @memberof $.JsonRpcClient
+ */
+
+ $.JsonRpcClient.prototype.socketReady = function() {
+ if (this._ws_socket === null || this._ws_socket.readyState > 1) {
+ return false;
+ }
- // No WebSocket, and no HTTP backend? This won't work.
- if (this.options.ajaxUrl === null) {
- throw "$.JsonRpcClient.notify used with no websocket and no http endpoint.";
+ return true;
}
- $.ajax({
- type : 'POST',
- url : this.options.ajaxUrl,
- data : $.toJSON(request),
- dataType : 'json',
- cache : false
- });
- };
-
- /**
- * Make a batch-call by using a callback.
- *
- * The callback will get an object "batch" as only argument. On batch, you can call the methods
- * "call" and "notify" just as if it was a normal $.JsonRpcClient object, and all calls will be
- * sent as a batch call then the callback is done.
- *
- * @fn batch
- * @memberof $.JsonRpcClient
- *
- * @param callback The main function which will get a batch handler to run call and notify on.
- * @param all_done_cb A callback function to call after all results have been handled.
- * @param error_cb A callback function to call if there is an error from the server.
- * Note, that batch calls should always get an overall success, and the
- * only error
- */
- $.JsonRpcClient.prototype.batch = function(callback, all_done_cb, error_cb) {
- var batch = new $.JsonRpcClient._batchObject(this, all_done_cb, error_cb);
- callback(batch);
- batch._execute();
- };
-
- /**
- * The default getSocket handler.
- *
- * @param onmessage_cb The callback to be bound to onmessage events on the socket.
- *
- * @fn _getSocket
- * @memberof $.JsonRpcClient
- */
-
- $.JsonRpcClient.prototype.socketReady = function() {
- if (this._ws_socket === null || this._ws_socket.readyState > 1) {
- return false;
- }
-
- return true;
- }
-
- $.JsonRpcClient.prototype.closeSocket = function() {
- if (self.socketReady()) {
- this._ws_socket.onclose = function (w) {console.log("Closing Socket")}
- this._ws_socket.close();
- }
- }
-
- $.JsonRpcClient.prototype.loginData = function(params) {
- self.options.login = params.login;
- self.options.passwd = params.passwd;
- }
-
- $.JsonRpcClient.prototype.connectSocket = function(onmessage_cb) {
- var self = this;
-
- if (self.to) {
- clearTimeout(self.to);
- }
-
- if (!self.socketReady()) {
- self.authing = false;
-
- if (self._ws_socket) {
- delete self._ws_socket;
- }
-
- // No socket, or dying socket, let's get a new one.
- self._ws_socket = new WebSocket(self.options.socketUrl);
-
- if (self._ws_socket) {
- // Set up onmessage handler.
- self._ws_socket.onmessage = onmessage_cb;
- self._ws_socket.onclose = function (w) {
- if (!self.ws_sleep) {
- self.ws_sleep = 1000;
- }
-
- if (self.options.onWSClose) {
- self.options.onWSClose(self);
- }
-
- console.error("Websocket Lost " + self.ws_cnt + " sleep: " + self.ws_sleep + "msec");
-
- self.to = setTimeout(function() {
- console.log("Attempting Reconnection....");
- self.connectSocket(onmessage_cb);
- }, self.ws_sleep);
-
- self.ws_cnt++;
-
- if (self.ws_sleep < 3000 && (self.ws_cnt % 10) == 0) {
- self.ws_sleep += 1000;
- }
- }
-
- // Set up sending of message for when the socket is open.
- self._ws_socket.onopen = function() {
- if (self.to) {
- clearTimeout(self.to);
- }
- self.ws_sleep = 1000;
- self.ws_cnt = 0;
- if (self.options.onWSConnect) {
- self.options.onWSConnect(self);
- }
-
- var req;
- // Send the requests.
- while (req = $.JsonRpcClient.q.pop()) {
- self._ws_socket.send(req);
- }
- }
- }
- }
-
- return self._ws_socket ? true : false;
- }
-
- $.JsonRpcClient.prototype._getSocket = function(onmessage_cb) {
- // If there is no ws url set, we don't have a socket.
- // Likewise, if there is no window.WebSocket.
- if (this.options.socketUrl === null || !("WebSocket" in window)) return null;
-
- this.connectSocket(onmessage_cb);
-
- return this._ws_socket;
- };
-
- /**
- * Queue to save messages delivered when websocket is not ready
- */
- $.JsonRpcClient.q = [];
-
- /**
- * Internal handler to dispatch a JRON-RPC request through a websocket.
- *
- * @fn _wsCall
- * @memberof $.JsonRpcClient
- */
- $.JsonRpcClient.prototype._wsCall = function(socket, request, success_cb, error_cb) {
- var request_json = $.toJSON(request);
+ $.JsonRpcClient.prototype.closeSocket = function() {
+ if (self.socketReady()) {
+ this._ws_socket.onclose = function (w) {console.log("Closing Socket")}
+ this._ws_socket.close();
+ }
+ }
- if (socket.readyState < 1) {
- // The websocket is not open yet; we have to set sending of the message in onopen.
- self = this; // In closure below, this is set to the WebSocket. Use self instead.
+ $.JsonRpcClient.prototype.loginData = function(params) {
+ self.options.login = params.login;
+ self.options.passwd = params.passwd;
+ }
- $.JsonRpcClient.q.push(request_json);
+ $.JsonRpcClient.prototype.connectSocket = function(onmessage_cb) {
+ var self = this;
+ if (self.to) {
+ clearTimeout(self.to);
+ }
- }
- else {
- // We have a socket and it should be ready to send on.
- socket.send(request_json);
- }
+ if (!self.socketReady()) {
+ self.authing = false;
+
+ if (self._ws_socket) {
+ delete self._ws_socket;
+ }
+
+ // No socket, or dying socket, let's get a new one.
+ self._ws_socket = new WebSocket(self.options.socketUrl);
+
+ if (self._ws_socket) {
+ // Set up onmessage handler.
+ self._ws_socket.onmessage = onmessage_cb;
+ self._ws_socket.onclose = function (w) {
+ if (!self.ws_sleep) {
+ self.ws_sleep = 1000;
+ }
+
+ if (self.options.onWSClose) {
+ self.options.onWSClose(self);
+ }
+
+ console.error("Websocket Lost " + self.ws_cnt + " sleep: " + self.ws_sleep + "msec");
+
+ self.to = setTimeout(function() {
+ console.log("Attempting Reconnection....");
+ self.connectSocket(onmessage_cb);
+ }, self.ws_sleep);
+
+ self.ws_cnt++;
+
+ if (self.ws_sleep < 3000 && (self.ws_cnt % 10) == 0) {
+ self.ws_sleep += 1000;
+ }
+ }
+
+ // Set up sending of message for when the socket is open.
+ self._ws_socket.onopen = function() {
+ if (self.to) {
+ clearTimeout(self.to);
+ }
+ self.ws_sleep = 1000;
+ self.ws_cnt = 0;
+ if (self.options.onWSConnect) {
+ self.options.onWSConnect(self);
+ }
+
+ var req;
+ // Send the requests.
+ while (req = $.JsonRpcClient.q.pop()) {
+ self._ws_socket.send(req);
+ }
+ }
+ }
+ }
- // Setup callbacks. If there is an id, this is a call and not a notify.
- if ('id' in request && typeof success_cb !== 'undefined') {
- this._ws_callbacks[request.id] = { request: request_json, request_obj: request, success_cb: success_cb, error_cb: error_cb };
+ return self._ws_socket ? true : false;
}
- };
- /**
- * Internal handler for the websocket messages. It determines if the message is a JSON-RPC
- * response, and if so, tries to couple it with a given callback. Otherwise, it falls back to
- * given external onmessage-handler, if any.
- *
- * @param event The websocket onmessage-event.
- */
- $.JsonRpcClient.prototype._wsOnMessage = function(event) {
- // Check if this could be a JSON RPC message.
- var response;
- try {
- response = $.parseJSON(event.data);
-
- /// @todo Make using the jsonrcp 2.0 check optional, to use this on JSON-RPC 1 backends.
-
- if (typeof response === 'object'
- && 'jsonrpc' in response
- && response.jsonrpc === '2.0') {
+ $.JsonRpcClient.prototype._getSocket = function(onmessage_cb) {
+ // If there is no ws url set, we don't have a socket.
+ // Likewise, if there is no window.WebSocket.
+ if (this.options.socketUrl === null || !("WebSocket" in window)) return null;
- /// @todo Handle bad response (without id).
+ this.connectSocket(onmessage_cb);
- // If this is an object with result, it is a response.
- if ('result' in response && this._ws_callbacks[response.id]) {
- // Get the success callback.
- var success_cb = this._ws_callbacks[response.id].success_cb;
+ return this._ws_socket;
+ };
-/*
- // set the sessid if present
- if ('sessid' in response.result && !this.options.sessid || (this.options.sessid != response.result.sessid)) {
- this.options.sessid = response.result.sessid;
- if (this.options.sessid) {
- console.log("setting session UUID to: " + this.options.sessid);
- }
- }
-*/
- // Delete the callback from the storage.
- delete this._ws_callbacks[response.id];
-
- // Run callback with result as parameter.
- success_cb(response.result, this);
- return;
+ /**
+ * Queue to save messages delivered when websocket is not ready
+ */
+ $.JsonRpcClient.q = [];
+
+ /**
+ * Internal handler to dispatch a JRON-RPC request through a websocket.
+ *
+ * @fn _wsCall
+ * @memberof $.JsonRpcClient
+ */
+ $.JsonRpcClient.prototype._wsCall = function(socket, request, success_cb, error_cb) {
+ var request_json = $.toJSON(request);
+
+ if (socket.readyState < 1) {
+ // The websocket is not open yet; we have to set sending of the message in onopen.
+ self = this; // In closure below, this is set to the WebSocket. Use self instead.
+ $.JsonRpcClient.q.push(request_json);
+ } else {
+ // We have a socket and it should be ready to send on.
+ socket.send(request_json);
}
- // If this is an object with error, it is an error response.
- else if ('error' in response && this._ws_callbacks[response.id]) {
-
- // Get the error callback.
- var error_cb = this._ws_callbacks[response.id].error_cb;
- var orig_req = this._ws_callbacks[response.id].request;
-
- // if this is an auth request, send the credentials and resend the failed request
- if (!self.authing && response.error.code == -32000 && self.options.login && self.options.passwd) {
- self.authing = true;
-
- this.call("login", { login: self.options.login, passwd: self.options.passwd},
- this._ws_callbacks[response.id].request_obj.method == "login"
- ?
- function(e) {
- self.authing = false;
- console.log("logged in");
- delete self._ws_callbacks[response.id];
-
- if (self.options.onWSLogin) {
- self.options.onWSLogin(true, self);
- }
- }
-
- :
-
- function(e) {
- self.authing = false;
- console.log("logged in, resending request id: " + response.id);
- var socket = self.options.getSocket(self.wsOnMessage);
- if (socket !== null) {
- socket.send(orig_req);
- }
- if (self.options.onWSLogin) {
- self.options.onWSLogin(true, self);
- }
- },
-
- function(e) {
- console.log("error logging in, request id:", response.id);
- delete self._ws_callbacks[response.id];
- error_cb(response.error, this);
- if (self.options.onWSLogin) {
- self.options.onWSLogin(false, self);
- }
- }
-
- );
- return;
- }
-
- // Delete the callback from the storage.
- delete this._ws_callbacks[response.id];
-
- // Run callback with the error object as parameter.
- error_cb(response.error, this);
-
- return;
+ // Setup callbacks. If there is an id, this is a call and not a notify.
+ if ('id' in request && typeof success_cb !== 'undefined') {
+ this._ws_callbacks[request.id] = { request: request_json, request_obj: request, success_cb: success_cb, error_cb: error_cb };
}
- }
- }
- catch (err) {
- // Probably an error while parsing a non json-string as json. All real JSON-RPC cases are
- // handled above, and the fallback method is called below.
- console.log("ERROR: "+ err);
- return;
- }
-
- // This is not a JSON-RPC response. Call the fallback message handler, if given.
- if (typeof this.options.onmessage === 'function') {
- event.eventData = response;
- if (!event.eventData) {
- event.eventData = {};
- }
-
- var reply = this.options.onmessage(event);
-
- if (reply && typeof reply === "object" && event.eventData.id) {
- var msg = {
- jsonrpc: "2.0",
- id: event.eventData.id,
- result: reply
- };
-
- var socket = self.options.getSocket(self.wsOnMessage);
- if (socket !== null) {
- socket.send($.toJSON(msg));
- }
- }
+ };
- }
- };
+ /**
+ * Internal handler for the websocket messages. It determines if the message is a JSON-RPC
+ * response, and if so, tries to couple it with a given callback. Otherwise, it falls back to
+ * given external onmessage-handler, if any.
+ *
+ * @param event The websocket onmessage-event.
+ */
+ $.JsonRpcClient.prototype._wsOnMessage = function(event) {
+ // Check if this could be a JSON RPC message.
+ var response;
+ try {
+ response = $.parseJSON(event.data);
+
+ /// @todo Make using the jsonrcp 2.0 check optional, to use this on JSON-RPC 1 backends.
+
+ if (typeof response === 'object'
+ && 'jsonrpc' in response
+ && response.jsonrpc === '2.0') {
+
+ /// @todo Handle bad response (without id).
+
+ // If this is an object with result, it is a response.
+ if ('result' in response && this._ws_callbacks[response.id]) {
+ // Get the success callback.
+ var success_cb = this._ws_callbacks[response.id].success_cb;
+
+ /*
+ // set the sessid if present
+ if ('sessid' in response.result && !this.options.sessid || (this.options.sessid != response.result.sessid)) {
+ this.options.sessid = response.result.sessid;
+ if (this.options.sessid) {
+ console.log("setting session UUID to: " + this.options.sessid);
+ }
+ }
+ */
+ // Delete the callback from the storage.
+ delete this._ws_callbacks[response.id];
+
+ // Run callback with result as parameter.
+ success_cb(response.result, this);
+ return;
+ } else if ('error' in response && this._ws_callbacks[response.id]) {
+ // If this is an object with error, it is an error response.
+
+ // Get the error callback.
+ var error_cb = this._ws_callbacks[response.id].error_cb;
+ var orig_req = this._ws_callbacks[response.id].request;
+
+ // if this is an auth request, send the credentials and resend the failed request
+ if (!self.authing && response.error.code == -32000 && self.options.login && self.options.passwd) {
+ self.authing = true;
+
+ this.call("login", { login: self.options.login, passwd: self.options.passwd},
+ this._ws_callbacks[response.id].request_obj.method == "login"
+ ?
+ function(e) {
+ self.authing = false;
+ console.log("logged in");
+ delete self._ws_callbacks[response.id];
+
+ if (self.options.onWSLogin) {
+ self.options.onWSLogin(true, self);
+ }
+ }
+
+ :
+
+ function(e) {
+ self.authing = false;
+ console.log("logged in, resending request id: " + response.id);
+ var socket = self.options.getSocket(self.wsOnMessage);
+ if (socket !== null) {
+ socket.send(orig_req);
+ }
+ if (self.options.onWSLogin) {
+ self.options.onWSLogin(true, self);
+ }
+ },
+
+ function(e) {
+ console.log("error logging in, request id:", response.id);
+ delete self._ws_callbacks[response.id];
+ error_cb(response.error, this);
+ if (self.options.onWSLogin) {
+ self.options.onWSLogin(false, self);
+ }
+ });
+ return;
+ }
+
+ // Delete the callback from the storage.
+ delete this._ws_callbacks[response.id];
+
+ // Run callback with the error object as parameter.
+ error_cb(response.error, this);
+ return;
+ }
+ }
+ } catch (err) {
+ // Probably an error while parsing a non json-string as json. All real JSON-RPC cases are
+ // handled above, and the fallback method is called below.
+ console.log("ERROR: "+ err);
+ return;
+ }
+ // This is not a JSON-RPC response. Call the fallback message handler, if given.
+ if (typeof this.options.onmessage === 'function') {
+ event.eventData = response;
+ if (!event.eventData) {
+ event.eventData = {};
+ }
+
+ var reply = this.options.onmessage(event);
+
+ if (reply && typeof reply === "object" && event.eventData.id) {
+ var msg = {
+ jsonrpc: "2.0",
+ id: event.eventData.id,
+ result: reply
+ };
+
+ var socket = self.options.getSocket(self.wsOnMessage);
+ if (socket !== null) {
+ socket.send($.toJSON(msg));
+ }
+ }
+ }
+ };
- /************************************************************************************************
- * Batch object with methods
- ************************************************************************************************/
- /**
- * Handling object for batch calls.
- */
- $.JsonRpcClient._batchObject = function(jsonrpcclient, all_done_cb, error_cb) {
- // Array of objects to hold the call and notify requests. Each objects will have the request
- // object, and unless it is a notify, success_cb and error_cb.
- this._requests = [];
+ /************************************************************************************************
+ * Batch object with methods
+ ************************************************************************************************/
- this.jsonrpcclient = jsonrpcclient;
- this.all_done_cb = all_done_cb;
- this.error_cb = typeof error_cb === 'function' ? error_cb : function() {};
+ /**
+ * Handling object for batch calls.
+ */
+ $.JsonRpcClient._batchObject = function(jsonrpcclient, all_done_cb, error_cb) {
+ // Array of objects to hold the call and notify requests. Each objects will have the request
+ // object, and unless it is a notify, success_cb and error_cb.
+ this._requests = [];
- };
+ this.jsonrpcclient = jsonrpcclient;
+ this.all_done_cb = all_done_cb;
+ this.error_cb = typeof error_cb === 'function' ? error_cb : function() {};
- /**
- * @sa $.JsonRpcClient.prototype.call
- */
- $.JsonRpcClient._batchObject.prototype.call = function(method, params, success_cb, error_cb) {
+ };
- if (!params) {
- params = {};
- }
+ /**
+ * @sa $.JsonRpcClient.prototype.call
+ */
+ $.JsonRpcClient._batchObject.prototype.call = function(method, params, success_cb, error_cb) {
- if (this.options.sessid) {
- params.sessid = this.options.sessid;
- }
+ if (!params) {
+ params = {};
+ }
- if (!success_cb) {
- success_cb = function(e){console.log("Success: ", e);};
- }
+ if (this.options.sessid) {
+ params.sessid = this.options.sessid;
+ }
- if (!error_cb) {
- error_cb = function(e){console.log("Error: ", e);};
- }
+ if (!success_cb) {
+ success_cb = function(e){console.log("Success: ", e);};
+ }
- this._requests.push({
- request : {
- jsonrpc : '2.0',
- method : method,
- params : params,
- id : this.jsonrpcclient._current_id++ // Use the client's id series.
- },
- success_cb : success_cb,
- error_cb : error_cb
- });
- };
+ if (!error_cb) {
+ error_cb = function(e){console.log("Error: ", e);};
+ }
- /**
- * @sa $.JsonRpcClient.prototype.notify
- */
- $.JsonRpcClient._batchObject.prototype.notify = function(method, params) {
- if (this.options.sessid) {
- params.sessid = this.options.sessid;
- }
+ this._requests.push({
+ request : {
+ jsonrpc : '2.0',
+ method : method,
+ params : params,
+ id : this.jsonrpcclient._current_id++ // Use the client's id series.
+ },
+ success_cb : success_cb,
+ error_cb : error_cb
+ });
+ };
- this._requests.push({
- request : {
- jsonrpc : '2.0',
- method : method,
- params : params
- }
- });
- };
+ /**
+ * @sa $.JsonRpcClient.prototype.notify
+ */
+ $.JsonRpcClient._batchObject.prototype.notify = function(method, params) {
+ if (this.options.sessid) {
+ params.sessid = this.options.sessid;
+ }
- /**
- * Executes the batched up calls.
- */
- $.JsonRpcClient._batchObject.prototype._execute = function() {
- var self = this;
-
- if (this._requests.length === 0) return; // All done :P
-
- // Collect all request data and sort handlers by request id.
- var batch_request = [];
- var handlers = {};
-
- // If we have a WebSocket, just send the requests individually like normal calls.
- var socket = self.jsonrpcclient.options.getSocket(self.jsonrpcclient.wsOnMessage);
- if (socket !== null) {
- for (var i = 0; i < this._requests.length; i++) {
- var call = this._requests[i];
- var success_cb = ('success_cb' in call) ? call.success_cb : undefined;
- var error_cb = ('error_cb' in call) ? call.error_cb : undefined;
- self.jsonrpcclient._wsCall(socket, call.request, success_cb, error_cb);
- }
- if (typeof all_done_cb === 'function') all_done_cb(result);
- return;
- }
+ this._requests.push({
+ request : {
+ jsonrpc : '2.0',
+ method : method,
+ params : params
+ }
+ });
+ };
- for (var i = 0; i < this._requests.length; i++) {
- var call = this._requests[i];
- batch_request.push(call.request);
+ /**
+ * Executes the batched up calls.
+ */
+ $.JsonRpcClient._batchObject.prototype._execute = function() {
+ var self = this;
+
+ if (this._requests.length === 0) return; // All done :P
+
+ // Collect all request data and sort handlers by request id.
+ var batch_request = [];
+ var handlers = {};
+
+ // If we have a WebSocket, just send the requests individually like normal calls.
+ var socket = self.jsonrpcclient.options.getSocket(self.jsonrpcclient.wsOnMessage);
+ if (socket !== null) {
+ for (var i = 0; i < this._requests.length; i++) {
+ var call = this._requests[i];
+ var success_cb = ('success_cb' in call) ? call.success_cb : undefined;
+ var error_cb = ('error_cb' in call) ? call.error_cb : undefined;
+ self.jsonrpcclient._wsCall(socket, call.request, success_cb, error_cb);
+ }
+
+ if (typeof all_done_cb === 'function') all_done_cb(result);
+ return;
+ }
- // If the request has an id, it should handle returns (otherwise it's a notify).
- if ('id' in call.request) {
- handlers[call.request.id] = {
- success_cb : call.success_cb,
- error_cb : call.error_cb
- };
- }
- }
+ for (var i = 0; i < this._requests.length; i++) {
+ var call = this._requests[i];
+ batch_request.push(call.request);
+
+ // If the request has an id, it should handle returns (otherwise it's a notify).
+ if ('id' in call.request) {
+ handlers[call.request.id] = {
+ success_cb : call.success_cb,
+ error_cb : call.error_cb
+ };
+ }
+ }
- var success_cb = function(data) { self._batchCb(data, handlers, self.all_done_cb); };
+ var success_cb = function(data) { self._batchCb(data, handlers, self.all_done_cb); };
- // No WebSocket, and no HTTP backend? This won't work.
- if (self.jsonrpcclient.options.ajaxUrl === null) {
- throw "$.JsonRpcClient.batch used with no websocket and no http endpoint.";
- }
+ // No WebSocket, and no HTTP backend? This won't work.
+ if (self.jsonrpcclient.options.ajaxUrl === null) {
+ throw "$.JsonRpcClient.batch used with no websocket and no http endpoint.";
+ }
- // Send request
- $.ajax({
- url : self.jsonrpcclient.options.ajaxUrl,
- data : $.toJSON(batch_request),
- dataType : 'json',
- cache : false,
- type : 'POST',
-
- // Batch-requests should always return 200
- error : function(jqXHR, textStatus, errorThrown) {
- self.error_cb(jqXHR, textStatus, errorThrown);
- },
- success : success_cb
- });
- };
+ // Send request
+ $.ajax({
+ url : self.jsonrpcclient.options.ajaxUrl,
+ data : $.toJSON(batch_request),
+ dataType : 'json',
+ cache : false,
+ type : 'POST',
+
+ // Batch-requests should always return 200
+ error : function(jqXHR, textStatus, errorThrown) {
+ self.error_cb(jqXHR, textStatus, errorThrown);
+ },
+ success : success_cb
+ });
+ };
- /**
- * Internal helper to match the result array from a batch call to their respective callbacks.
- *
- * @fn _batchCb
- * @memberof $.JsonRpcClient
- */
- $.JsonRpcClient._batchObject.prototype._batchCb = function(result, handlers, all_done_cb) {
- for (var i = 0; i < result.length; i++) {
- var response = result[i];
-
- // Handle error
- if ('error' in response) {
- if (response.id === null || !(response.id in handlers)) {
- // An error on a notify? Just log it to the console.
- if ('console' in window) console.log(response);
+ /**
+ * Internal helper to match the result array from a batch call to their respective callbacks.
+ *
+ * @fn _batchCb
+ * @memberof $.JsonRpcClient
+ */
+ $.JsonRpcClient._batchObject.prototype._batchCb = function(result, handlers, all_done_cb) {
+ for (var i = 0; i < result.length; i++) {
+ var response = result[i];
+
+ // Handle error
+ if ('error' in response) {
+ if (response.id === null || !(response.id in handlers)) {
+ // An error on a notify? Just log it to the console.
+ if ('console' in window) console.log(response);
+ } else {
+ handlers[response.id].error_cb(response.error, this);
+ }
+ } else {
+ // Here we should always have a correct id and no error.
+ if (!(response.id in handlers) && 'console' in window) {
+ console.log(response);
+ } else {
+ handlers[response.id].success_cb(response.result, this);
+ }
+ }
}
- else handlers[response.id].error_cb(response.error, this);
- }
- else {
- // Here we should always have a correct id and no error.
- if (!(response.id in handlers) && 'console' in window) console.log(response);
- else handlers[response.id].success_cb(response.result, this);
- }
- }
- if (typeof all_done_cb === 'function') all_done_cb(result);
- };
+ if (typeof all_done_cb === 'function') all_done_cb(result);
+ };
})(jQuery);
tag: null,
videoParams: {},
audioParams: {},
- iceServers: false,
+ iceServers: false,
ringSleep: 6000
- },
- options);
+ }, options);
verto.sessid = $.cookie('verto_session_uuid') || generateGUID();
$.cookie('verto_session_uuid', verto.sessid, {
});
verto.dialogs = {};
-
verto.callbacks = callbacks || {};
-
verto.eventSUBS = {};
verto.rpcClient = new $.JsonRpcClient({
$.verto.prototype.iceServers = function(on) {
var verto = this;
-
verto.options.iceServers = on;
};
$.verto.prototype.processReply = function(method, success, e) {
var verto = this;
- var i;
+ var i;
//console.log("Response: " + method, success, e);
}
var SERNO = 1;
-
+
function do_subscribe(verto, channel, subChannels, sparams) {
var params = sparams || {};
$.verto.prototype.unsubscribe = function(handle) {
var verto = this;
- var i;
+ var i;
if (!handle) {
for (i in verto.eventSUBS) {
} else {
var unsubChannels = {};
var sendChannels = [];
- var channel;
+ var channel;
if (typeof(handle) == "string") {
delete verto.eventSUBS[handle];
$.verto.prototype.purge = function(callID) {
var verto = this;
var x = 0;
- var i;
+ var i;
for (i in verto.dialogs) {
if (!x) {
console.log("purging dialogs");
}
- x++;
+ x++;
verto.dialogs[i].setState($.verto.enum.state.purge);
}
$.verto.prototype.handleMessage = function(data) {
var verto = this;
- if (!(data && data.method)) {
- console.error("Invalid Data", data);
- return;
- }
+ if (!(data && data.method)) {
+ console.error("Invalid Data", data);
+ return;
+ }
if (data.params.callID) {
var dialog = verto.dialogs[data.params.callID];
data.params.useStereo = true;
}
- dialog = new $.verto.dialog($.verto.enum.direction.inbound, verto, data.params);
+ dialog = new $.verto.dialog($.verto.enum.direction.inbound, verto, data.params);
dialog.setState($.verto.enum.state.recovering);
- break;
+ break;
case 'verto.invite':
if (data.params.sdp && data.params.sdp.indexOf("m=video") > 0) {
}
}
- if (!list && key && key === verto.sessid) {
- if (verto.callbacks.onMessage) {
- verto.callbacks.onMessage(verto, null, $.verto.enum.message.pvtEvent, data.params);
- }
+ if (!list && key && key === verto.sessid) {
+ if (verto.callbacks.onMessage) {
+ verto.callbacks.onMessage(verto, null, $.verto.enum.message.pvtEvent, data.params);
+ }
} else if (!list && key && verto.dialogs[key]) {
verto.dialogs[key].sendMessage($.verto.enum.message.pvtEvent, data.params);
} else if (!list) {
la.verto.unsubscribe(binding);
};
- la.sendCommand = function(cmd, obj) {
+ la.sendCommand = function(cmd, obj) {
var self = la;
- self.broadcast(self.context, {
- liveArray: {
+ self.broadcast(self.context, {
+ liveArray: {
command: cmd,
context: self.context,
name: self.name,
obj: obj
}
- });
- };
+ });
+ };
la.bootstrap = function(obj) {
var self = la;
- la.sendCommand("bootstrap", obj);
+ la.sendCommand("bootstrap", obj);
//self.heartbeat();
};
} else {
obj.errs = 0;
}
-
+
};
la.onChange(la, {
};
var CONFMAN_SERNO = 1;
-
+
$.verto.confMan = function(verto, params) {
- var confMan = this;
- conf
+ var confMan = this;
+ conf
confMan.params = $.extend({
- tableID: null,
- statusID: null,
- mainModID: null,
- dialog: null,
- hasVid: false,
- laData: null,
- onBroadcast: null,
- onLaChange: null,
- onLaRow: null
- },
- params);
-
- confMan.verto = verto;
- confMan.serno = CONFMAN_SERNO++;
-
- function genMainMod(jq) {
- var play_id = "play_" + confMan.serno;
- var stop_id = "stop_" + confMan.serno;
- var recording_id = "recording_" + confMan.serno;
- var rec_stop_id = "recording_stop" + confMan.serno;
- var div_id = "confman_" + confMan.serno;
-
- var html = "<div id='" + div_id + "'><br>" +
- "<button class='ctlbtn' id='" + play_id + "'>Play</button>" +
- "<button class='ctlbtn' id='" + stop_id + "'>Stop</button>" +
- "<button class='ctlbtn' id='" + recording_id + "'>Record</button>" +
- "<button class='ctlbtn' id='" + rec_stop_id + "'>Record Stop</button>"
-
- + "<br><br></div>";
-
- jq.html(html);
-
- $("#" + play_id).click(function() {
- var file = prompt("Please enter file name", "");
- confMan.modCommand("play", null, file);
- });
-
- $("#" + stop_id).click(function() {
- confMan.modCommand("stop", null, "all");
- });
-
- $("#" + recording_id).click(function() {
- var file = prompt("Please enter file name", "");
- confMan.modCommand("recording", null, ["start", file]);
- });
-
- $("#" + rec_stop_id).click(function() {
- confMan.modCommand("recording", null, ["stop", "all"]);
- });
-
- }
-
- function genControls(jq, rowid) {
- var x = parseInt(rowid);
- var kick_id = "kick_" + x;
- var tmute_id = "tmute_" + x;
- var box_id = "box_" + x;
- var volup_id = "volume_in_up" + x;
- var voldn_id = "volume_in_dn" + x;
- var transfer_id = "transfer" + x;
-
-
- var html = "<div id='" + box_id + "'>" +
- "<button class='ctlbtn' id='" + kick_id + "'>Kick</button>" +
- "<button class='ctlbtn' id='" + tmute_id + "'>Mute</button>" +
- "<button class='ctlbtn' id='" + voldn_id + "'>Vol -</button>" +
- "<button class='ctlbtn' id='" + volup_id + "'>Vol +</button>" +
- "<button class='ctlbtn' id='" + transfer_id + "'>Transfer</button>" +
- "</div>"
- ;
-
- jq.html(html);
-
- if (!jq.data("mouse")) {
- $("#" + box_id).hide();
- }
-
- jq.mouseover(function(e) {
- jq.data({"mouse": true});
- $("#" + box_id).show();
- });
-
- jq.mouseout(function(e) {
- jq.data({"mouse": false});
- $("#" + box_id).hide();
- });
-
- $("#" + transfer_id).click(function() {
- var xten = prompt("Enter Extension");
- confMan.modCommand("transfer", x, xten);
- });
-
- $("#" + kick_id).click(function() {
- confMan.modCommand("kick", x);
- });
-
- $("#" + tmute_id).click(function() {
- confMan.modCommand("tmute", x);
- });
-
- $("#" + volup_id).click(function() {
- confMan.modCommand("volume_in", x, "up");
- });
-
- $("#" + voldn_id).click(function() {
- confMan.modCommand("volume_in", x, "down");
- });
-
- return html;
- }
-
-
-
- var atitle = "";
- var awidth = 0;
-
+ tableID: null,
+ statusID: null,
+ mainModID: null,
+ dialog: null,
+ hasVid: false,
+ laData: null,
+ onBroadcast: null,
+ onLaChange: null,
+ onLaRow: null
+ }, params);
+
+ confMan.verto = verto;
+ confMan.serno = CONFMAN_SERNO++;
+
+ function genMainMod(jq) {
+ var play_id = "play_" + confMan.serno;
+ var stop_id = "stop_" + confMan.serno;
+ var recording_id = "recording_" + confMan.serno;
+ var rec_stop_id = "recording_stop" + confMan.serno;
+ var div_id = "confman_" + confMan.serno;
+
+ var html = "<div id='" + div_id + "'><br>" +
+ "<button class='ctlbtn' id='" + play_id + "'>Play</button>" +
+ "<button class='ctlbtn' id='" + stop_id + "'>Stop</button>" +
+ "<button class='ctlbtn' id='" + recording_id + "'>Record</button>" +
+ "<button class='ctlbtn' id='" + rec_stop_id + "'>Record Stop</button>"
+
+ + "<br><br></div>";
+
+ jq.html(html);
+
+ $("#" + play_id).click(function() {
+ var file = prompt("Please enter file name", "");
+ confMan.modCommand("play", null, file);
+ });
+
+ $("#" + stop_id).click(function() {
+ confMan.modCommand("stop", null, "all");
+ });
+
+ $("#" + recording_id).click(function() {
+ var file = prompt("Please enter file name", "");
+ confMan.modCommand("recording", null, ["start", file]);
+ });
+
+ $("#" + rec_stop_id).click(function() {
+ confMan.modCommand("recording", null, ["stop", "all"]);
+ });
+
+ }
+
+ function genControls(jq, rowid) {
+ var x = parseInt(rowid);
+ var kick_id = "kick_" + x;
+ var tmute_id = "tmute_" + x;
+ var box_id = "box_" + x;
+ var volup_id = "volume_in_up" + x;
+ var voldn_id = "volume_in_dn" + x;
+ var transfer_id = "transfer" + x;
+
+
+ var html = "<div id='" + box_id + "'>" +
+ "<button class='ctlbtn' id='" + kick_id + "'>Kick</button>" +
+ "<button class='ctlbtn' id='" + tmute_id + "'>Mute</button>" +
+ "<button class='ctlbtn' id='" + voldn_id + "'>Vol -</button>" +
+ "<button class='ctlbtn' id='" + volup_id + "'>Vol +</button>" +
+ "<button class='ctlbtn' id='" + transfer_id + "'>Transfer</button>" +
+ "</div>"
+ ;
+
+ jq.html(html);
+
+ if (!jq.data("mouse")) {
+ $("#" + box_id).hide();
+ }
+
+ jq.mouseover(function(e) {
+ jq.data({"mouse": true});
+ $("#" + box_id).show();
+ });
+
+ jq.mouseout(function(e) {
+ jq.data({"mouse": false});
+ $("#" + box_id).hide();
+ });
+
+ $("#" + transfer_id).click(function() {
+ var xten = prompt("Enter Extension");
+ confMan.modCommand("transfer", x, xten);
+ });
+
+ $("#" + kick_id).click(function() {
+ confMan.modCommand("kick", x);
+ });
+
+ $("#" + tmute_id).click(function() {
+ confMan.modCommand("tmute", x);
+ });
+
+ $("#" + volup_id).click(function() {
+ confMan.modCommand("volume_in", x, "up");
+ });
+
+ $("#" + voldn_id).click(function() {
+ confMan.modCommand("volume_in", x, "down");
+ });
+
+ return html;
+ }
+
+ var atitle = "";
+ var awidth = 0;
+
//$(".jsDataTable").width(confMan.params.hasVid ? "900px" : "800px");
-
- if (confMan.params.laData.role === "moderator") {
- atitle = "Action";
- awidth = 200;
-
- if (confMan.params.mainModID) {
- genMainMod($(confMan.params.mainModID));
- $(confMan.params.displayID).html("Moderator Controls Ready<br><br>")
- } else {
- $(confMan.params.mainModID).html("");
- }
-
- verto.subscribe(confMan.params.laData.modChannel, {
- handler: function(v, e) {
- console.error("MODDATA:", e.data);
- if (confMan.params.onBroadcast) {
- confMan.params.onBroadcast(verto, confMan, e.data);
- }
- if (!confMan.destroyed && confMan.params.displayID) {
- $(confMan.params.displayID).html(e.data.response + "<br><br>");
- if (confMan.lastTimeout) {
- clearTimeout(confMan.lastTimeout);
- confMan.lastTimeout = 0;
- }
- confMan.lastTimeout = setTimeout(function() { $(confMan.params.displayID).html(confMan.destroyed ? "" : "Moderator Controls Ready<br><br>")}, 4000);
- }
-
- }
- });
-
- }
-
- var row_callback = null;
-
- if (confMan.params.laData.role === "moderator") {
- row_callback = function(nRow, aData, iDisplayIndex, iDisplayIndexFull) {
- if (!aData[5]) {
- var $row = $('td:eq(5)', nRow);
- genControls($row, aData);
-
- if (confMan.params.onLaRow) {
- confMan.params.onLaRow(verto, confMan, $row, aData);
- }
-
- }
- };
- }
-
+
+ if (confMan.params.laData.role === "moderator") {
+ atitle = "Action";
+ awidth = 200;
+
+ if (confMan.params.mainModID) {
+ genMainMod($(confMan.params.mainModID));
+ $(confMan.params.displayID).html("Moderator Controls Ready<br><br>")
+ } else {
+ $(confMan.params.mainModID).html("");
+ }
+
+ verto.subscribe(confMan.params.laData.modChannel, {
+ handler: function(v, e) {
+ console.error("MODDATA:", e.data);
+ if (confMan.params.onBroadcast) {
+ confMan.params.onBroadcast(verto, confMan, e.data);
+ }
+ if (!confMan.destroyed && confMan.params.displayID) {
+ $(confMan.params.displayID).html(e.data.response + "<br><br>");
+ if (confMan.lastTimeout) {
+ clearTimeout(confMan.lastTimeout);
+ confMan.lastTimeout = 0;
+ }
+ confMan.lastTimeout = setTimeout(function() { $(confMan.params.displayID).html(confMan.destroyed ? "" : "Moderator Controls Ready<br><br>")}, 4000);
+ }
+ }
+ });
+ }
+
+ var row_callback = null;
+
+ if (confMan.params.laData.role === "moderator") {
+ row_callback = function(nRow, aData, iDisplayIndex, iDisplayIndexFull) {
+ if (!aData[5]) {
+ var $row = $('td:eq(5)', nRow);
+ genControls($row, aData);
+
+ if (confMan.params.onLaRow) {
+ confMan.params.onLaRow(verto, confMan, $row, aData);
+ }
+ }
+ };
+ }
+
confMan.lt = new $.verto.liveTable(verto, confMan.params.laData.laChannel, confMan.params.laData.laName, $(confMan.params.tableID), {
subParams: {
callID: confMan.params.dialog ? confMan.params.dialog.callID : null
},
-
-
+
"onChange": function(obj, args) {
$(confMan.params.statusID).text("Conference Members: " + " (" + obj.arrayLen() + " Total)");
- if (confMan.params.onLaChange) {
- confMan.params.onLaChange(verto, confMan, $.verto.enum.confEvent.laChange, obj, args);
- }
+ if (confMan.params.onLaChange) {
+ confMan.params.onLaChange(verto, confMan, $.verto.enum.confEvent.laChange, obj, args);
+ }
},
"aaData": [],
- "aoColumns": [{
- "sTitle": "ID"
- },
- {
- "sTitle": "Number"
- },
- {
- "sTitle": "Name"
- },
- {
- "sTitle": "Codec"
- },
- {
- "sTitle": "Status",
- "sWidth": confMan.params.hasVid ? "300px" : "150px"
- },
- {
- "sTitle": atitle,
- "sWidth": awidth,
-
- }],
+ "aoColumns": [
+ {
+ "sTitle": "ID"
+ },
+ {
+ "sTitle": "Number"
+ },
+ {
+ "sTitle": "Name"
+ },
+ {
+ "sTitle": "Codec"
+ },
+ {
+ "sTitle": "Status",
+ "sWidth": confMan.params.hasVid ? "300px" : "150px"
+ },
+ {
+ "sTitle": atitle,
+ "sWidth": awidth,
+ }
+ ],
"bAutoWidth": true,
"bDestroy": true,
"bSort": false,
"sEmptyTable": "The Conference is Empty....."
},
- "fnRowCallback": row_callback
+ "fnRowCallback": row_callback
});
}
$.verto.confMan.prototype.modCommand = function(cmd, id, value) {
- var confMan = this;
-
- confMan.verto.sendMethod("verto.broadcast", {
- "eventChannel": confMan.params.laData.modChannel,
- "data": {
- "application": "conf-control",
- "command": cmd,
- "id": id,
- "value": value
- }
- });
+ var confMan = this;
+
+ confMan.verto.sendMethod("verto.broadcast", {
+ "eventChannel": confMan.params.laData.modChannel,
+ "data": {
+ "application": "conf-control",
+ "command": cmd,
+ "id": id,
+ "value": value
+ }
+ });
}
$.verto.confMan.prototype.destroy = function() {
- var confMan = this;
+ var confMan = this;
- confMan.destroyed = true;
+ confMan.destroyed = true;
- if (confMan.lt) {
- confMan.lt.destroy();
- }
+ if (confMan.lt) {
+ confMan.lt.destroy();
+ }
- if (confMan.params.laData.modChannel) {
- confMan.verto.unsubscribe(confMan.params.laData.modChannel);
- }
+ if (confMan.params.laData.modChannel) {
+ confMan.verto.unsubscribe(confMan.params.laData.modChannel);
+ }
- if (confMan.params.mainModID) {
- $(confMan.params.mainModID).html("");
- }
+ if (confMan.params.mainModID) {
+ $(confMan.params.mainModID).html("");
+ }
}
$.verto.dialog = function(direction, verto, params) {
useVideo: verto.options.useVideo,
useStereo: verto.options.useStereo,
tag: verto.options.tag,
- login: verto.options.login
- },
- params);
+ login: verto.options.login
+ }, params);
dialog.verto = verto;
dialog.direction = direction;
var RTCcallbacks = {};
if (dialog.direction == $.verto.enum.direction.inbound) {
- if (dialog.params.display_direction === "outbound") {
- dialog.params.remote_caller_id_name = dialog.params.caller_id_name;
- dialog.params.remote_caller_id_number = dialog.params.caller_id_number;
- } else {
- dialog.params.remote_caller_id_name = dialog.params.callee_id_name;
- dialog.params.remote_caller_id_number = dialog.params.callee_id_number;
- }
+ if (dialog.params.display_direction === "outbound") {
+ dialog.params.remote_caller_id_name = dialog.params.caller_id_name;
+ dialog.params.remote_caller_id_number = dialog.params.caller_id_number;
+ } else {
+ dialog.params.remote_caller_id_name = dialog.params.callee_id_name;
+ dialog.params.remote_caller_id_number = dialog.params.callee_id_number;
+ }
if (!dialog.params.remote_caller_id_name) {
dialog.params.remote_caller_id_name = "Nobody";
dialog.sendMethod("verto.invite", {
sdp: rtc.mediaData.SDP
});
- } else { //answer
+ } else { //answer
dialog.setState($.verto.enum.state.answering);
dialog.sendMethod(dialog.attach ? "verto.attach" : "verto.answer", {
sdp: dialog.rtc.mediaData.SDP
});
}
-
};
RTCcallbacks.onICE = function(rtc) {
console.log("offer", rtc.mediaData.candidate);
return;
}
-
};
RTCcallbacks.onError = function(e) {
useStereo: dialog.params.useStereo,
videoParams: verto.options.videoParams,
audioParams: verto.options.audioParams,
- iceServers: verto.options.iceServers
+ iceServers: verto.options.iceServers
});
dialog.rtc.verto = dialog.verto;
dialog.lastState = dialog.state;
dialog.state = state;
-
- if (!dialog.causeCode) {
- dialog.causeCode = 16;
- }
- if (!dialog.cause) {
- dialog.cause = "NORMAL CLEARING";
- }
+ if (!dialog.causeCode) {
+ dialog.causeCode = 16;
+ }
+
+ if (!dialog.cause) {
+ dialog.cause = "NORMAL CLEARING";
+ }
if (dialog.callbacks.onDialogState) {
dialog.callbacks.onDialogState(this);
switch (dialog.state) {
case $.verto.enum.state.trying:
- setTimeout(function() {
+ setTimeout(function() {
if (dialog.state == $.verto.enum.state.trying) {
- dialog.setState($.verto.enum.state.hangup);
+ dialog.setState($.verto.enum.state.hangup);
}
}, 30000);
- break;
+ break;
case $.verto.enum.state.purge:
dialog.setState($.verto.enum.state.destroy);
break;
dialog.setState($.verto.enum.state.destroy);
break;
case $.verto.enum.state.destroy:
- delete dialog.verto.dialogs[dialog.callID];
+ delete dialog.verto.dialogs[dialog.callID];
dialog.rtc.stop();
break;
}
$.verto.dialog.prototype.hangup = function(params) {
var dialog = this;
- if (params) {
- if (params.causeCode) {
- dialog.causeCode = params.causeCode;
- }
-
- if (params.cause) {
- dialog.cause = params.cause;
- }
- }
+ if (params) {
+ if (params.causeCode) {
+ dialog.causeCode = params.causeCode;
+ }
+
+ if (params.cause) {
+ dialog.cause = params.cause;
+ }
+ }
if (dialog.state.val > $.verto.enum.state.new.val && dialog.state.val < $.verto.enum.state.hangup.val) {
dialog.setState($.verto.enum.state.hangup);
var dialog = this;
var err = 0;
- msg.from = dialog.params.login;
+ msg.from = dialog.params.login;
if (!msg.to) {
console.error("Missing To");
if (params.useVideo) {
dialog.useVideo(true);
}
- dialog.params.callee_id_name = params.callee_id_name;
- dialog.params.callee_id_number = params.callee_id_number;
+ dialog.params.callee_id_name = params.callee_id_name;
+ dialog.params.callee_id_number = params.callee_id_number;
}
dialog.rtc.createAnswer(dialog.params.sdp);
dialog.answered = true;
$.verto.dialog.prototype.handleAnswer = function(params) {
var dialog = this;
- dialog.gotAnswer = true;
+ dialog.gotAnswer = true;
if (dialog.state.val >= $.verto.enum.state.active.val) {
return;
if (dialog.state.val >= $.verto.enum.state.early.val) {
dialog.setState($.verto.enum.state.active);
} else {
- if (dialog.gotEarly) {
- console.log("Dialog " + dialog.callID + "Got answer while still establishing early media, delaying...");
- } else {
- console.log("Dialog " + dialog.callID + "Answering Channel");
- dialog.rtc.answer(params.sdp, function() {
+ if (dialog.gotEarly) {
+ console.log("Dialog " + dialog.callID + "Got answer while still establishing early media, delaying...");
+ } else {
+ console.log("Dialog " + dialog.callID + "Answering Channel");
+ dialog.rtc.answer(params.sdp, function() {
dialog.setState($.verto.enum.state.active);
- },
- function(e) {
- console.error(e);
- dialog.hangup();
- });
- console.log("Dialog " + dialog.callID + "ANSWER SDP", params.sdp);
- }
- }
+ }, function(e) {
+ console.error(e);
+ dialog.hangup();
+ });
+ console.log("Dialog " + dialog.callID + "ANSWER SDP", params.sdp);
+ }
+ }
};
$.verto.dialog.prototype.cidString = function(enc) {
return;
}
- dialog.gotEarly = true;
-
+ dialog.gotEarly = true;
+
dialog.rtc.answer(params.sdp, function() {
- console.log("Dialog " + dialog.callID + "Establishing early media");
- dialog.setState($.verto.enum.state.early);
+ console.log("Dialog " + dialog.callID + "Establishing early media");
+ dialog.setState($.verto.enum.state.early);
- if (dialog.gotAnswer) {
- console.log("Dialog " + dialog.callID + "Answering Channel");
- dialog.setState($.verto.enum.state.active);
- }
- },
- function(e) {
+ if (dialog.gotAnswer) {
+ console.log("Dialog " + dialog.callID + "Answering Channel");
+ dialog.setState($.verto.enum.state.active);
+ }
+ }, function(e) {
console.error(e);
dialog.hangup();
});
$.verto.enum.states = Object.freeze({
new: {
requesting: 1,
- recovering: 1,
+ recovering: 1,
ringing: 1,
destroy: 1,
answering: 1
hangup: 1
},
active: {
- answering: 1,
- requesting: 1,
+ answering: 1,
+ requesting: 1,
hangup: 1,
held: 1
},