New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

freedom

Package Overview
Dependencies
Maintainers
2
Versions
73
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

freedom - npm Package Compare versions

Comparing version 0.5.2 to 0.5.3

demo/filedrop/freedom-modules/filefetcher.js

35

demo/chat/main.js

@@ -14,2 +14,3 @@ /**

var myClientState = null;
var messages = [];

@@ -28,2 +29,17 @@ /**

freedom.on('boot', function(val) {
if (myClientState !== null) {
if (myClientState.status == social.STATUS["ONLINE"]) {
freedom.emit('recv-uid', myClientState.clientId);
freedom.emit('recv-status', "online");
} else {
freedom.emit('recv-status', "offline");
}
}
updateBuddyList();
for (var i=0; i<messages.length; i++) {
freedom.emit('recv-message', messages[i]);
}
});
/**

@@ -34,2 +50,3 @@ * on an 'onMessage' event from the Social provider

social.on('onMessage', function(data) {
messages.push(data);
freedom.emit('recv-message', data);

@@ -44,2 +61,3 @@ });

userList[data.userId] = data;
updateBuddyList();
});

@@ -66,12 +84,19 @@

}
// Iterate over our roster and just send over userId's where there is at least 1 client online
var buddylist = [];
updateBuddyList();
});
function updateBuddyList() {
// Iterate over our roster and send over user profiles where there is at least 1 client online
var buddylist = {};
for (var k in clientList) {
if (clientList.hasOwnProperty(k)) {
buddylist.push(k);
var userId = clientList[k].userId;
if (userId in userList) {
buddylist[userId] = userList[userId];
}
}
freedom.emit('recv-buddylist', buddylist);
});
}
/** LOGIN AT START **/

@@ -78,0 +103,0 @@ social.login({

@@ -5,3 +5,8 @@ {

"app": {
"script": "main.js"
"script": "main.js",
"index": "index.html",
"static": [
"style.css",
"ux.js"
]
},

@@ -8,0 +13,0 @@ "dependencies": {

34

demo/chat/ux.js

@@ -7,3 +7,3 @@ /*

// If messages are going to a specific user, store that here.
var activeId;
var activeBuddylistEntry;
var buddylist;

@@ -28,6 +28,12 @@

function makeDisplayString(buddylistEntry) {
return buddylistEntry.name && buddylistEntry.name != buddylistEntry.userId ?
buddylistEntry.name + ' (' + buddylistEntry.userId + ')' :
buddylistEntry.userId;
}
function redrawBuddylist() {
var onClick = function(jid, child) {
console.log("Messages will be sent to: " + activeId);
activeId = jid;
var onClick = function(buddylistEntry, child) {
console.log("Messages will be sent to: " + buddylistEntry.userId);
activeBuddylistEntry = buddylistEntry;
redrawBuddylist();

@@ -42,11 +48,11 @@ document.getElementById('msg-input').focus();

// Create a new element for each buddy
for (var i in buddylist) {
for (var userId in buddylist) {
var child = document.createElement('div');
if (activeId == buddylist[i]) {
child.innerHTML = "[" + buddylist[i] + "]";
if (activeBuddylistEntry == buddylist[userId]) {
child.innerHTML = "[" + makeDisplayString(buddylist[userId]) + "]";
} else {
child.innerHTML = buddylist[i];
child.innerHTML = makeDisplayString(buddylist[userId]);
}
// If the user clicks on a buddy, change our current destination for messages
child.addEventListener('click', onClick.bind(this, buddylist[i], child), true);
child.addEventListener('click', onClick.bind(this, buddylist[userId], child), true);
buddylistDiv.appendChild(child);

@@ -65,3 +71,6 @@ }

window.freedom.on('recv-message', function(data) {
var message = data.from.userId + ": " + data.message;
// Show the name instead of the userId, if it's available.
var userId = data.from.userId;
var displayName = buddylist[userId].name || userId;
var message = displayName + ": " + data.message;
appendLog(document.createTextNode(message));

@@ -100,5 +109,8 @@ });

appendLog(document.createTextNode("You: " + text));
window.freedom.emit('send-message', {to: activeId, message: text});
window.freedom.emit('send-message',
{to: activeBuddylistEntry.userId, message: text});
}
};
freedom.emit('boot');
};

@@ -5,4 +5,6 @@ {

"app": {
"script": "counter.js"
"script": "counter.js",
"index": "index.html",
"static": [ "style.css" ]
}
}

@@ -12,6 +12,11 @@ /**

// FreeDOM APIs
var core = freedom.core();
var social = freedom.socialprovider();
var socialProviders = [ freedom.socialprovider ];
var transportProviders = [ freedom.transport ];
var social = new SocialTransport(socialProviders, transportProviders);
var storage = freedom.storageprovider();
// Actors
var fileServer = new FileServer(social);
var fileFetcher = new FileFetcher(social);
// Internal State

@@ -21,98 +26,19 @@ var myClientState = null;

var clientList = {};
var files = {}; // Files served from this node
var fetchQueue = []; // Files on queue to be downloaded
// PC
var connections = {};
var signallingChannels = {};
console.log('File Drop root module');
function updateStats(key, inprogress, done) {
if (!files[key].stats.hasOwnProperty('inprogress')) {
files[key].stats.inprogress = 0;
}
if (!files[key].stats.hasOwnProperty('done')) {
files[key].stats.done = 0;
}
files[key].stats.key = key;
files[key].stats.inprogress += inprogress;
files[key].stats.done += done;
freedom.emit('stats', files[key].stats);
}
freedom.on('serve-data', function(data) {
if (!data.key || !data.value) {
console.log('serve-data: malformed request ' + JSON.stringify(data));
return;
}
console.log('serve-data: now serving ' + data.key);
files[data.key] = {
data: data.value,
stats: {}
};
if (myClientState.status == social.STATUS["ONLINE"]) {
freedom.emit('serve-descriptor', {
targetId: myClientState.clientId,
key: data.key,
name: data.name
});
} else {
freedom.emit('serve-error', "Error connecting to server.");
}
updateStats(data.key, 0, 0);
fileServer.serve(myClientState, data.key, data.value, data.name);
});
function setupConnection(name, targetId, key) {
connections[targetId] = freedom.transport();
connections[targetId].on('onData', function(message) {
console.log("Receiving data with tag: " + message.tag);
social.sendMessage(targetId, JSON.stringify({
cmd: 'done',
data: key
}));
freedom.emit('download-data', message.data);
});
return core.createChannel().then(function (chan) {
// Set up the signalling channel first, it may be needed in the
// peerconnection setup.
chan.channel.on('message', function(msg) {
social.sendMessage(targetId, JSON.stringify({
cmd: 'signal',
data: msg
}));
});
signallingChannels[targetId] = chan.channel;
return connections[targetId].setup(name, chan.identifier);
});
}
function fetch(data) {
//@todo smarter way to choose a target in the future
var serverId = data.targetId;
var key = data.key;
console.log("fetch: downloading " + key + " from " + serverId);
//Tell 'em I'm comin' for them
social.sendMessage(serverId, JSON.stringify({
cmd: 'fetch',
data: key
}));
setupConnection("fetcher", serverId, key);
}
freedom.on('download', function(data) {
if (myClientState !== null &&
myClientState.status == social.STATUS["ONLINE"]) {
fetch(data);
} else {
fetchQueue.push(data);
}
freedom.on('download', function(downloadDesc) {
fileFetcher.download(downloadDesc);
});
social.on('onUserProfile', function(data) {
userList[data.userId] = data;
social.on('onUserProfile', function(val) {
userList[val.userId] = val;
});
social.on('onClientState', function(data) {
console.log('onClientState:' + JSON.stringify(data));
clientList[data.clientId] = data;

@@ -123,54 +49,11 @@ if (myClientState !== null &&

}
fileFetcher.onClientState(data);
});
social.on('onMessage', function(data) {
var msg;
var targetId;
var key;
// Try parsing message
try {
msg = JSON.parse(data.message);
} catch (e) {
console.log("Error parsing message: " + data);
return;
}
if (data.from.clientId && msg.cmd && msg.data && msg.cmd == 'fetch') {
key = msg.data;
targetId = data.from.clientId;
updateStats(key, 1, 0);
console.log("social.onMessage: Received request for " + key + " from " + targetId);
setupConnection("server-"+targetId, targetId).then(function(){ //SEND IT
if (files[key] && files[key].data) {
console.log("social.onMessage: Sending " + key + " to " + targetId);
connections[targetId].send('filedrop', files[key].data);
} else {
console.log("social.onMessage: I don't have key: " + key);
social.sendMessage(targetId, JSON.stringify({
cmd: 'error',
data: 'File missing!'
}));
}
});
} else if (data.from.clientId && msg.cmd && msg.data && msg.cmd == 'done') {
key = msg.data;
updateStats(key, -1, 1);
} else if (data.from.clientId && msg.cmd && msg.data && msg.cmd == 'signal') {
console.log('social.onMessage: signalling message');
targetId = data.from.clientId;
if (signallingChannels[targetId]) {
signallingChannels[targetId].emit('message', msg.data);
} else {
//DEBUG
console.error("Signalling channel missing!!");
}
} else if (data.from.clientId && msg.cmd && msg.data && msg.cmd == 'error') {
console.log('social.onMessage: ' + msg.data);
freedom.emit('download-error', msg.data);
social.on('onMessage', function(val) {
if (val.tag == 'f2s') {
fileServer.onMessage(val);
} else {
console.log("social.onMessage: Unrecognized message: " + JSON.stringify(data));
fileFetcher.onMessage(val);
}
});

@@ -189,7 +72,5 @@

if (ret.status == social.STATUS["ONLINE"]) {
console.log('social.onStatus: ONLINE!');
while (fetchQueue.length > 0) {
fetch(fetchQueue.shift());
}
console.log('social.login: ONLINE!');
} else {
console.log('social.login: ERROR!');
freedom.emit("serve-error", "Failed logging in. Status: "+ret.status);

@@ -196,0 +77,0 @@ }

@@ -21,2 +21,6 @@ // After loading freedom.js, the window is populated with a 'freedom'

$("#dropUrl").val(val);
$("#dropUrl").click(function() {
$(this).select();
});
$("#dropUrl").click();
},

@@ -96,3 +100,3 @@ displayDownload: function() {

onFile: function(e) {
console.log(e);
//console.log(e);
e = e || window.event; // get window.event if e argument missing (in IE)

@@ -99,0 +103,0 @@ if (e.preventDefault) { e.preventDefault(); } // stops the browser from redirecting off to the image.

@@ -5,7 +5,9 @@ {

"app": {
"script": "main.js"
"script": "main.js",
"index": "index.html",
"static": [ "style.css" ]
},
"dependencies": {
"localstorage": {
"url": "../../providers/storage/isolated/storage.isolated.json",
"url": "../../providers/storage/shared/storage.shared.json",
"api": "storage"

@@ -12,0 +14,0 @@ }

@@ -133,3 +133,9 @@ /**

single: { singleRun: true, autoWatch: false },
watch: { singleRun: false, autoWatch: true },
watch: {
singleRun: false,
autoWatch: true,
reporters: ['progress', 'story'],
preprocessors: {},
coverageReporter: {}
},
phantom: {

@@ -136,0 +142,0 @@ exclude: unGlob(FILES.srcJasmineHelper).exclude.concat(

@@ -65,2 +65,4 @@ /*globals fdom:true */

'OFFLINE': 'User is currently offline',
// Improper parameters
'MALFORMEDPARAMETERS': 'Parameters are malformed',

@@ -67,0 +69,0 @@ /** LOGIN **/

@@ -24,2 +24,16 @@ /*globals fdom:true */

/**
* error codes and default messages that may be returned on failures.
*/
'ERRCODE': {type: 'constant', value: {
/** GENERAL **/
'SUCCESS': 'Success!',
// Unknown
'UNKNOWN': 'Unknown error',
// Database not ready
'OFFLINE': 'Database not reachable',
// Improper parameters
'MALFORMEDPARAMETERS': 'Parameters are malformed'
}},
/**

@@ -26,0 +40,0 @@ * Create a storage provider.

{
"name": "freedom",
"description": "Embracing a distributed web",
"version": "0.5.2",
"homepage": "http://freedomjs.com",
"version": "0.5.3",
"homepage": "http://freedomjs.org",
"bugs": {

@@ -7,0 +7,0 @@ "url": "http://github.com/freedomjs/freedom/issues",

@@ -53,4 +53,5 @@ /*globals fdom, localStorage */

Storage_unprivileged.prototype.set = function (key, value, continuation) {
var ret = localStorage.getItem(key);
localStorage.setItem(key, value);
continuation();
continuation(ret);
};

@@ -64,4 +65,5 @@

Storage_unprivileged.prototype.remove = function (key, continuation) {
var ret = localStorage.getItem(key);
localStorage.removeItem(key);
continuation();
continuation(ret);
};

@@ -68,0 +70,0 @@

@@ -1,2 +0,2 @@

/*globals freedom:true, fdom, WebSocket, console*/
/*globals freedom:true, fdom, WebSocket, console, require*/
/*jslint sloppy:true*/

@@ -13,3 +13,12 @@

var WS = function (module, dispatchEvent, url, protocols, socket) {
var WSImplementation = socket || WebSocket;
var WSImplementation = null;
if (typeof socket !== 'undefined') {
WSImplementation = socket;
} else if (typeof WebSocket !== 'undefined') {
WSImplementation = WebSocket;
} else if (typeof require !== 'undefined') {
WSImplementation = require('ws');
} else {
console.error('Platform does not support WebSocket');
}

@@ -107,5 +116,5 @@ this.dispatchEvent = dispatchEvent;

var data = {};
if (event.data instanceof ArrayBuffer) {
if (typeof ArrayBuffer !== 'undefined' && event.data instanceof ArrayBuffer) {
data.buffer = data;
} else if (event.data instanceof Blob) {
} else if (typeof Blob !== 'undefined' && event.data instanceof Blob) {
data.binary = data;

@@ -112,0 +121,0 @@ } else if (typeof event.data === 'string') {

@@ -23,3 +23,3 @@ /*globals freedom:true, location */

}
this.flushQueue();
this._flushQueue();
}.bind(this));

@@ -30,3 +30,3 @@ }

if (this.magic === "") {
this.pushQueue("keys", null, null, continuation);
this._pushQueue("keys", null, null, continuation);
return;

@@ -40,4 +40,4 @@ }

for (i = 0; i < val.length; i += 1) {
if (this.isMyKey(val[i])) {
result.push(this.fromStoredKey(val[i]));
if (this._isMyKey(val[i])) {
result.push(this._fromStoredKey(val[i]));
}

@@ -51,7 +51,7 @@ }

if (this.magic === "") {
this.pushQueue("get", key, null, continuation);
this._pushQueue("get", key, null, continuation);
return;
}
var promise = this.store.get(this.toStoredKey(key));
var promise = this.store.get(this._toStoredKey(key));
promise.then(continuation);

@@ -62,7 +62,7 @@ };

if (this.magic === "") {
this.pushQueue("set", key, value, continuation);
this._pushQueue("set", key, value, continuation);
return;
}
var promise = this.store.set(this.toStoredKey(key), value);
var promise = this.store.set(this._toStoredKey(key), value);
promise.then(continuation);

@@ -73,7 +73,7 @@ };

if (this.magic === "") {
this.pushQueue("remove", key, null, continuation);
this._pushQueue("remove", key, null, continuation);
return;
}
var promise = this.store.remove(this.toStoredKey(key));
var promise = this.store.remove(this._toStoredKey(key));
promise.then(continuation);

@@ -87,3 +87,3 @@ };

for (i = 0; i < keys.length; i += 1) {
if (this.isMyKey(keys[i])) {
if (this._isMyKey(keys[i])) {
this.store.remove(keys[i]);

@@ -98,3 +98,3 @@ }

//Insert call into queue
IsolatedStorageProvider.prototype.pushQueue = function(method, key, value, continuation) {
IsolatedStorageProvider.prototype._pushQueue = function(method, key, value, continuation) {
this.queue.push({

@@ -109,3 +109,3 @@ cmd: method,

//Flush commands in queue
IsolatedStorageProvider.prototype.flushQueue = function() {
IsolatedStorageProvider.prototype._flushQueue = function() {
var i, elt;

@@ -122,2 +122,4 @@ for (i = 0; i < this.queue.length; i += 1) {

this.remove(elt.key, elt.cont);
} else if (elt.cmd === "clear") {
this.clear(elt.cont);
} else {

@@ -133,3 +135,3 @@ console.error("Isolated Storage: unrecognized command " + JSON.stringify(elt));

// e.g. 'keyA' => 'partition1+keyA'
IsolatedStorageProvider.prototype.toStoredKey = function(key) {
IsolatedStorageProvider.prototype._toStoredKey = function(key) {
return (this.magic + key);

@@ -140,3 +142,3 @@ };

// e.g. 'partition1+keyA' => 'keyA'
IsolatedStorageProvider.prototype.fromStoredKey = function(key) {
IsolatedStorageProvider.prototype._fromStoredKey = function(key) {
return key.substr(this.magic.length);

@@ -146,3 +148,3 @@ };

// Check if this stored key is in my partition
IsolatedStorageProvider.prototype.isMyKey = function(storedKey) {
IsolatedStorageProvider.prototype._isMyKey = function(storedKey) {
return (storedKey.substr(0, this.magic.length) === this.magic);

@@ -149,0 +151,0 @@ };

@@ -1,2 +0,4 @@

describe("integration: storage.isolated.json", STORAGE_INTEGRATION_SPEC.bind(this, "/providers/storage/isolated/storage.isolated.json"));
describe("integration: storage.shared.json", STORAGE_INTEGRATION_SPEC.bind(this, "/providers/storage/shared/storage.shared.json"));
describe("integration: storage.isolated.json", STORAGE_INTEGRATION_SPEC.bind(this, "/providers/storage/isolated/storage.isolated.json", false));
describe("integration: storage.shared.json", STORAGE_INTEGRATION_SPEC.bind(this, "/providers/storage/shared/storage.shared.json", false));
describe("integration: storage.indexeddb.json", STORAGE_INTEGRATION_SPEC.bind(this, "/providers/storage/indexeddb/storage.indexeddb.json", false));
describe("integration: storebuffer.indexeddb.json", STORAGE_INTEGRATION_SPEC.bind(this, "/providers/storage/indexeddb/storebuffer.indexeddb.json", true));

@@ -1,6 +0,33 @@

var STORAGE_INTEGRATION_SPEC = function(provider_url) {
var STORAGE_INTEGRATION_SPEC = function(provider_url, useArrayBuffer) {
var helper;
function beforeSet(str) {
if (typeof useArrayBuffer == 'undefined' || useArrayBuffer == false) {
return str;
} else {
var buf = new ArrayBuffer(str.length*2); // 2 bytes for each char
var bufView = new Uint16Array(buf);
for (var i=0, strLen=str.length; i<strLen; i++) {
bufView[i] = str.charCodeAt(i);
}
return buf;
}
}
function afterGet(val) {
if (val == null) {
return null;
} else if (typeof useArrayBuffer == 'undefined' || useArrayBuffer == false) {
return val;
} else {
return String.fromCharCode.apply(null, new Uint16Array(val));
}
}
beforeEach(function(done) {
helper = providerFor(provider_url, "storage")
if (typeof useArrayBuffer == 'undefined' || useArrayBuffer == false) {
helper = providerFor(provider_url, "storage")
} else {
helper = providerFor(provider_url, "storebuffer")
}
helper.create("s");

@@ -14,3 +41,3 @@ helper.call("s", "clear", [], done);

});
it("sets and gets keys", function(done) {

@@ -21,8 +48,21 @@ var callbackOne = function(ret) {

var callbackTwo = function(ret) {
expect(ret).toEqual("myvalue");
expect(afterGet(ret)).toEqual("myvalue");
helper.call("s", "clear", [], done);
};
helper.call("s", "set", ["key", "myvalue"], callbackOne);
helper.call("s", "set", ["key", beforeSet("myvalue")], callbackOne);
});
it("set returns old value", function(done) {
var callbackOne = function(ret) {
expect(afterGet(ret)).toEqual(null);
helper.call("s", "set", ["key", beforeSet("value2")], callbackTwo);
};
var callbackTwo = function(ret) {
expect(afterGet(ret)).toEqual("value1");
helper.call("s", "clear", [], done);
};
helper.call("s", "set", ["key", beforeSet("value1")], callbackOne);
});
it("removes a key", function(done) {

@@ -33,2 +73,3 @@ var callbackOne = function(ret) {

var callbackTwo = function(ret) {
expect(afterGet(ret)).toEqual("myvalue");
helper.call("s", "keys", [], callbackThree);

@@ -40,3 +81,3 @@ };

};
helper.call("s", "set", ["key", "myvalue"], callbackOne);
helper.call("s", "set", ["key", beforeSet("myvalue")], callbackOne);
});

@@ -46,3 +87,3 @@

var callbackOne = function(ret) {
helper.call("s", "set", ["k2", "v2"], callbackTwo);
helper.call("s", "set", ["k2", beforeSet("v2")], callbackTwo);
};

@@ -58,3 +99,3 @@ var callbackTwo = function(ret) {

};
helper.call("s", "set", ["k1", "v1"], callbackOne);
helper.call("s", "set", ["k1", beforeSet("v1")], callbackOne);
});

@@ -73,6 +114,7 @@

};
helper.call("s", "set", ["key", "value"], callbackOne);
helper.call("s", "set", ["key", beforeSet("value")], callbackOne);
});
it("shares data between different instances", function(done) {
//@todo - not sure if this is even desired behavior
xit("shares data between different instances", function(done) {
var callbackOne = function(ret) {

@@ -82,3 +124,3 @@ helper.call("s2", "get", ["key"], callbackTwo);

var callbackTwo = function(ret) {
expect(ret).toEqual("value");
expect(afterGet(ret)).toEqual("value");
helper.call("s", "clear", [], callbackThree);

@@ -90,5 +132,5 @@ };

helper.create("s2");
helper.call("s", "set", ["key", "value"], callbackOne);
helper.call("s", "set", ["key", beforeSet("value")], callbackOne);
});
};

@@ -388,4 +388,4 @@ /*globals fdom:true, Promise */

fdom.debug.error("If the stack trace is not useful, see https://" +
"github.com/UWNetworksLab/freedom/wiki/Debugging-Script-Parse-Errors");
"github.com/freedomjs/freedom/wiki/Debugging-Script-Parse-Errors");
});
};

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc