This repository has been archived by the owner on Sep 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 616
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #209 from adobe/jrb/bring-ws-into-repo
check thirdparty ws library in to repo
- Loading branch information
Showing
19 changed files
with
2,542 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,8 +4,5 @@ | |
"description": "Node core for appshell", | ||
"main": "Launcher.js", | ||
"author": "Joel Brandt <[email protected]>", | ||
"license": "MIT", | ||
"dependencies": { | ||
"ws-deploy": "git+https://github.com/joelrbrandt/ws-deploy.git#7a3bdc6b21ebd66d4b360003391257945ab0585f" | ||
} | ||
"license": "MIT" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# Overview | ||
|
||
This module contains a minimal repackaging of ws for deployment. | ||
It is currently at version 0.4.25. The main repository for ws can be | ||
found at https://github.com/einaros/ws | ||
|
||
This repository also incorporates options.js instead of relying on it | ||
as an external dependency. The main repository for options.js can be | ||
found at https://github.com/einaros/options.js | ||
|
||
No modifications are made to either library except for a.) removing | ||
files that are not necessary for deployment and b.) fixing up paths. | ||
Specifically, this module was made by following these steps: | ||
|
||
1. Start with version 0.4.25 of ws | ||
2. Incorporate options.js directly into ws and fix up paths | ||
3. Remove files not needed for deployment (tests, etc.) | ||
4. Remove "compiled" code, and fix up paths to use "fallback" | ||
JS code by default. (Removing "compiled" code makes it easier | ||
to have this work in a cross-platform way.) | ||
|
||
Both ws and options.js are written by Einar Otto Stangvik and licensed | ||
under the MIT license (see below). | ||
|
||
## License for ws## | ||
|
||
(The MIT License) | ||
|
||
Copyright (c) 2011 Einar Otto Stangvik <[email protected]> | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
'Software'), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | ||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | ||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
|
||
## License for options.js## | ||
|
||
(The MIT License) | ||
|
||
Copyright (c) 2012 Einar Otto Stangvik <[email protected]> | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
'Software'), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | ||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | ||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/*! | ||
* ws: a node.js websocket client | ||
* Copyright(c) 2011 Einar Otto Stangvik <[email protected]> | ||
* MIT Licensed | ||
*/ | ||
|
||
module.exports = require('./lib/WebSocket'); | ||
module.exports.Server = require('./lib/WebSocketServer'); | ||
module.exports.Sender = require('./lib/Sender'); | ||
module.exports.Receiver = require('./lib/Receiver'); | ||
|
||
module.exports.createServer = function (options, connectionListener) { | ||
var server = new module.exports.Server(options); | ||
if (typeof connectionListener === 'function') { | ||
server.on('connection', connectionListener); | ||
} | ||
return server; | ||
}; | ||
|
||
module.exports.connect = module.exports.createConnection = function (address, openListener) { | ||
var client = new module.exports(address); | ||
if (typeof openListener === 'function') { | ||
client.on('open', openListener); | ||
} | ||
return client; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/*! | ||
* ws: a node.js websocket client | ||
* Copyright(c) 2011 Einar Otto Stangvik <[email protected]> | ||
* MIT Licensed | ||
*/ | ||
|
||
var util = require('util'); | ||
|
||
function BufferPool(initialSize, growStrategy, shrinkStrategy) { | ||
if (typeof initialSize === 'function') { | ||
shrinkStrategy = growStrategy; | ||
growStrategy = initialSize; | ||
initialSize = 0; | ||
} | ||
else if (typeof initialSize === 'undefined') { | ||
initialSize = 0; | ||
} | ||
this._growStrategy = (growStrategy || function(db, size) { | ||
return db.used + size; | ||
}).bind(null, this); | ||
this._shrinkStrategy = (shrinkStrategy || function(db) { | ||
return initialSize; | ||
}).bind(null, this); | ||
this._buffer = initialSize ? new Buffer(initialSize) : null; | ||
this._offset = 0; | ||
this._used = 0; | ||
this._changeFactor = 0; | ||
this.__defineGetter__('size', function(){ | ||
return this._buffer == null ? 0 : this._buffer.length; | ||
}); | ||
this.__defineGetter__('used', function(){ | ||
return this._used; | ||
}); | ||
} | ||
|
||
BufferPool.prototype.get = function(length) { | ||
if (this._buffer == null || this._offset + length > this._buffer.length) { | ||
var newBuf = new Buffer(this._growStrategy(length)); | ||
this._buffer = newBuf; | ||
this._offset = 0; | ||
} | ||
this._used += length; | ||
var buf = this._buffer.slice(this._offset, this._offset + length); | ||
this._offset += length; | ||
return buf; | ||
} | ||
|
||
BufferPool.prototype.reset = function(forceNewBuffer) { | ||
var len = this._shrinkStrategy(); | ||
if (len < this.size) this._changeFactor -= 1; | ||
if (forceNewBuffer || this._changeFactor < -2) { | ||
this._changeFactor = 0; | ||
this._buffer = len ? new Buffer(len) : null; | ||
} | ||
this._offset = 0; | ||
this._used = 0; | ||
} | ||
|
||
module.exports = BufferPool; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/*! | ||
* ws: a node.js websocket client | ||
* Copyright(c) 2011 Einar Otto Stangvik <[email protected]> | ||
* MIT Licensed | ||
*/ | ||
|
||
module.exports.BufferUtil = { | ||
merge: function(mergedBuffer, buffers) { | ||
var offset = 0; | ||
for (var i = 0, l = buffers.length; i < l; ++i) { | ||
var buf = buffers[i]; | ||
buf.copy(mergedBuffer, offset); | ||
offset += buf.length; | ||
} | ||
}, | ||
mask: function(source, mask, output, offset, length) { | ||
var maskNum = mask.readUInt32LE(0, true); | ||
var i = 0; | ||
for (; i < length - 3; i += 4) { | ||
var num = maskNum ^ source.readUInt32LE(i, true); | ||
if (num < 0) num = 4294967296 + num; | ||
output.writeUInt32LE(num, offset + i, true); | ||
} | ||
switch (length % 4) { | ||
case 3: output[offset + i + 2] = source[i + 2] ^ mask[2]; | ||
case 2: output[offset + i + 1] = source[i + 1] ^ mask[1]; | ||
case 1: output[offset + i] = source[i] ^ mask[0]; | ||
case 0:; | ||
} | ||
}, | ||
unmask: function(data, mask) { | ||
var maskNum = mask.readUInt32LE(0, true); | ||
var length = data.length; | ||
var i = 0; | ||
for (; i < length - 3; i += 4) { | ||
var num = maskNum ^ data.readUInt32LE(i, true); | ||
if (num < 0) num = 4294967296 + num; | ||
data.writeUInt32LE(num, i, true); | ||
} | ||
switch (length % 4) { | ||
case 3: data[i + 2] = data[i + 2] ^ mask[2]; | ||
case 2: data[i + 1] = data[i + 1] ^ mask[1]; | ||
case 1: data[i] = data[i] ^ mask[0]; | ||
case 0:; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/*! | ||
* ws: a node.js websocket client | ||
* Copyright(c) 2011 Einar Otto Stangvik <[email protected]> | ||
* MIT Licensed | ||
*/ | ||
|
||
module.exports = { | ||
isValidErrorCode: function(code) { | ||
return (code >= 1000 && code <= 1011 && code != 1004 && code != 1005 && code != 1006) || | ||
(code >= 3000 && code <= 4999); | ||
}, | ||
1000: 'normal', | ||
1001: 'going away', | ||
1002: 'protocol error', | ||
1003: 'unsupported data', | ||
1004: 'reserved', | ||
1005: 'reserved for extensions', | ||
1006: 'reserved for extensions', | ||
1007: 'inconsistent or invalid data', | ||
1008: 'policy violation', | ||
1009: 'message too big', | ||
1010: 'extension handshake missing', | ||
1011: 'an unexpected condition prevented the request from being fulfilled', | ||
}; |
Oops, something went wrong.