Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Peering #121

Open
wants to merge 32 commits into
base: polymer-identity
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
fcadd84
Begin to add the peer manager
martindale Mar 5, 2016
fde4afd
Import peer.js for basic implementation.
martindale Mar 5, 2016
63cd9e2
Add peerJS to the package file.
martindale Mar 5, 2016
2864d4b
Add support for populate on `create`.
martindale Mar 6, 2016
0aa9c92
Add some changes for peering.
martindale Mar 14, 2016
2ca65eb
Make single component URLs function correctly for deployed applications.
martindale Mar 14, 2016
4d62f16
Switch to `async` for most component scripts.
martindale Mar 16, 2016
b1fa022
Add new `step-ladder` component for onboarding to identity.
martindale Mar 16, 2016
89b54f9
Patch _register.
martindale Mar 22, 2016
0d130ad
Merge branch 'polymer' into peering
martindale Mar 28, 2016
dd98eec
Implement better flow for identity manager.
martindale Mar 28, 2016
073512e
Improve logout flow.
martindale Mar 28, 2016
39e55a7
Always fall back to server.
martindale Mar 29, 2016
eff184e
Always use PUT instead of POST.
martindale Mar 29, 2016
4424373
Improve code for channel, step-ladder.
martindale Mar 29, 2016
c0f9ede
Switch to POST instead of PUT.
martindale Mar 31, 2016
67dce68
Add jQuery to top-level bundle.
martindale Mar 31, 2016
2fabbb1
Update to latest jQuery.
martindale Apr 1, 2016
5443cb7
Remove jQuery from bundler.
martindale Apr 1, 2016
453ef61
Add project status to README
martindale May 29, 2016
ed65290
Improve the 404 page (to become default later).
martindale May 29, 2016
821f2d7
Add better sorting to the `get` method.
martindale May 29, 2016
36abd6d
Handle patches on sockets, accept resourcemap.
martindale May 29, 2016
101814c
Add browserify-shim and upgrade understcore
martindale May 29, 2016
478f7f1
Bundle most recent changes to identity creator.
martindale Jun 2, 2016
bd3225d
Disable PATCH events from websockets.
martindale Jun 3, 2016
eea92d1
Add missing async.min.js
martindale Jun 3, 2016
020156c
Add missing "resource" component.
martindale Jun 3, 2016
e609250
Add NeDB for data storage.
martindale Jun 3, 2016
86dce3b
Add the content-store.
martindale Jun 3, 2016
6d131ff
Simple key-value store.
martindale Jun 3, 2016
c99eae0
Merge pull request #124 from martindale/reconcile
martindale Sep 21, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ Maki
==============
[![Build Status](https://img.shields.io/travis/martindale/maki.svg?branch=master&style=flat-square)](https://travis-ci.org/martindale/maki)
[![Coverage Status](https://img.shields.io/coveralls/martindale/maki.svg?style=flat-square)](https://coveralls.io/r/martindale/maki)
![Project Status](https://img.shields.io/badge/status-alpha-red.svg?style=flat-square)
[![Community](https://chat.maki.io/badge.svg)](https://chat.maki.io/)

The complete stack for building extensible apps, faster than ever. Hand-roll your application by telling Maki what your application does, and it takes care of the rest – without getting in your way if you want to customize it.
Expand Down
13 changes: 11 additions & 2 deletions components/404.jade
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
dom-module#maki-undefined
template
.ui.container
h1 Not Found
.ui.text.container
h1 Nothing known.
p We're sorry, but we don't know anything about that. Here are some alternative resources you might be interested in.

.ui.horizontal.segments
.ui.segment
p One
.ui.segment
p Two
.ui.segment
p Two
script.
Polymer({
is: 'maki-undefined'
Expand Down
4 changes: 2 additions & 2 deletions components/application.jade
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ dom-module#maki-application
i.icon.medium
| Medium

script(src="/js/page.min.js")
script(src="/js/jquery.js")
script(src="/js/page.min.js", async)
script(src="/js/jquery.js", async)
script.
window.maki = Polymer({
is: 'maki-application',
Expand Down
104 changes: 59 additions & 45 deletions components/channel.jade
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
dom-module#maki-channel
script(src="/js/uuid.js")
script(src="/js/jsonrpc.js")
script(src="/js/uuid.js", async)
script(src="/js/jsonrpc.js", async)
script.
Polymer({
is: 'maki-channel',
properties: {
namespace: {
type: String
},
autoconnect: {
type: Boolean
},
Expand All @@ -21,13 +24,6 @@ dom-module#maki-channel
type: String
},
},
ready: function() {
var self = this;
console.log('[MAKI:CHANNEL]', 'ready');
if (self.autoconnect === true) {
self._connect();
}
},
_send: function(method, params) {
var self = this;
self.ws.send(JSON.stringify({
Expand Down Expand Up @@ -55,9 +51,54 @@ dom-module#maki-channel
self._subscribe(element.src);
}
},
_handleMessage: function(msg) {
var self = this;
console.log('[MAKI:CHANNEL]', '_handleMessage', msg);

try {
var data = JSON.parse( msg.data );
} catch (e) {
var data = {};
}

console.log('[MAKI:CHANNEL]', '_handleMessage', 'resulting data:', data);

// experimental JSON-RPC implementation
if (data.jsonrpc === '2.0') {
console.log('[MAKI:CHANNEL]', '_handleMessage', 'valid jsonrpc!');

switch (data.method) {
case 'ping':
console.log('[MAKI:CHANNEL]', 'received ping. playing pong...');
self.ws.send(JSON.stringify({
'jsonrpc': '2.0',
'result': 'pong',
'id': data.id
}));
break;
case 'patch':
// TODO: update in-memory data (two-way binding);
console.log('[MAKI:CHANNEL]', 'received `patch` event:', data.params.channel , data );
var channel = data.params.channel;
var ops = data.params.ops;
var datastore = document.querySelector('maki-datastore[name='+self.namespace+']');
var manager = document.querySelector('maki-peer-manager');

datastore._patch(channel, ops);
manager._relay(data);

break;
default:
console.error('[MAKI:CHANNEL]', 'unhandled jsonrpc method ' , data.method);
break;
}
} else {

}
},
_connect: function() {
var self = this;
var maki = document.querySelectorAll('maki-application')[0];
var maki = document.querySelector('maki-application');
var protocol = (document.location.protocol === 'http:') ? 'ws://' : 'wss://';
var path = protocol + document.location.host; // + self.src;

Expand All @@ -71,43 +112,16 @@ dom-module#maki-channel
}, 500);
}
}
self.ws.onmessage = function onMessage(msg) {
try {
var data = JSON.parse( msg.data );
} catch (e) {
var data = {};
}
// experimental JSON-RPC implementation
if (data.jsonrpc === '2.0') {
switch (data.method) {
case 'ping':
console.log('[MAKI:CHANNEL]', 'received ping. playing pong...');
self.ws.send(JSON.stringify({
'jsonrpc': '2.0',
'result': 'pong',
'id': data.id
}));
break;
case 'patch':
// TODO: update in-memory data (two-way binding);
console.log('[MAKI:CHANNEL]', 'received `patch` event:', data.params.channel , data );
var channel = data.params.channel;
var ops = data.params.ops;
var datastore = document.querySelectorAll('maki-datastore')[0];

datastore._patch(channel, ops);

break;
default:
console.error('[MAKI:CHANNEL]', 'unhandled jsonrpc method ' , data.method);
break;
}
} else {

}
}
self.ws.onmessage = self._handleMessage.bind(self);
self.ws.onopen = function onOpen() {
console.log('[MAKI:CHANNEL]', 'websocket open.');
}
},
ready: function() {
var self = this;
console.log('[MAKI:CHANNEL]', 'ready');
if (self.autoconnect === true) {
self._connect();
}
},
});
25 changes: 25 additions & 0 deletions components/content-store.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
dom-module#maki-content-store
template
maki-crypto-worker
//- TODO: replace this with maki-peer-manager
maki-key-value(name="fabric")
script.
Polymer({
is: 'maki-content-store',
_get: function(key, cb) {
var db = document.querySelector('maki-key-value[name=fabric]');
db._retrieve(key, cb);
},
_store: function(doc, cb) {
var db = document.querySelector('maki-key-value[name=fabric]');
var worker = document.querySelector('maki-crypto-worker');
if (typeof doc !== 'string') {
doc = JSON.stringify(doc);
}
worker._digest(doc, function(err, hash) {
db._store(hash, doc, function(err) {
cb(err, hash);
});
});
}
});
Loading