openvidu-browser: beautify .js files
This commit is contained in:
parent
ae686ffbb6
commit
317b388088
@ -1,49 +1,45 @@
|
||||
function Mapper()
|
||||
{
|
||||
function Mapper() {
|
||||
var sources = {};
|
||||
|
||||
|
||||
this.forEach = function(callback)
|
||||
{
|
||||
for(var key in sources)
|
||||
{
|
||||
this.forEach = function (callback) {
|
||||
for (var key in sources) {
|
||||
var source = sources[key];
|
||||
|
||||
for(var key2 in source)
|
||||
for (var key2 in source)
|
||||
callback(source[key2]);
|
||||
};
|
||||
};
|
||||
|
||||
this.get = function(id, source)
|
||||
{
|
||||
this.get = function (id, source) {
|
||||
var ids = sources[source];
|
||||
if(ids == undefined)
|
||||
if (ids == undefined)
|
||||
return undefined;
|
||||
|
||||
return ids[id];
|
||||
};
|
||||
|
||||
this.remove = function(id, source)
|
||||
{
|
||||
this.remove = function (id, source) {
|
||||
var ids = sources[source];
|
||||
if(ids == undefined)
|
||||
if (ids == undefined)
|
||||
return;
|
||||
|
||||
delete ids[id];
|
||||
|
||||
// Check it's empty
|
||||
for(var i in ids){return false}
|
||||
for (var i in ids) {
|
||||
return false
|
||||
}
|
||||
|
||||
delete sources[source];
|
||||
};
|
||||
|
||||
this.set = function(value, id, source)
|
||||
{
|
||||
if(value == undefined)
|
||||
this.set = function (value, id, source) {
|
||||
if (value == undefined)
|
||||
return this.remove(id, source);
|
||||
|
||||
var ids = sources[source];
|
||||
if(ids == undefined)
|
||||
if (ids == undefined)
|
||||
sources[source] = ids = {};
|
||||
|
||||
ids[id] = value;
|
||||
@ -51,10 +47,9 @@ function Mapper()
|
||||
};
|
||||
|
||||
|
||||
Mapper.prototype.pop = function(id, source)
|
||||
{
|
||||
Mapper.prototype.pop = function (id, source) {
|
||||
var value = this.get(id, source);
|
||||
if(value == undefined)
|
||||
if (value == undefined)
|
||||
return undefined;
|
||||
|
||||
this.remove(id, source);
|
||||
@ -63,4 +58,4 @@ Mapper.prototype.pop = function(id, source)
|
||||
};
|
||||
|
||||
|
||||
module.exports = Mapper;
|
||||
module.exports = Mapper;
|
||||
@ -15,7 +15,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
var JsonRpcClient = require('./jsonrpcclient');
|
||||
var JsonRpcClient = require('./jsonrpcclient');
|
||||
|
||||
|
||||
exports.JsonRpcClient = JsonRpcClient;
|
||||
exports.JsonRpcClient = JsonRpcClient;
|
||||
@ -15,7 +15,6 @@
|
||||
*
|
||||
*/
|
||||
|
||||
var WebSocketWithReconnection = require('./webSocketWithReconnection');
|
||||
var WebSocketWithReconnection = require('./webSocketWithReconnection');
|
||||
|
||||
|
||||
exports.WebSocketWithReconnection = WebSocketWithReconnection;
|
||||
exports.WebSocketWithReconnection = WebSocketWithReconnection;
|
||||
File diff suppressed because it is too large
Load Diff
@ -10,37 +10,31 @@
|
||||
*
|
||||
* @return {String} - the stringified JsonRPC 2.0 message
|
||||
*/
|
||||
function pack(message, id)
|
||||
{
|
||||
var result =
|
||||
{
|
||||
function pack(message, id) {
|
||||
var result = {
|
||||
jsonrpc: "2.0"
|
||||
};
|
||||
|
||||
// Request
|
||||
if(message.method)
|
||||
{
|
||||
if (message.method) {
|
||||
result.method = message.method;
|
||||
|
||||
if(message.params)
|
||||
if (message.params)
|
||||
result.params = message.params;
|
||||
|
||||
// Request is a notification
|
||||
if(id != undefined)
|
||||
if (id != undefined)
|
||||
result.id = id;
|
||||
}
|
||||
|
||||
// Response
|
||||
else if(id != undefined)
|
||||
{
|
||||
if(message.error)
|
||||
{
|
||||
if(message.result !== undefined)
|
||||
else if (id != undefined) {
|
||||
if (message.error) {
|
||||
if (message.result !== undefined)
|
||||
throw new TypeError("Both result and error are defined");
|
||||
|
||||
result.error = message.error;
|
||||
}
|
||||
else if(message.result !== undefined)
|
||||
} else if (message.result !== undefined)
|
||||
result.result = message.result;
|
||||
else
|
||||
throw new TypeError("No result or error is defined");
|
||||
@ -60,35 +54,33 @@ function pack(message, id)
|
||||
*
|
||||
* @return {Object} - object filled with the JsonRPC 2.0 message content
|
||||
*/
|
||||
function unpack(message)
|
||||
{
|
||||
function unpack(message) {
|
||||
var result = message;
|
||||
|
||||
if(typeof message === 'string' || message instanceof String) {
|
||||
if (typeof message === 'string' || message instanceof String) {
|
||||
result = JSON.parse(message);
|
||||
}
|
||||
|
||||
// Check if it's a valid message
|
||||
|
||||
var version = result.jsonrpc;
|
||||
if(version !== '2.0')
|
||||
if (version !== '2.0')
|
||||
throw new TypeError("Invalid JsonRPC version '" + version + "': " + message);
|
||||
|
||||
// Response
|
||||
if(result.method == undefined)
|
||||
{
|
||||
if(result.id == undefined)
|
||||
throw new TypeError("Invalid message: "+message);
|
||||
if (result.method == undefined) {
|
||||
if (result.id == undefined)
|
||||
throw new TypeError("Invalid message: " + message);
|
||||
|
||||
var result_defined = result.result !== undefined;
|
||||
var error_defined = result.error !== undefined;
|
||||
var error_defined = result.error !== undefined;
|
||||
|
||||
// Check only result or error is defined, not both or none
|
||||
if(result_defined && error_defined)
|
||||
throw new TypeError("Both result and error are defined: "+message);
|
||||
if (result_defined && error_defined)
|
||||
throw new TypeError("Both result and error are defined: " + message);
|
||||
|
||||
if(!result_defined && !error_defined)
|
||||
throw new TypeError("No result or error is defined: "+message);
|
||||
if (!result_defined && !error_defined)
|
||||
throw new TypeError("No result or error is defined: " + message);
|
||||
|
||||
result.ack = result.id;
|
||||
delete result.id;
|
||||
@ -99,5 +91,5 @@ function unpack(message)
|
||||
};
|
||||
|
||||
|
||||
exports.pack = pack;
|
||||
exports.unpack = unpack;
|
||||
exports.pack = pack;
|
||||
exports.unpack = unpack;
|
||||
@ -1,13 +1,10 @@
|
||||
function pack(message)
|
||||
{
|
||||
function pack(message) {
|
||||
throw new TypeError("Not yet implemented");
|
||||
};
|
||||
|
||||
function unpack(message)
|
||||
{
|
||||
function unpack(message) {
|
||||
throw new TypeError("Not yet implemented");
|
||||
};
|
||||
|
||||
|
||||
exports.pack = pack;
|
||||
exports.unpack = unpack;
|
||||
exports.pack = pack;
|
||||
exports.unpack = unpack;
|
||||
@ -1,6 +1,6 @@
|
||||
var JsonRPC = require('./JsonRPC');
|
||||
var XmlRPC = require('./XmlRPC');
|
||||
var XmlRPC = require('./XmlRPC');
|
||||
|
||||
|
||||
exports.JsonRPC = JsonRPC;
|
||||
exports.XmlRPC = XmlRPC;
|
||||
exports.XmlRPC = XmlRPC;
|
||||
Loading…
x
Reference in New Issue
Block a user