mirror of
https://github.com/socketio/socket.io.git
synced 2026-04-30 03:00:39 -04:00
22
README.md
22
README.md
@@ -87,6 +87,21 @@ socket.on('open', function(){
|
||||
});
|
||||
```
|
||||
|
||||
### Node.js with certificates
|
||||
```js
|
||||
var opts = {
|
||||
key: fs.readFileSync('test/fixtures/client.key'),
|
||||
cert: fs.readFileSync('test/fixtures/client.crt'),
|
||||
ca: fs.readFileSync('test/fixtures/ca.crt')
|
||||
};
|
||||
|
||||
var socket = require('engine.io-client')('ws://localhost', opts);
|
||||
socket.on('open', function(){
|
||||
socket.on('message', function(data){});
|
||||
socket.on('close', function(){});
|
||||
});
|
||||
```
|
||||
|
||||
## Features
|
||||
|
||||
- Lightweight
|
||||
@@ -177,6 +192,13 @@ Exposed as `eio` in the browser standalone build.
|
||||
try websocket. A connection attempt following a transport error will use the
|
||||
normal upgrade process. It is recommended you turn this on only when using
|
||||
SSL/TLS connections, or if you know that your network does not block websockets.
|
||||
- `pfx` (`String`): Certificate, Private key and CA certificates to use for SSL. Can be used in Node.js client environment to manually specify certificate information.
|
||||
- `key` (`String`): Private key to use for SSL. Can be used in Node.js client environment to manually specify certificate information.
|
||||
- `passphrase` (`String`): A string of passphrase for the private key or pfx. Can be used in Node.js client environment to manually specify certificate information.
|
||||
- `cert` (`String`): Public x509 certificate to use. Can be used in Node.js client environment to manually specify certificate information.
|
||||
- `ca` (`String`|`Array`): An authority certificate or array of authority certificates to check the remote host against.. Can be used in Node.js client environment to manually specify certificate information.
|
||||
- `ciphers` (`String`): A string describing the ciphers to use or exclude. Consult the [cipher format list](http://www.openssl.org/docs/apps/ciphers.html#CIPHER_LIST_FORMAT) for details on the format.. Can be used in Node.js client environment to manually specify certificate information.
|
||||
- `rejectUnauthorized` (`Boolean`): If true, the server certificate is verified against the list of supplied CAs. An 'error' event is emitted if verification fails. Verification happens at the connection level, before the HTTP request is sent. Can be used in Node.js client environment to manually specify certificate information.
|
||||
- `send`
|
||||
- Sends a message to the server
|
||||
- **Parameters**
|
||||
|
||||
@@ -82,9 +82,19 @@ function Socket(uri, opts){
|
||||
this.callbackBuffer = [];
|
||||
this.policyPort = opts.policyPort || 843;
|
||||
this.rememberUpgrade = opts.rememberUpgrade || false;
|
||||
this.open();
|
||||
this.binaryType = null;
|
||||
this.onlyBinaryUpgrades = opts.onlyBinaryUpgrades;
|
||||
|
||||
// SSL options for Node.js client
|
||||
this.pfx = opts.pfx || null;
|
||||
this.key = opts.key || null;
|
||||
this.passphrase = opts.passphrase || null;
|
||||
this.cert = opts.cert || null;
|
||||
this.ca = opts.ca || null;
|
||||
this.ciphers = opts.ciphers || null;
|
||||
this.rejectUnauthorized = opts.rejectUnauthorized || null;
|
||||
|
||||
this.open();
|
||||
}
|
||||
|
||||
Socket.priorWebsocketSuccess = false;
|
||||
@@ -148,7 +158,14 @@ Socket.prototype.createTransport = function (name) {
|
||||
timestampRequests: this.timestampRequests,
|
||||
timestampParam: this.timestampParam,
|
||||
policyPort: this.policyPort,
|
||||
socket: this
|
||||
socket: this,
|
||||
pfx: this.pfx,
|
||||
key: this.key,
|
||||
passphrase: this.passphrase,
|
||||
cert: this.cert,
|
||||
ca: this.ca,
|
||||
ciphers: this.ciphers,
|
||||
rejectUnauthorized: this.rejectUnauthorized
|
||||
});
|
||||
|
||||
return transport;
|
||||
|
||||
@@ -30,6 +30,15 @@ function Transport (opts) {
|
||||
this.agent = opts.agent || false;
|
||||
this.socket = opts.socket;
|
||||
this.enablesXDR = opts.enablesXDR;
|
||||
|
||||
// SSL options for Node.js client
|
||||
this.pfx = opts.pfx;
|
||||
this.key = opts.key;
|
||||
this.passphrase = opts.passphrase;
|
||||
this.cert = opts.cert;
|
||||
this.ca = opts.ca;
|
||||
this.ciphers = opts.ciphers;
|
||||
this.rejectUnauthorized = opts.rejectUnauthorized;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -73,6 +73,16 @@ XHR.prototype.request = function(opts){
|
||||
opts.agent = this.agent || false;
|
||||
opts.supportsBinary = this.supportsBinary;
|
||||
opts.enablesXDR = this.enablesXDR;
|
||||
|
||||
// SSL options for Node.js client
|
||||
opts.pfx = this.pfx;
|
||||
opts.key = this.key;
|
||||
opts.passphrase = this.passphrase;
|
||||
opts.cert = this.cert;
|
||||
opts.ca = this.ca;
|
||||
opts.ciphers = this.ciphers;
|
||||
opts.rejectUnauthorized = this.rejectUnauthorized;
|
||||
|
||||
return new Request(opts);
|
||||
};
|
||||
|
||||
@@ -132,6 +142,16 @@ function Request(opts){
|
||||
this.isBinary = opts.isBinary;
|
||||
this.supportsBinary = opts.supportsBinary;
|
||||
this.enablesXDR = opts.enablesXDR;
|
||||
|
||||
// SSL options for Node.js client
|
||||
this.pfx = opts.pfx;
|
||||
this.key = opts.key;
|
||||
this.passphrase = opts.passphrase;
|
||||
this.cert = opts.cert;
|
||||
this.ca = opts.ca;
|
||||
this.ciphers = opts.ciphers;
|
||||
this.rejectUnauthorized = opts.rejectUnauthorized;
|
||||
|
||||
this.create();
|
||||
}
|
||||
|
||||
@@ -148,7 +168,18 @@ Emitter(Request.prototype);
|
||||
*/
|
||||
|
||||
Request.prototype.create = function(){
|
||||
var xhr = this.xhr = new XMLHttpRequest({ agent: this.agent, xdomain: this.xd, xscheme: this.xs, enablesXDR: this.enablesXDR });
|
||||
var opts = { agent: this.agent, xdomain: this.xd, xscheme: this.xs, enablesXDR: this.enablesXDR };
|
||||
|
||||
// SSL options for Node.js client
|
||||
opts.pfx = this.pfx;
|
||||
opts.key = this.key;
|
||||
opts.passphrase = this.passphrase;
|
||||
opts.cert = this.cert;
|
||||
opts.ca = this.ca;
|
||||
opts.ciphers = this.ciphers;
|
||||
opts.rejectUnauthorized = this.rejectUnauthorized;
|
||||
|
||||
var xhr = this.xhr = new XMLHttpRequest(opts);
|
||||
var self = this;
|
||||
|
||||
try {
|
||||
|
||||
@@ -74,6 +74,15 @@ WS.prototype.doOpen = function(){
|
||||
var protocols = void(0);
|
||||
var opts = { agent: this.agent };
|
||||
|
||||
// SSL options for Node.js client
|
||||
opts.pfx = this.pfx;
|
||||
opts.key = this.key;
|
||||
opts.passphrase = this.passphrase;
|
||||
opts.cert = this.cert;
|
||||
opts.ca = this.ca;
|
||||
opts.ciphers = this.ciphers;
|
||||
opts.rejectUnauthorized = this.rejectUnauthorized;
|
||||
|
||||
this.ws = new WebSocket(uri, protocols, opts);
|
||||
|
||||
if (this.ws.binaryType === undefined) {
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
"dependencies": {
|
||||
"has-cors": "1.0.3",
|
||||
"ws": "0.4.31",
|
||||
"xmlhttprequest": "https://github.com/LearnBoost/node-XMLHttpRequest/archive/0f36d0b5ebc03d85f860d42a64ae9791e1daa433.tar.gz",
|
||||
"xmlhttprequest": "rase-/node-XMLHttpRequest#a6b6f2",
|
||||
"component-emitter": "1.1.2",
|
||||
"indexof": "0.0.1",
|
||||
"engine.io-parser": "1.1.0",
|
||||
|
||||
Reference in New Issue
Block a user