Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add setProtocols() to enable dynamic protocols. Added minification script for development. #104

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,30 @@ socket.timeoutInterval = 5400;
- Transmits data to the server over the WebSocket connection.
- Accepts @param data a text string, ArrayBuffer or Blob

#### `ws.setProtocols(protocols)`
- Set a new protocols value to be used on follow up reconnects. Useful when connection requires an access token that expires and renews.


## Release and Verify

NPM scripts are included in the package.json to create a minified version for release and to verify the minified version included in a release.
Run *npm install* to load the development modules required for the release and verify scripts.


#### Release

The npm release script will create a new minified version of the library.

> npm run release


#### Verify

The verify script can be used to validate the minified release matches the source by creating a new verification minified file and then making the comparison.

> npm run verify


Like this? Check out [websocketd](https://github.com/joewalnes/websocketd) for the simplest way to create WebSocket backends from any programming language.

[Follow @joewalnes](https://twitter.com/joewalnes)
Expand Down
13 changes: 10 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
{
"name": "ReconnectingWebSocket",
"version": "1.0.1",
"version": "1.0.2",
"description": "A small JavaScript library that decorates the WebSocket API to provide a WebSocket connection that will automatically reconnect if the connection is dropped.",
"main": "reconnecting-websocket.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\" && exit 1",
"release": "npm run minifi -- -o reconnecting-websocket.min.js reconnecting-websocket.js",
"verify": "npm run minifi -- -o verify_reconnecting-websocket.min.js reconnecting-websocket.js && files-compare reconnecting-websocket.min.js verify_reconnecting-websocket.min.js",
"minifi": "uglifyjs --compress --mangle"
},
"repository": {
"type": "git",
Expand All @@ -15,5 +18,9 @@
"bugs": {
"url": "https://github.com/joewalnes/reconnecting-websocket/issues"
},
"homepage": "https://github.com/joewalnes/reconnecting-websocket"
"homepage": "https://github.com/joewalnes/reconnecting-websocket",
"devDependencies": {
"files-compare": "^1.0.2",
"uglify-js": "^3.4.9"
}
}
11 changes: 9 additions & 2 deletions reconnecting-websocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,10 @@
maxReconnectAttempts: null,

/** The binary type, possible values 'blob' or 'arraybuffer', default 'blob'. */
binaryType: 'blob'
binaryType: 'blob',

/** The sub-protocols to use when creating a websocket */
protocols: protocols || null
}
if (!options) { options = {}; }

Expand Down Expand Up @@ -205,8 +208,12 @@
return evt;
};

this.setProtocols = function (protocols) {
settings.protocols = protocols;
};

this.open = function (reconnectAttempt) {
ws = new WebSocket(self.url, protocols || []);
ws = new WebSocket(self.url, settings.protocols || []);
ws.binaryType = this.binaryType;

if (reconnectAttempt) {
Expand Down
2 changes: 1 addition & 1 deletion reconnecting-websocket.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.