Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Avoid conflicts with other WebSocketServer's by enabling more options. #31

Open
wants to merge 3 commits into from

3 participants

@jseb

webRTC accepted one parameter to it's listen method, which value could be either a port or a httpServer. The parameter were checked for type, and then either the option(s) { server: parameter } or { port: parameter } were sent to ws.WebSocketServer constructor.

To enable more options (in this case the path option was wanted to avoid conflicts with other websocket servers) and also re-use the option parsing in WebSocketServer, the listen method now accepts an options object, which it then directly passes on to the WebSocketServer constructor.

  • no option parsing in the form of typechecking or other is needed in webRTC's listen method
  • more options are available, for example the path option
  • options to webRTC will have the same form as WebSocketServer, which makes code more consistent
@sarenji
Owner

That makes sense. @dennismartensson @cavedweller opinions?

@dennismartensson

I think it looks good!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 21, 2013
  1. re-use ws WebSocketServer options parsing, for DRY, consistency, and …

    jseb authored
    …enabling of more options
  2. @jseb

    Update README.md

    jseb authored
    Fixed broken styling of code.
This page is out of date. Refresh to see the latest.
Showing with 19 additions and 13 deletions.
  1. +17 −1 README.md
  2. +2 −12 lib/webrtc.io.js
View
18 README.md
@@ -48,10 +48,26 @@ To run the server in debug mode, append '-debug' to the node command
### Server
```javascript
-var webRTC = require('webrtc.io').listen(8001);
+var webRTC = require('webrtc.io').listen({ 'port': 8001 });
//then a bunch of callbacks are available
```
+Or passing a http server:
+```javascript
+var httpServer = require('http').createServer(),
+ webRTC = require('webrtc.io').listen({ 'server': httpServer });
+httpServer.listen(8001);
+```
+
+When using another websocket server on the httpServer, pass a path option:
+```javascript
+var httpServer = require('http').createServer(),
+ wsServer = require('ws').createServer({ 'server': httpServer, 'path': '/websocket' }),
+ webRTC = require('webrtc.io').listen({ 'server': httpServer, 'path': '/webrtc' });
+httpServer.listen(8001);
+```
+
+
## Stumped?
```
#webrtc.io on freenode
View
14 lib/webrtc.io.js
@@ -44,18 +44,8 @@ rtc.fire = function(eventName, _) {
}
};
-module.exports.listen = function(server) {
- var manager;
- if (typeof server === 'number') {
- manager = new WebSocketServer({
- port: server
- });
- } else {
- manager = new WebSocketServer({
- server: server
- });
- }
-
+module.exports.listen = function(options) {
+ var manager = new WebSocketServer(options);
manager.rtc = rtc;
attachEvents(manager);
return manager;
Something went wrong with that request. Please try again.