Comparing version 0.0.26 to 0.0.27
import hash from 'string-hash'; | ||
import { c, create, parse, set, struct, subscribe } from 'brisky-struct'; | ||
import { create, parse, subscribe } from 'brisky-struct'; | ||
import bs from 'brisky-stamp'; | ||
@@ -29,7 +29,7 @@ | ||
const serialize = (hub, t, struct$$1, val, level) => { | ||
const path = struct$$1.path(); | ||
const serialize = (hub, t, struct, val, level) => { | ||
const path = struct.path(); | ||
const len = path.length; | ||
if (struct$$1.val !== void 0 || val === null) { | ||
if (struct.val !== void 0 || val === null) { | ||
var s = t[0] || (t[0] = {}); | ||
@@ -43,7 +43,9 @@ | ||
s = t; | ||
if (s.val === null) { return } | ||
if (s.val === null) { | ||
return | ||
} | ||
} | ||
} | ||
s.stamp = parse$1(struct$$1.stamp, hub, t); | ||
s.stamp = parse$1(struct.stamp, hub, t); | ||
@@ -57,8 +59,8 @@ if (val === null) { | ||
s.val = null; | ||
} else if (struct$$1.val && struct$$1.val.inherits) { | ||
s.val = struct$$1.val.path(); | ||
} else if (struct.val && struct.val.inherits) { | ||
s.val = struct.val.path(); | ||
s.val.unshift('@', 'root'); | ||
serialize(hub, t, struct$$1.val, val, level); | ||
} else if (struct$$1.val !== void 0) { | ||
s.val = struct$$1.val; | ||
serialize(hub, t, struct.val, val, level); | ||
} else if (struct.val !== void 0) { | ||
s.val = struct.val; | ||
} | ||
@@ -76,21 +78,22 @@ } | ||
const send = (val, stamp, struct$$1) => { | ||
const send = (val, stamp, struct) => { | ||
if (bs.type(stamp) !== 'upstream') { | ||
let hub; | ||
let p = struct$$1; | ||
let p = struct; | ||
while (p) { | ||
if (p.url && !p._c) { hub = p; } | ||
if (p.url && !p.context) { hub = p; } | ||
p = p.parent(); // needs to walk over context (for multi server) | ||
} | ||
if (hub && !hub.receiveOnly && struct$$1.key !== 'clients') { | ||
if (struct$$1 === hub) { | ||
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$$1._p.key === 'clients') { | ||
if (struct$$1.key !== hub.id) { | ||
} else if (struct._p.key === 'clients') { | ||
if (struct.key !== hub.id) { | ||
return | ||
} | ||
} | ||
serialize(hub, inProgress(hub, bs.on), struct$$1, val, hub.urlIndex); | ||
serialize(hub, inProgress(hub, bs.on), struct, val, hub.urlIndex); | ||
} | ||
@@ -137,8 +140,7 @@ } | ||
const parse$2 = (struct$$1, obj, key, root) => { | ||
const parse$2 = (struct, obj, key, root) => { | ||
const result = {}; | ||
if (!root) { root = result; } | ||
if (obj.type) result.type = obj.type; // need to be done before the rest of subs to sync correctly | ||
for (let i in obj) { | ||
if (i !== '_' && i !== 'type') { | ||
if (i !== '_') { | ||
// @todo more resolve for parent and client | ||
@@ -177,3 +179,3 @@ // need more just use client (since milti hub) | ||
// empty objects are very uninteresetting maybe just skip them | ||
let parsed = parse$2(struct$$1, obj[i], i, root); | ||
let parsed = parse$2(struct, obj[i], i, root); | ||
@@ -192,3 +194,3 @@ // if (i === 'root' || i === 'parent') { | ||
} | ||
// if result is empty ignore -- may not be a good idea | ||
// if result is empty ignore | ||
return isEmpty(result) ? void 0 : result | ||
@@ -231,4 +233,4 @@ }; | ||
socket.onopen = () => { | ||
hub.socket = socket; | ||
const stamp = bs.create('connected', hub.id); | ||
hub.socket = socket; | ||
meta(hub); | ||
@@ -241,5 +243,7 @@ hub.set({ connected: true }, stamp); | ||
const stamp = bs.create('upstream'); | ||
// console.log(JSON.stringify(JSON.parse(data), false, 2)) | ||
// 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') | ||
}; | ||
@@ -267,3 +271,3 @@ }; | ||
hub.on((val, stamp, t) => { | ||
if (val === null && !t._c && t === hub) { | ||
if (val === null && !t.context && t === hub) { | ||
hub.subscriptions = []; | ||
@@ -311,3 +315,5 @@ removeUrl(hub); | ||
const connected = { type: 'struct' }; | ||
const connected = { | ||
type: 'struct' | ||
}; | ||
@@ -370,34 +376,33 @@ const context = (hub, val) => { | ||
const props$1 = { contextKey: true }; | ||
// import { struct } from 'brisky-struct' | ||
const define$1 = { | ||
getContext (val) { | ||
var result = find(this, val); | ||
if (!result) { | ||
result = this.create({ contextKey: val }, false); | ||
} | ||
return result | ||
const clientHub = { | ||
type: 'hub', | ||
props: { | ||
cache: true, | ||
upstreamSubscriptions: true, | ||
// isUpstream: true, | ||
// myupstream subs | ||
resolve: true, | ||
socket: true // only nessecary for downstream clients | ||
} | ||
}; | ||
const find = (hub, val) => { | ||
const instances = hub.instances; | ||
if (instances) { | ||
let i = instances.length; | ||
while (i--) { | ||
if (instances[i].contextKey === val) { | ||
// console.log('found context --->', val, instances[i].clients.keys()) | ||
return instances[i] | ||
} | ||
const props$1 = { | ||
clients: { // need to exclude on context | ||
props: { | ||
default: clientHub | ||
} | ||
} | ||
}, | ||
client: true // test if you can subscribe to it | ||
}; | ||
var context$1 = Object.freeze({ | ||
props: props$1, | ||
define: define$1 | ||
var clients = Object.freeze({ | ||
props: props$1 | ||
}); | ||
const types = struct.props.types; | ||
// need to be able to set timestamp mode on bs -- allways fo ts on bs | ||
@@ -407,55 +412,18 @@ const hub = create({ | ||
instances: false, | ||
define: { isHub: true }, | ||
types: { hub: 'self' }, | ||
props: { | ||
default: 'self', | ||
id: (t, val) => { t.set({ define: { id: val } }); }, | ||
clients: (t, val, key, stamp) => { | ||
if (!t.clients) { | ||
t.clients = c(clients, val, stamp, t, key); | ||
} else { | ||
set(t.clients, val, stamp); | ||
} | ||
}, | ||
types: types.bind(), // to not interfere with struct type | ||
type: struct.props.type.bind(), | ||
client: true | ||
id: (t, val) => { t.set({ define: { id: val } }); } | ||
}, | ||
id | ||
id: id, | ||
inject: [ | ||
client, | ||
server, | ||
clients | ||
] | ||
}); | ||
hub.props.types.struct = c(hub, { | ||
props: { default: types.struct.props.default.bind() } | ||
}); | ||
hub.props.types.struct.props.default.struct = hub.props.type.struct = hub; | ||
hub.set({ types: { hub: 'self' }, inject: [ server, context$1, client ] }, false); | ||
hub.types._ks = void 0; | ||
const clients = create({ | ||
props: { | ||
default: hub.create({ | ||
props: { | ||
cache: true, | ||
upstreamSubscriptions: true, | ||
resolve: true, | ||
socket: true, | ||
context: true | ||
} | ||
}) | ||
} | ||
}); | ||
// import bs from 'brisky-stamp' | ||
var index = (val, stamp) => { | ||
if (stamp === void 0) { | ||
const r = hub.create(val, bs.create()); | ||
bs.close(); | ||
return r | ||
} else { | ||
return hub.create(val, stamp) | ||
} | ||
}; | ||
var index = (val, stamp) => hub.create(val); | ||
@@ -462,0 +430,0 @@ // add uids to stamps else it sucks -- dont compromise for tests think of that as an after thought |
@@ -33,7 +33,7 @@ 'use strict'; | ||
const serialize = (hub, t, struct$$1, val, level) => { | ||
const path = struct$$1.path(); | ||
const serialize = (hub, t, struct, val, level) => { | ||
const path = struct.path(); | ||
const len = path.length; | ||
if (struct$$1.val !== void 0 || val === null) { | ||
if (struct.val !== void 0 || val === null) { | ||
var s = t[0] || (t[0] = {}); | ||
@@ -47,7 +47,9 @@ | ||
s = t; | ||
if (s.val === null) { return } | ||
if (s.val === null) { | ||
return | ||
} | ||
} | ||
} | ||
s.stamp = parse$1(struct$$1.stamp, hub, t); | ||
s.stamp = parse$1(struct.stamp, hub, t); | ||
@@ -61,8 +63,8 @@ if (val === null) { | ||
s.val = null; | ||
} else if (struct$$1.val && struct$$1.val.inherits) { | ||
s.val = struct$$1.val.path(); | ||
} else if (struct.val && struct.val.inherits) { | ||
s.val = struct.val.path(); | ||
s.val.unshift('@', 'root'); | ||
serialize(hub, t, struct$$1.val, val, level); | ||
} else if (struct$$1.val !== void 0) { | ||
s.val = struct$$1.val; | ||
serialize(hub, t, struct.val, val, level); | ||
} else if (struct.val !== void 0) { | ||
s.val = struct.val; | ||
} | ||
@@ -80,21 +82,22 @@ } | ||
const send = (val, stamp, struct$$1) => { | ||
const send = (val, stamp, struct) => { | ||
if (bs.type(stamp) !== 'upstream') { | ||
let hub; | ||
let p = struct$$1; | ||
let p = struct; | ||
while (p) { | ||
if (p.url && !p._c) { hub = p; } | ||
if (p.url && !p.context) { hub = p; } | ||
p = p.parent(); // needs to walk over context (for multi server) | ||
} | ||
if (hub && !hub.receiveOnly && struct$$1.key !== 'clients') { | ||
if (struct$$1 === hub) { | ||
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$$1._p.key === 'clients') { | ||
if (struct$$1.key !== hub.id) { | ||
} else if (struct._p.key === 'clients') { | ||
if (struct.key !== hub.id) { | ||
return | ||
} | ||
} | ||
serialize(hub, inProgress(hub, bs.on), struct$$1, val, hub.urlIndex); | ||
serialize(hub, inProgress(hub, bs.on), struct, val, hub.urlIndex); | ||
} | ||
@@ -141,8 +144,7 @@ } | ||
const parse$2 = (struct$$1, obj, key, root) => { | ||
const parse$2 = (struct, obj, key, root) => { | ||
const result = {}; | ||
if (!root) { root = result; } | ||
if (obj.type) result.type = obj.type; // need to be done before the rest of subs to sync correctly | ||
for (let i in obj) { | ||
if (i !== '_' && i !== 'type') { | ||
if (i !== '_') { | ||
// @todo more resolve for parent and client | ||
@@ -181,3 +183,3 @@ // need more just use client (since milti hub) | ||
// empty objects are very uninteresetting maybe just skip them | ||
let parsed = parse$2(struct$$1, obj[i], i, root); | ||
let parsed = parse$2(struct, obj[i], i, root); | ||
@@ -196,3 +198,3 @@ // if (i === 'root' || i === 'parent') { | ||
} | ||
// if result is empty ignore -- may not be a good idea | ||
// if result is empty ignore | ||
return isEmpty(result) ? void 0 : result | ||
@@ -235,4 +237,4 @@ }; | ||
socket.onopen = () => { | ||
hub.socket = socket; | ||
const stamp = bs.create('connected', hub.id); | ||
hub.socket = socket; | ||
meta(hub); | ||
@@ -245,5 +247,7 @@ hub.set({ connected: true }, stamp); | ||
const stamp = bs.create('upstream'); | ||
// console.log(JSON.stringify(JSON.parse(data), false, 2)) | ||
// 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') | ||
}; | ||
@@ -271,3 +275,3 @@ }; | ||
hub.on((val, stamp, t) => { | ||
if (val === null && !t._c && t === hub) { | ||
if (val === null && !t.context && t === hub) { | ||
hub.subscriptions = []; | ||
@@ -315,3 +319,5 @@ removeUrl(hub); | ||
const connected = { type: 'struct' }; | ||
const connected = { | ||
type: 'struct' | ||
}; | ||
@@ -374,34 +380,33 @@ const context = (hub, val) => { | ||
const props$1 = { contextKey: true }; | ||
// import { struct } from 'brisky-struct' | ||
const define$1 = { | ||
getContext (val) { | ||
var result = find(this, val); | ||
if (!result) { | ||
result = this.create({ contextKey: val }, false); | ||
} | ||
return result | ||
const clientHub = { | ||
type: 'hub', | ||
props: { | ||
cache: true, | ||
upstreamSubscriptions: true, | ||
// isUpstream: true, | ||
// myupstream subs | ||
resolve: true, | ||
socket: true // only nessecary for downstream clients | ||
} | ||
}; | ||
const find = (hub, val) => { | ||
const instances = hub.instances; | ||
if (instances) { | ||
let i = instances.length; | ||
while (i--) { | ||
if (instances[i].contextKey === val) { | ||
// console.log('found context --->', val, instances[i].clients.keys()) | ||
return instances[i] | ||
} | ||
const props$1 = { | ||
clients: { // need to exclude on context | ||
props: { | ||
default: clientHub | ||
} | ||
} | ||
}, | ||
client: true // test if you can subscribe to it | ||
}; | ||
var context$1 = Object.freeze({ | ||
props: props$1, | ||
define: define$1 | ||
var clients = Object.freeze({ | ||
props: props$1 | ||
}); | ||
const types = briskyStruct.struct.props.types; | ||
// need to be able to set timestamp mode on bs -- allways fo ts on bs | ||
@@ -411,55 +416,18 @@ const hub = briskyStruct.create({ | ||
instances: false, | ||
define: { isHub: true }, | ||
types: { hub: 'self' }, | ||
props: { | ||
default: 'self', | ||
id: (t, val) => { t.set({ define: { id: val } }); }, | ||
clients: (t, val, key, stamp) => { | ||
if (!t.clients) { | ||
t.clients = briskyStruct.c(clients, val, stamp, t, key); | ||
} else { | ||
briskyStruct.set(t.clients, val, stamp); | ||
} | ||
}, | ||
types: types.bind(), // to not interfere with struct type | ||
type: briskyStruct.struct.props.type.bind(), | ||
client: true | ||
id: (t, val) => { t.set({ define: { id: val } }); } | ||
}, | ||
id | ||
id: id, | ||
inject: [ | ||
client, | ||
server, | ||
clients | ||
] | ||
}); | ||
hub.props.types.struct = briskyStruct.c(hub, { | ||
props: { default: types.struct.props.default.bind() } | ||
}); | ||
hub.props.types.struct.props.default.struct = hub.props.type.struct = hub; | ||
hub.set({ types: { hub: 'self' }, inject: [ server, context$1, client ] }, false); | ||
hub.types._ks = void 0; | ||
const clients = briskyStruct.create({ | ||
props: { | ||
default: hub.create({ | ||
props: { | ||
cache: true, | ||
upstreamSubscriptions: true, | ||
resolve: true, | ||
socket: true, | ||
context: true | ||
} | ||
}) | ||
} | ||
}); | ||
// import bs from 'brisky-stamp' | ||
var index = (val, stamp) => { | ||
if (stamp === void 0) { | ||
const r = hub.create(val, bs.create()); | ||
bs.close(); | ||
return r | ||
} else { | ||
return hub.create(val, stamp) | ||
} | ||
}; | ||
var index = (val, stamp) => hub.create(val); | ||
@@ -466,0 +434,0 @@ // add uids to stamps else it sucks -- dont compromise for tests think of that as an after thought |
@@ -202,56 +202,42 @@ var $1662971556 = require('brisky-struct') | ||
;const $3700476957_maxSize = 1e7 // byteLength -- has to be like 10mb | ||
;var $1385737091 = 1e7 // byteLength -- has to be like 10mb | ||
const $3700476957_send = (client, payload, next) => { | ||
client.socket.send(payload) | ||
process.nextTick(next) | ||
} | ||
; | ||
const $3700476957_sendLarge = (raw, client) => { | ||
const size = Buffer.byteLength(raw, 'utf8') | ||
if (size > $3700476957_maxSize) { | ||
if (!client.blobInProgress) { | ||
client.blobInProgress = [] | ||
} | ||
console.log('📡 exceeds framelimit - split up', (size / (1024 * 1024)) | 0, 'mb') | ||
const buf = Buffer.from(raw, 'utf8') | ||
let i = 0 | ||
// TODO: implement send | ||
const drainInProgress = done => { | ||
if (client.blobInProgress.length > 0) { | ||
$3700476957_send(client, client.blobInProgress.shift(), () => drainInProgress(done)) | ||
} else { | ||
done() | ||
} | ||
} | ||
var $2003515468_blobArray = false | ||
const next = () => { | ||
i++ | ||
// make sure you end with an non maxsize buffer (send an empty one if nessecary) | ||
if (i * $3700476957_maxSize <= size) { | ||
$3700476957_send(client, buf.slice(i * $3700476957_maxSize, (i + 1) * $3700476957_maxSize), next) | ||
} else { | ||
drainInProgress(() => { | ||
client.blobInProgress = false | ||
}) | ||
} | ||
const $2003515468_receiveLarge = (data, cb) => { | ||
if (!$2003515468_blobArray) $2003515468_blobArray = [] | ||
$2003515468_blobArray.push(data) | ||
if (data.size < $1385737091) { | ||
let i = $2003515468_blobArray.length | ||
let stringArray = [] | ||
while (i--) { | ||
const reader = new FileReader() // eslint-disable-line | ||
console.log(i) | ||
const onLoadEnd = ((i, e) => { | ||
reader.removeEventListener('loadend', onLoadEnd, false) | ||
if (!e.error) { | ||
stringArray[i] = reader.result | ||
if (i === 0) cb(stringArray.join('')) | ||
} | ||
}).bind(null, i) | ||
reader.addEventListener('loadend', onLoadEnd, false) | ||
reader.readAsText($2003515468_blobArray[i]) | ||
} | ||
$3700476957_send(client, buf.slice(i * $3700476957_maxSize, (i + 1) * $3700476957_maxSize), next) | ||
return true | ||
$2003515468_blobArray = false | ||
} | ||
} | ||
const $3700476957_receiveLarge = (data, bufferArray) => { | ||
// make sure new Buffer works on the browser... | ||
bufferArray.push(new Buffer(data).toString('utf8')) | ||
if (data.byteLength < $3700476957_maxSize) return bufferArray.join('') | ||
} | ||
var $3700476957_$ALL$ = { | ||
sendLarge: $3700476957_sendLarge, | ||
receiveLarge: $3700476957_receiveLarge | ||
var $2003515468_$ALL$ = { | ||
receiveLarge: $2003515468_receiveLarge | ||
} | ||
@@ -270,3 +256,2 @@ ; | ||
const client = hub.client || $2828932010(hub, {}, false) | ||
var bufferArray = false | ||
@@ -311,15 +296,15 @@ hub.set({ client }, false) | ||
typeof data !== 'string' && | ||
typeof window === 'undefined' && | ||
data instanceof ArrayBuffer | ||
( | ||
data instanceof ArrayBuffer || | ||
(('Blob' in global) && data instanceof Blob) || // eslint-disable-line | ||
(('WebkitBlob' in global) && data instanceof WebkitBlob) // eslint-disable-line | ||
) | ||
) { | ||
if (!bufferArray) bufferArray = [] | ||
const result = $3700476957_receiveLarge(data, bufferArray) | ||
if (result) { | ||
data = result | ||
bufferArray = false | ||
} else { | ||
return | ||
} | ||
$2003515468_receiveLarge(data, setInHub) | ||
} else { | ||
setInHub(data) | ||
} | ||
} | ||
const setInHub = data => { | ||
if (!hub.receiveOnly) { | ||
@@ -326,0 +311,0 @@ hub.receiveOnly = true |
import hash from 'string-hash'; | ||
import { c, create, get, getKeys, getType, parse, set, struct, subscribe } from 'brisky-struct'; | ||
import { create, get, getKeys, parse, subscribe } from 'brisky-struct'; | ||
import bs from 'brisky-stamp'; | ||
@@ -28,7 +28,7 @@ import WebSocket from 'uws'; | ||
const serialize = (hub, t, struct$$1, val, level) => { | ||
const path = struct$$1.path(); | ||
const serialize = (hub, t, struct, val, level) => { | ||
const path = struct.path(); | ||
const len = path.length; | ||
if (struct$$1.val !== void 0 || val === null) { | ||
if (struct.val !== void 0 || val === null) { | ||
var s = t[0] || (t[0] = {}); | ||
@@ -42,7 +42,9 @@ | ||
s = t; | ||
if (s.val === null) { return } | ||
if (s.val === null) { | ||
return | ||
} | ||
} | ||
} | ||
s.stamp = parse$1(struct$$1.stamp, hub, t); | ||
s.stamp = parse$1(struct.stamp, hub, t); | ||
@@ -56,8 +58,8 @@ if (val === null) { | ||
s.val = null; | ||
} else if (struct$$1.val && struct$$1.val.inherits) { | ||
s.val = struct$$1.val.path(); | ||
} else if (struct.val && struct.val.inherits) { | ||
s.val = struct.val.path(); | ||
s.val.unshift('@', 'root'); | ||
serialize(hub, t, struct$$1.val, val, level); | ||
} else if (struct$$1.val !== void 0) { | ||
s.val = struct$$1.val; | ||
serialize(hub, t, struct.val, val, level); | ||
} else if (struct.val !== void 0) { | ||
s.val = struct.val; | ||
} | ||
@@ -75,21 +77,22 @@ } | ||
const send = (val, stamp, struct$$1) => { | ||
const send = (val, stamp, struct) => { | ||
if (bs.type(stamp) !== 'upstream') { | ||
let hub; | ||
let p = struct$$1; | ||
let p = struct; | ||
while (p) { | ||
if (p.url && !p._c) { hub = p; } | ||
if (p.url && !p.context) { hub = p; } | ||
p = p.parent(); // needs to walk over context (for multi server) | ||
} | ||
if (hub && !hub.receiveOnly && struct$$1.key !== 'clients') { | ||
if (struct$$1 === hub) { | ||
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$$1._p.key === 'clients') { | ||
if (struct$$1.key !== hub.id) { | ||
} else if (struct._p.key === 'clients') { | ||
if (struct.key !== hub.id) { | ||
return | ||
} | ||
} | ||
serialize(hub, inProgress(hub, bs.on), struct$$1, val, hub.urlIndex); | ||
serialize(hub, inProgress(hub, bs.on), struct, val, hub.urlIndex); | ||
} | ||
@@ -133,8 +136,7 @@ } | ||
const parse$2 = (struct$$1, obj, key, root) => { | ||
const parse$2 = (struct, obj, key, root) => { | ||
const result = {}; | ||
if (!root) { root = result; } | ||
if (obj.type) result.type = obj.type; // need to be done before the rest of subs to sync correctly | ||
for (let i in obj) { | ||
if (i !== '_' && i !== 'type') { | ||
if (i !== '_') { | ||
// @todo more resolve for parent and client | ||
@@ -173,3 +175,3 @@ // need more just use client (since milti hub) | ||
// empty objects are very uninteresetting maybe just skip them | ||
let parsed = parse$2(struct$$1, obj[i], i, root); | ||
let parsed = parse$2(struct, obj[i], i, root); | ||
@@ -188,3 +190,3 @@ // if (i === 'root' || i === 'parent') { | ||
} | ||
// if result is empty ignore -- may not be a good idea | ||
// if result is empty ignore | ||
return isEmpty(result) ? void 0 : result | ||
@@ -227,4 +229,4 @@ }; | ||
socket.onopen = () => { | ||
hub.socket = socket; | ||
const stamp = bs.create('connected', hub.id); | ||
hub.socket = socket; | ||
meta(hub); | ||
@@ -237,5 +239,7 @@ hub.set({ connected: true }, stamp); | ||
const stamp = bs.create('upstream'); | ||
// console.log(JSON.stringify(JSON.parse(data), false, 2)) | ||
// 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') | ||
}; | ||
@@ -263,3 +267,3 @@ }; | ||
hub.on((val, stamp, t) => { | ||
if (val === null && !t._c && t === hub) { | ||
if (val === null && !t.context && t === hub) { | ||
hub.subscriptions = []; | ||
@@ -307,3 +311,5 @@ removeUrl(hub); | ||
const connected = { type: 'struct' }; | ||
const connected = { | ||
type: 'struct' | ||
}; | ||
@@ -399,3 +405,3 @@ const context = (hub, val) => { | ||
i = i.slice(4); | ||
// need to fix bublé stuff in these fn creations -- prop need to add buble | ||
// need to fix buble stuff in these fn creations -- prop need to add buble | ||
// runtime in a hub | ||
@@ -443,17 +449,3 @@ let pass; | ||
} | ||
if (!isEmpty) { | ||
// bit hacky... | ||
if (client.inProgress.types) { | ||
for (let i in client.inProgress) { | ||
if (i === 'types') { | ||
break | ||
} else { | ||
let tmp = client.inProgress[i]; | ||
delete client.inProgress[i]; | ||
client.inProgress[i] = tmp; | ||
} | ||
} | ||
} | ||
client.socket.send(JSON.stringify(client.inProgress)); | ||
} | ||
if (!isEmpty) { client.socket.send(JSON.stringify(client.inProgress)); } | ||
client.inProgress = false; | ||
@@ -477,22 +469,28 @@ } | ||
if (tree.$t && tree.$t._p && !tree.$t._p[tree.$t.key]) { | ||
serialize$2(hub.id, client, progress(client), subs, tree.$t, null, get(hub, 'serverIndex'), tree); | ||
serialize$2(hub.id, client, progress(client), subs, tree.$t, null, hub.serverIndex, tree); | ||
} | ||
} | ||
if (t.val !== void 0 || val === null || subs.val === true) { | ||
// opt this line (the get) just use a define or something | ||
serialize$2(hub.id, client, progress(client), subs, t, val, get(hub, 'serverIndex'), tree); | ||
serialize$2(hub.id, client, progress(client), subs, t, val, hub.serverIndex, tree); | ||
} | ||
}; | ||
const cache = (client, struct$$1, stamp, level, val) => { | ||
if (!client.cache) client.cache = {}; | ||
client.cache[struct$$1.uid()] = stamp[0]; | ||
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 = (client, struct$$1, stamp) => { | ||
return client.cache && client.cache[struct$$1.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$$1, id, client, level) => { | ||
cache(client, struct$$1, stamp, level); | ||
const setStamp = (s, stamp, src, struct, id, client, level) => { | ||
cache(client, struct, stamp, level); | ||
s.stamp = !src | ||
@@ -503,13 +501,7 @@ ? bs.create(bs.type(stamp), id, bs.val(stamp)) | ||
// clean the cached up a bit | ||
const serialize$2 = (id, client, t, subs, struct$$1, val, level) => { | ||
const stamp = get(struct$$1, 'stamp'); | ||
var cached, isType; | ||
if (stamp && (val === null || !(cached = isCached(client, struct$$1, stamp))) || subs.val === true) { | ||
const serialize$2 = (id, client, t, subs, struct, val, level) => { | ||
const stamp = struct.stamp; | ||
if (stamp && (val === null || !isCached(client, struct, stamp))) { | ||
const src = bs.src(stamp); | ||
if ( | ||
src !== client.key && bs.src(t.tStamp) !== client.key || | ||
(isType = struct$$1.key === 'type') | ||
) { | ||
if (src !== client.key && bs.src(t.tStamp) !== client.key) { | ||
if ( | ||
@@ -521,60 +513,47 @@ client.resolve && | ||
if (val !== null) { | ||
if (struct$$1.val !== void 0) cache(client, struct$$1, stamp, level); | ||
if (struct.val !== void 0) cache(client, struct, stamp, level); | ||
if (subs.val === true) { | ||
const keys = getKeys(struct$$1); | ||
if (keys) deepSerialize(keys, id, client, t, subs, struct$$1, val, level); | ||
const keys = getKeys(struct); | ||
if (keys) { | ||
deepSerialize(keys, id, client, t, subs, struct, val, level); | ||
} | ||
} | ||
} | ||
} else { | ||
if (subs.type) { | ||
// simple but will make it better need more checks | ||
var p = struct$$1; | ||
while (p) { | ||
if (p.key === 'types') { | ||
return | ||
} | ||
p = p._p; | ||
} | ||
} | ||
if (isType) { // means its blocked otherwise (could be a set form own client) | ||
typeSerialize(id, client, t, subs, struct$$1, val, level); | ||
} else if (!cached && (struct$$1.val !== void 0 || val === null)) { | ||
const path = struct$$1.path(); | ||
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++) { | ||
let tt = s[path[i]]; | ||
if (!tt) { | ||
// prev = s | ||
let t = s[path[i]]; | ||
if (!t) { | ||
s = s[path[i]] = {}; | ||
} else { | ||
s = tt; | ||
if (s.val === null) return | ||
s = t; | ||
if (s.val === null) { | ||
return | ||
} | ||
} | ||
} | ||
if (val === null) { | ||
setStamp(s, stamp, src, struct$$1, id, client, level, val); | ||
setStamp(s, stamp, src, struct, id, client, level, val); | ||
s.val = null; | ||
} else { | ||
if (struct$$1.key === 'type') { | ||
typeSerialize(id, client, t, subs, struct$$1, val, level); | ||
} | ||
setStamp(s, stamp, src, struct$$1, id, client, level); | ||
if (struct$$1.val && struct$$1.val.inherits) { | ||
s.val = struct$$1.val.path(); | ||
setStamp(s, stamp, src, struct, id, client, level); | ||
if (struct.val && struct.val.inherits) { | ||
s.val = struct.val.path(); | ||
s.val.unshift('@', 'root'); | ||
serialize$2(id, client, t, subs, struct$$1.val, val, level); | ||
} else if (struct$$1.val !== void 0) { | ||
s.val = struct$$1.val; | ||
serialize$2(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); | ||
} | ||
} | ||
if (subs.val === true) { | ||
const keys = getKeys(struct$$1); | ||
if (keys) deepSerialize(keys, id, client, t, subs, struct$$1, val, level); | ||
} | ||
} | ||
@@ -585,20 +564,20 @@ } | ||
const typeSerialize = (id, client, t, subs, struct$$1, val, level) => { | ||
serialize$2(id, client, t, subs, getType(struct$$1.parent(2), struct$$1.compute()), val, level); | ||
}; | ||
const deepSerialize = (keys, id, client, t, subs, struct$$1, val, level) => { | ||
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$$1, keys[i]); | ||
if (prop && prop.isHub) serialize$2(id, client, t, subs, prop, val, level); | ||
let prop = get(struct, keys[i]); | ||
if (get(prop, 'type') === 'hub') { | ||
serialize$2(id, client, t, subs, prop, val, level); | ||
} | ||
} | ||
} | ||
// feels really shacky /w context :/ needs tests | ||
if (struct$$1._removed) { | ||
for (let i = 0, len = struct$$1._removed.length; i < len; i++) { | ||
let prop = struct$$1._removed[i]; | ||
if (prop && prop.isHub) serialize$2(id, client, t, subs, prop, null, level); | ||
} | ||
} | ||
// 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) | ||
// } | ||
// } | ||
// } | ||
}; | ||
@@ -614,10 +593,8 @@ | ||
t = hub; | ||
if (client.context != meta.context) { // eslint-disable-line | ||
client.set(null); | ||
t = create$2(hub, socket, meta); | ||
client = socket.client; | ||
} else if (meta.subscriptions) { | ||
// switch etc | ||
if (meta.subscriptions) { | ||
incomingSubscriptions(t, client, meta, client.id); | ||
bs.close(); | ||
} | ||
// console.log('perhaps replace something (e.g. subs or whatever') | ||
} else { | ||
@@ -646,6 +623,12 @@ t = create$2(hub, socket, meta); | ||
const id = meta.id; | ||
const t = meta.context ? hub.getContext(meta.context) : hub; | ||
t.set({ clients: { [id]: { socket, context: meta.context } } }, stamp); | ||
var t; | ||
if (meta.context) { | ||
} else { | ||
t = hub; // will also become secured -- default will ofc be IP | ||
} | ||
t.set({ clients: { [id]: { socket } } }, stamp); | ||
const client = socket.client = t.clients[id]; | ||
if (meta.subscriptions) incomingSubscriptions(t, client, meta, id); | ||
if (meta.subscriptions) { | ||
incomingSubscriptions(t, client, meta, id); | ||
} | ||
bs.close(stamp); | ||
@@ -656,4 +639,10 @@ return t | ||
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 update = (t, type, subs, tree) => { | ||
send$1(hub, client, t, type, subs, tree); | ||
}; | ||
if (!client.upstreamSubscriptions) { | ||
client.upstreamSubscriptions = {}; | ||
} | ||
for (let key in meta.subscriptions) { | ||
@@ -665,3 +654,4 @@ let uid = key + '-' + id; | ||
subscribe(hub, subs, update); | ||
hub.subscriptions[hub.subscriptions.length - 1].id = id; | ||
// can also just add the function to the map | ||
hub.subscriptions[hub.subscriptions.length - 1].id = id; // it aint pretty but works... | ||
} | ||
@@ -674,6 +664,6 @@ } | ||
const removeSubscriptions = (t, id) => { | ||
if (t.subscriptions) { | ||
let i = t.subscriptions.length; | ||
while (i--) { // clean this up with unsubscribe in struct | ||
if (t.subscriptions[i].id === id) t.subscriptions.splice(i, 1); | ||
let i = t.subscriptions ? t.subscriptions.length : 0; | ||
while (i--) { // clean this up with system in struct | ||
if (t.subscriptions[i].id === id) { | ||
t.subscriptions.splice(i, 1); | ||
} | ||
@@ -696,8 +686,6 @@ } | ||
const id = client.key; | ||
// console.log(`CLIENT DC ${hub.id} - REMOVE THE CLIENT CONTEXT (missing)`) | ||
const t = client.parent(2); | ||
removeSubscriptions(t, id); | ||
client.set(null, stamp); | ||
if (client.context && t.clients.keys().length === (t.url ? 1 : 0)) { | ||
t.set(null, stamp); | ||
} | ||
bs.close(); | ||
@@ -708,2 +696,3 @@ } | ||
socket.on('close', close); | ||
// socket.on('error', () => close()) // need to do something here as well no leaks! | ||
@@ -748,3 +737,4 @@ }); | ||
hub.on((val, stamp, t) => { | ||
if (val === null && !t._c && t === hub) { | ||
if (val === null && !t.context && t === hub) { | ||
// console.log(`☠️ REMOVE ${hub.id} SERVER ☠️`) | ||
removeServer(hub); | ||
@@ -757,2 +747,3 @@ removePort(hub); | ||
if (hub.server) { | ||
// console.log('🚀 SWITCH SERVER 🚀') | ||
removeServer(hub); | ||
@@ -782,12 +773,15 @@ } | ||
data: { | ||
remove$: (val, stamp, struct$$1) => { | ||
if (val === null && (!struct$$1._c || struct$$1._cLevel === 1)) { | ||
let p = struct$$1; | ||
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._c) { hub = p; } | ||
if (p.port && !p.context) { hub = p; } | ||
p = p.parent(); | ||
} | ||
if (hub) { | ||
const target = struct$$1.parent(); | ||
const target = struct.parent(); | ||
if (target) { | ||
@@ -807,3 +801,3 @@ if (!target._removed) { | ||
} | ||
struct$$1._p._removed.push(struct$$1); | ||
struct._p._removed.push(struct); | ||
} | ||
@@ -824,34 +818,33 @@ } | ||
const props$2 = { contextKey: true }; | ||
// import { struct } from 'brisky-struct' | ||
const define$1 = { | ||
getContext (val) { | ||
var result = find(this, val); | ||
if (!result) { | ||
result = this.create({ contextKey: val }, false); | ||
} | ||
return result | ||
const clientHub = { | ||
type: 'hub', | ||
props: { | ||
cache: true, | ||
upstreamSubscriptions: true, | ||
// isUpstream: true, | ||
// myupstream subs | ||
resolve: true, | ||
socket: true // only nessecary for downstream clients | ||
} | ||
}; | ||
const find = (hub, val) => { | ||
const instances = hub.instances; | ||
if (instances) { | ||
let i = instances.length; | ||
while (i--) { | ||
if (instances[i].contextKey === val) { | ||
// console.log('found context --->', val, instances[i].clients.keys()) | ||
return instances[i] | ||
} | ||
const props$2 = { | ||
clients: { // need to exclude on context | ||
props: { | ||
default: clientHub | ||
} | ||
} | ||
}, | ||
client: true // test if you can subscribe to it | ||
}; | ||
var context$1 = Object.freeze({ | ||
props: props$2, | ||
define: define$1 | ||
var clients = Object.freeze({ | ||
props: props$2 | ||
}); | ||
const types = struct.props.types; | ||
// need to be able to set timestamp mode on bs -- allways fo ts on bs | ||
@@ -861,55 +854,18 @@ const hub = create({ | ||
instances: false, | ||
define: { isHub: true }, | ||
types: { hub: 'self' }, | ||
props: { | ||
default: 'self', | ||
id: (t, val) => { t.set({ define: { id: val } }); }, | ||
clients: (t, val, key, stamp) => { | ||
if (!t.clients) { | ||
t.clients = c(clients, val, stamp, t, key); | ||
} else { | ||
set(t.clients, val, stamp); | ||
} | ||
}, | ||
types: types.bind(), // to not interfere with struct type | ||
type: struct.props.type.bind(), | ||
client: true | ||
id: (t, val) => { t.set({ define: { id: val } }); } | ||
}, | ||
id | ||
id: id, | ||
inject: [ | ||
client, | ||
server, | ||
clients | ||
] | ||
}); | ||
hub.props.types.struct = c(hub, { | ||
props: { default: types.struct.props.default.bind() } | ||
}); | ||
hub.props.types.struct.props.default.struct = hub.props.type.struct = hub; | ||
hub.set({ types: { hub: 'self' }, inject: [ server, context$1, client ] }, false); | ||
hub.types._ks = void 0; | ||
const clients = create({ | ||
props: { | ||
default: hub.create({ | ||
props: { | ||
cache: true, | ||
upstreamSubscriptions: true, | ||
resolve: true, | ||
socket: true, | ||
context: true | ||
} | ||
}) | ||
} | ||
}); | ||
// import bs from 'brisky-stamp' | ||
var index = (val, stamp) => { | ||
if (stamp === void 0) { | ||
const r = hub.create(val, bs.create()); | ||
bs.close(); | ||
return r | ||
} else { | ||
return hub.create(val, stamp) | ||
} | ||
}; | ||
var index = (val, stamp) => hub.create(val); | ||
@@ -916,0 +872,0 @@ // add uids to stamps else it sucks -- dont compromise for tests think of that as an after thought |
@@ -205,5 +205,7 @@ var $1662971556 = require('brisky-struct') | ||
;const $3700476957_maxSize = 1e7 // byteLength -- has to be like 10mb | ||
;var $1385737091 = 1e7 // byteLength -- has to be like 10mb | ||
const $3700476957_send = (client, payload, next) => { | ||
; | ||
const $2003515468_send = (client, payload, next) => { | ||
client.socket.send(payload) | ||
@@ -213,5 +215,5 @@ process.nextTick(next) | ||
const $3700476957_sendLarge = (raw, client) => { | ||
const $2003515468_sendLarge = (raw, client) => { | ||
const size = Buffer.byteLength(raw, 'utf8') | ||
if (size > $3700476957_maxSize) { | ||
if (size > $1385737091) { | ||
if (!client.blobInProgress) { | ||
@@ -226,3 +228,3 @@ client.blobInProgress = [] | ||
if (client.blobInProgress.length > 0) { | ||
$3700476957_send(client, client.blobInProgress.shift(), () => drainInProgress(done)) | ||
$2003515468_send(client, client.blobInProgress.shift(), () => drainInProgress(done)) | ||
} else { | ||
@@ -236,4 +238,4 @@ done() | ||
// make sure you end with an non maxsize buffer (send an empty one if nessecary) | ||
if (i * $3700476957_maxSize <= size) { | ||
$3700476957_send(client, buf.slice(i * $3700476957_maxSize, (i + 1) * $3700476957_maxSize), next) | ||
if (i * $1385737091 <= size) { | ||
$2003515468_send(client, buf.slice(i * $1385737091, (i + 1) * $1385737091), next) | ||
} else { | ||
@@ -246,3 +248,3 @@ drainInProgress(() => { | ||
$3700476957_send(client, buf.slice(i * $3700476957_maxSize, (i + 1) * $3700476957_maxSize), next) | ||
$2003515468_send(client, buf.slice(i * $1385737091, (i + 1) * $1385737091), next) | ||
@@ -253,6 +255,11 @@ return true | ||
const $3700476957_receiveLarge = (data, bufferArray) => { | ||
// make sure new Buffer works on the browser... | ||
bufferArray.push(new Buffer(data).toString('utf8')) | ||
if (data.byteLength < $3700476957_maxSize) return bufferArray.join('') | ||
var $2003515468_bufferArray = false | ||
const $2003515468_receiveLarge = (data, cb) => { | ||
if (!$2003515468_bufferArray) $2003515468_bufferArray = [] | ||
$2003515468_bufferArray.push(new Buffer(data).toString('utf8')) | ||
if (data.byteLength < $1385737091) { | ||
cb($2003515468_bufferArray.join('')) | ||
$2003515468_bufferArray = false | ||
} | ||
} | ||
@@ -262,5 +269,5 @@ | ||
var $3700476957_$ALL$ = { | ||
sendLarge: $3700476957_sendLarge, | ||
receiveLarge: $3700476957_receiveLarge | ||
var $2003515468_$ALL$ = { | ||
sendLarge: $2003515468_sendLarge, | ||
receiveLarge: $2003515468_receiveLarge | ||
} | ||
@@ -279,3 +286,2 @@ ; | ||
const client = hub.client || $2828932010(hub, {}, false) | ||
var bufferArray = false | ||
@@ -320,15 +326,15 @@ hub.set({ client }, false) | ||
typeof data !== 'string' && | ||
typeof window === 'undefined' && | ||
data instanceof ArrayBuffer | ||
( | ||
data instanceof ArrayBuffer || | ||
(('Blob' in global) && data instanceof Blob) || // eslint-disable-line | ||
(('WebkitBlob' in global) && data instanceof WebkitBlob) // eslint-disable-line | ||
) | ||
) { | ||
if (!bufferArray) bufferArray = [] | ||
const result = $3700476957_receiveLarge(data, bufferArray) | ||
if (result) { | ||
data = result | ||
bufferArray = false | ||
} else { | ||
return | ||
} | ||
$2003515468_receiveLarge(data, setInHub) | ||
} else { | ||
setInHub(data) | ||
} | ||
} | ||
const setInHub = data => { | ||
if (!hub.receiveOnly) { | ||
@@ -712,3 +718,3 @@ hub.receiveOnly = true | ||
const raw = JSON.stringify(client.inProgress) | ||
if (!$3700476957_sendLarge(raw, client)) { | ||
if (!$2003515468_sendLarge(raw, client)) { | ||
if (client.blobInProgress) { | ||
@@ -715,0 +721,0 @@ client.blobInProgress.push(raw) |
{ | ||
"name": "hub.js", | ||
"description": "Seamless realtime communcation", | ||
"version": "0.0.26", | ||
"version": "0.0.27", | ||
"main": "dist/index.js", | ||
@@ -10,2 +10,3 @@ "browser": { | ||
"./src/server/index.js": "./src/server/browser.js", | ||
"./src/size/index.js": "./src/size/browser.js", | ||
"./src/client/websocket/index.js": "./src/client/websocket/browser.js", | ||
@@ -12,0 +13,0 @@ "source-map-support": false |
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
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
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
15
410144
3850
3