Skip to content

cgeorg/cycle-socket.io

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Cycle-Socket.IO

A Cycle driver for applications using Socket.IO

Usage

import io from 'socket.io-client';
import {run} from '@cycle/xstream-run';
import {makeDOMDriver} from '@cycle/dom';
import {makeSocketIODriver} from 'cycle-socket.io';

function main({socketIO, dom}) {
    const vtree$ = render(dom);

    const incomingMessages$ = socketIO.get('messageType');
    const outgoingMessages$ = stream$.map(eventData => ({
      messageType: 'someEvent',
      message: eventData,
    }));
    
    return {dom: vtree$, socketIO: outgoingMessages$}
};

var socketIODriver = makeSocketIODriver(io(window.location.origin));
var domDriver = makeDOMDriver(document.body);
run(main, {
    dom: domDriver,
    socketIO: socketIODriver
});

API

makeSocketIODriver(socket)

Creates a socket.io driver which uses the provided socket to listen to and emit events.

sources.get(eventName, { multiArgs = false })

Returns a stream of eventName from the given socket. If the event expects multiple arguments from the Socket.IO server, pass in multiArgs = true, and the stream will emit an array with the arguments.

About

A Cycle driver for Socket.IO clients

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published