package.json
14.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
{
"_args": [
[
{
"raw": "websocket",
"scope": null,
"escapedName": "websocket",
"name": "websocket",
"rawSpec": "",
"spec": "latest",
"type": "tag"
},
"/Users/fzy/project/3mang"
]
],
"_from": "websocket@latest",
"_id": "websocket@1.0.24",
"_inCache": true,
"_location": "/websocket",
"_nodeVersion": "7.3.0",
"_npmOperationalInternal": {
"host": "packages-12-west.internal.npmjs.com",
"tmp": "tmp/websocket-1.0.24.tgz_1482977757939_0.1858439394272864"
},
"_npmUser": {
"name": "theturtle32",
"email": "brian@worlize.com"
},
"_npmVersion": "3.10.10",
"_phantomChildren": {},
"_requested": {
"raw": "websocket",
"scope": null,
"escapedName": "websocket",
"name": "websocket",
"rawSpec": "",
"spec": "latest",
"type": "tag"
},
"_requiredBy": [
"#DEV:/",
"#USER"
],
"_resolved": "https://registry.npmjs.org/websocket/-/websocket-1.0.24.tgz",
"_shasum": "74903e75f2545b6b2e1de1425bc1c905917a1890",
"_shrinkwrap": null,
"_spec": "websocket",
"_where": "/Users/fzy/project/3mang",
"author": {
"name": "Brian McKelvey",
"email": "brian@worlize.com",
"url": "https://www.worlize.com/"
},
"browser": "lib/browser.js",
"bugs": {
"url": "https://github.com/theturtle32/WebSocket-Node/issues"
},
"config": {
"verbose": false
},
"contributors": [
{
"name": "Iñaki Baz Castillo",
"email": "ibc@aliax.net",
"url": "http://dev.sipdoc.net"
}
],
"dependencies": {
"debug": "^2.2.0",
"nan": "^2.3.3",
"typedarray-to-buffer": "^3.1.2",
"yaeti": "^0.0.6"
},
"description": "Websocket Client & Server Library implementing the WebSocket protocol as specified in RFC 6455.",
"devDependencies": {
"buffer-equal": "^1.0.0",
"faucet": "^0.0.1",
"gulp": "git+https://github.com/gulpjs/gulp.git#4.0",
"gulp-jshint": "^2.0.4",
"jshint": "^2.0.0",
"jshint-stylish": "^2.2.1",
"tape": "^4.0.1"
},
"directories": {
"lib": "./lib"
},
"dist": {
"shasum": "74903e75f2545b6b2e1de1425bc1c905917a1890",
"tarball": "https://registry.npmjs.org/websocket/-/websocket-1.0.24.tgz"
},
"engines": {
"node": ">=0.8.0"
},
"gitHead": "0e15f9445953927c39ce84a232cb7dd6e3adf12e",
"homepage": "https://github.com/theturtle32/WebSocket-Node",
"keywords": [
"websocket",
"websockets",
"socket",
"networking",
"comet",
"push",
"RFC-6455",
"realtime",
"server",
"client"
],
"license": "Apache-2.0",
"main": "index",
"maintainers": [
{
"name": "theturtle32",
"email": "brian@worlize.com"
}
],
"name": "websocket",
"optionalDependencies": {},
"readme": "WebSocket Client & Server Implementation for Node\n=================================================\n\n[](http://badge.fury.io/js/websocket)\n\n[](https://www.npmjs.com/package/websocket)\n\n[](https://nodei.co/npm/websocket/)\n\n[](https://nodei.co/npm/websocket/)\n\n[ ](https://codeship.com/projects/61106)\n\nOverview\n--------\nThis is a (mostly) pure JavaScript implementation of the WebSocket protocol versions 8 and 13 for Node. There are some example client and server applications that implement various interoperability testing protocols in the \"test/scripts\" folder.\n\nFor a WebSocket client written in ActionScript 3, see my [AS3WebScocket](https://github.com/theturtle32/AS3WebSocket) project.\n\n\nDocumentation\n=============\n\n[You can read the full API documentation in the docs folder.](docs/index.md)\n\n\nChangelog\n---------\n\n***Current Version: 1.0.24*** — Released 2016-12-28\n\n***Version 1.0.24***\n\n* Fixed a bug when using native keepalive on Node >= 6.0. (Thanks, [@prossin](https://github.com/prossin))\n* Upgrading outdated dependencies\n\n***Version 1.0.23***\n\n* Official support for Node 6.x\n* Updating dependencies. Specifically, updating nan to ^2.3.3\n\n***Version 1.0.22***\n\n* Updating to work with nan 2.x\n\n\n***Version 1.0.21***\n\n* Incremented and re-published to work around an aborted npm publish of v1.0.20.\n\n***Version 1.0.20***\n\n* Added EventTarget to the W3CWebSocket interface (Thanks, [@ibc](https://github.com/ibc)!)\n* Corrected an inaccurate error message. (Thanks, [@lekoaf](https://github.com/lekoaf)!)\n\n***Version 1.0.19***\n\n* Updated to nan v1.8.x (tested with v1.8.4)\n* Added `\"license\": \"Apache-2.0\"` to package.json via [pull request #199](https://github.com/theturtle32/WebSocket-Node/pull/199) by [@pgilad](https://github.com/pgilad). See [npm1k.org](http://npm1k.org/).\n\n[View the full changelog](CHANGELOG.md)\n\nBrowser Support\n---------------\n\nAll current browsers are fully supported.\n\n* Firefox 7-9 (Old) (Protocol Version 8)\n* Firefox 10+ (Protocol Version 13)\n* Chrome 14,15 (Old) (Protocol Version 8)\n* Chrome 16+ (Protocol Version 13)\n* Internet Explorer 10+ (Protocol Version 13)\n* Safari 6+ (Protocol Version 13)\n\n***Safari older than 6.0 is not supported since it uses a very old draft of WebSockets***\n\n***If you need to simultaneously support legacy browser versions that had implemented draft-75/draft-76/draft-00, take a look here: https://gist.github.com/1428579***\n\nBenchmarks\n----------\nThere are some basic benchmarking sections in the Autobahn test suite. I've put up a [benchmark page](http://theturtle32.github.com/WebSocket-Node/benchmarks/) that shows the results from the Autobahn tests run against AutobahnServer 0.4.10, WebSocket-Node 1.0.2, WebSocket-Node 1.0.4, and ws 0.3.4.\n\nAutobahn Tests\n--------------\nThe very complete [Autobahn Test Suite](http://autobahn.ws/testsuite/) is used by most WebSocket implementations to test spec compliance and interoperability.\n\n- [View Server Test Results](http://theturtle32.github.com/WebSocket-Node/test-report/servers/)\n- [View Client Test Results](http://theturtle32.github.com/WebSocket-Node/test-report/clients/)\n\nNotes\n-----\nThis library has been used in production on [worlize.com](https://www.worlize.com) since April 2011 and seems to be stable. Your mileage may vary.\n\n**Tested with the following node versions:**\n\n- 6.2.0\n- 5.11.1\n- 4.4.4\n- 0.10.45\n\nIt may work in earlier or later versions but I'm not actively testing it outside of the listed versions. YMMV.\n\nInstallation\n------------\n\nA few users have reported difficulties building the native extensions without first manually installing node-gyp. If you have trouble building the native extensions, make sure you've got a C++ compiler, and have done `npm install -g node-gyp` first. \n\nNative extensions are optional, however, and WebSocket-Node will work even if the extensions cannot be compiled.\n\nIn your project root:\n\n $ npm install websocket\n \nThen in your code:\n\n```javascript\nvar WebSocketServer = require('websocket').server;\nvar WebSocketClient = require('websocket').client;\nvar WebSocketFrame = require('websocket').frame;\nvar WebSocketRouter = require('websocket').router;\nvar W3CWebSocket = require('websocket').w3cwebsocket;\n```\n\nNote for Windows Users\n----------------------\nBecause there is a small C++ component used for validating UTF-8 data, you will need to install a few other software packages in addition to Node to be able to build this module:\n\n- [Microsoft Visual C++](http://www.microsoft.com/visualstudio/en-us/products/2010-editions/visual-cpp-express)\n- [Python 2.7](http://www.python.org/download/) (NOT Python 3.x)\n\n\nCurrent Features:\n-----------------\n- Licensed under the Apache License, Version 2.0\n- Protocol version \"8\" and \"13\" (Draft-08 through the final RFC) framing and handshake\n- Can handle/aggregate received fragmented messages\n- Can fragment outgoing messages\n- Router to mount multiple applications to various path and protocol combinations\n- TLS supported for outbound connections via WebSocketClient\n- TLS supported for server connections (use https.createServer instead of http.createServer)\n - Thanks to [pors](https://github.com/pors) for confirming this!\n- Cookie setting and parsing\n- Tunable settings\n - Max Receivable Frame Size\n - Max Aggregate ReceivedMessage Size\n - Whether to fragment outgoing messages\n - Fragmentation chunk size for outgoing messages\n - Whether to automatically send ping frames for the purposes of keepalive\n - Keep-alive ping interval\n - Whether or not to automatically assemble received fragments (allows application to handle individual fragments directly)\n - How long to wait after sending a close frame for acknowledgment before closing the socket.\n- [W3C WebSocket API](http://www.w3.org/TR/websockets/) for applications running on both Node and browsers (via the `W3CWebSocket` class). \n\n\nKnown Issues/Missing Features:\n------------------------------\n- No API for user-provided protocol extensions.\n\n\nUsage Examples\n==============\n\nServer Example\n--------------\n\nHere's a short example showing a server that echos back anything sent to it, whether utf-8 or binary.\n\n```javascript\n#!/usr/bin/env node\nvar WebSocketServer = require('websocket').server;\nvar http = require('http');\n\nvar server = http.createServer(function(request, response) {\n console.log((new Date()) + ' Received request for ' + request.url);\n response.writeHead(404);\n response.end();\n});\nserver.listen(8080, function() {\n console.log((new Date()) + ' Server is listening on port 8080');\n});\n\nwsServer = new WebSocketServer({\n httpServer: server,\n // You should not use autoAcceptConnections for production\n // applications, as it defeats all standard cross-origin protection\n // facilities built into the protocol and the browser. You should\n // *always* verify the connection's origin and decide whether or not\n // to accept it.\n autoAcceptConnections: false\n});\n\nfunction originIsAllowed(origin) {\n // put logic here to detect whether the specified origin is allowed.\n return true;\n}\n\nwsServer.on('request', function(request) {\n if (!originIsAllowed(request.origin)) {\n // Make sure we only accept requests from an allowed origin\n request.reject();\n console.log((new Date()) + ' Connection from origin ' + request.origin + ' rejected.');\n return;\n }\n \n var connection = request.accept('echo-protocol', request.origin);\n console.log((new Date()) + ' Connection accepted.');\n connection.on('message', function(message) {\n if (message.type === 'utf8') {\n console.log('Received Message: ' + message.utf8Data);\n connection.sendUTF(message.utf8Data);\n }\n else if (message.type === 'binary') {\n console.log('Received Binary Message of ' + message.binaryData.length + ' bytes');\n connection.sendBytes(message.binaryData);\n }\n });\n connection.on('close', function(reasonCode, description) {\n console.log((new Date()) + ' Peer ' + connection.remoteAddress + ' disconnected.');\n });\n});\n```\n\nClient Example\n--------------\n\nThis is a simple example client that will print out any utf-8 messages it receives on the console, and periodically sends a random number.\n\n*This code demonstrates a client in Node.js, not in the browser*\n\n```javascript\n#!/usr/bin/env node\nvar WebSocketClient = require('websocket').client;\n\nvar client = new WebSocketClient();\n\nclient.on('connectFailed', function(error) {\n console.log('Connect Error: ' + error.toString());\n});\n\nclient.on('connect', function(connection) {\n console.log('WebSocket Client Connected');\n connection.on('error', function(error) {\n console.log(\"Connection Error: \" + error.toString());\n });\n connection.on('close', function() {\n console.log('echo-protocol Connection Closed');\n });\n connection.on('message', function(message) {\n if (message.type === 'utf8') {\n console.log(\"Received: '\" + message.utf8Data + \"'\");\n }\n });\n \n function sendNumber() {\n if (connection.connected) {\n var number = Math.round(Math.random() * 0xFFFFFF);\n connection.sendUTF(number.toString());\n setTimeout(sendNumber, 1000);\n }\n }\n sendNumber();\n});\n\nclient.connect('ws://localhost:8080/', 'echo-protocol');\n```\n\nClient Example using the *W3C WebSocket API*\n--------------------------------------------\n\nSame example as above but using the [W3C WebSocket API](http://www.w3.org/TR/websockets/).\n\n```javascript\nvar W3CWebSocket = require('websocket').w3cwebsocket;\n\nvar client = new W3CWebSocket('ws://localhost:8080/', 'echo-protocol');\n\nclient.onerror = function() {\n console.log('Connection Error');\n};\n\nclient.onopen = function() {\n console.log('WebSocket Client Connected');\n\n function sendNumber() {\n if (client.readyState === client.OPEN) {\n var number = Math.round(Math.random() * 0xFFFFFF);\n client.send(number.toString());\n setTimeout(sendNumber, 1000);\n }\n }\n sendNumber();\n};\n\nclient.onclose = function() {\n console.log('echo-protocol Client Closed');\n};\n\nclient.onmessage = function(e) {\n if (typeof e.data === 'string') {\n console.log(\"Received: '\" + e.data + \"'\");\n }\n};\n```\n \nRequest Router Example\n----------------------\n\nFor an example of using the request router, see `libwebsockets-test-server.js` in the `test` folder.\n\n\nResources\n---------\n\nA presentation on the state of the WebSockets protocol that I gave on July 23, 2011 at the LA Hacker News meetup. [WebSockets: The Real-Time Web, Delivered](http://www.scribd.com/doc/60898569/WebSockets-The-Real-Time-Web-Delivered)\n",
"readmeFilename": "README.md",
"repository": {
"type": "git",
"url": "git+https://github.com/theturtle32/WebSocket-Node.git"
},
"scripts": {
"gulp": "gulp",
"install": "(node-gyp rebuild 2> builderror.log) || (exit 0)",
"test": "faucet test/unit"
},
"version": "1.0.24"
}