{"name":"simple-websocket","description":"Simple, EventEmitter API for WebSockets (browser)","version":"2.2.0","author":{"name":"Feross Aboukhadijeh","email":"feross@feross.org","url":"http://feross.org/"},"browser":{"ws":false},"bugs":{"url":"https://github.com/feross/simple-websocket/issues"},"dependencies":{"debug":"^2.1.3","inherits":"^2.0.1","is-typedarray":"0.0.0","typedarray-to-buffer":"^3.0.1","ws":"^0.7.1"},"devDependencies":{"browserify":"^10.1.0","standard":"^3.3.2","tape":"^4.0.0","uglify-js":"^2.4.15","zuul":"^3.0.0"},"homepage":"https://github.com/feross/simple-websocket","keywords":["websocket","socket","ws","simple","simple websocket","simple-websocket"],"license":"MIT","main":"index.js","repository":{"type":"git","url":"git://github.com/feross/simple-websocket.git"},"scripts":{"test":"standard && npm run test-node && npm run test-browser","test-browser":"zuul -- test/*.js","test-browser-local":"zuul --local -- test/*.js","test-node":"tape test/*.js","build":"browserify -s SimpleWebsocket -r ./ | uglifyjs -c warnings=false -m > simplewebsocket.bundle.js"},"standard":{"ignore":["simplewebsocket.bundle.js"]},"testling":{"files":"test/*.js"},"gitHead":"3b9421381a80db2c0fa1ad452abe861406b29194","_id":"simple-websocket@2.2.0","_shasum":"41c1953220d73ecb4f6fb4620675c68d9a8d4681","_from":".","_npmVersion":"2.9.1","_nodeVersion":"0.12.3","_npmUser":{"name":"feross","email":"feross@feross.org"},"maintainers":[{"name":"feross","email":"feross@feross.org"}],"dist":{"shasum":"41c1953220d73ecb4f6fb4620675c68d9a8d4681","tarball":"http://registry-npm.ywwl.com/simple-websocket/download/simple-websocket-2.2.0.tgz","integrity":"sha512-rZr0goqXu1PzRBlQs9uAk193n7taZO+jdtKo8SDkRd4P500gqqD13zWrXzNID4Slh6MTCTrWA08t4GAGpj54hQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIACfHp1z+DsDNDAeftbPsr2rhWJlVeLIbft0H+OGJyKzAiAtjSp1YuDI9MD/rI5YIPn6gYRr+NDk+cNepUwv4YcnwQ=="}],"size":21986,"noattachment":false,"key":"/simple-websocket/-/simple-websocket-2.2.0.tgz"},"directories":{},"readme":"# simple-websocket [![travis][travis-image]][travis-url] [![npm][npm-image]][npm-url] [![downloads][downloads-image]][downloads-url] [![javascript style guide][standard-image]][standard-url]\n\n[travis-image]: https://img.shields.io/travis/feross/simple-websocket/master.svg\n[travis-url]: https://travis-ci.org/feross/simple-websocket\n[npm-image]: https://img.shields.io/npm/v/simple-websocket.svg\n[npm-url]: https://npmjs.org/package/simple-websocket\n[downloads-image]: https://img.shields.io/npm/dm/simple-websocket.svg\n[downloads-url]: https://npmjs.org/package/simple-websocket\n[standard-image]: https://img.shields.io/badge/code_style-standard-brightgreen.svg\n[standard-url]: https://standardjs.com\n\n#### Simple, EventEmitter API for WebSockets\n\n[![Sauce Test Status](https://saucelabs.com/browser-matrix/simple-websocket.svg)](https://saucelabs.com/u/simple-websocket)\n\n## features\n\n- **super simple** API for working with WebSockets in the browser\n- supports **text and binary data**\n- node.js [duplex stream](http://nodejs.org/api/stream.html) interface\n- client & server implementations\n\nThis package is used by [WebTorrent](https://webtorrent.io).\n\n## install\n\n```\nnpm install simple-websocket\n```\n\nThis package works in the browser with [browserify](https://browserify.org). If\nyou do not use a bundler, you can use the `simplewebsocket.min.js` standalone script\ndirectly in a `<script>` tag. This exports a `SimpleWebsocket` constructor on\n`window`. Wherever you see `Socket` in the examples below, substitute that with\n`SimpleWebsocket`.\n\n## real-world applications that use simple-websocket\n\n- [Virus Cafe](https://virus.cafe) - Make a friend in 2 minutes\n- [WebTorrent](https://webtorrent.io) - The streaming torrent app\n- [StudyNotes](http://www.apstudynotes.org) - Helping students learn faster and better\n- [bittorrent-tracker](https://github.com/feross/bittorrent-tracker) - Simple, robust, BitTorrent tracker (client & server) implementation\n- [instant.io](https://github.com/feross/instant.io) - Secure, anonymous, streaming file transfer\n- [lxjs-chat](https://github.com/feross/lxjs-chat) - Omegle chat clone\n- [Metastream](https://github.com/samuelmaddock/metastream) - Watch streaming media with friends.\n- \\[ your application here - send a PR \\]\n\n## usage\n\n```js\nvar Socket = require('simple-websocket')\n\nvar socket = new Socket('wss://echo.websocket.org')\nsocket.on('connect', function () {\n  // socket is connected!\n  socket.send('sup!')\n})\n\nsocket.on('data', function (data) {\n  console.log('got message: ' + data)\n})\n```\n\n## api\n\n### `socket = new Socket(url)`\n\nCreate a new WebSocket connection to the server at `url`. This usage is a shorthand\nfor `socket = new Socket({ url: url })`\n\n### `socket = new Socket(opts)`\n\nIf `opts.url` is specified as a string, then a WebSocket connection will be created\nto the server at `opts.url`.\n\nIf `opts.socket` is specified as an instance of a raw WebSocket object, then the\ngiven WebSocket object will be used and one will not be automatically be created\ninternally. (This is for advanced users.)\n\nOther properties on `opts` will be passed through to the underlying superclass,\n`stream.Duplex`.\n\n### `socket.send(data)`\n\nSend text/binary data to the WebSocket server. `data` can be any of several types:\n`String`, `Buffer` (see [buffer](https://github.com/feross/buffer)), `TypedArrayView`\n(`Uint8Array`, etc.), `ArrayBuffer`, or `Blob` (in browsers that support it).\n\nNote: If this method is called before the `socket.on('connect')` event has fired, then\ndata will be buffered.\n\n### `socket.destroy([err])`\n\nDestroy and cleanup this websocket connection.\n\nIf the optional `err` parameter is passed, then it will be emitted as an `'error'`\nevent on the stream.\n\n### `Socket.WEBSOCKET_SUPPORT`\n\nDetect WebSocket support in the javascript environment.\n\n```js\nvar Socket = require('simple-websocket')\n\nif (Socket.WEBSOCKET_SUPPORT) {\n  // websocket support!\n} else {\n  // fallback\n}\n```\n\n## events\n\n### `socket.on('connect', function () {})`\n\nFired when the websocket connection is ready to use.\n\n### `socket.on('data', function (data) {})`\n\nReceived a message from the websocket server.\n\n`data` will be either a `String` or a `Buffer/Uint8Array` (see [buffer](https://github.com/feross/buffer)).\nJSON strings will be parsed and the resulting `Object` emitted.\n\n### `socket.on('close', function () {})`\n\nCalled when the websocket connection has closed.\n\n### `socket.on('error', function (err) {})`\n\n`err` is an `Error` object.\n\nFired when a fatal error occurs.\n\n## server\n\nThe server implementation is basically `ws` but the `'connection'` event provides\nsockets that are instances of `simple-websocket`, i.e. they are duplex streams.\n\n```js\nvar Server = require('simple-websocket/server')\n\nvar server = new Server({ port: port }) // see `ws` docs for other options\n\nserver.on('connection', function (socket) {\n  socket.write('pong')\n  socket.on('data', function (data) {})\n  socket.on('close', function () {})\n  socket.on('error', function (err) {})\n})\n\nserver.close()\n```\n\n## license\n\nMIT. Copyright (c) [Feross Aboukhadijeh](http://feross.org).\n","publish_time":1432035990636,"_cnpm_publish_time":1432035990636,"dist-tags":{"latest":"9.1.0"}}