Skip to content

Commit

Permalink
Testing bitfocus-cloud connection
Browse files Browse the repository at this point in the history
  • Loading branch information
haakonnessjoen committed Apr 24, 2021
1 parent 397c93f commit cccaf1c
Show file tree
Hide file tree
Showing 4 changed files with 194 additions and 2 deletions.
1 change: 1 addition & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ system.ready = function (logToFile) {
var satellite = require('./lib/satellite_server')(system)
var ws_api = require('./lib/ws_api')(system)
var help = require('./lib/help')(system)
var bitfocus_cloud = require('./lib/bitfocus_cloud')(system)

system.emit('modules_loaded')

Expand Down
73 changes: 73 additions & 0 deletions lib/bitfocus_cloud.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
const fs = require('fs')
const debug = require('debug')('lib/bitfocus-cloud')
const SCClient = require("socketcluster-client");

class BitfocusCloud {
/**
* @param {EventEmitter} _system
*/
constructor(_system) {
/** @type {EventEmitter} */
this.system = _system;
this.banks = [];

debug('Constructing');
this.connect();
}

async connect() {
debug('Connecting');
this.socket = SCClient.create({
hostname: '127.0.0.1',
port: 8001,
secure: false,
autoReconnectOptions: {
initialDelay: 1000, //milliseconds
randomness: 500, //milliseconds
multiplier: 1.5, //decimal
maxDelay: 20000 //milliseconds
}
});

(async () => {
while (1) {
for await (let _event of this.socket.listener("connect")) { // eslint-disable-line
debug('Socket is connected')

this.system.emit('db_get', 'bank', (banks) => {
this.banks = banks;

this.socket.transmitPublish('companion-banks:123-123-123-123', {
type: 'full',
data: banks
});
});
}
await delay(1000);
}
})()

this.system.on('graphics_bank_invalidate', (page, bank) => this.updateBank(page, bank));

setImmediate(() => {
this.system.emit('db_get', 'bank', (banks) => {
this.banks = banks;
});
});
}

async updateBank(page, bank) {
this.system.emit('db_get', 'bank', (banks) => {
this.banks = banks;

this.socket.transmitPublish('companion-banks:123-123-123-123', {
type: 'single',
page,
bank,
data: banks[page][bank]
});
});
}
}

module.exports = (system) => new BitfocusCloud(system)
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,7 @@
"sharp": "^0.27.2",
"shortid": "^2.2.16",
"socket.io": "^4.0.0",
"socketcluster-client": "^16.0.2",
"strip-ansi": "^5.2.0",
"websocket": "^1.0.32"
},
Expand Down
121 changes: 119 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,20 @@ [email protected]:
resolved "https://registry.yarnpkg.com/after/-/after-0.8.2.tgz#fedb394f9f0e02aa9768e702bda23b505fae7e1f"
integrity sha1-/ts5T58OAqqXaOcCvaI7UF+ufh8=

ag-channel@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/ag-channel/-/ag-channel-5.0.0.tgz#c2c00dfbe372ae43e0466ec89e29aca1bbb2fb3e"
integrity sha512-bArHkdqQxynim981t8FLZM5TfA0v7p081OlFdOxs6clB79GSGcGlOQMDa31DT9F5VMjzqNiJmhfGwinvfU/3Zg==
dependencies:
consumable-stream "^2.0.0"

ag-request@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/ag-request/-/ag-request-1.0.0.tgz#3eeb77ef709cadac7758b74cc7b1836bc1a9194a"
integrity sha512-2f7I0cQLMVyGAqjSewVMEFuAsJsIY6egdE16UHS636r+8c6Oevrv0j6SrOIXyRN6yuNT4PBuhiKmrhHbh9OvEg==
dependencies:
sc-errors "^2.0.0"

agent-base@4, agent-base@^4.2.0, agent-base@^4.3.0:
version "4.3.0"
resolved "https://registry.yarnpkg.com/agent-base/-/agent-base-4.3.0.tgz#8165f01c436009bccad0b1d122f05ed770efc6ee"
Expand Down Expand Up @@ -715,6 +729,13 @@ async-limiter@~1.0.0:
resolved "https://registry.yarnpkg.com/async-limiter/-/async-limiter-1.0.1.tgz#dd379e94f0db8310b08291f9d64c3209766617fd"
integrity sha512-csOlWGAcRFJaI6m+F2WKdnMKr4HhdhFVBk0H/QbJFMCr+uO2kwohwXQPxw/9OCxp05r5ghVBFSyioixx3gfkNQ==

async-stream-emitter@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/async-stream-emitter/-/async-stream-emitter-4.0.0.tgz#97f4a910f078c43720a8a8c4ea73a5fdefb6f62a"
integrity sha512-zPVflmOEN4EFEAk2/p+BbLRRM/i4Iol2nvO2RSFNuYUiYZdBmBJi5O/PMQeO9Unj1EONQqUN0W5PadVS/bA6/g==
dependencies:
stream-demux "^8.0.0"

async@, async@^3.2.0:
version "3.2.0"
resolved "https://registry.yarnpkg.com/async/-/async-3.2.0.tgz#b3a2685c5ebb641d3de02d161002c60fc9f85720"
Expand Down Expand Up @@ -1077,7 +1098,7 @@ [email protected]:
ieee754 "^1.1.4"
isarray "^1.0.0"

buffer@^5.1.0, buffer@^5.5.0:
buffer@^5.1.0, buffer@^5.2.1, buffer@^5.5.0:
version "5.7.1"
resolved "https://registry.yarnpkg.com/buffer/-/buffer-5.7.1.tgz#ba62e7c13133053582197160851a8f648e99eed0"
integrity sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ==
Expand Down Expand Up @@ -1349,6 +1370,15 @@ cliui@^7.0.2:
strip-ansi "^6.0.0"
wrap-ansi "^7.0.0"

clone-deep@^4.0.1:
version "4.0.1"
resolved "https://registry.yarnpkg.com/clone-deep/-/clone-deep-4.0.1.tgz#c19fd9bdbbf85942b4fd979c84dcf7d5f07c2387"
integrity sha512-neHB9xuzh/wk0dIHweyAXv2aPGZIVk3pLMe+/RNzINf17fe0OG96QroktYAUm7SM1PBnzTabaLboqqxDyMU+SQ==
dependencies:
is-plain-object "^2.0.4"
kind-of "^6.0.2"
shallow-clone "^3.0.0"

clone-response@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/clone-response/-/clone-response-1.0.2.tgz#d1dc973920314df67fbeb94223b4ee350239e96b"
Expand Down Expand Up @@ -2722,6 +2752,11 @@ console-control-strings@^1.0.0, console-control-strings@~1.1.0:
resolved "https://registry.yarnpkg.com/console-control-strings/-/console-control-strings-1.1.0.tgz#3d7cf4464db6446ea644bf4b39507f9851008e8e"
integrity sha1-PXz0Rk22RG6mRL9LOVB/mFEAjo4=

consumable-stream@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/consumable-stream/-/consumable-stream-2.0.0.tgz#11d3c7281b747eb9efd31c199b3a8b1711bec654"
integrity sha512-I6WA2JVYXs/68rEvi1ie3rZjP6qusTVFEQkbzR+WC+fY56TpwiGTIDJETsrnlxv5CsnmK69ps6CkYvIbpEEqBA==

[email protected]:
version "0.5.3"
resolved "https://registry.yarnpkg.com/content-disposition/-/content-disposition-0.5.3.tgz#e130caf7e7279087c5616c2007d0485698984fbd"
Expand Down Expand Up @@ -4717,6 +4752,13 @@ is-path-inside@^3.0.1, is-path-inside@^3.0.2:
resolved "https://registry.yarnpkg.com/is-path-inside/-/is-path-inside-3.0.3.tgz#d231362e53a07ff2b0e0ea7fed049161ffd16283"
integrity sha512-Fd4gABb+ycGAmKou8eMftCupSir5lRxqf4aD/vd0cD2qc4HL07OjCeuHMr8Ro4CoMaeCKDB0/ECBOVWjTwUvPQ==

is-plain-object@^2.0.4:
version "2.0.4"
resolved "https://registry.yarnpkg.com/is-plain-object/-/is-plain-object-2.0.4.tgz#2c163b3fafb1b606d9d17928f05c2a1c38e07677"
integrity sha512-h5PpgXkWitc38BBMYawTYMWJHFZJVnBquFE57xFpjB8pJFiF6gZ+bU+WyI/yqXiFR5mdLsgYNaPe8uao6Uv9Og==
dependencies:
isobject "^3.0.1"

is-redirect@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/is-redirect/-/is-redirect-1.0.0.tgz#1d03dded53bd8db0f30c26e4f95d36fc7c87dc24"
Expand Down Expand Up @@ -4829,6 +4871,11 @@ isexe@^2.0.0:
resolved "https://registry.yarnpkg.com/isexe/-/isexe-2.0.0.tgz#e8fbf374dc556ff8947a10dcb0572d633f2cfa10"
integrity sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=

isobject@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/isobject/-/isobject-3.0.1.tgz#4e431e92b11a9731636aa1f9c8d1ccbcfdab78df"
integrity sha1-TkMekrEalzFjaqH5yNHMvP2reN8=

isomorphic-unfetch@^3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/isomorphic-unfetch/-/isomorphic-unfetch-3.1.0.tgz#87341d5f4f7b63843d468438128cb087b7c3e98f"
Expand Down Expand Up @@ -5008,6 +5055,11 @@ keyv@^3.0.0:
dependencies:
json-buffer "3.0.0"

kind-of@^6.0.2:
version "6.0.3"
resolved "https://registry.yarnpkg.com/kind-of/-/kind-of-6.0.3.tgz#07c05034a6c349fa06e24fa35aa76db4580ce4dd"
integrity sha512-dcS1ul+9tmeD95T+x28/ehLgd9mENa3LsvDTtzm3vyBEO7RPptvAD+t44WVXaUjTBRcrpFeFlC8WCruUR456hw==

latest-version@^5.0.0, latest-version@^5.1.0:
version "5.1.0"
resolved "https://registry.yarnpkg.com/latest-version/-/latest-version-5.1.0.tgz#119dfe908fe38d15dfa43ecd13fa12ec8832face"
Expand Down Expand Up @@ -5048,6 +5100,11 @@ [email protected]:
graphql "15.5.0"
graphql-request "3.4.0"

linked-list@^0.1.0:
version "0.1.0"
resolved "https://registry.yarnpkg.com/linked-list/-/linked-list-0.1.0.tgz#798b0ff97d1b92a4fd08480f55aea4e9d49d37bf"
integrity sha1-eYsP+X0bkqT9CEgPVa6k6dSdN78=

listenercount@~1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/listenercount/-/listenercount-1.0.1.tgz#84c8a72ab59c4725321480c975e6508342e70937"
Expand Down Expand Up @@ -6142,6 +6199,11 @@ [email protected]:
resolved "https://registry.yarnpkg.com/querystring/-/querystring-0.2.0.tgz#b209849203bb25df820da756e747005878521620"
integrity sha1-sgmEkgO7Jd+CDadW50cAWHhSFiA=

querystring@^0.2.0:
version "0.2.1"
resolved "https://registry.yarnpkg.com/querystring/-/querystring-0.2.1.tgz#40d77615bb09d16902a85c3e38aa8b5ed761c2dd"
integrity sha512-wkvS7mL/JMugcup3/rMitHmd9ecIGd2lhFhK9N3UUQ450h66d1r3Y9nvXzQAW1Lq+wyx61k/1pfKS5KuKiyEbg==

querystringify@^2.1.1:
version "2.2.0"
resolved "https://registry.yarnpkg.com/querystringify/-/querystringify-2.2.0.tgz#3345941b4153cb9d082d8eee4cda2016a9aef7f6"
Expand Down Expand Up @@ -6440,6 +6502,16 @@ sax@>=0.6.0, sax@^1.2.2, sax@^1.2.4:
resolved "https://registry.yarnpkg.com/sax/-/sax-1.2.4.tgz#2816234e2378bddc4e5354fab5caa895df7100d9"
integrity sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw==

sc-errors@^2.0.0, sc-errors@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/sc-errors/-/sc-errors-2.0.1.tgz#3af2d934dfd82116279a4b2c1552c1e021ddcb03"
integrity sha512-JoVhq3Ud+3Ujv2SIG7W0XtjRHsrNgl6iXuHHsh0s+Kdt5NwI6N2EGAZD4iteitdDv68ENBkpjtSvN597/wxPSQ==

sc-formatter@^3.0.2:
version "3.0.2"
resolved "https://registry.yarnpkg.com/sc-formatter/-/sc-formatter-3.0.2.tgz#9abdb14e71873ce7157714d3002477bbdb33c4e6"
integrity sha512-9PbqYBpCq+OoEeRQ3QfFIGE6qwjjBcd2j7UjgDlhnZbtSnuGgHdcRklPKYGuYFH82V/dwd+AIpu8XvA1zqTd+A==

semver-compare@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/semver-compare/-/semver-compare-1.0.0.tgz#0dee216a1c941ab37e9efb1788f6afc5ff5537fc"
Expand Down Expand Up @@ -6550,6 +6622,13 @@ sha.js@^2.4.9:
inherits "^2.0.1"
safe-buffer "^5.0.1"

shallow-clone@^3.0.0:
version "3.0.1"
resolved "https://registry.yarnpkg.com/shallow-clone/-/shallow-clone-3.0.1.tgz#8f2981ad92531f55035b01fb230769a40e02efa3"
integrity sha512-/6KqX+GVUdqPuPPd2LxDDxzX6CAbjJehAAOKlNpqqUpAqPM6HeL8f+o3a+JsyGjn2lv0WY8UsTgUJjU9Ok55NA==
dependencies:
kind-of "^6.0.2"

sharp@^0.27.2:
version "0.27.2"
resolved "https://registry.yarnpkg.com/sharp/-/sharp-0.27.2.tgz#a939775e630e88600c0b5e68f20593aea722252f"
Expand Down Expand Up @@ -6755,6 +6834,24 @@ socket.io@^4.0.0:
socket.io-adapter "~2.2.0"
socket.io-parser "~4.0.3"

socketcluster-client@^16.0.2:
version "16.0.2"
resolved "https://registry.yarnpkg.com/socketcluster-client/-/socketcluster-client-16.0.2.tgz#078d8570e3f58d007755854c1ba4db6c1128666a"
integrity sha512-Qm50yg33kegbY3mqQC/8qvHPslLfQh/76RWMt76oAi1GDSi/USx9RcF9z9we5Nx/5AK/mYJW3wrGeXGI/np6Vg==
dependencies:
ag-channel "^5.0.0"
ag-request "^1.0.0"
async-stream-emitter "^4.0.0"
buffer "^5.2.1"
clone-deep "^4.0.1"
linked-list "^0.1.0"
querystring "^0.2.0"
sc-errors "^2.0.1"
sc-formatter "^3.0.2"
stream-demux "^8.0.0"
uuid "^3.2.1"
ws "^7.2.1"

socks-proxy-agent@^4.0.1:
version "4.0.2"
resolved "https://registry.yarnpkg.com/socks-proxy-agent/-/socks-proxy-agent-4.0.2.tgz#3c8991f3145b2799e70e11bd5fbc8b1963116386"
Expand Down Expand Up @@ -6890,6 +6987,14 @@ stealthy-require@^1.1.1:
resolved "https://registry.yarnpkg.com/stealthy-require/-/stealthy-require-1.1.1.tgz#35b09875b4ff49f26a777e509b3090a3226bf24b"
integrity sha1-NbCYdbT/SfJqd35QmzCQoyJr8ks=

stream-demux@^8.0.0:
version "8.0.0"
resolved "https://registry.yarnpkg.com/stream-demux/-/stream-demux-8.0.0.tgz#d7d33bf47dfaeb2e94f1966e990d206b6d26ef1e"
integrity sha512-vt6P85yEUxiapK9F+ET5BLyto1DnCD4Sl7MlDklDgcb4K5SGXPtOPz9DiP7vTooJ1wW1F/VRPlcSV22Coeim1A==
dependencies:
consumable-stream "^2.0.0"
writable-consumable-stream "^2.0.0"

stream-shift@^1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/stream-shift/-/stream-shift-1.0.1.tgz#d7088281559ab2778424279b0877da3c392d5a3d"
Expand Down Expand Up @@ -7610,7 +7715,7 @@ [email protected]:
resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.3.2.tgz#1b4af4955eb3077c501c23872fc6513811587131"
integrity sha512-yXJmeNaw3DnnKAOKJE51sL/ZaYfWJRl1pK9dr19YFCu0ObS231AB1/LbqTKRAQ5kw8A90rA6fr4riOUpTZvQZA==

uuid@^3.3.2:
uuid@^3.2.1, uuid@^3.3.2:
version "3.4.0"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.4.0.tgz#b23e4358afa8a202fe7a100af1f5f883f02007ee"
integrity sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A==
Expand Down Expand Up @@ -7848,6 +7953,13 @@ wrappy@1:
resolved "https://registry.yarnpkg.com/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f"
integrity sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=

writable-consumable-stream@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/writable-consumable-stream/-/writable-consumable-stream-2.0.0.tgz#102beeea0b20b4862f263dd8688c926a4caa28d3"
integrity sha512-SITambzxtPTFU/wR82h+zOKGBiEv5V8gC1mt8xvoE1/168ApEa8H+6s2UToYJo3VLL7sNYTaApKuPD+pZHMGJQ==
dependencies:
consumable-stream "^2.0.0"

write-file-atomic@^3.0.0:
version "3.0.3"
resolved "https://registry.yarnpkg.com/write-file-atomic/-/write-file-atomic-3.0.3.tgz#56bd5c5a5c70481cd19c571bd39ab965a5de56e8"
Expand Down Expand Up @@ -7882,6 +7994,11 @@ ws@^7.2.0, ws@^7.3.1, ws@^7.4.1, ws@~7.4.2:
resolved "https://registry.yarnpkg.com/ws/-/ws-7.4.4.tgz#383bc9742cb202292c9077ceab6f6047b17f2d59"
integrity sha512-Qm8k8ojNQIMx7S+Zp8u/uHOx7Qazv3Yv4q68MiWWWOJhiwG5W3x7iqmRtJo8xxrciZUY4vRxUTJCKuRnF28ZZw==

ws@^7.2.1:
version "7.4.5"
resolved "https://registry.yarnpkg.com/ws/-/ws-7.4.5.tgz#a484dd851e9beb6fdb420027e3885e8ce48986c1"
integrity sha512-xzyu3hFvomRfXKH8vOFMU3OguG6oOvhXMo3xsGy3xWExqaM2dxBbVxuD99O7m3ZUFMvvscsZDqxfgMaRr/Nr1g==

ws@~6.1.0:
version "6.1.4"
resolved "https://registry.yarnpkg.com/ws/-/ws-6.1.4.tgz#5b5c8800afab925e94ccb29d153c8d02c1776ef9"
Expand Down

0 comments on commit cccaf1c

Please sign in to comment.