Comparing version 0.0.11-b18830bfc1eb8e295a5dfd13af34af3d5a5f1070 to 0.0.11-b890f50ac4ecbed46729f19777085b28b48511e5
@@ -411,3 +411,4 @@ import { create, parse, set, struct, subscribe } from 'brisky-struct'; | ||
if (!this.upstreamSubscriptions) { | ||
this.upstreamSubscriptions = { [key]: parsed }; | ||
this.upstreamSubscriptions = {}; | ||
this.upstreamSubscriptions[key] = parsed; // for buble | ||
if (this.url) meta(this); | ||
@@ -436,6 +437,7 @@ } else if (!this.upstreamSubscriptions[key]) { | ||
// no server in the browser -- yet | ||
const stub$1 = {}; | ||
var server = Object.freeze({ | ||
stub: stub$1 | ||
}); | ||
@@ -524,3 +526,3 @@ | ||
if (typeof __dirname !== 'undefined') console.log('hub.js:', __dirname); | ||
if (typeof __filename !== 'undefined') console.log('hub.js:', __filename); | ||
@@ -527,0 +529,0 @@ const fn = (val, stamp) => hub.create(val, stamp); |
@@ -415,3 +415,4 @@ 'use strict'; | ||
if (!this.upstreamSubscriptions) { | ||
this.upstreamSubscriptions = { [key]: parsed }; | ||
this.upstreamSubscriptions = {}; | ||
this.upstreamSubscriptions[key] = parsed; // for buble | ||
if (this.url) meta(this); | ||
@@ -440,6 +441,7 @@ } else if (!this.upstreamSubscriptions[key]) { | ||
// no server in the browser -- yet | ||
const stub$1 = {}; | ||
var server = Object.freeze({ | ||
stub: stub$1 | ||
}); | ||
@@ -528,3 +530,3 @@ | ||
if (typeof __dirname !== 'undefined') console.log('hub.js:', __dirname); | ||
if (typeof __filename !== 'undefined') console.log('hub.js:', __filename); | ||
@@ -531,0 +533,0 @@ const fn = (val, stamp) => hub.create(val, stamp); |
@@ -411,3 +411,4 @@ import { create, get, getKeys, getType, getVal, parse, puid, set, struct, subscribe } from 'brisky-struct'; | ||
if (!this.upstreamSubscriptions) { | ||
this.upstreamSubscriptions = { [key]: parsed }; | ||
this.upstreamSubscriptions = {}; | ||
this.upstreamSubscriptions[key] = parsed; // for buble | ||
if (this.url) meta(this); | ||
@@ -994,3 +995,3 @@ } else if (!this.upstreamSubscriptions[key]) { | ||
if (typeof __dirname !== 'undefined') console.log('hub.js:', __dirname); | ||
if (typeof __filename !== 'undefined') console.log('hub.js:', __filename); | ||
@@ -997,0 +998,0 @@ const fn = (val, stamp) => hub.create(val, stamp); |
1011
dist/index.js
@@ -1,33 +0,30 @@ | ||
'use strict'; | ||
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } | ||
// FILE: external-brisky-struct | ||
const $1084818551 = require('brisky-struct') | ||
// FILE: external-brisky-stamp | ||
const $2379534587 = require('brisky-stamp') | ||
// FILE: /Users/youzi/dev/hub.js/src/client/send.js | ||
var briskyStruct = require('brisky-struct'); | ||
var bs = _interopDefault(require('brisky-stamp')); | ||
var websocket = require('websocket'); | ||
var hash = _interopDefault(require('string-hash')); | ||
var ua = _interopDefault(require('vigour-ua')); | ||
var uws = _interopDefault(require('uws')); | ||
const next = typeof window === 'undefined' | ||
const $4125568599_next = typeof window === 'undefined' | ||
? process.nextTick | ||
: global.requestAnimationFrame; | ||
: global.requestAnimationFrame | ||
const serialize = (hub, t, struct$$1, val, level) => { | ||
if (!struct$$1.isHub || struct$$1.key === 'clients' || (struct$$1._p && struct$$1._p.key === 'clients')) { | ||
const $4125568599_serialize = (hub, t, struct, val, level) => { | ||
if (!struct.isHub || struct.key === 'clients' || (struct._p && struct._p.key === 'clients')) { | ||
return | ||
} | ||
const path = struct$$1.path(); // cached version (later) | ||
const len = path.length; | ||
const path = struct.path() // cached version (later) | ||
const len = path.length | ||
if (struct$$1.val !== void 0 || val === null) { | ||
var s = t[0] || (t[0] = {}); | ||
if (struct.val !== void 0 || val === null) { | ||
var s = t[0] || (t[0] = {}) | ||
for (let i = level; i < len; i++) { | ||
let t = s[path[i]]; | ||
let t = s[path[i]] | ||
if (!t) { | ||
s = s[path[i]] = {}; | ||
s = s[path[i]] = {} | ||
} else { | ||
s = t; | ||
s = t | ||
if (s.val === null) { return } | ||
@@ -37,3 +34,3 @@ } | ||
s.stamp = struct$$1.stamp; | ||
s.stamp = struct.stamp | ||
@@ -43,85 +40,98 @@ if (val === null) { | ||
if (key !== 'stamp') { | ||
delete s[key]; | ||
delete s[key] | ||
} | ||
} | ||
s.val = null; | ||
} else if (struct$$1.val && struct$$1.val.inherits) { | ||
s.val = null | ||
} else if (struct.val && struct.val.inherits) { | ||
// make a bit more secure... | ||
// if (!s.val) { | ||
s.val = struct$$1.val.path(); | ||
s.val.unshift('@', 'root'); | ||
s.val = struct.val.path() | ||
s.val.unshift('@', 'root') | ||
// if allrdy serialized stop it! | ||
serialize(hub, t, struct$$1.val, val, level); | ||
$4125568599_serialize(hub, t, struct.val, val, level) | ||
// } | ||
} else if (struct$$1.val !== void 0) { | ||
s.val = struct$$1.val; | ||
} else if (struct.val !== void 0) { | ||
s.val = struct.val | ||
} | ||
} | ||
}; | ||
} | ||
const meta = hub => { | ||
const $4125568599_meta = hub => { | ||
if (!hub.receiveOnly) { | ||
const store = inProgress(hub, bs.inProgress ? bs.on : next); | ||
if (!store[1]) store[1] = {}; | ||
const store = $4125568599_inProgress(hub, $2379534587.inProgress ? $2379534587.on : $4125568599_next) | ||
if (!store[1]) store[1] = {} | ||
if (hub.context) { | ||
if (hub.context.keys().length > 0) { | ||
store[1].context = hub.context.compute() ? hub.context.serialize() : false; | ||
store[1].context = hub.context.compute() ? hub.context.serialize() : false | ||
} else { | ||
store[1].context = hub.context.compute() || false; | ||
store[1].context = hub.context.compute() || false | ||
} | ||
} | ||
store[1].id = hub.client.key; | ||
store[1].subscriptions = hub.upstreamSubscriptions; | ||
store[1].id = hub.client.key | ||
store[1].subscriptions = hub.upstreamSubscriptions | ||
} | ||
}; | ||
} | ||
const send = (val, stamp, struct$$1) => { | ||
const $4125568599_send = (val, stamp, struct) => { | ||
// -1 means upsteam (floats for extra speed) | ||
let hub; | ||
let p = struct$$1; | ||
let hub | ||
let p = struct | ||
while (p) { | ||
if (p._url_ && !p._c) hub = p; | ||
p = p.parent(); // needs to walk over context (for multi server) | ||
if (p._url_ && !p._c) hub = p | ||
p = p.parent() // needs to walk over context (for multi server) | ||
} | ||
if (hub && !hub.receiveOnly) { | ||
if (struct$$1 === hub) { | ||
if (struct === hub) { | ||
if (val === null) { | ||
return | ||
} | ||
} else if (struct$$1._p.key === 'clients') { | ||
if (struct$$1.key !== hub.client.key) { | ||
} else if (struct._p.key === 'clients') { | ||
if (struct.key !== hub.client.key) { | ||
return | ||
} | ||
} | ||
serialize(hub, inProgress(hub, bs.on), struct$$1, val, hub.urlIndex); | ||
$4125568599_serialize(hub, $4125568599_inProgress(hub, $2379534587.on), struct, val, hub.urlIndex) | ||
} | ||
}; | ||
} | ||
const inProgress = (hub, tick) => { | ||
const $4125568599_inProgress = (hub, tick) => { | ||
if (!hub.inProgress) { | ||
hub.inProgress = []; | ||
hub.inProgress = [] | ||
tick(() => { | ||
if (hub.connected.compute() === true) { | ||
out(hub); | ||
$4125568599_out(hub) | ||
} else { | ||
hub.connected.once(true, () => out(hub)); | ||
hub.connected.once(true, () => $4125568599_out(hub)) | ||
} | ||
}); | ||
}) | ||
} | ||
return hub.inProgress | ||
}; | ||
} | ||
const out = t => { | ||
t.socket.send(JSON.stringify(t.inProgress)); | ||
t.inProgress = false; | ||
}; | ||
const $4125568599_out = t => { | ||
t.socket.send(JSON.stringify(t.inProgress)) | ||
t.inProgress = false | ||
} | ||
const $4125568599_$ALL$ = { | ||
meta: $4125568599_meta, | ||
send: $4125568599_send | ||
} | ||
// FILE: external-websocket | ||
const $4063337664 = require('websocket') | ||
// FILE: /Users/youzi/dev/hub.js/src/client/websocket/index.js | ||
// import WebSocket from 'uws' | ||
// export default WebSocket | ||
const isEmpty = t => { | ||
const $2878564687 = $4063337664.w3cwebsocket | ||
// FILE: /Users/youzi/dev/hub.js/src/subscription/serialize.js | ||
const $2711378567_isEmpty = t => { | ||
for (let i in t) { return false } | ||
return true | ||
}; | ||
} | ||
@@ -138,7 +148,7 @@ // function merge (a, b) { | ||
const parse$1 = (struct$$1, obj, key, root) => { | ||
const result = {}; | ||
if (!root) { root = result; } | ||
const $2711378567_parse = (struct, obj, key, root) => { | ||
const result = {} | ||
if (!root) { root = result } | ||
// need to be done before the rest of subs to sync correctly | ||
if (obj.type) result.type = parse$1(struct$$1, obj.type, 'type'); | ||
if (obj.type) result.type = $2711378567_parse(struct, obj.type, 'type') | ||
for (let i in obj) { | ||
@@ -155,16 +165,16 @@ if (i !== '_' && i !== 'type') { | ||
} else if (typeof obj[i] === 'function') { | ||
let val = obj[i].toString(); | ||
let val = obj[i].toString() | ||
if (!/^(function|\()/.test(val)) { | ||
if (/^.+=>/.test(val)) { | ||
if (!/^(\(){0, 1}.+(\)){0, 1} +=>/.test(val)) { | ||
val = val.replace(/^(.*?)( +=>)/, '($1)$2'); | ||
val = val.replace(/^(.*?)( +=>)/, '($1)$2') | ||
} | ||
if (!/^(.*?)+=> +{(.*?)}$/.test(val) && val.indexOf('return ') === -1) { | ||
val = val.replace(/^(.+=> *?)(.*?)/, '$1 { return $2') + ' }'; | ||
val = val.replace(/^(.+=> *?)(.*?)/, '$1 { return $2') + ' }' | ||
} | ||
val = val.replace('=>', ''); | ||
val = val.replace('=>', '') | ||
} | ||
val = 'function ' + val; | ||
val = 'function ' + val | ||
} | ||
result['$fn|' + i] = val; | ||
result['$fn|' + i] = val | ||
// also here we need to rewrite client to use client id | ||
@@ -176,7 +186,7 @@ } else if (typeof obj[i] !== 'object') { | ||
// } else { | ||
result[i] = obj[i]; | ||
result[i] = obj[i] | ||
// } | ||
} else { | ||
// empty objects are very uninteresetting maybe just skip them | ||
let parsed = parse$1(struct$$1, obj[i], i, root); | ||
let parsed = $2711378567_parse(struct, obj[i], i, root) | ||
@@ -191,3 +201,3 @@ // if (i === 'root' || i === 'parent') { | ||
if (parsed !== void 0) { result[i] = parsed; } | ||
if (parsed !== void 0) { result[i] = parsed } | ||
} | ||
@@ -197,39 +207,61 @@ } | ||
// if result is empty ignore -- may not be a good idea | ||
return isEmpty(result) ? void 0 : result | ||
}; | ||
return $2711378567_isEmpty(result) ? void 0 : result | ||
} | ||
const uniq = process.pid; | ||
var uid = () => hash(`b-${Date.now()}-${(Math.random() * 10000) | 0}-${uniq}`); | ||
// can be one less fn... | ||
const $2711378567 = $2711378567_parse | ||
var createClient = (t, val, stamp, useragent, id) => { | ||
if (!id) id = t._uid_ || uid(); | ||
ua(useragent, val); | ||
t.set({ clients: { [id]: val } }, stamp); | ||
// FILE: external-string-hash | ||
const $3794736159 = require('string-hash') | ||
// FILE: external-vigour-ua | ||
const $1807313084 = require('vigour-ua') | ||
// FILE: /Users/youzi/dev/hub.js/src/client/uid/index.js | ||
const $1123050690_uniq = process.pid | ||
const $1123050690 = () => $3794736159(`b-${Date.now()}-${(Math.random() * 10000) | 0}-${$1123050690_uniq}`) | ||
// FILE: /Users/youzi/dev/hub.js/src/client/create.js | ||
const $3376394415 = (t, val, stamp, useragent, id) => { | ||
if (!id) id = t._uid_ || $1123050690() | ||
$1807313084(useragent, val) | ||
t.set({ clients: { [id]: val } }, stamp) | ||
return t.clients[id] | ||
}; | ||
} | ||
const connect = (hub, url, reconnect) => { | ||
const socket = new websocket.w3cwebsocket(url); | ||
// FILE: /Users/youzi/dev/hub.js/src/client/index.js | ||
const $48594293_connect = (hub, url, reconnect) => { | ||
const socket = new $2878564687(url) | ||
// t, val, stamp, useragent, id | ||
const client = hub.client || createClient(hub, {}, false); | ||
const client = hub.client || $3376394415(hub, {}, false) | ||
hub.set({ client }, false); | ||
hub.set({ client }, false) | ||
hub.reconnect = null; | ||
hub.reconnect = null | ||
const close = () => { | ||
const stamp = bs.create(); | ||
hub.socket = false; | ||
hub.set({ connected: false }, stamp); | ||
bs.close(); | ||
const stamp = $2379534587.create() | ||
hub.socket = false | ||
hub.set({ connected: false }, stamp) | ||
$2379534587.close() | ||
if (!socket.blockReconnect && hub._url_) { | ||
reconnect = Math.min((reconnect * 1.5), 2000); | ||
hub.reconnect = setTimeout(connect, reconnect, hub, url, reconnect); | ||
reconnect = Math.min((reconnect * 1.5), 2000) | ||
hub.reconnect = setTimeout($48594293_connect, reconnect, hub, url, reconnect) | ||
} | ||
}; | ||
} | ||
socket.onclose = close; | ||
socket.onclose = close | ||
if (typeof window === 'undefined') { | ||
socket.hackyOnClose = close; | ||
socket.hackyOnClose = close | ||
} | ||
@@ -239,82 +271,82 @@ | ||
? close | ||
: () => socket.close(); | ||
: () => socket.close() | ||
socket.onopen = () => { | ||
const stamp = bs.create(); | ||
hub.socket = socket; | ||
meta(hub); | ||
hub.set({ connected: true }, stamp); | ||
bs.close(); | ||
}; | ||
const stamp = $2379534587.create() | ||
hub.socket = socket | ||
$4125568599_meta(hub) | ||
hub.set({ connected: true }, stamp) | ||
$2379534587.close() | ||
} | ||
socket.onmessage = (data) => { | ||
data = data.data; | ||
data = data.data | ||
// console.warn('INCOMING\n', JSON.parse(data)) | ||
if (!hub.receiveOnly) { | ||
hub.receiveOnly = true; | ||
hub.set(JSON.parse(data), false); | ||
hub.receiveOnly = null; | ||
hub.receiveOnly = true | ||
hub.set(JSON.parse(data), false) | ||
hub.receiveOnly = null | ||
} else { | ||
hub.set(JSON.parse(data), false); | ||
hub.set(JSON.parse(data), false) | ||
} | ||
bs.close(); | ||
}; | ||
}; | ||
$2379534587.close() | ||
} | ||
} | ||
const removeUrl = hub => { | ||
hub.url = hub._url_ = hub.urlIndex = null; | ||
hub.emitters.set({ data: { url$: null } }, false); | ||
}; | ||
const $48594293_removeUrl = hub => { | ||
hub.url = hub._url_ = hub.urlIndex = null | ||
hub.emitters.set({ data: { url$: null } }, false) | ||
} | ||
const removeSocket = hub => { | ||
const $48594293_removeSocket = hub => { | ||
if (hub.reconnect) { | ||
clearTimeout(hub.reconnect); | ||
hub.reconnect = null; | ||
clearTimeout(hub.reconnect) | ||
hub.reconnect = null | ||
} | ||
if (hub.socket) { | ||
hub.socket.blockReconnect = true; | ||
console.log('GO GO GOREMOVE', hub.socket._readyState); | ||
hub.socket.blockReconnect = true | ||
console.log('GO GO GOREMOVE', hub.socket._readyState) | ||
if (hub.connected.compute() === false || !hub.socket._readyState) { | ||
console.log('hacky!'); | ||
hub.socket.hackyOnClose(); | ||
console.log('hacky!') | ||
hub.socket.hackyOnClose() | ||
} else { | ||
hub.socket.close(); | ||
hub.socket.close() | ||
} | ||
} | ||
// hub.socket = false | ||
}; | ||
} | ||
const url = (hub, val, key, stamp) => { | ||
const $48594293_url = (hub, val, key, stamp) => { | ||
hub.on((val, stamp, t) => { | ||
if (val === null && !t._c && t === hub) { | ||
hub.subscriptions = []; | ||
removeUrl(hub); | ||
removeSocket(hub); | ||
hub.subscriptions = [] | ||
$48594293_removeUrl(hub) | ||
$48594293_removeSocket(hub) | ||
} | ||
}, 'url$'); | ||
}, 'url$') | ||
if (!val) val = null; | ||
if (!val) val = null | ||
if ((!hub.url && val) || (hub.url.compute() !== val)) { | ||
removeSocket(hub); | ||
$48594293_removeSocket(hub) | ||
if (!val) { | ||
hub.set({ connected: false }, stamp); | ||
hub._url_ = null; | ||
if (hub.url) hub.url.set(null, stamp); | ||
hub.set({ connected: false }, stamp) | ||
hub._url_ = null | ||
if (hub.url) hub.url.set(null, stamp) | ||
} else { | ||
if (!hub.url) { | ||
briskyStruct.create({ | ||
$1084818551.create({ | ||
on: { | ||
data: { | ||
url: (val, stamp, struct$$1) => { | ||
val = struct$$1.compute(); | ||
url: (val, stamp, struct) => { | ||
val = struct.compute() | ||
if (val) { | ||
hub.set({ connected: false }, stamp); | ||
let i = -1; | ||
if (hub.key) i++; | ||
hub.parent(() => { i++; }); | ||
hub.urlIndex = i; // use this for checks | ||
hub._url_ = val; | ||
connect(hub, val, 50); | ||
hub.set({ connected: false }, stamp) | ||
let i = -1 | ||
if (hub.key) i++ | ||
hub.parent(() => { i++ }) | ||
hub.urlIndex = i // use this for checks | ||
hub._url_ = val | ||
$48594293_connect(hub, val, 50) | ||
} else { | ||
hub._url_ = null; | ||
hub._url_ = null | ||
} | ||
@@ -324,11 +356,11 @@ } | ||
} | ||
}, stamp, briskyStruct.struct, hub, key); | ||
}, stamp, $1084818551.struct, hub, key) | ||
} | ||
hub.url.set(val, stamp); | ||
hub.url.set(val, stamp) | ||
} | ||
} | ||
}; | ||
} | ||
const removeClients = (hub, stamp) => { | ||
const clients = hub.clients; | ||
const $48594293_removeClients = (hub, stamp) => { | ||
const clients = hub.clients | ||
if (clients && clients.keys().length > 1) { | ||
@@ -340,10 +372,10 @@ clients.forEach((client, key) => { | ||
) { | ||
client.set(null, stamp); | ||
delete clients[key]; | ||
client.set(null, stamp) | ||
delete clients[key] | ||
} | ||
}); | ||
}) | ||
} | ||
}; | ||
} | ||
const connected = { | ||
const $48594293_connected = { | ||
type: 'struct', | ||
@@ -355,3 +387,3 @@ on: { | ||
// all instances! -- fix this | ||
removeClients(t._p, stamp); | ||
$48594293_removeClients(t._p, stamp) | ||
} | ||
@@ -361,5 +393,5 @@ } | ||
} | ||
}; | ||
} | ||
const contextStruct = briskyStruct.struct.create({ | ||
const $48594293_contextStruct = $1084818551.struct.create({ | ||
props: { | ||
@@ -370,4 +402,4 @@ default: { | ||
updateParent: (val, stamp, t) => { | ||
console.log('👻 GO UPDATE PARENT!!! 👻'); | ||
t.parent().emit('data', val, stamp); | ||
console.log('👻 GO UPDATE PARENT!!! 👻') | ||
t.parent().emit('data', val, stamp) | ||
} | ||
@@ -378,9 +410,9 @@ } | ||
} | ||
}); | ||
}) | ||
const contextIsNotEqual = (val, context) => { | ||
const $48594293_contextIsNotEqual = (val, context) => { | ||
if (val && typeof val === 'object') { | ||
for (let field in val) { | ||
if (!context[field] || val[field] !== context[field].compute()) { | ||
console.log('😜', field); | ||
console.log('😜', field) | ||
return true | ||
@@ -390,21 +422,21 @@ } | ||
} else { | ||
console.log('😜 ?????'); | ||
console.log('😜 ?????') | ||
return val !== context.compute() | ||
} | ||
}; | ||
} | ||
const context = (hub, val, key, stamp) => { | ||
if (!hub.context || contextIsNotEqual(val, hub.context)) { | ||
console.log('⚽️ fire fire fire FLAME context ⚽️', val, stamp); | ||
const $48594293_context = (hub, val, key, stamp) => { | ||
if (!hub.context || $48594293_contextIsNotEqual(val, hub.context)) { | ||
console.log('⚽️ fire fire fire FLAME context ⚽️', val, stamp) | ||
if (!hub.context) { | ||
briskyStruct.create(val, stamp, contextStruct, hub, key); | ||
$1084818551.create(val, stamp, $48594293_contextStruct, hub, key) | ||
} else { | ||
removeClients(hub, stamp); | ||
hub.context.set(val, stamp); | ||
$48594293_removeClients(hub, stamp) | ||
hub.context.set(val, stamp) | ||
} | ||
if (hub.connected && hub.connected.compute() === true) meta(hub); | ||
if (hub.connected && hub.connected.compute() === true) $4125568599_meta(hub) | ||
} | ||
}; | ||
} | ||
const props = { | ||
const $48594293_props = { | ||
reconnect: true, | ||
@@ -415,42 +447,44 @@ socket: true, | ||
receiveOnly: true, | ||
url, | ||
context, | ||
connected | ||
}; | ||
url: $48594293_url, | ||
context: $48594293_context, | ||
connected: $48594293_connected | ||
} | ||
const stub = () => {}; | ||
const $48594293_stub = () => {} | ||
const define = { | ||
const $48594293_define = { | ||
subscribe (subs, cb, raw, tree) { | ||
if (!raw) subs = briskyStruct.parse(subs); | ||
if (!raw) subs = $1084818551.parse(subs) | ||
if (!this.receiveOnly) { | ||
const parsed = parse$1(this, subs); | ||
const parsed = $2711378567(this, subs) | ||
if (parsed) { | ||
const key = hash(JSON.stringify(parsed)); | ||
const key = $3794736159(JSON.stringify(parsed)) | ||
if (!this.upstreamSubscriptions) { | ||
this.upstreamSubscriptions = { [key]: parsed }; | ||
if (this.url) meta(this); | ||
this.upstreamSubscriptions = {} | ||
this.upstreamSubscriptions[key] = parsed // for buble | ||
if (this.url) $4125568599_meta(this) | ||
} else if (!this.upstreamSubscriptions[key]) { | ||
this.upstreamSubscriptions[key] = parsed; | ||
if (this.url) meta(this); | ||
this.upstreamSubscriptions[key] = parsed | ||
if (this.url) $4125568599_meta(this) | ||
} | ||
} | ||
} | ||
return briskyStruct.subscribe(this, subs, cb || stub, tree) | ||
return $1084818551.subscribe(this, subs, cb || $48594293_stub, tree) | ||
} | ||
}; | ||
} | ||
const on = { data: { send } }; | ||
const $48594293_on = { data: { send: $4125568599_send } } | ||
var client = Object.freeze({ | ||
props: props, | ||
on: on, | ||
define: define | ||
}); | ||
const isFn = /^\$fn\|/; | ||
const dummy = () => false; | ||
const $48594293_$ALL$ = { | ||
props: $48594293_props, | ||
on: $48594293_on, | ||
define: $48594293_define | ||
} | ||
// FILE: external-uws | ||
const $354051556 = require('uws') | ||
// FILE: /Users/youzi/dev/hub.js/src/subscription/parse.js | ||
const $3742651364_isFn = /^\$fn\|/ | ||
const $3742651364_dummy = () => false | ||
// const client = (tree) => { | ||
@@ -488,17 +522,17 @@ // while (tree) { | ||
const parse$2 = (obj, state, key) => { | ||
const result = {}; | ||
const $3742651364_parse = (obj, state, key) => { | ||
const result = {} | ||
for (let i in obj) { | ||
if (isFn.test(i)) { | ||
let val = obj[i]; | ||
i = i.slice(4); | ||
if ($3742651364_isFn.test(i)) { | ||
let val = obj[i] | ||
i = i.slice(4) | ||
// need to fix bublé stuff in these fn creations -- prop need to add buble | ||
// runtime in a hub | ||
let pass; | ||
let pass | ||
try { | ||
obj[i] = new Function('return ' + val)(); // eslint-disable-line | ||
obj[i] = new Function('return ' + val)() // eslint-disable-line | ||
// if (/\.client|\[['"']client['"]\]/.test(val)) { // eslint-disable-line | ||
// obj[i] = clientContext(obj[i]) | ||
// } | ||
pass = true; | ||
pass = true | ||
// do dry run with your own key in a props object | ||
@@ -509,30 +543,48 @@ // 2 options for this ofcourse | ||
} catch (e) { | ||
let msg; | ||
let msg | ||
// if (!pass) { | ||
msg = `cannot parse function ${key}.exec\n${val}`; | ||
msg = `cannot parse function ${key}.exec\n${val}` | ||
// } else { | ||
// msg = `cannot run function ${key}.exec\n${val}` | ||
// } | ||
state.emit('error', new Error(msg)); | ||
obj[i] = dummy; | ||
state.emit('error', new Error(msg)) | ||
obj[i] = $3742651364_dummy | ||
} | ||
} | ||
if (typeof obj[i] !== 'object') { | ||
result[i] = obj[i]; | ||
result[i] = obj[i] | ||
} else { | ||
result[i] = parse$2(obj[i], state, i); | ||
result[i] = $3742651364_parse(obj[i], state, i) | ||
} | ||
} | ||
return result | ||
}; | ||
} | ||
const cache = (client, struct$$1, stamp) => { | ||
if (!client.cache) client.cache = {}; | ||
client.cache[briskyStruct.puid(struct$$1)] = stamp; | ||
}; | ||
const $3742651364 = $3742651364_parse | ||
const isCached = (client, struct$$1, stamp) => client.cache && | ||
client.cache[briskyStruct.puid(struct$$1)] === stamp; | ||
// FILE: /Users/youzi/dev/hub.js/src/server/cache.js | ||
const isEmpty$1 = obj => { | ||
const $3904796091_cache = (client, struct, stamp) => { | ||
if (!client.cache) client.cache = {} | ||
client.cache[$1084818551.puid(struct)] = stamp | ||
} | ||
const $3904796091_isCached = (client, struct, stamp) => client.cache && | ||
client.cache[$1084818551.puid(struct)] === stamp | ||
// const isCached = () => false | ||
const $3904796091_$ALL$ = { | ||
cache: $3904796091_cache, | ||
isCached: $3904796091_isCached | ||
} | ||
// FILE: /Users/youzi/dev/hub.js/src/server/send.js | ||
const $1622386187_isEmpty = obj => { | ||
for (let i in obj) { //eslint-disable-line | ||
@@ -542,10 +594,10 @@ return false | ||
return true | ||
}; | ||
} | ||
const progress = (client) => { | ||
const $1622386187_progress = (client) => { | ||
if (!client.inProgress) { | ||
client.inProgress = {}; | ||
bs.on(() => { | ||
client.inProgress = {} | ||
$2379534587.on(() => { | ||
if (client.val !== null) { | ||
if (!isEmpty$1(client.inProgress)) { | ||
if (!$1622386187_isEmpty(client.inProgress)) { | ||
if (client.inProgress.types) { | ||
@@ -558,55 +610,55 @@ for (let i in client.inProgress) { | ||
} else { | ||
let tmp = client.inProgress[i]; | ||
delete client.inProgress[i]; | ||
client.inProgress[i] = tmp; | ||
let tmp = client.inProgress[i] | ||
delete client.inProgress[i] | ||
client.inProgress[i] = tmp | ||
} | ||
} | ||
} | ||
client.socket.send(JSON.stringify(client.inProgress)); | ||
client.socket.send(JSON.stringify(client.inProgress)) | ||
} | ||
client.inProgress = false; | ||
client.inProgress = false | ||
} | ||
}); | ||
}) | ||
} | ||
return client.inProgress | ||
}; | ||
} | ||
const send$1 = (hub, client, struct$$1, type, subs, tree) => { | ||
if (struct$$1.isHub && client.val !== null) { | ||
let isRemoved; | ||
const $1622386187_send = (hub, client, struct, type, subs, tree) => { | ||
if (struct.isHub && client.val !== null) { | ||
let isRemoved | ||
if (type === 'remove') { | ||
if (!struct$$1._p[struct$$1.key]) isRemoved = true; | ||
} else if (type === 'update' && tree.$t !== struct$$1) { | ||
if (!struct._p[struct.key]) isRemoved = true | ||
} else if (type === 'update' && tree.$t !== struct) { | ||
if (tree.$t && tree.$t._p && !tree.$t._p[tree.$t.key]) { | ||
let previous = tree.$t; | ||
let prop = previous; | ||
let previous = tree.$t | ||
let prop = previous | ||
while (previous) { | ||
if (previous._p && previous._p[previous.key]) { | ||
// think of something fast for level... | ||
serialize$2(client, progress(client), subs, prop, briskyStruct.get(hub, 'serverIndex'), true); | ||
$1622386187_serialize(client, $1622386187_progress(client), subs, prop, $1084818551.get(hub, 'serverIndex'), true) | ||
} | ||
prop = previous; | ||
previous = previous._p; | ||
prop = previous | ||
previous = previous._p | ||
} | ||
} | ||
} | ||
serialize$2(client, progress(client), subs, struct$$1, briskyStruct.get(hub, 'serverIndex'), isRemoved); | ||
$1622386187_serialize(client, $1622386187_progress(client), subs, struct, $1084818551.get(hub, 'serverIndex'), isRemoved) | ||
} | ||
}; | ||
} | ||
const serialize$2 = (client, t, subs, struct$$1, level, isRemoved) => { | ||
const stamp = briskyStruct.get(struct$$1, 'stamp') || 1; // remove the need for this default (feels wrong) | ||
const val = isRemoved ? null : briskyStruct.getVal(struct$$1); | ||
const $1622386187_serialize = (client, t, subs, struct, level, isRemoved) => { | ||
const stamp = $1084818551.get(struct, 'stamp') || 1 // remove the need for this default (feels wrong) | ||
const val = isRemoved ? null : $1084818551.getVal(struct) | ||
if (val !== void 0 && stamp && !isCached(client, struct$$1, stamp)) { | ||
if (val !== void 0 && stamp && !$3904796091_isCached(client, struct, stamp)) { | ||
// val === null -- double chck if this is nessecary | ||
const path = struct$$1.path(); | ||
const len = path.length; | ||
let s = t; | ||
const path = struct.path() | ||
const len = path.length | ||
let s = t | ||
for (let i = level; i < len; i++) { | ||
let tt = s[path[i]]; | ||
let tt = s[path[i]] | ||
if (!tt) { | ||
s = s[path[i]] = {}; | ||
s = s[path[i]] = {} | ||
} else { | ||
s = tt; | ||
s = tt | ||
if (s.val === null) return | ||
@@ -617,18 +669,18 @@ } | ||
if (isRemoved) { | ||
cache(client, struct$$1, stamp); | ||
s.stamp = stamp; | ||
s.val = val; | ||
$3904796091_cache(client, struct, stamp) | ||
s.stamp = stamp | ||
s.val = val | ||
} else { | ||
if (subs.type) { | ||
const type = briskyStruct.get(struct$$1, 'type'); // make getType (fast) | ||
if (briskyStruct.getVal(type) !== 'hub') { | ||
serialize$2(client, t, subs.type, type, level); | ||
const type = $1084818551.get(struct, 'type') // make getType (fast) | ||
if ($1084818551.getVal(type) !== 'hub') { | ||
$1622386187_serialize(client, t, subs.type, type, level) | ||
} | ||
} | ||
cache(client, struct$$1, stamp); | ||
s.stamp = stamp; | ||
if (struct$$1.key === 'type') { | ||
$3904796091_cache(client, struct, stamp) | ||
s.stamp = stamp | ||
if (struct.key === 'type') { | ||
if (val === 'hub') return | ||
serialize$2(client, t, subs, briskyStruct.getType(struct$$1.parent(2), val), level); | ||
$1622386187_serialize(client, t, subs, $1084818551.getType(struct.parent(2), val), level) | ||
// allways need a stamp! | ||
@@ -638,7 +690,7 @@ } | ||
if (typeof val === 'object' && val.inherits) { | ||
s.val = val.path(); | ||
s.val.unshift('@', 'root'); | ||
serialize$2(client, t, subs, val, level); | ||
s.val = val.path() | ||
s.val.unshift('@', 'root') | ||
$1622386187_serialize(client, t, subs, val, level) | ||
} else if (val !== void 0) { | ||
s.val = val; | ||
s.val = val | ||
} | ||
@@ -648,87 +700,105 @@ } | ||
// can send a bit too much data when val: true and overlapping keys | ||
serialize$2(client, t, subs, val, level); | ||
$1622386187_serialize(client, t, subs, val, level) | ||
} | ||
if (subs.val === true && !isRemoved) { | ||
deepSerialize(briskyStruct.getKeys(struct$$1), client, t, subs, struct$$1, level); | ||
$1622386187_deepSerialize($1084818551.getKeys(struct), client, t, subs, struct, level) | ||
} | ||
}; | ||
} | ||
const deepSerialize = (keys, client, t, subs, struct$$1, level) => { | ||
if (struct$$1.get('type') && struct$$1.get('type').compute() !== 'hub') { | ||
serialize$2(client, t, subs, struct$$1.get('type'), level); | ||
const $1622386187_deepSerialize = (keys, client, t, subs, struct, level) => { | ||
if (struct.get('type') && struct.get('type').compute() !== 'hub') { | ||
$1622386187_serialize(client, t, subs, struct.get('type'), level) | ||
} | ||
if (keys) { | ||
for (let i = 0, len = keys.length; i < len; i++) { | ||
let prop = briskyStruct.get(struct$$1, keys[i]); | ||
if (prop && prop.isHub) serialize$2(client, t, subs, prop, level); | ||
let prop = $1084818551.get(struct, keys[i]) | ||
if (prop && prop.isHub) $1622386187_serialize(client, t, subs, prop, level) | ||
} | ||
} | ||
if (struct$$1._removed) { | ||
for (let i = 0, len = struct$$1._removed.length; i < len; i++) { | ||
let prop = struct$$1._removed[i]; | ||
serialize$2(client, t, subs, prop, level, true); | ||
if (struct._removed) { | ||
for (let i = 0, len = struct._removed.length; i < len; i++) { | ||
let prop = struct._removed[i] | ||
$1622386187_serialize(client, t, subs, prop, level, true) | ||
} | ||
} | ||
}; | ||
} | ||
const removeSubscriptions = (t, id) => { | ||
const $1622386187 = $1622386187_send | ||
// FILE: /Users/youzi/dev/hub.js/src/server/remove.js | ||
const $2931540049_removeSubscriptions = (t, id) => { | ||
if (t.subscriptions) { | ||
let i = t.subscriptions.length; | ||
let i = t.subscriptions.length | ||
while (i--) { // clean this up with unsubscribe in struct | ||
if (t.subscriptions[i]._uid_ == id) { //eslint-disable-line | ||
t.subscriptions.splice(i, 1); | ||
t.subscriptions.splice(i, 1) | ||
} | ||
} | ||
} | ||
}; | ||
} | ||
const removeClient = (client) => { | ||
const id = client.key; | ||
client.val = null; | ||
const $2931540049_removeClient = (client) => { | ||
const id = client.key | ||
client.val = null | ||
if (client.socket) { | ||
client.socket.client = null; | ||
client.socket = null; | ||
client.socket.client = null | ||
client.socket = null | ||
} | ||
const t = client.parent(2); | ||
removeSubscriptions(t, id); | ||
client.set(null); | ||
const t = client.parent(2) | ||
$2931540049_removeSubscriptions(t, id) | ||
client.set(null) | ||
// if (client.context && t.clients.keys().length === (t.url ? 1 : 0)) { | ||
// t.set(null, stamp) | ||
// } | ||
}; | ||
} | ||
var incoming = (hub, socket, data) => { | ||
const payload = data[0]; | ||
const meta = data[1]; | ||
var client = socket.client; | ||
const $2931540049_$ALL$ = { | ||
removeSubscriptions: $2931540049_removeSubscriptions, | ||
removeClient: $2931540049_removeClient | ||
} | ||
// FILE: /Users/youzi/dev/hub.js/src/server/incoming.js | ||
const $1353865041 = (hub, socket, data) => { | ||
const payload = data[0] | ||
const meta = data[1] | ||
var client = socket.client | ||
if (meta) { | ||
let t; | ||
let t | ||
if (client) { | ||
t = hub; | ||
t = hub | ||
if ('context' in meta && client.context != meta.context) { // eslint-disable-line | ||
removeClient(client); | ||
create$1(hub, socket, meta, payload); | ||
$2931540049_removeClient(client) | ||
$1353865041_create(hub, socket, meta, payload) | ||
} else if (meta.subscriptions) { | ||
if (payload) setPayload(t, payload, client); | ||
incomingSubscriptions(t, client, meta, client.key); | ||
bs.close(); | ||
if (payload) $1353865041_setPayload(t, payload, client) | ||
$1353865041_incomingSubscriptions(t, client, meta, client.key) | ||
$2379534587.close() | ||
} | ||
} else { | ||
create$1(hub, socket, meta, payload); | ||
$1353865041_create(hub, socket, meta, payload) | ||
} | ||
} else { | ||
setPayload(client.parent(2), payload, client); | ||
bs.close(); | ||
$1353865041_setPayload(client.parent(2), payload, client) | ||
$2379534587.close() | ||
} | ||
}; | ||
} | ||
const addToCache = (client, hub, payload) => { | ||
const $1353865041_addToCache = (client, hub, payload) => { | ||
if (typeof payload === 'object' && payload) { | ||
for (let key in payload) { | ||
if (key !== 'val' && key !== 'stamp') { | ||
let struct$$1 = hub[key]; | ||
if (struct$$1 && struct$$1.isHub) { | ||
addToCache(client, hub[key], payload[key]); | ||
let struct = hub[key] | ||
if (struct && struct.isHub) { | ||
$1353865041_addToCache(client, hub[key], payload[key]) | ||
} | ||
@@ -738,85 +808,88 @@ } | ||
if (payload.val !== void 0 && payload.stamp) { | ||
cache(client, hub, payload.stamp); | ||
$3904796091_cache(client, hub, payload.stamp) | ||
} | ||
} | ||
}; | ||
} | ||
const setPayload = (hub, payload, client) => { | ||
hub.set(payload, false); | ||
addToCache(client, hub, payload); | ||
}; | ||
const $1353865041_setPayload = (hub, payload, client) => { | ||
hub.set(payload, false) | ||
$1353865041_addToCache(client, hub, payload) | ||
} | ||
const set$1 = (meta, socket, t, payload) => { | ||
const stamp = bs.create(); | ||
const id = meta.id; | ||
const context = meta.context; | ||
const $1353865041_set = (meta, socket, t, payload) => { | ||
const stamp = $2379534587.create() | ||
const id = meta.id | ||
const context = meta.context | ||
// const ip = socket._socket.remoteAddress | ||
const client = socket.client = createClient( | ||
const client = socket.client = $3376394415( | ||
t, { socket, context }, stamp, socket.useragent, id | ||
); | ||
if (payload) setPayload(t, payload, client); | ||
if (meta.subscriptions) incomingSubscriptions(t, client, meta, id); | ||
bs.close(); | ||
}; | ||
) | ||
if (payload) $1353865041_setPayload(t, payload, client) | ||
if (meta.subscriptions) $1353865041_incomingSubscriptions(t, client, meta, id) | ||
$2379534587.close() | ||
} | ||
const create$1 = (hub, socket, meta, payload) => { | ||
const t = meta.context ? hub.getContext(meta.context, socket) : hub; | ||
const $1353865041_create = (hub, socket, meta, payload) => { | ||
const t = meta.context ? hub.getContext(meta.context, socket) : hub | ||
if (!t.inherits && t.then) { | ||
t.then((t) => { | ||
if (socket.external !== null) { | ||
console.log('client connected and found informations'); | ||
set$1(meta, socket, t, payload); | ||
console.log('client connected and found informations') | ||
$1353865041_set(meta, socket, t, payload) | ||
} else { | ||
console.log('client discconected when logging in'); | ||
console.log('client discconected when logging in') | ||
} | ||
}).catch(err => hub.emit('error', err)); | ||
}).catch(err => hub.emit('error', err)) | ||
} else { | ||
set$1(meta, socket, t, payload); | ||
$1353865041_set(meta, socket, t, payload) | ||
} | ||
}; | ||
} | ||
const incomingSubscriptions = (hub, client, meta, id) => { | ||
const update = (t, type, subs, tree) => send$1(hub, client, t, type, subs, tree); | ||
if (!client.upstreamSubscriptions) client.upstreamSubscriptions = {}; | ||
const $1353865041_incomingSubscriptions = (hub, client, meta, id) => { | ||
const update = (t, type, subs, tree) => $1622386187(hub, client, t, type, subs, tree) | ||
if (!client.upstreamSubscriptions) client.upstreamSubscriptions = {} | ||
for (let key in meta.subscriptions) { | ||
let uid = key + '-' + id; | ||
let uid = key + '-' + id | ||
if (!client.upstreamSubscriptions[uid]) { | ||
let subs = parse$2(meta.subscriptions[key], hub); | ||
client.upstreamSubscriptions[uid] = subs; | ||
briskyStruct.subscribe(hub, subs, update); | ||
hub.subscriptions[hub.subscriptions.length - 1]._uid_ = id; | ||
let subs = $3742651364(meta.subscriptions[key], hub) | ||
client.upstreamSubscriptions[uid] = subs | ||
$1084818551.subscribe(hub, subs, update) | ||
hub.subscriptions[hub.subscriptions.length - 1]._uid_ = id | ||
} | ||
} | ||
}; | ||
} | ||
var removedInProgress; | ||
const on$1 = { | ||
// FILE: /Users/youzi/dev/hub.js/src/server/on.js | ||
var $2138030230_removedInProgress | ||
const $2138030230_on = { | ||
data: { | ||
remove$: (val, stamp, struct$$1) => { | ||
remove$: (val, stamp, struct) => { | ||
// just do a diff with the payload rly the best way for now... | ||
if (val === null && (!struct$$1._c || struct$$1._cLevel === 1)) { | ||
let p = struct$$1; | ||
let hub; | ||
if (val === null && (!struct._c || struct._cLevel === 1)) { | ||
let p = struct | ||
let hub | ||
while (p) { | ||
if (p.port && !p._c) { hub = p; } | ||
p = p.parent(); | ||
if (p.port && !p._c) { hub = p } | ||
p = p.parent() | ||
} | ||
if (hub) { | ||
// probably not working correctly with context | ||
const target = struct$$1.parent(); | ||
const target = struct.parent() | ||
if (target) { | ||
if (!target._removed) { | ||
target._removed = []; | ||
if (!removedInProgress) { | ||
removedInProgress = []; | ||
bs.on(() => { | ||
let i = removedInProgress.length; | ||
target._removed = [] | ||
if (!$2138030230_removedInProgress) { | ||
$2138030230_removedInProgress = [] | ||
$2379534587.on(() => { | ||
let i = $2138030230_removedInProgress.length | ||
while (i--) { | ||
delete removedInProgress[i]._removed; | ||
delete $2138030230_removedInProgress[i]._removed | ||
} | ||
}); | ||
}) | ||
} | ||
removedInProgress.push(target); | ||
$2138030230_removedInProgress.push(target) | ||
} | ||
target._removed.push(struct$$1); | ||
target._removed.push(struct) | ||
} | ||
@@ -827,90 +900,99 @@ } | ||
} | ||
}; | ||
} | ||
const Server = uws.Server; | ||
const $2138030230 = $2138030230_on | ||
const createServer = (hub, port) => { | ||
const server = new Server({ port }); | ||
console.log(`💫 hub listening on ${port} 💫`); | ||
// FILE: /Users/youzi/dev/hub.js/src/server/index.js | ||
const $3248609833_Server = $354051556.Server | ||
const $3248609833_createServer = (hub, port) => { | ||
const server = new $3248609833_Server({ port }) | ||
console.log(`💫 hub listening on ${port} 💫`) | ||
server.on('connection', socket => { | ||
socket.useragent = socket.upgradeReq && socket.upgradeReq.headers['user-agent']; | ||
socket.useragent = socket.upgradeReq && socket.upgradeReq.headers['user-agent'] | ||
// need to remove when done -- its the best thing todo (mem!!!) | ||
socket.on('message', (data) => { | ||
data = JSON.parse(data); | ||
if (data) { incoming(hub, socket, data); } | ||
}); | ||
data = JSON.parse(data) | ||
if (data) { $1353865041(hub, socket, data) } | ||
}) | ||
const close = () => { | ||
if (socket.client) removeClient(socket.client); | ||
}; | ||
if (socket.client) $2931540049_removeClient(socket.client) | ||
} | ||
socket.on('close', close); | ||
socket.on('close', close) | ||
// socket.on('error', () => close()) // need to do something here as well no leaks! | ||
}); | ||
}) | ||
return server | ||
}; | ||
} | ||
const removeServer = hub => { | ||
const server = hub._server_; | ||
const instances = hub.instances; | ||
closeConnections(hub); | ||
const $3248609833_removeServer = hub => { | ||
const server = hub._server_ | ||
const instances = hub.instances | ||
$3248609833_closeConnections(hub) | ||
for (let i = 0, len = instances && instances.length; i < len; i++) { | ||
closeConnections(instances[i]); | ||
$3248609833_closeConnections(instances[i]) | ||
} | ||
server.httpServer.close(); | ||
server.httpServer.close() | ||
// remove all clients subscriptions | ||
hub._server_ = null; | ||
}; | ||
hub._server_ = null | ||
} | ||
const closeConnections = hub => { | ||
const clients = hub.clients; | ||
const id = hub._uid_; // to exclude the client (not nessecary) | ||
const $3248609833_closeConnections = hub => { | ||
const clients = hub.clients | ||
const id = hub._uid_ // to exclude the client (not nessecary) | ||
if (clients) { | ||
clients.forEach(client => { | ||
if (client.socket && client.key !== id) { | ||
client.val = null; | ||
removeSubscriptions(hub, client.key); | ||
client.socket.close(); | ||
client.val = null | ||
$2931540049_removeSubscriptions(hub, client.key) | ||
client.socket.close() | ||
} | ||
}); | ||
}) | ||
} | ||
}; | ||
} | ||
const removePort = hub => { | ||
hub.port = null; | ||
hub.serverIndex = null; | ||
hub.emitters.set({ data: { port$: null } }); | ||
}; | ||
const $3248609833_removePort = hub => { | ||
hub.port = null | ||
hub.serverIndex = null | ||
hub.emitters.set({ data: { port$: null } }) | ||
} | ||
const port = (hub, val, key, stamp) => { | ||
const $3248609833_port = (hub, val, key, stamp) => { | ||
// use remove | ||
hub.on((val, stamp, t) => { | ||
if (val === null && !t._c && t === hub) { | ||
removeServer(hub); | ||
removePort(hub); | ||
$3248609833_removeServer(hub) | ||
$3248609833_removePort(hub) | ||
} | ||
}, 'port$'); | ||
if (!val) val = null; | ||
}, 'port$') | ||
if (!val) val = null | ||
if ((!hub.port && val) || (hub.port.compute() !== val)) { | ||
if (hub._server_) { | ||
removeServer(hub); | ||
$3248609833_removeServer(hub) | ||
} | ||
if (!val) { | ||
if (hub.port) hub.port.set(null, stamp); | ||
removePort(hub); | ||
if (hub.port) hub.port.set(null, stamp) | ||
$3248609833_removePort(hub) | ||
} else { | ||
if (!hub.port) { | ||
briskyStruct.create({ | ||
$1084818551.create({ | ||
on: { | ||
data: { | ||
port: (val, stamp, struct$$1) => { | ||
val = struct$$1.compute(); | ||
port: (val, stamp, struct) => { | ||
val = struct.compute() | ||
if (val) { | ||
let i = -1; | ||
if (hub.key) i++; | ||
hub.parent(() => { i++; }); | ||
hub.serverIndex = i; | ||
hub._server_ = createServer(hub, val); | ||
let i = -1 | ||
if (hub.key) i++ | ||
hub.parent(() => { i++ }) | ||
hub.serverIndex = i | ||
hub._server_ = $3248609833_createServer(hub, val) | ||
} | ||
@@ -920,24 +1002,23 @@ } | ||
} | ||
}, stamp, briskyStruct.struct, hub, key); | ||
}, stamp, $1084818551.struct, hub, key) | ||
} | ||
hub.port.set(val, stamp); | ||
hub.port.set(val, stamp) | ||
} | ||
} | ||
}; | ||
} | ||
const props$1 = { | ||
const $3248609833_props = { | ||
_server_: true, | ||
serverIndex: true, | ||
port | ||
}; | ||
port: $3248609833_port | ||
} | ||
var server = Object.freeze({ | ||
props: props$1, | ||
on: on$1 | ||
}); | ||
var context$1 = { | ||
const $3248609833_$ALL$ = { | ||
props: $3248609833_props, | ||
on: $2138030230 | ||
} | ||
// FILE: /Users/youzi/dev/hub.js/src/context.js | ||
const $25049122 = { | ||
props: { | ||
@@ -949,23 +1030,23 @@ contextKey: true, | ||
getContext (key, socket) { | ||
return fn(key, (key) => createContext(this, key), this, socket) | ||
return fn(key, (key) => $25049122_createContext(this, key), this, socket) | ||
} | ||
} | ||
}); | ||
}) | ||
} | ||
}, | ||
getContext: (key, context) => context() | ||
}; | ||
} | ||
const createContext = (hub, val) => { | ||
var result = find(hub, val); | ||
const $25049122_createContext = (hub, val) => { | ||
var result = $25049122_find(hub, val) | ||
if (!result) { | ||
result = hub.create({ contextKey: val }, false); | ||
result = hub.create({ contextKey: val }, false) | ||
} | ||
return result | ||
}; | ||
} | ||
const find = (hub, val) => { | ||
const instances = hub.instances; | ||
const $25049122_find = (hub, val) => { | ||
const instances = hub.instances | ||
if (instances) { | ||
let i = instances.length; | ||
let i = instances.length | ||
while (i--) { | ||
@@ -975,7 +1056,13 @@ if (instances[i].contextKey === val) return instances[i] | ||
} | ||
}; | ||
} | ||
const types = briskyStruct.struct.props.types; | ||
// FILE: /Users/youzi/dev/hub.js/src/hub.js | ||
const hub = briskyStruct.create({ | ||
const $302300578_types = $1084818551.struct.props.types | ||
const $302300578_hub = $1084818551.create({ | ||
type: 'hub', | ||
@@ -986,30 +1073,30 @@ instances: false, | ||
default: 'self', | ||
_uid_: (t, val) => { t.set({ define: { _uid_: val } }); }, | ||
_uid_: (t, val) => { t.set({ define: { _uid_: val } }) }, | ||
// why nto call this client id -- thats what it is | ||
clients: (t, val, key, stamp) => { | ||
if (!t.clients) { | ||
t.clients = briskyStruct.create(val, stamp, clients, t, key); | ||
t.clients = $1084818551.create(val, stamp, $302300578_clients, t, key) | ||
} else { | ||
briskyStruct.set(t.clients, val, stamp); | ||
$1084818551.set(t.clients, val, stamp) | ||
} | ||
}, | ||
types: types.bind(), // to not interfere with struct type | ||
type: briskyStruct.struct.props.type.bind(), | ||
types: $302300578_types.bind(), // to not interfere with struct type | ||
type: $1084818551.struct.props.type.bind(), | ||
client: true | ||
} | ||
}); | ||
}) | ||
hub.props.types.struct = hub.create({ | ||
props: { default: types.struct.props.default.bind() } | ||
}, false); | ||
$302300578_hub.props.types.struct = $302300578_hub.create({ | ||
props: { default: $302300578_types.struct.props.default.bind() } | ||
}, false) | ||
hub.props.types.struct.props.default.struct = hub.props.type.struct = hub; | ||
$302300578_hub.props.types.struct.props.default.struct = $302300578_hub.props.type.struct = $302300578_hub | ||
hub.set({ types: { hub: 'self' }, inject: [ server, client, context$1 ] }, false); | ||
$302300578_hub.set({ types: { hub: 'self' }, inject: [ $3248609833_$ALL$, $48594293_$ALL$, $25049122 ] }, false) | ||
hub.types._ks = void 0; | ||
$302300578_hub.types._ks = void 0 | ||
const clients = briskyStruct.create({ | ||
const $302300578_clients = $1084818551.create({ | ||
props: { | ||
default: hub.create({ | ||
default: $302300578_hub.create({ | ||
props: { | ||
@@ -1024,11 +1111,17 @@ cache: true, | ||
} | ||
}, false); | ||
}, false) | ||
if (typeof __dirname !== 'undefined') console.log('hub.js:', __dirname); | ||
const $302300578 = $302300578_hub | ||
const fn = (val, stamp) => hub.create(val, stamp); | ||
// FILE: /Users/youzi/dev/hub.js/src/index.js | ||
if (typeof __filename !== 'undefined') console.log('hub.js:', __filename) | ||
const $621652771_fn = (val, stamp) => $302300578.create(val, stamp) | ||
const $621652771 = $621652771_fn | ||
// add uids to stamps else it sucks -- dont compromise for tests think of that as an after thought | ||
module.exports = fn; | ||
module.exports = $621652771 |
{ | ||
"name": "hub.js", | ||
"description": "Seamless realtime communcation", | ||
"version": "0.0.11-b18830bfc1eb8e295a5dfd13af34af3d5a5f1070", | ||
"version": "0.0.11-b890f50ac4ecbed46729f19777085b28b48511e5", | ||
"main": "dist/index.js", | ||
"module": "dist/index.es.js", | ||
"jsnext:main": "dist/index.es.js", | ||
"browser": { | ||
"./dist/index.js": "./dist/browser.js", | ||
"./dist/index.es.js": "./dist/browser.es.js", | ||
"./dist/index.js": "./dist/index.browser.js", | ||
"./src/client/uid/index.js": "./src/client/uid/browser.js", | ||
@@ -17,5 +14,4 @@ "./src/server/index.js": "./src/server/browser.js", | ||
"scripts": { | ||
"build": "node rollup/build", | ||
"pretest": "npm run build && standard", | ||
"watch": "node rollup/watch", | ||
"build": "builder-boy src/index.js dist/index.js", | ||
"lint": "standard --fix", | ||
"version-commit": "npm --no-git-tag-version version $(node -pe \"require('./package.json').version.split('-')[0]\")-$(git log -n 1 --pretty=format:'%H')", | ||
@@ -25,6 +21,6 @@ "publish-branch": "npm run version-commit && npm publish --tag $(git rev-parse --abbrev-ref HEAD | sed 's/\\//-/g')", | ||
"test": "node test/index.js", | ||
"dev": "node rollup/watch & nodemon --harmony-async-await test/index.js", | ||
"cover": "nyc npm test", | ||
"travis": "nyc npm test && nyc report --reporter=text-lcov | coveralls" | ||
}, | ||
"precommit": "lint, test", | ||
"repository": { | ||
@@ -62,2 +58,3 @@ "type": "git", | ||
"devDependencies": { | ||
"builder-boy": "latest", | ||
"buble": "0.15.1", | ||
@@ -68,6 +65,2 @@ "coveralls": "^2.11.9", | ||
"pre-commit": "^1.1.3", | ||
"rollup": "^0.37.0", | ||
"rollup-plugin-commonjs": "^6.0.0", | ||
"rollup-plugin-istanbul": "^1.1.0", | ||
"rollup-plugin-node-resolve": "^2.0.0", | ||
"rollup-watch": "^2.5.0", | ||
@@ -74,0 +67,0 @@ "standard": "^8.1.0", |
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 not supported yet
400574
9
13
3261