Comparing version 0.0.0 to 0.0.1
@@ -5,4 +5,4 @@ import bs from 'brisky-stamp' | ||
import { parse, subscribe } from 'brisky-struct' | ||
import { serialize } from '../subscription' | ||
import hash from 'quick-hash' | ||
import serialize from '../subscription/serialize' | ||
import hash from 'string-hash' | ||
@@ -13,4 +13,3 @@ const connect = (hub, url, reconnect) => { | ||
hub.set({ clients: { [id]: { id: id } } }, false) | ||
hub.set({ clients: { [id]: { } } }, false) | ||
const client = hub.clients[id] | ||
@@ -22,2 +21,3 @@ hub.set({ client }, false) | ||
const stamp = bs.create('disconnect', hub.id) | ||
hub.socket = false | ||
hub.set({ connected: false }, stamp) | ||
@@ -43,2 +43,3 @@ bs.close() | ||
const stamp = bs.create('connected', hub.id) | ||
hub.socket = socket | ||
meta(hub) | ||
@@ -51,29 +52,49 @@ hub.set({ connected: true }, stamp) | ||
const stamp = bs.create('upstream') | ||
console.warn(JSON.parse(data), stamp, ((encodeURI(data).split(/%..|./).length - 1) / 1e3).toFixed(2) + 'kb') | ||
// console.log(`\n🌚 receive on ${hub.id} from ${hub.url} -->`, stamp, ((encodeURI(data).split(/%..|./).length - 1) / 1e3).toFixed(2) + 'kb 🌚') | ||
// console.log(' ', JSON.stringify(JSON.parse(data), false, 2)) | ||
hub.set(JSON.parse(data), stamp) | ||
bs.close(stamp) | ||
// console.log('🌚 done 🌚\n') | ||
} | ||
} | ||
hub.socket = socket | ||
const removeUrl = hub => { | ||
hub.url = null | ||
hub.urlIndex = null | ||
hub.emitters.set({ data: { url$: null } }) | ||
} | ||
const removeSocket = hub => { | ||
if (hub.socket) { | ||
if (hub.reconnect) { | ||
clearTimeout(hub.reconnect) | ||
hub.reconnect = null | ||
} | ||
hub.socket.blockReconnect = true | ||
hub.socket.close() | ||
} | ||
} | ||
const url = (hub, val, stamp) => { | ||
hub.on((val, stamp, t) => { | ||
if (val === null && !t.context && t === hub) { | ||
// console.log('☠️ REMOVE CLIENT ☠️') | ||
removeUrl(hub) | ||
removeSocket(hub) | ||
} | ||
}, 'url$') | ||
if (!val) val = null | ||
if (val !== hub.url) { | ||
if (hub.socket) { | ||
if (hub.reconnect) { | ||
clearTimeout(hub.reconnect) | ||
hub.reconnect = null | ||
} | ||
hub.socket.blockReconnect = true | ||
hub.socket.close() | ||
removeSocket(hub) | ||
hub.set({ connected: false }, stamp) | ||
if (!val) { | ||
removeUrl(hub) | ||
} else { | ||
let i = -1 | ||
if (hub.key) i++ | ||
hub.parent(() => { i++ }) | ||
hub.urlIndex = i | ||
hub.url = val | ||
connect(hub, val, 50) | ||
} | ||
if (val === null) { | ||
// remove all props spwaned from this one | ||
} | ||
let i = -1 | ||
hub.parent(() => { i++ }) | ||
hub.urlIndex = i | ||
hub.url = val | ||
hub.set({ connected: false }, stamp) | ||
connect(hub, val, 50) | ||
} | ||
@@ -110,4 +131,4 @@ } | ||
if (hub.connected && hub.connected.compute() === true) { | ||
console.log('ai need to re-send some stuff') | ||
console.log('this will tigh in to sendMeta') | ||
// console.log('ai need to re-send some stuff') | ||
// console.log('this will tigh in to sendMeta') | ||
meta(hub) | ||
@@ -123,2 +144,3 @@ } | ||
upstreamSubscriptions: true, | ||
receiveOnly: true, | ||
url, | ||
@@ -129,3 +151,2 @@ context, | ||
// subscribe -- add unsubscribe later | ||
const stub = () => {} | ||
@@ -135,18 +156,13 @@ | ||
subscribe (subs, cb, raw, tree) { | ||
if (!raw) { | ||
subs = parse(subs) | ||
console.log('lullz?') | ||
} | ||
if (this.url) { | ||
const parsed = serialize(this, subs) | ||
if (parsed) { | ||
const key = hash(JSON.stringify(parsed)) | ||
// why not just add them to client... so much easier | ||
if (!this.upstreamSubscriptions) { | ||
this.upstreamSubscriptions = { [key]: parsed } | ||
meta(this) | ||
} else if (!this.upstreamSubscriptions[key]) { | ||
this.upstreamSubscriptions[key] = parsed | ||
meta(this) | ||
} | ||
if (!raw) subs = parse(subs) | ||
const parsed = serialize(this, subs) | ||
if (parsed) { | ||
const key = hash(JSON.stringify(parsed)) | ||
// why not just add them to client... so much easier | ||
if (!this.upstreamSubscriptions) { | ||
this.upstreamSubscriptions = { [key]: parsed } | ||
if (this.url) meta(this) | ||
} else if (!this.upstreamSubscriptions[key]) { | ||
this.upstreamSubscriptions[key] = parsed | ||
if (this.url) meta(this) | ||
} | ||
@@ -153,0 +169,0 @@ } |
@@ -7,6 +7,13 @@ import bs from 'brisky-stamp' | ||
const parse = (stamp, id) => { | ||
if (!isNaN(Number(bs.val(stamp)))) { | ||
return bs.create(bs.type(stamp), id, bs.val(stamp), true) | ||
const parse = (stamp, hub, t) => { | ||
const src = bs.src(stamp) | ||
if (!src) { | ||
return bs.create(bs.type(stamp), hub.id, bs.val(stamp)) | ||
} else { | ||
const val = bs.val(stamp) | ||
if (!t[1]) t[1] = {} | ||
const meta = t[1] | ||
if (!meta.resolve) meta.resolve = {} | ||
const resolve = meta.resolve[src] | ||
if (!resolve || val < resolve) meta.resolve[src] = val | ||
return stamp | ||
@@ -16,3 +23,3 @@ } | ||
const serialize = (id, t, struct, val, level) => { | ||
const serialize = (hub, t, struct, val, level) => { | ||
const path = struct.path() | ||
@@ -22,4 +29,4 @@ const len = path.length | ||
if (struct.val !== void 0 || val === null) { | ||
const stamp = parse(struct.stamp, id) | ||
var s = t[0] || (t[0] = {}) | ||
for (let i = level; i < len; i++) { | ||
@@ -37,3 +44,3 @@ let t = s[path[i]] | ||
s.stamp = stamp | ||
s.stamp = parse(struct.stamp, hub, t) | ||
@@ -50,3 +57,3 @@ if (val === null) { | ||
s.val.unshift('@', 'root') | ||
send(id, t, struct.val) | ||
serialize(hub, t, struct.val, val, level) | ||
} else if (struct.val !== void 0) { | ||
@@ -59,29 +66,45 @@ s.val = struct.val | ||
const meta = hub => { | ||
const store = inProgress(hub, next) | ||
store[1] = { | ||
context: hub.clientContext, | ||
id: hub.id, | ||
subscriptions: hub.upstreamSubscriptions | ||
} | ||
const store = inProgress(hub, bs.inProgress ? bs.on : next) | ||
if (!store[1]) store[1] = {} | ||
store[1].context = hub.clientContext | ||
store[1].id = hub.id | ||
store[1].subscriptions = hub.upstreamSubscriptions | ||
} | ||
const send = (val, stamp, struct) => { | ||
const hub = struct.parent(hub => hub.url && hub) | ||
if (hub && bs.type(stamp) !== 'upstream') { | ||
serialize(hub.id, inProgress(hub, bs.on), struct, val, hub.urlIndex) | ||
if (bs.type(stamp) !== 'upstream') { | ||
let hub | ||
let p = struct | ||
while (p) { | ||
if (p.url && !p.context) { hub = p } | ||
p = p.parent() // needs to walk over context (for multi server) | ||
} | ||
if (hub && !hub.receiveOnly && struct.key !== 'clients') { | ||
// console.log('✍️ go send --->', hub.id, struct.path(), '✍️', val) | ||
if (struct === hub) { | ||
if (val === null) { | ||
return | ||
} | ||
} else if (struct._p.key === 'clients') { | ||
if (struct.key !== hub.id) { | ||
return | ||
} | ||
} | ||
serialize(hub, inProgress(hub, bs.on), struct, val, hub.urlIndex) | ||
} | ||
} | ||
} | ||
const inProgress = (t, tick) => { | ||
if (!t.inProgress) { | ||
t.inProgress = [] | ||
const inProgress = (hub, tick) => { | ||
if (!hub.inProgress) { | ||
hub.inProgress = [] | ||
tick(() => { | ||
if (t.connected.compute() === true) { | ||
out(t) | ||
if (hub.connected.compute() === true) { | ||
out(hub) | ||
} else { | ||
t.connected.once(true, () => out(t)) | ||
hub.connected.once(true, () => out(hub)) | ||
} | ||
}) | ||
} | ||
return t.inProgress | ||
return hub.inProgress | ||
} | ||
@@ -88,0 +111,0 @@ |
@@ -6,3 +6,7 @@ // import { struct } from 'brisky-struct' | ||
props: { | ||
cache: true, | ||
upstreamSubscriptions: true, | ||
// isUpstream: true, | ||
// myupstream subs | ||
resolve: true, | ||
socket: true // only nessecary for downstream clients | ||
@@ -14,3 +18,2 @@ } | ||
clients: { // need to exclude on context | ||
type: 'struct', | ||
props: { | ||
@@ -17,0 +20,0 @@ default: clientHub |
@@ -9,2 +9,3 @@ import id from './uid' | ||
const hub = create({ | ||
type: 'hub', | ||
types: { hub: 'self' }, | ||
@@ -11,0 +12,0 @@ props: { |
@@ -1,2 +0,2 @@ | ||
import { parse } from '../subscription' | ||
import parse from '../subscription/parse' | ||
import { subscribe } from 'brisky-struct' | ||
@@ -11,9 +11,14 @@ import bs from 'brisky-stamp' | ||
var t | ||
if (meta) { | ||
console.log(' \n meta time') | ||
if (client) { | ||
console.log('perhaps replace something (e.g. subs or whatever') | ||
t = hub | ||
// switch etc | ||
if (meta.subscriptions) { | ||
incomingSubscriptions(t, client, meta, client.id) | ||
bs.close() | ||
} | ||
// console.log('perhaps replace something (e.g. subs or whatever') | ||
} else { | ||
t = create(hub, socket, meta) | ||
client = socket.client | ||
} | ||
@@ -23,11 +28,16 @@ } else { | ||
} | ||
// need to handle .stamp in the data... | ||
if (payload) { | ||
console.log('\n👾👾👾👾 in 👾👾👾👾') | ||
var d = Date.now() | ||
// console.log(`\n👾👾👾👾👾 in ${hub.id} 👾👾👾👾👾`) | ||
// console.log(JSON.stringify(payload, false, 2)) | ||
// if you have your own upstream you instan send this upstream as well -- not enough -- need to know more like | ||
t.set(payload, false) | ||
// var d = Date.now() | ||
if (meta && meta.resolve) { | ||
client.resolve = meta.resolve | ||
t.set(payload, false) | ||
bs.on(() => { client.resolve = false }) | ||
} else { | ||
t.set(payload, false) | ||
} | ||
bs.close() | ||
console.log(`👾👾👾👾 ${Date.now() - d} ms 👾👾👾👾`) | ||
// console.log(`👾👾👾👾👾 ${Date.now() - d} ms 👾👾👾👾👾`) | ||
} | ||
@@ -38,12 +48,11 @@ } | ||
const stamp = bs.create('connect') | ||
console.log('create client') | ||
const id = meta.id | ||
// console.log(`\n🐠 create client "${id}" on "${hub.id}" 🐠`) | ||
var t | ||
if (meta.context) { | ||
console.log('got context! go do it!') | ||
// console.log('got context! go do it!') | ||
} else { | ||
t = hub // will also become secured -- default will ofc be IP | ||
} | ||
// actually pretty nice to fire this one... | ||
t.set({ clients: { [id]: { id: id, socket } } }, stamp) | ||
t.set({ clients: { [id]: { socket } } }, stamp) | ||
const client = socket.client = t.clients[id] | ||
@@ -58,3 +67,5 @@ if (meta.subscriptions) { | ||
const incomingSubscriptions = (hub, client, meta, id) => { | ||
const update = (t, type, subs, tree) => send(hub, client, t, type, subs, tree) | ||
const update = (t, type, subs, tree) => { | ||
send(hub, client, t, type, subs, tree) | ||
} | ||
@@ -70,3 +81,2 @@ if (!client.upstreamSubscriptions) { | ||
client.upstreamSubscriptions[uid] = subs | ||
subs._ = { id } | ||
subscribe(hub, subs, update) | ||
@@ -73,0 +83,0 @@ // can also just add the function to the map |
@@ -1,5 +0,7 @@ | ||
import { Server } from 'uws' | ||
import uws from 'uws' | ||
import incoming from './incoming' | ||
import bs from 'brisky-stamp' | ||
const Server = uws.Server | ||
const create = (hub, port) => { | ||
@@ -17,11 +19,7 @@ const server = new Server({ port }) | ||
const stamp = bs.create('disconnect') | ||
const id = client.id | ||
// need to do more ofcourse... | ||
// make upstream and downstream client so listeners are shared | ||
console.log('CLIENT DC - REMOVE SUBSCRIPTION') | ||
console.log('CLIENT DC - MAYBE REMOVE THE CLIENT CONTEXT') | ||
const id = client.key | ||
console.log(`CLIENT DC ${hub.id} - REMOVE THE CLIENT CONTEXT (missing)`) | ||
const t = client.parent(2) | ||
let i = t.subscriptions ? t.subscriptions.length : 0 | ||
while (i--) { | ||
console.log(t.subscriptions[i].id) | ||
while (i--) { // clean this up with system in struct | ||
if (t.subscriptions[i].id === id) { | ||
@@ -37,3 +35,4 @@ t.subscriptions.splice(i, 1) | ||
socket.on('close', close) | ||
// socket.on('error', () => close()) | ||
// socket.on('error', () => close()) // need to do something here as well no leaks! | ||
}) | ||
@@ -43,11 +42,53 @@ return server | ||
const props = { | ||
server: true, | ||
port: (hub, val) => { | ||
console.log('set port!') | ||
if (val !== hub.port) { | ||
if (hub.server) { | ||
console.log('NEW SERVER KILL OLD ONE') | ||
const removeServer = hub => { | ||
const server = hub.server | ||
const instances = hub.instances | ||
closeConnections(hub) | ||
for (let i = 0, len = instances && instances.length; i < len; i++) { | ||
closeConnections(instances[i]) | ||
} | ||
server.httpServer.close() | ||
hub.server = null | ||
} | ||
const closeConnections = hub => { | ||
const clients = hub.clients | ||
const id = hub.id // to exclude the client (not nessecary) | ||
if (clients) { | ||
clients.forEach(client => { | ||
if (client.socket && client.key !== id) { | ||
client.socket.close() | ||
} | ||
}) | ||
} | ||
} | ||
const removePort = hub => { | ||
hub.port = null | ||
hub.serverIndex = null | ||
hub.emitters.set({ data: { port$: null } }) | ||
} | ||
const port = (hub, val) => { | ||
hub.on((val, stamp, t) => { | ||
if (val === null && !t.context && t === hub) { | ||
console.log('☠️ REMOVE server ☠️') | ||
removeServer(hub) | ||
removePort(hub) | ||
} | ||
}, 'port$') | ||
if (!val) val = null | ||
if (val !== hub.port) { | ||
if (hub.server) { | ||
console.log('🚀 SWITCH SERVER 🚀') | ||
removeServer(hub) | ||
} | ||
if (!val) { | ||
removePort(hub) | ||
} else { | ||
hub.port = val | ||
let i = -1 | ||
if (hub.key) i++ | ||
hub.parent(() => { i++ }) | ||
hub.serverIndex = i | ||
hub.server = create(hub, val) | ||
@@ -58,37 +99,46 @@ } | ||
export { props } | ||
const props = { | ||
server: true, | ||
serverIndex: true, | ||
port | ||
} | ||
// exports.properties = { | ||
// downstream: true, | ||
// } | ||
var removedInProgress | ||
const on = { | ||
data: { | ||
remove$: (val, stamp, struct) => { | ||
if (val === null && (!struct.context || struct.contextLevel === 1)) { | ||
// console.log('remove handler -- need to 100x double check') | ||
// if a server is there... --- this is wrong | ||
let p = struct | ||
let hub | ||
while (p) { | ||
if (p.port && !p.context) { hub = p } | ||
p = p.parent() | ||
} | ||
// exports.on = { | ||
// remove: { | ||
// port () { | ||
// if (this.port && this.hasOwnProperty('port')) { | ||
// this.port.set(null) | ||
// } | ||
// } | ||
// } | ||
// } | ||
if (hub) { | ||
const target = struct.parent() | ||
if (target) { | ||
if (!target._removed) { | ||
target._removed = [] | ||
if (!removedInProgress) { | ||
removedInProgress = [] | ||
bs.on(() => { | ||
let i = removedInProgress.length | ||
while (i--) { | ||
delete removedInProgress[i]._removed | ||
} | ||
}) | ||
} | ||
removedInProgress.push(target) | ||
} | ||
struct._p._removed.push(struct) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
// module.exports = function closeServer (hub) { | ||
// const server = hub.downstream | ||
// const instances = hub.instances | ||
// closeConnections(hub) | ||
// for (let i = 0, len = instances && instances.length; i < len; i++) { | ||
// closeConnections(instances[i]) | ||
// } | ||
// server.httpServer.close() | ||
// } | ||
// function closeConnections (hub) { | ||
// const clients = hub.clients | ||
// const id = hub.id | ||
// // 1000x double check this | ||
// clients.each((client) => { | ||
// if (client.upstream && client.upstream.compute() === id) { | ||
// client.socket.close() | ||
// } | ||
// }) | ||
// } | ||
export { props, on } |
import bs from 'brisky-stamp' | ||
import { get, getKeys } from 'brisky-struct' | ||
const progress = (client) => { | ||
if (!client.inProgress) { | ||
client.inProgress = {} | ||
bs.on(() => { | ||
var isEmpty = true | ||
for (let i in client.inProgress) { //eslint-disable-line | ||
isEmpty = false | ||
break | ||
} | ||
if (!isEmpty) { client.socket.send(JSON.stringify(client.inProgress)) } | ||
client.inProgress = false | ||
}) | ||
} | ||
return client.inProgress | ||
} | ||
const send = (hub, client, t, type, subs, tree) => { | ||
// think abotu context here | ||
const stamp = t.stamp | ||
if (stamp && bs.src(stamp) !== client.key && bs.src(t.tStamp) !== client.key) { | ||
if (!client.inProgress) { | ||
client.inProgress = {} | ||
bs.on(() => { | ||
client.socket.send(JSON.stringify(client.inProgress)) | ||
client.inProgress = false | ||
}) | ||
} | ||
// console.log(client.key, bs.src(stamp), stamp, bs.src(t.tStamp)) | ||
// console.log('\n', type, t.path()) | ||
let val = void 0 | ||
if (type === 'remove') { | ||
// console.log('REMOVE?') | ||
if (!t._p[t.key]) { | ||
// console.log('☠️ TRUE REMOVAL ☠️') | ||
val = null | ||
if (bs.src(t._p.tStamp) === client.key) { | ||
return | ||
} | ||
var val | ||
if (type === 'remove') { | ||
if (!t._p[t.key]) { | ||
val = null | ||
if (bs.src(t._p.tStamp) === client.key) { | ||
return | ||
} | ||
// console.log() | ||
} else if (type === 'update' && tree.$t !== t) { | ||
// console.log('🔬 SWITCHED 🔬') | ||
if (tree.$t && tree.$t._p && !tree.$t._p[tree.$t.key]) { | ||
// console.log('☠️ TRUE REMOVAL ☠️') | ||
serialize(hub.id, client, client.inProgress, subs, tree.$t, null, 0) | ||
} | ||
} | ||
// console.log(tree.$t && tree.$t.path(), t.path()) | ||
if (t.val !== void 0 || val === null) { | ||
serialize(hub.id, client, client.inProgress, subs, t, val, 0) | ||
} else if (type === 'update' && tree.$t !== t) { | ||
if (tree.$t && tree.$t._p && !tree.$t._p[tree.$t.key]) { | ||
serialize(hub.id, client, progress(client), subs, tree.$t, null, hub.serverIndex, tree) | ||
} | ||
} | ||
if (t.val !== void 0 || val === null || subs.val === true) { | ||
serialize(hub.id, client, progress(client), subs, t, val, hub.serverIndex, tree) | ||
} | ||
} | ||
const cache = (client, struct, stamp, level, val) => { | ||
if (!client.cache) { client.cache = {} } | ||
// console.log('CACHE IT---->', struct.path()) | ||
client.cache[struct.uid()] = stamp[0] | ||
} | ||
// const isCached = () => {} | ||
const isCached = (client, struct, stamp) => { | ||
// // console.log('CACHE:', struct.path(), client.cache, c, stamp) | ||
// if (client.cache && client.cache[struct.uid()] === stamp[0]) { | ||
// console.log('BLOCKED BY CACHE') | ||
// } | ||
return client.cache && client.cache[struct.uid()] === stamp[0] | ||
} | ||
const setStamp = (s, stamp, src, struct, id, client, level) => { | ||
cache(client, struct, stamp, level) | ||
s.stamp = !src | ||
? bs.create(bs.type(stamp), id, bs.val(stamp)) | ||
: stamp | ||
} | ||
const serialize = (id, client, t, subs, struct, val, level) => { | ||
const path = struct.path() | ||
const len = path.length | ||
const stamp = struct.stamp | ||
var s = t | ||
for (let i = level; i < len; i++) { | ||
let t = s[path[i]] | ||
if (val === null && i === len - 1) { | ||
s[path[i]] = val | ||
return | ||
} | ||
if (!t) { | ||
if (t === null) { | ||
return | ||
if (stamp && (val === null || !isCached(client, struct, stamp))) { | ||
const src = bs.src(stamp) | ||
if (src !== client.key && bs.src(t.tStamp) !== client.key) { | ||
if ( | ||
client.resolve && | ||
client.resolve[src] && | ||
bs.val(stamp) >= client.resolve[src] | ||
) { | ||
if (val !== null) { | ||
if (struct.val !== void 0) cache(client, struct, stamp, level) | ||
if (subs.val === true) { | ||
const keys = getKeys(struct) | ||
if (keys) { | ||
deepSerialize(keys, id, client, t, subs, struct, val, level) | ||
} | ||
} | ||
} | ||
} else { | ||
s = s[path[i]] = {} | ||
if (struct.val !== void 0 || val === null) { | ||
const path = struct.path() | ||
const len = path.length | ||
var s = t | ||
// var prev = t | ||
for (let i = level; i < len; i++) { | ||
// prev = s | ||
let t = s[path[i]] | ||
if (!t) { | ||
s = s[path[i]] = {} | ||
} else { | ||
s = t | ||
if (s.val === null) { | ||
return | ||
} | ||
} | ||
} | ||
if (val === null) { | ||
setStamp(s, stamp, src, struct, id, client, level, val) | ||
s.val = null | ||
} else { | ||
setStamp(s, stamp, src, struct, id, client, level) | ||
if (struct.val && struct.val.inherits) { | ||
s.val = struct.val.path() | ||
s.val.unshift('@', 'root') | ||
serialize(id, client, subs, t, struct.val, val, level) | ||
} else if (struct.val !== void 0) { | ||
s.val = struct.val | ||
} | ||
} | ||
} else if (subs.val === true) { | ||
const keys = getKeys(struct) | ||
if (keys) { | ||
deepSerialize(keys, id, client, t, subs, struct, val, level) | ||
} | ||
} | ||
} | ||
} else { | ||
s = t | ||
} | ||
} | ||
} | ||
if (typeof stamp === 'number') { | ||
s.stamp = bs.create(bs.type(stamp), id, bs.val(stamp)) | ||
} else { | ||
s.stamp = stamp | ||
const deepSerialize = (keys, id, client, t, subs, struct, val, level) => { | ||
if (keys) { | ||
for (let i = 0, len = keys.length; i < len; i++) { | ||
let prop = get(struct, keys[i]) | ||
if (get(prop, 'type') === 'hub') { | ||
serialize(id, client, t, subs, prop, val, level) | ||
} | ||
} | ||
} | ||
if (struct.val && struct.val.inherits) { | ||
s.val = struct.val.path() | ||
s.val.unshift('@', 'root') | ||
send(id, client, subs, t, struct.val, val, level) | ||
} else if (struct.val !== void 0) { | ||
s.val = struct.val | ||
} | ||
// feel really shacky /w context :/ | ||
// if (struct._removed) { | ||
// for (let i = 0, len = struct._removed.length; i < len; i++) { | ||
// let prop = struct._removed[i] | ||
// if (get(prop, 'type') === 'hub') { | ||
// serialize(id, client, t, subs, prop, null, level) | ||
// } | ||
// } | ||
// } | ||
} | ||
export default send |
@@ -24,3 +24,3 @@ const isEmpty = t => { | ||
if (i === 'client') { // && (!key || key === 'root' || key === 'parent') | ||
console.log('CLIENT NEED TO HANDLE MORE SPECIAL THEN JUST ROOT') | ||
// console.log('CLIENT NEED TO HANDLE MORE SPECIAL THEN JUST ROOT') | ||
// let id = state.id | ||
@@ -27,0 +27,0 @@ // if (!root.clients) { root.clients = {} } |
@@ -1,2 +0,2 @@ | ||
import hash from 'quick-hash' // uses murmur for collision avoidance | ||
import hash from 'string-hash' | ||
const uniq = global.navigator.userAgent + | ||
@@ -3,0 +3,0 @@ global.navigator.userLanguage + |
@@ -1,3 +0,3 @@ | ||
import hash from 'quick-hash' // uses murmur for collision avoidance | ||
import hash from 'string-hash' | ||
const uniq = process.pid | ||
export default hash(`b-${Date.now()}-${(Math.random() * 10000) | 0}-${uniq}`) |
{ | ||
"name": "hub.js", | ||
"description": "Seamless realtime communcation", | ||
"version": "0.0.0", | ||
"version": "0.0.1", | ||
"main": "dist/index.js", | ||
@@ -11,12 +11,13 @@ "module": "dist/index.es.js", | ||
"watch": "rollup -c rollup/dist.js -w & rollup -c rollup/browser.js -w", | ||
"pretest": "rollup -c rollup/test.js", | ||
"pretest": "npm run build && standard", | ||
"prepublish": "npm run build", | ||
"test": "standard && (node dist/test/index.js | tap-spec)", | ||
"wip": "rollup -c rollup/browser.js -w ", | ||
"dev": "rollup -c rollup/test.js -w & nodemon -C -w dist/test/index.js --harmony-async-await dist/test/index.js", | ||
"cover": "nyc npm test" | ||
"postinstall": "[ -d dist ] || npm run build || ( mkdir dist && yarn && npm run build )", | ||
"test": "node test/index.js", | ||
"dev": "rollup -c rollup/dist.js -w & nodemon --harmony-async-await test/index.js", | ||
"cover": "nyc npm test", | ||
"travis": "nyc npm test && nyc report --reporter=text-lcov | coveralls" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/vigour-io/brisky-struct.git" | ||
"url": "git+https://github.com/vigour-io/hub.js.git" | ||
}, | ||
@@ -36,8 +37,7 @@ "keywords": [ | ||
"dependencies": { | ||
"brisky-stamp": "^2.0.0", | ||
"brisky-struct": "0.0.0", | ||
"monotonic-timestamp": "^0.0.9", | ||
"quick-hash": "^1.0.1", | ||
"brisky-stamp": "^3.0.11", | ||
"brisky-struct": "^1.0.2", | ||
"string-hash": "^1.1.0", | ||
"uws": "0.12.0", | ||
"vigour-ua": "^2.0.0" | ||
"vigour-ua": "^2.2.3" | ||
}, | ||
@@ -58,6 +58,6 @@ "nyc": { | ||
"devDependencies": { | ||
"chalk": "1.1.3", | ||
"source-map-support": "^0.4.7", | ||
"buble": "0.15.1", | ||
"nodemon": "^1.11.0", | ||
"coveralls": "^2.11.9", | ||
"nodemon": "^1.11.0", | ||
"nyc": "^10.0.0", | ||
@@ -71,3 +71,2 @@ "pre-commit": "^1.1.3", | ||
"standard": "^8.1.0", | ||
"tap-spec": "4.1.1", | ||
"tape": "4.6.0" | ||
@@ -78,5 +77,5 @@ }, | ||
"bugs": { | ||
"url": "https://github.com/vigour-io/brisky-struct/issues" | ||
"url": "https://github.com/vigour-io/hub.js/issues" | ||
}, | ||
"homepage": "https://github.com/vigour-io/brisky-struct#readme", | ||
"homepage": "https://github.com/vigour-io/hub.js#readme", | ||
"contributors": [ | ||
@@ -83,0 +82,0 @@ "Jim de Beer <jim@vigour.io>" |
# hub.js | ||
[![Build Status](https://travis-ci.org/vigour-io/z.svg?branch=master)](https://travis-ci.org/vigour-io/hub.js) | ||
[![Build Status](https://travis-ci.org/vigour-io/hub.js.svg?branch=master)](https://travis-ci.org/vigour-io/hub.js) | ||
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/) | ||
[![npm version](https://badge.fury.io/js/hub.js.svg)](https://badge.fury.io/js/hub.js) | ||
[![Coverage Status](https://coveralls.io/repos/github/vigour-io/hub.js/badge.svg?branch=master)](https://coveralls.io/github/vigour-io/hub?branch=master) | ||
[![Coverage Status](https://coveralls.io/repos/github/vigour-io/hub.js/badge.svg?branch=master)](https://coveralls.io/github/vigour-io/hub.js?branch=master) | ||
@@ -14,9 +14,7 @@ Seamless realtime communcation | ||
url: 'ws://someurl.com', | ||
port: 80 // some port | ||
port: 80 // some port to listen to | ||
}) | ||
node.subscribe({ | ||
$any: { | ||
title: { val: true } | ||
} | ||
$any: { title: true } | ||
}, (target, type) => { | ||
@@ -23,0 +21,0 @@ console.log('update!', target, type) |
@@ -18,10 +18,8 @@ import resolve from 'rollup-plugin-node-resolve' | ||
'brisky-stamp', | ||
'monotonic-timestamp', | ||
'quick-hash', | ||
'string-hash', | ||
'uws', | ||
'vigour-ua', | ||
'brisky-struct' | ||
], | ||
targets: [ | ||
// { dest: 'dist/test/index.js', format: 'cjs' }, | ||
// { dest: 'dist/test/index.es.js', format: 'es' }, | ||
{ | ||
@@ -28,0 +26,0 @@ dest: 'dist/index.browser.js', |
@@ -16,5 +16,5 @@ import resolve from 'rollup-plugin-node-resolve' | ||
'brisky-stamp', | ||
'monotonic-timestamp', | ||
'quick-hash', | ||
'string-hash', | ||
'uws', | ||
'vigour-ua', | ||
'brisky-struct' | ||
@@ -21,0 +21,0 @@ ], |
@@ -20,4 +20,3 @@ import nodeResolve from 'rollup-plugin-node-resolve' | ||
'brisky-stamp', | ||
'monotonic-timestamp', | ||
'quick-hash', | ||
'string-hash', | ||
'uws', | ||
@@ -24,0 +23,0 @@ 'brisky-struct' |
@@ -1,40 +0,6 @@ | ||
import hub from '../lib' | ||
const client = hub({ | ||
url: 'ws://localhost:6060', | ||
id: 'client', | ||
nested: { | ||
field: { | ||
id: 'client', | ||
url: 'ws://localhost:6061' | ||
} | ||
} | ||
}) | ||
client.subscribe({ | ||
gurt: true | ||
}, (t) => { | ||
console.log('INCOMING ON CLIENT', t.path()) | ||
}) | ||
setTimeout(() => { | ||
const server2 = hub({ //eslint-disable-line | ||
port: 6061, | ||
id: 'server2' | ||
}) | ||
const server = hub({ //eslint-disable-line | ||
port: 6060, | ||
id: 'server', | ||
gurt: 'its a gurt!' | ||
}) | ||
}, 100) | ||
client.set({ | ||
hello: true, // to server 1 | ||
nested: { | ||
field: { | ||
haha: true // will be send to server2 | ||
} | ||
} | ||
}) | ||
if (typeof window === 'undefined') { | ||
require('source-map-support').install() | ||
} | ||
require('./connect') | ||
require('./multiple') | ||
// require('./data-size') |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Install scripts
Supply chain riskInstall scripts are run when the package is installed. The majority of malware in npm is hidden in install scripts.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
135937
5
13
1032
29
23
1
+ Addedstring-hash@^1.1.0
+ Addedbrisky-stamp@3.0.12(transitive)
+ Addedbrisky-struct@1.10.13(transitive)
+ Addeddom-walk@0.1.2(transitive)
+ Addedglobal@4.4.0(transitive)
+ Addedmin-document@2.19.0(transitive)
+ Addedprocess@0.11.10(transitive)
+ Addedstamp@4.0.2(transitive)
+ Addedstring-hash@1.1.3(transitive)
- Removedmonotonic-timestamp@^0.0.9
- Removedquick-hash@^1.0.1
- Removedacorn@3.3.0(transitive)
- Removedacorn-jsx@3.0.1(transitive)
- Removedacorn-object-spread@1.0.0(transitive)
- Removedansi-regex@2.1.1(transitive)
- Removedansi-styles@2.2.1(transitive)
- Removedbrisky-stamp@2.1.7(transitive)
- Removedbuble@0.12.5(transitive)
- Removedbubleify@0.5.1(transitive)
- Removedchalk@1.1.3(transitive)
- Removedescape-string-regexp@1.0.5(transitive)
- Removedhas-ansi@2.0.0(transitive)
- Removedmagic-string@0.14.0(transitive)
- Removedminimist@1.2.8(transitive)
- Removedmonotonic-timestamp@0.0.9(transitive)
- Removedobject-assign@4.1.1(transitive)
- Removedos-homedir@1.0.2(transitive)
- Removedquick-hash@1.0.4(transitive)
- Removedstrip-ansi@3.0.1(transitive)
- Removedsupports-color@2.0.0(transitive)
- Removedvlq@0.2.3(transitive)
Updatedbrisky-stamp@^3.0.11
Updatedbrisky-struct@^1.0.2
Updatedvigour-ua@^2.2.3