Added NATS server and frontend code to connect to it
parent
ccb95980c0
commit
174e66e36d
@ -0,0 +1,3 @@
|
|||||||
|
FROM nats:2.7.4-scratch
|
||||||
|
COPY ./nats-server.conf /nats-server.conf
|
||||||
|
EXPOSE 4223
|
@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
cd "${0%/*}" # set current directory of this script to where the script is located. necessary for podman "-v" bind mounts to be relative paths
|
||||||
|
podman run -d --name sakal-nats -p 4222:4222 -p 4223:4223 localhost/sakal-nats-server:latest
|
@ -0,0 +1,44 @@
|
|||||||
|
import {pub, sub} from './pubsub.js';
|
||||||
|
import state from './state.js';
|
||||||
|
import redraw from './redraw.js';
|
||||||
|
|
||||||
|
// "raw" event listeners, which publish meaningful events, which are listened-to further-down:
|
||||||
|
// ...
|
||||||
|
|
||||||
|
|
||||||
|
// "meaningful" event listeners:
|
||||||
|
//sub('set-current-node', (node_vm)=>{
|
||||||
|
// state.current_node_vm = node_vm;
|
||||||
|
// redraw();
|
||||||
|
// });
|
||||||
|
|
||||||
|
// connect to NATS thru WebSockets:
|
||||||
|
import { connect, StringCodec } from "nats.ws";
|
||||||
|
const strcodec = StringCodec();
|
||||||
|
const init_nats = async function(){
|
||||||
|
const nc = await connect({servers: "ws://localhost:4223"});
|
||||||
|
console.log(nc);
|
||||||
|
|
||||||
|
(async ()=>{
|
||||||
|
const sub = nc.subscribe('price');
|
||||||
|
for await (const msg of sub){
|
||||||
|
console.log(`[${sub.getProcessed()}]: ${strcodec.decode(msg.data)}`);
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
(async ()=>{
|
||||||
|
const sub = nc.subscribe('close');
|
||||||
|
for await (const msg of sub){
|
||||||
|
nc.close();
|
||||||
|
console.log('closed!');
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
|
||||||
|
nc.publish('price', strcodec.encode('4.23'));
|
||||||
|
nc.publish('price', strcodec.encode('5.00'));
|
||||||
|
//nc.close();
|
||||||
|
};
|
||||||
|
init_nats()
|
||||||
|
|
||||||
|
|
||||||
|
export default null;
|
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
@ -1,3 +1,4 @@
|
|||||||
|
const someFn = null;
|
||||||
const state = {
|
const state = {
|
||||||
front_months: { // front months, i.e. calendar expiry, at which the user has an opinion on where the underlying price may be
|
front_months: { // front months, i.e. calendar expiry, at which the user has an opinion on where the underlying price may be
|
||||||
"2022-03-11": {
|
"2022-03-11": {
|
@ -1,16 +0,0 @@
|
|||||||
import {pub, sub} from './pubsub.js';
|
|
||||||
import state from './state.js';
|
|
||||||
import redraw from './redraw.js';
|
|
||||||
|
|
||||||
// "raw" event listeners, which publish meaningful events, which are listened-to further-down:
|
|
||||||
// ...
|
|
||||||
|
|
||||||
|
|
||||||
// "meaningful" event listeners:
|
|
||||||
//sub('set-current-node', (node_vm)=>{
|
|
||||||
// state.current_node_vm = node_vm;
|
|
||||||
// redraw();
|
|
||||||
// });
|
|
||||||
|
|
||||||
|
|
||||||
export default null;
|
|
Loading…
Reference in New Issue