0

I'm new to cyclejs and I'm looking for websocket support and I don't see any (apart from the read only websocket driver from the docs and some 0.1.2 node side npm package).

Am I supposed to create my own driver or am I missing something?

Thanks in advance

Live Nono
  • 3
  • 1
  • Have you looked at [cycle-websocket](https://github.com/Orbmancer/cycle-websocket)? – bloodyKnuckles Mar 19 '17 at 10:42
  • On its github it says: "Node, browser ? This was built and tested for node, not tested in the browser but it should work. Keep me in touch if it's working or not !" => not really thought for browser – Live Nono Mar 19 '17 at 20:01

1 Answers1

0

Does this page help you?

https://cycle.js.org/drivers.html

Specifically the example code mentioned:

function WSDriver(/* no sinks */) {
  return xs.create({
    start: listener => {
       this.connection = new WebSocket('ws://localhost:4000');
       connection.onerror = (err) => {
          listener.error(err)
       }
       connection.onmessage = (msg) => {
         listener.next(msg)
       }
    },
    stop: () => {
      this.connection.close();
    },
 });
}

If you add a sink this should be a write and read driver. From their documentation:

Most drivers, like the DOM Driver, take sinks (to describe a write) and return sources (to catch reads). However, we might have valid cases for write-only drivers and read-only drivers.

For instance, the one-liner log driver we just saw above is a write-only driver. Notice how it is a function that does not return any stream, it simply consumes the sink msg$ it receives.

Other drivers only create source streams that emit events to the main(), but don’t take in any sink from main(). An example of such would be a read-only Web Socket driver, drafted below:

Community
  • 1
  • 1