fl-observable-socket
v1.0.0-rc7
Published
Wraps a websocket in an Observable.
Downloads
8
Maintainers
Readme
fantasy-land observable-socket
Like observable-socket with more algebra. Works with ws and window.WebSocket.
Install:
npm i fl-observable-socket -S
Use:
var ws = require('ws')
var flos = require('fl-observable-socket')
// Wrap a WebSocket
var socket = flos(ws('wss://echo.websocket.org'))
// Send messages up the socket
socket.up('hello')
.fork(e => console.error(e), a => console.log(a))
// Receive messages down the socket
socket.down
.observe(msg => console.log(msg))
.then(() => console.log('done'))
.catch(err => console.error(err))
<script type="text/javascript" src="https://unpkg.com/[email protected]"></script>
<script type="text/javascript" src="https://unpkg.com/[email protected]/dist/most"></script>
<script type="text/javascript" src="https://unpkg.com/@most/[email protected]"></script>
<script type="text/javascript" src="https://unpkg.com/[email protected]/dist/index.js"></script>
<script>
var socket = FLObservableSocket(new WebSocket('wss://echo.websocket.org'))
// Send messages up the socket
socket.up('hello')
.fork(e => console.error(e), a => console.log(a))
// Receive messages down the socket
socket.down
.observe(msg => console.log(msg))
.then(() => console.log('done'))
.catch(err => console.error(err))
</script>