@@ -47,16 +47,16 @@ A simplified echo SockJS server could look more or less like:
4747const http = require (' http' );
4848const sockjs = require (' sockjs' );
4949
50- const echo = sockjs .createServer ({ sockjs_url: ' http://cdn.jsdelivr.net/sockjs/1.0. 1/sockjs.min.js' });
50+ const echo = sockjs .createServer ({ prefix : ' /echo ' , sockjs_url: ' http://cdn.jsdelivr.net/sockjs/1/sockjs.min.js' });
5151echo .on (' connection' , function (conn ) {
52- conn .on (' data' , function (message ) {
53- conn .write (message);
54- });
55- conn .on (' close' , function () {});
52+ conn .on (' data' , function (message ) {
53+ conn .write (message);
54+ });
55+ conn .on (' close' , function () {});
5656});
5757
5858const server = http .createServer ();
59- echo .installHandlers (server, {prefix : ' /echo ' } );
59+ echo .attach (server);
6060server .listen (9999 , ' 0.0.0.0' );
6161```
6262
@@ -98,7 +98,7 @@ Where `options` is a hash which can contain:
9898 domain local to the SockJS server. This iframe also does need to
9999 load SockJS javascript client library, and this option lets you specify
100100 its url (if you're unsure, point it to
101- <a href =" http://cdn.jsdelivr.net/sockjs/1.0.1 /sockjs.min.js " >
101+ <a href =" http://cdn.jsdelivr.net/sockjs/1/sockjs.min.js " >
102102 the latest minified SockJS client release</a >, this is the default).
103103 You must explicitly specify this url on the server side for security
104104 reasons - we don't want the possibility of running any foreign
@@ -122,10 +122,10 @@ Where `options` is a hash which can contain:
122122 streaming and will make streaming transports to behave like polling
123123 transports. The default value is 128K.</dd >
124124
125- <dt >websocket (boolean )</dt >
126- <dd >Some load balancers don't support websockets. This option can be used
127- to disable websockets support by the server. By default websockets are
128- enabled .</dd >
125+ <dt >transports (Array of strings )</dt >
126+ <dd >List of transports to enable. Select from `eventsource`, `htmlfile`,
127+ ` jsonp-polling ` , ` websocket ` , ` websocket-raw ` , ` xhr-polling ` ,
128+ and ` xhr-streaming ` .</dd >
129129
130130<dt >jsessionid (boolean or function)</dt >
131131<dd >Some hosting providers enable sticky sessions only to requests that
@@ -137,7 +137,7 @@ Where `options` is a hash which can contain:
137137<dt >log (function(severity, message))</dt >
138138<dd >It's quite useful, especially for debugging, to see some messages
139139 printed by a SockJS-node library. This is done using this ` log `
140- function, which is by default set to ` console.log ` . If this
140+ function, which is by default set to nothing . If this
141141 behaviour annoys you for some reason, override ` log ` setting with a
142142 custom handler. The following ` severities ` are used: ` debug `
143143 (miscellaneous logs), ` info ` (requests logs), ` error ` (serious
@@ -161,7 +161,7 @@ Where `options` is a hash which can contain:
161161 <a href =" https://en.wikipedia.org/wiki/Cross-origin_resource_sharing " >CORS</a >
162162 headers from being included in the HTTP response. Can be used when the
163163 sockjs client is known to be connecting from the same origin as the
164- sockjs server.</dd >
164+ sockjs server. This also disables the iframe HTML endpoint. </dd >
165165</dl >
166166
167167
@@ -172,13 +172,10 @@ Once you have create `Server` instance you can hook it to the
172172
173173``` javascript
174174var http_server = http .createServer ();
175- sockjs_server .installHandlers (http_server, options );
175+ sockjs_server .attach (http_server);
176176http_server .listen (... );
177177```
178178
179- Where ` options ` can overshadow options given when creating ` Server `
180- instance.
181-
182179` Server ` instance is an
183180[ EventEmitter] ( https://nodejs.org/api/events.html#events_class_eventemitter ) ,
184181and emits following event:
@@ -191,7 +188,7 @@ and emits following event:
191188All http requests that don't go under the path selected by ` prefix `
192189will remain unanswered and will be passed to previously registered
193190handlers. You must install your custom http handlers before calling
194- ` installHandlers ` .
191+ ` attach ` .
195192
196193### Connection instance
197194
@@ -266,14 +263,13 @@ For example:
266263
267264``` javascript
268265sockjs_server .on (' connection' , function (conn ) {
269- console .log (' connection' + conn);
270- conn .on (' close' , function () {
271- console .log (' close ' + conn);
272- });
273- conn .on (' data' , function (message ) {
274- console .log (' message ' + conn,
275- message);
276- });
266+ console .log (' connection' + conn);
267+ conn .on (' close' , function () {
268+ console .log (' close ' + conn);
269+ });
270+ conn .on (' data' , function (message ) {
271+ console .log (' message ' + conn, message);
272+ });
277273});
278274```
279275
0 commit comments