Published
Edited
Nov 5, 2018
Importers
Insert cell
Insert cell
Insert cell
Insert cell
ws = ({ url, onConnectEmit, parser = JSON.parse }) =>
Generators.observe(notify => {
// Import socket.io with a connection to a channel (i.e. tops)
const socket = io(url);

// Listen to the channel's messages
socket.on("message", message => {
notify(parser(message));
});

// Connect to the channel
socket.on("connect", function() {
// use function to bind parent `this`
// Subscribe to topics (i.e. appl,fb,aig+)
console.log(`Connected to ${url}.`);
// s.emit("subscribe", "firehose");
onConnectEmit && socket.emit.apply(this, onConnectEmit);
// Unsubscribe from topics (i.e. aig+)
});

// Disconnect from the channel
socket.on("disconnect", () => console.log(`Disconnected from ${url}.`));

return () => socket.close();
})
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more