I have successfully created a node server that uses the WSSharedDoc
class from utils.js
from y-websocket-server
. I am running a spawned process that writes its stdout
to a document that then syncs up (beautifully) with a client browser. This is the node side updater:
//get the right document
output = utils.docs.get(data['code']).getText('output')
//clear the document before starting spawn
output.delete(0,output.length);
//spawn process
ps[data['code']] = spawn("python3",[`-u`,`code/${data['code']}.py`])
//stream spawned process into ytext
ps[data['code']].stdout.on('data',(data) => {output.insert(output.length,`${data}`)
})
And this is the client listener
const yO = ydoc.getText('output')
yO.observe(event => { $("#output").html(yO.toString());})
So long as a client is open, this works beautifully and the spawned stream updates in the browser in real time. But if I close all clients, the spawned process continues, but the ytext
in the WSSharedDoc
no longer receives the updates. If I restart the process with the client attached it works fine. To be clear, if I have multiple browser windows open the spawn stream updates continute, but if I close all browsers and then reopen I only see the ytext
as recent as the last browser tab was closed.
I am guessing there is some flag that prevents the ytext
from receiving updates if there is no client attached to the websocketserver, if so how can I override
Thanks for taking the time to help me.