UNPKG

signal-channel

Version:

A signal channel that empowers webrtc

30 lines (29 loc) 2.54 kB
{ "name": "remote-events", "version": "1.1.1", "description": "a two ended EventEmitter connected through a Stream", "homepage": "http://github.com/dominictarr/remote-events", "repository": { "type": "git", "url": "https://github.com/dominictarr/remote-events.git" }, "dependencies": { "through": "~1.1.2", "stream-serializer": "0.0.3" }, "devDependencies": { "assertions": "2" }, "author": { "name": "Dominic Tarr", "email": "dominic.tarr@gmail.com", "url": "dominictarr.com" }, "readme": "# RemoteEvents\n\nconnect two EventEmitters through a stream!\n\n``` js\nvar RemoteEventEmitter = require('..')\nvar es = require('event-stream')\nvar net = require('net')\n\nvar server = net.createServer(function (con) {\n var ree = new RemoteEventEmitter()\n con.pipe(ree.getStream())\n\n ree.on('ping', function (time) {\n console.log('PING', time)\n ree.emit('pong', Date.now())\n })\n}).listen(2468, function () {\n\n var con = net.connect(2468)\n var ree = new RemoteEventEmitter()\n con.pipe(ree.getStream()).pipe(con)\n\n var time = Date.now()\n ree.on('pong', function (_time) {\n console.log('PONG', _time, _time - time)\n ree.disconnect()\n server.close()\n })\n ree.emit('ping', time)\n})\n\n```\n\nnow, one may wish to subclass `RemoteEventEmitter` wrap `net` or `http` or [shoe](http://github.com/substack/shoe) and provide a `connect` and `createServer` methods.\n\nthen you will have a very [socket.io](http://socket.io) like interface (but without the silly bundled RPC, etc)\n\nhowever, I recommend instead wrap this with [browser-stream](http://github.com/dominictarr/browser-stream) -- which will allow you to multiplex streams through `RemoteEventEmitter`\n\nwhich will be useful for A) keeping nice `Stream` abstractions when you have a limited budget for connections (like in the browser) and B) seperating interprocess communication abstractions (such as [dnode](http://github.com/substack/dnode) or [crdt](http://github.com/dominictarr/crdt). This has been a problem with libraries using the socket.io api directly.\n\n## options\n\nYou can pass in `opts.wrap` to `RemoteEventEmitter` to set the\nwrapper function that should be used by [`stream-serializer`][1]\n\n [1]: https://github.com/dominictarr/stream-serializer\n", "readmeFilename": "readme.markdown", "_id": "remote-events@1.1.1", "dist": { "shasum": "96e08621f1ba333aae38e9c633fabb1b718ae94f" }, "_from": "remote-events@git://github.com/Raynos/remote-events#update" }