Produced by Araxis Merge on 7/26/2017 10:13:39 AM Central Daylight Time. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.
| # | Location | File | Last Modified |
|---|---|---|---|
| 1 | C:\AraxisMergeCompare\Pri_un\TGZ\ws-1.1.0 | ws-1.1.0.tar | Sat Feb 18 15:03:58 2017 UTC |
| 2 | C:\AraxisMergeCompare\Pri_re\TGZ\ws-1.1.0 | ws-1.1.0.tar | Wed Jul 26 13:35:07 2017 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 2 | 7962 |
| Changed | 1 | 2 |
| Inserted | 0 | 0 |
| Removed | 0 | 0 |
| Whitespace | |
|---|---|
| Character case | Differences in character case are significant |
| Line endings | Differences in line endings (CR and LF characters) are ignored |
| CR/LF characters | Not shown in the comparison detail |
No regular expressions were active.
| 1 | package/pa ckage.json \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 000644 \x000000 0765 \x00000000 24 \x0000000000 1613 \x00001270 2710705\x000001 3017 \x00000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000ust ar\x000000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x00000 00000 \x0000000 000 \x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000{ | |
| 2 | "author" : "Einar O tto Stangv ik <einaro s@gmail.co m> (http:/ /2x.io)", | |
| 3 | "name": "ws", | |
| 4 | "descrip tion": "si mple to us e, blazing fast and thoroughly tested we bsocket cl ient, serv er and con sole for n ode.js, up -to-date a gainst RFC -6455", | |
| 5 | "version ": "1.1.0" , | |
| 6 | "license ": "MIT", | |
| 7 | "main": "index.js" , | |
| 8 | "keyword s": [ | |
| 9 | "Hixie ", | |
| 10 | "HyBi" , | |
| 11 | "Push" , | |
| 12 | "RFC-6 455", | |
| 13 | "WebSo cket", | |
| 14 | "WebSo ckets", | |
| 15 | "real- time" | |
| 16 | ], | |
| 17 | "reposit ory": { | |
| 18 | "type" : "git", | |
| 19 | "url": "git://gi thub.com/w ebsockets/ ws.git" | |
| 20 | }, | |
| 21 | "scripts ": { | |
| 22 | "test" : "make te st" | |
| 23 | }, | |
| 24 | "depende ncies": { | |
| 25 | "optio ns": ">=0. 0.5", | |
| 26 | "ultro n": "1.0.x " | |
| 27 | }, | |
| 28 | "devDepe ndencies": { | |
| 29 | "ansi" : "0.3.x", | |
| 30 | "bench mark": "0. 3.x", | |
| 31 | "buffe rutil": "1 .2.x", | |
| 32 | "expec t.js": "0. 3.x", | |
| 33 | "istan bul": "^0. 4.1", | |
| 34 | "mocha ": "2.3.x" , | |
| 35 | "shoul d": "8.0.x ", | |
| 36 | "tinyc olor": "0. 0.x", | |
| 37 | "utf-8 -validate" : "1.2.x" | |
| 38 | }, | |
| 39 | "gypfile ": true | |
| 40 | } | |
| 41 | \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000pac kage/.npmi gnore\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000000 644 \x000000076 5 \x0000000024 \x0000000000011 2 \x00001246165 1214\x000001252 2 \x00000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000ustar\x0000 00\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x00000000 00 \x0000000000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000n pm-debug.l og | |
| 42 | node_modul es | |
| 43 | .*.swp | |
| 44 | .lock-* | |
| 45 | build | |
| 46 | ||
| 47 | bench | |
| 48 | doc | |
| 49 | examples | |
| 50 | test | |
| 51 | ||
| 52 | \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000pa ckage/READ ME.md\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x000000 0644 \x00000007 65 \x0000000024 \x000000000157 17 \x0000127027 10666\x00000120 30 \x00000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000ustar \x000000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000000 000 \x000000000 0 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 # ws: a no de.js webs ocket libr ary | |
| 53 | ||
| 54 | [](https:/ /travis-ci .org/webso ckets/ws) | |
| 55 | ||
| 56 | `ws` is a simple to use WebSoc ket implem entation, up-to-date against R FC-6455, | |
| 57 | and [proba bly the fa stest WebS ocket libr ary for no de.js][arc hive]. | |
| 58 | ||
| 59 | Passes the quite ext ensive Aut obahn test suite. Se e http://w ebsockets. github.com /ws | |
| 60 | for the fu ll reports . | |
| 61 | ||
| 62 | ## Protoco l support | |
| 63 | ||
| 64 | * **Hixie draft 76** (Old and deprecated , but stil l in use b y Safari a nd Opera. | |
| 65 | Added to ws versio n 0.4.2, b ut server only. Can be disable d by setti ng the | |
| 66 | `disable Hixie` opt ion to tru e.) | |
| 67 | * **HyBi d rafts 07-1 2** (Use t he option `protocolV ersion: 8` ) | |
| 68 | * **HyBi d rafts 13-1 7** (Curre nt default , alternat ively opti on `protoc olVersion: 13`) | |
| 69 | ||
| 70 | ### Instal ling | |
| 71 | ||
| 72 | ``` | |
| 73 | npm instal l --save w s | |
| 74 | ``` | |
| 75 | ||
| 76 | ### Opt-in for perfo rmance | |
| 77 | ||
| 78 | There are 2 optional modules t hat can be installed along sid e with the `ws` | |
| 79 | module. Th ese module s are bina ry addons which impr ove certai n operatio ns, but as | |
| 80 | they are b inary addo ns they re quire comp ilation wh ich can fa il if no c ++ | |
| 81 | compiler i s installe d on the h ost system . | |
| 82 | ||
| 83 | - `npm ins tall --sav e bufferut il`: Impro ves intern al buffer operations which | |
| 84 | allows f or faster processing of masked WebSocket frames an d general buffer | |
| 85 | operatio ns. | |
| 86 | - `npm ins tall --sav e utf-8-va lidate`: T he specifi cation req uires vali dation of | |
| 87 | invalid UTF-8 char s, some of these val idations c ould not b e done in JavaScript | |
| 88 | hence th e need for a binary addon. In most cases you will already be | |
| 89 | validati ng the inp ut that yo u receive for securi ty purpose s leading to double | |
| 90 | validati on. But if you want to be 100% spec-conf orming and have fast | |
| 91 | validati on of UTF- 8 then thi s module i s a must. | |
| 92 | ||
| 93 | ### Sendin g and rece iving text data | |
| 94 | ||
| 95 | ```js | |
| 96 | var WebSoc ket = requ ire('ws'); | |
| 97 | var ws = n ew WebSock et('ws://w ww.host.co m/path'); | |
| 98 | ||
| 99 | ws.on('ope n', functi on open() { | |
| 100 | ws.send( 'something '); | |
| 101 | }); | |
| 102 | ||
| 103 | ws.on('mes sage', fun ction(data , flags) { | |
| 104 | // flags .binary wi ll be set if a binar y data is received. | |
| 105 | // flags .masked wi ll be set if the dat a was mask ed. | |
| 106 | }); | |
| 107 | ``` | |
| 108 | ||
| 109 | ### Sendin g binary d ata | |
| 110 | ||
| 111 | ```js | |
| 112 | var WebSoc ket = requ ire('ws'); | |
| 113 | var ws = n ew WebSock et('ws://w ww.host.co m/path'); | |
| 114 | ||
| 115 | ws.on('ope n', functi on open() { | |
| 116 | var arra y = new Fl oat32Array (5); | |
| 117 | ||
| 118 | for (var i = 0; i < array.le ngth; ++i) { | |
| 119 | array[ i] = i / 2 ; | |
| 120 | } | |
| 121 | ||
| 122 | ws.send( array, { b inary: tru e, mask: t rue }); | |
| 123 | }); | |
| 124 | ``` | |
| 125 | ||
| 126 | Setting `m ask`, as d one for th e send opt ions above , will cau se the dat a to be | |
| 127 | masked acc ording to the WebSoc ket protoc ol. The sa me option applies fo r text | |
| 128 | data. | |
| 129 | ||
| 130 | ### Server example | |
| 131 | ||
| 132 | ```js | |
| 133 | var WebSoc ketServer = require( 'ws').Serv er | |
| 134 | , wss = new WebSoc ketServer( { port: 80 80 }); | |
| 135 | ||
| 136 | wss.on('co nnection', function connection (ws) { | |
| 137 | ws.on('m essage', f unction in coming(mes sage) { | |
| 138 | consol e.log('rec eived: %s' , message) ; | |
| 139 | }); | |
| 140 | ||
| 141 | ws.send( 'something '); | |
| 142 | }); | |
| 143 | ``` | |
| 144 | ||
| 145 | ### Expres sJS exampl e | |
| 146 | ||
| 147 | ```js | |
| 148 | var server = require ('http').c reateServe r() | |
| 149 | , url = require('u rl') | |
| 150 | , WebSoc ketServer = require( 'ws').Serv er | |
| 151 | , wss = new WebSoc ketServer( { server: server }) | |
| 152 | , expres s = requir e('express ') | |
| 153 | , app = express() | |
| 154 | , PORT ; | |
| 155 | ||
| 156 | app.use(fu nction (re q, res) { | |
| 157 | res.send ({ msg: "h ello" }); | |
| 158 | }); | |
| 159 | ||
| 160 | wss.on('co nnection', function connection (ws) { | |
| 161 | var loca tion = url .parse(ws. upgradeReq .url, true ); | |
| 162 | // you m ight use l ocation.qu ery.access _token to authentica te or shar e sessions | |
| 163 | // or ws .upgradeRe q.headers. cookie (se e http://s tackoverfl ow.com/a/1 6395220/15 1312) | |
| 164 | ||
| 165 | ws.on('m essage', f unction in coming(mes sage) { | |
| 166 | consol e.log('rec eived: %s' , message) ; | |
| 167 | }); | |
| 168 | ||
| 169 | ws.send( 'something '); | |
| 170 | }); | |
| 171 | ||
| 172 | server.on( 'request', app); | |
| 173 | server.lis ten(port, function ( ) { consol e.log('Lis tening on ' + server .address() .port) }); | |
| 174 | ``` | |
| 175 | ||
| 176 | ### Server sending b roadcast d ata | |
| 177 | ||
| 178 | ```js | |
| 179 | var WebSoc ketServer = require( 'ws').Serv er | |
| 180 | , wss = new WebSoc ketServer( { port: 80 80 }); | |
| 181 | ||
| 182 | wss.broadc ast = func tion broad cast(data) { | |
| 183 | wss.clie nts.forEac h(function each(clie nt) { | |
| 184 | client .send(data ); | |
| 185 | }); | |
| 186 | }; | |
| 187 | ``` | |
| 188 | ||
| 189 | ### Error handling b est practi ces | |
| 190 | ||
| 191 | ```js | |
| 192 | // If the WebSocket is closed before the following send is a ttempted | |
| 193 | ws.send('s omething') ; | |
| 194 | ||
| 195 | // Errors (both imme diate and async writ e errors) can be det ected in a n optional | |
| 196 | // callbac k. The cal lback is a lso the on ly way of being noti fied that data has | |
| 197 | // actuall y been sen t. | |
| 198 | ws.send('s omething', function ack(error) { | |
| 199 | // if er ror is not defined, the send h as been co mpleted, | |
| 200 | // other wise the e rror objec t will ind icate what failed. | |
| 201 | }); | |
| 202 | ||
| 203 | // Immedia te errors can also b e handled with try/c atch-block s, but **n ote** that | |
| 204 | // since s ends are i nherently asynchrono us, socket write fai lures will *not* be | |
| 205 | // capture d when thi s techniqu e is used. | |
| 206 | try { ws.s end('somet hing'); } | |
| 207 | catch (e) { /* handl e error */ } | |
| 208 | ``` | |
| 209 | ||
| 210 | ### echo.w ebsocket.o rg demo | |
| 211 | ||
| 212 | ```js | |
| 213 | var WebSoc ket = requ ire('ws'); | |
| 214 | var ws = n ew WebSock et('ws://e cho.websoc ket.org/', { | |
| 215 | protocol Version: 8 , | |
| 216 | origin: 'http://we bsocket.or g' | |
| 217 | }); | |
| 218 | ||
| 219 | ws.on('ope n', functi on open() { | |
| 220 | console. log('conne cted'); | |
| 221 | ws.send( Date.now() .toString( ), {mask: true}); | |
| 222 | }); | |
| 223 | ||
| 224 | ws.on('clo se', funct ion close( ) { | |
| 225 | console. log('disco nnected'); | |
| 226 | }); | |
| 227 | ||
| 228 | ws.on('mes sage', fun ction mess age(data, flags) { | |
| 229 | console. log('Round trip time: ' + (Date .now() - p arseInt(da ta)) + 'ms ', flags); | |
| 230 | ||
| 231 | setTimeo ut(functio n timeout( ) { | |
| 232 | ws.sen d(Date.now ().toStrin g(), {mask : true}); | |
| 233 | }, 500); | |
| 234 | }); | |
| 235 | ``` | |
| 236 | ||
| 237 | ### Other examples | |
| 238 | ||
| 239 | For a full example w ith a brow ser client communica ting with a ws serve r, see the | |
| 240 | examples f older. | |
| 241 | ||
| 242 | Note that the usage together w ith Expres s 3.0 is q uite diffe rent from Express | |
| 243 | 2.x. The d ifference is express ed in the two differ ent server stats-exam ples. | |
| 244 | ||
| 245 | Otherwise, see the t est cases. | |
| 246 | ||
| 247 | ### Runnin g the test s | |
| 248 | ||
| 249 | ``` | |
| 250 | make test | |
| 251 | ``` | |
| 252 | ||
| 253 | ## API Doc s | |
| 254 | ||
| 255 | See [`/doc /ws.md`](h ttps://git hub.com/we bsockets/w s/blob/mas ter/doc/ws .md) for N ode.js-lik e docs for the ws cl asses. | |
| 256 | ||
| 257 | ## Changel og | |
| 258 | ||
| 259 | We're usin g the GitH ub [`relea ses`](http s://github .com/webso ckets/ws/r eleases) f or changel og entries . | |
| 260 | ||
| 261 | ## License | |
| 262 | ||
| 263 | (The MIT L icense) | |
| 264 | ||
| 265 | Copyright (c) 2011 E inar Otto Stangvik & lt;einaros @gmail.com > | |
| 266 | ||
| 267 | Permission is hereby granted, free of ch arge, to a ny person obtaining | |
| 268 | a copy of this softw are and as sociated d ocumentati on files ( the | |
| 269 | 'Software' ), to deal in the So ftware wit hout restr iction, in cluding | |
| 270 | without li mitation t he rights to use, co py, modify , merge, p ublish, | |
| 271 | distribute , sublicen se, and/or sell copi es of the Software, and to | |
| 272 | permit per sons to wh om the Sof tware is f urnished t o do so, s ubject to | |
| 273 | the follow ing condit ions: | |
| 274 | ||
| 275 | The above copyright notice and this perm ission not ice shall be | |
| 276 | included i n all copi es or subs tantial po rtions of the Softwa re. | |
| 277 | ||
| 278 | THE SOFTWA RE IS PROV IDED 'AS I S', WITHOU T WARRANTY OF ANY KI ND, | |
| 279 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LI MITED TO T HE WARRANT IES OF | |
| 280 | MERCHANTAB ILITY, FIT NESS FOR A PARTICULA R PURPOSE AND NONINF RINGEMENT. | |
| 281 | IN NO EVEN T SHALL TH E AUTHORS OR COPYRIG HT HOLDERS BE LIABLE FOR ANY | |
| 282 | CLAIM, DAM AGES OR OT HER LIABIL ITY, WHETH ER IN AN A CTION OF C ONTRACT, | |
| 283 | TORT OR OT HERWISE, A RISING FRO M, OUT OF OR IN CONN ECTION WIT H THE | |
| 284 | SOFTWARE O R THE USE OR OTHER D EALINGS IN THE SOFTW ARE. | |
| 285 | ||
| 286 | [archive]: http://we b.archive. org/web/20 1303142305 36/http:// hobbycodin g.posterou s.com/the- fastest-we bsocket-mo dule-for-n odejs | |
| 287 | \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000p ackage/ind ex.js\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x00000 00644 \x0000000 765 \x000000002 4 \x00000000002 037 \x000012461 651214\x0000012 200 \x00000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000usta r\x000000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x000000 0000 \x00000000 00 \x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000'use stri ct'; | |
| 288 | ||
| 289 | /*! | |
| 290 | * ws: a n ode.js web socket cli ent | |
| 291 | * Copyrig ht(c) 2011 Einar Ott o Stangvik <einaros@ gmail.com> | |
| 292 | * MIT Lic ensed | |
| 293 | */ | |
| 294 | ||
| 295 | var WS = m odule.expo rts = requ ire('./lib /WebSocket '); | |
| 296 | ||
| 297 | WS.Server = require( './lib/Web SocketServ er'); | |
| 298 | WS.Sender = require( './lib/Sen der'); | |
| 299 | WS.Receive r = requir e('./lib/R eceiver'); | |
| 300 | ||
| 301 | /** | |
| 302 | * Create a new WebS ocket serv er. | |
| 303 | * | |
| 304 | * @param {Object} o ptions Ser ver option s | |
| 305 | * @param {Function} fn Option al connect ion listen er. | |
| 306 | * @return s {WS.Serv er} | |
| 307 | * @api pu blic | |
| 308 | */ | |
| 309 | WS.createS erver = fu nction cre ateServer( options, f n) { | |
| 310 | var serv er = new W S.Server(o ptions); | |
| 311 | ||
| 312 | if (type of fn === 'function' ) { | |
| 313 | server .on('conne ction', fn ); | |
| 314 | } | |
| 315 | ||
| 316 | return s erver; | |
| 317 | }; | |
| 318 | ||
| 319 | /** | |
| 320 | * Create a new WebS ocket conn ection. | |
| 321 | * | |
| 322 | * @param {String} a ddress The URL/addre ss we need to connec t to. | |
| 323 | * @param {Function} fn Open l istener. | |
| 324 | * @return s {WS} | |
| 325 | * @api pu blic | |
| 326 | */ | |
| 327 | WS.connect = WS.crea teConnecti on = funct ion connec t(address, fn) { | |
| 328 | var clie nt = new W S(address) ; | |
| 329 | ||
| 330 | if (type of fn === 'function' ) { | |
| 331 | client .on('open' , fn); | |
| 332 | } | |
| 333 | ||
| 334 | return c lient; | |
| 335 | }; | |
| 336 | \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000package/S ECURITY.md \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000000644 \x00000 00765 \x0000000 024 \x000000000 02775 \x0000126 42470523\x00000 12340 \x00000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000us tar\x000000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 000000 \x000000 0000 \x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000# Secur ity Guidel ines | |
| 337 | ||
| 338 | Please con tact us di rectly at **security @3rd-Eden. com** for any bug th at might | |
| 339 | impact the security of this pr oject. Ple ase prefix the subje ct of your email | |
| 340 | with `[sec urity]` in lowercase and squar e brackets . Our emai l filters will | |
| 341 | automatica lly preven t these me ssages fro m being mo ved to our spam box. | |
| 342 | ||
| 343 | You will r eceive an acknowledg ement of y our report within ** 24 hours** . | |
| 344 | ||
| 345 | All emails that do n ot include security vulnerabil ities will be remove d and | |
| 346 | blocked in stantly. | |
| 347 | ||
| 348 | ## Excepti ons | |
| 349 | ||
| 350 | If you do not receiv e an ackno wledgement within th e said tim e frame pl ease give | |
| 351 | us the ben efit of th e doubt as it's poss ible that we haven't seen it y et. In | |
| 352 | this case please sen d us a mes sage **wit hout detai ls** using one of th e | |
| 353 | following methods: | |
| 354 | ||
| 355 | - Contact the lead d evelopers of this pr oject on t heir perso nal e-mail s. You | |
| 356 | can find the e-mai ls in the git logs, for exampl e using th e followin g command: | |
| 357 | `git --n o-pager sh ow -s --fo rmat='%an <%ae>' <gi tsha>` whe re `<gitsh a>` is the | |
| 358 | SHA1 of their late st commit in the pro ject. | |
| 359 | - Create a GitHub is sue statin g contact details an d the seve rity of th e issue. | |
| 360 | ||
| 361 | Once we ha ve acknowl edged rece ipt of you r report a nd confirm ed the bug | |
| 362 | ourselves we will wo rk with yo u to fix t he vulnera bility and publicly acknowledg e | |
| 363 | your respo nsible dis closure, i f you wish . In addit ion to tha t we will report | |
| 364 | all vulner abilities to the [No de Securit y Project] (https://n odesecurit y.io/). | |
| 365 | ||
| 366 | ## History | |
| 367 | ||
| 368 | 04 Jan 201 6: [Buffer vulnerabl ity](https ://github. com/websoc kets/ws/re leases/tag /1.0.1) | |
| 369 | \x0000\x0000\x0000package /.travis.y ml\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000000644 \x0000000765 \x00000 00024 \x0000000 0000342 \x00001 2636030277 \x0000012645 \x00000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 ustar\x000000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000000000 \x0000 000000 \x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000langu age: node_ js | |
| 370 | sudo: fals e | |
| 371 | node_js: | |
| 372 | - "5" | |
| 373 | - "4" | |
| 374 | - "0.12" | |
| 375 | addons: | |
| 376 | apt: | |
| 377 | source s: | |
| 378 | - ub untu-toolc hain-r-tes t | |
| 379 | packag es: | |
| 380 | - gc c-4.9 | |
| 381 | - g+ +-4.9 | |
| 382 | before_ins tall: | |
| 383 | - export CC="gcc-4 .9" CXX="g ++-4.9" | |
| 384 | \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000pack age/Makefi le\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x00000006 44 \x0000000765 \x0000000024 \x0000 0000001741 \x000012702710 666\x0000012201 \x00000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000ustar\x00000 0\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x000000000 0 \x0000000000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000AL L_TESTS = $(shell fi nd test/ - name '*.te st.js') | |
| 385 | ALL_INTEGR ATION = $( shell find test/ -na me '*.inte gration.js ') | |
| 386 | ||
| 387 | run-tests: | |
| 388 | @. /node_modu les/.bin/m ocha \ | |
| 389 | -t 5 000 \ | |
| 390 | -s 2 400 \ | |
| 391 | $(TE STFLAGS) \ | |
| 392 | $(TE STS) | |
| 393 | ||
| 394 | run-integr ationtests : | |
| 395 | @. /node_modu les/.bin/m ocha \ | |
| 396 | -t 5 000 \ | |
| 397 | -s 6 000 \ | |
| 398 | $(TE STFLAGS) \ | |
| 399 | $(TE STS) | |
| 400 | ||
| 401 | run-covera ge: | |
| 402 | @. /node_modu les/.bin/i stanbul co ver --repo rt html \ | |
| 403 | ./no de_modules /.bin/_moc ha -- \ | |
| 404 | -t 5 000 \ | |
| 405 | -s 6 000 \ | |
| 406 | $(TE STFLAGS) \ | |
| 407 | $(TE STS) | |
| 408 | ||
| 409 | test: | |
| 410 | @$ (MAKE) NOD E_TLS_REJE CT_UNAUTHO RIZED=0 NO DE_PATH=li b TESTS="$ (ALL_TESTS )" run-tes ts | |
| 411 | ||
| 412 | integratio ntest: | |
| 413 | @$ (MAKE) NOD E_TLS_REJE CT_UNAUTHO RIZED=0 NO DE_PATH=li b TESTS="$ (ALL_INTEG RATION)" r un-integra tiontests | |
| 414 | ||
| 415 | coverage: | |
| 416 | @$ (MAKE) NOD E_TLS_REJE CT_UNAUTHO RIZED=0 NO DE_PATH=li b TESTS="$ (ALL_TESTS )" run-cov erage | |
| 417 | ||
| 418 | benchmark: | |
| 419 | @n ode bench/ sender.ben chmark.js | |
| 420 | @n ode bench/ parser.ben chmark.js | |
| 421 | ||
| 422 | autobahn: | |
| 423 | @N ODE_PATH=l ib node te st/autobah n.js | |
| 424 | ||
| 425 | autobahn-s erver: | |
| 426 | @N ODE_PATH=l ib node te st/autobah n-server.j s | |
| 427 | ||
| 428 | .PHONY: te st coverag e | |
| 429 | \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000package/l ib/BufferP ool.js\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000000644 \x00000 00765 \x0000000 024 \x000000000 03357 \x0000125 63105043\x00000 13705 \x00000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000us tar\x000000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 000000 \x000000 0000 \x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000/*! | |
| 430 | * ws: a n ode.js web socket cli ent | |
| 431 | * Copyrig ht(c) 2011 Einar Ott o Stangvik <einaros@ gmail.com> | |
| 432 | * MIT Lic ensed | |
| 433 | */ | |
| 434 | ||
| 435 | var util = require(' util'); | |
| 436 | ||
| 437 | function B ufferPool( initialSiz e, growStr ategy, shr inkStrateg y) { | |
| 438 | if (this instanceo f BufferPo ol === fal se) { | |
| 439 | throw new TypeEr ror("Class es can't b e function -called"); | |
| 440 | } | |
| 441 | ||
| 442 | if (type of initial Size === ' function') { | |
| 443 | shrink Strategy = growStrat egy; | |
| 444 | growSt rategy = i nitialSize ; | |
| 445 | initia lSize = 0; | |
| 446 | } | |
| 447 | else if (typeof in itialSize === 'undef ined') { | |
| 448 | initia lSize = 0; | |
| 449 | } | |
| 450 | this._gr owStrategy = (growSt rategy || function(d b, size) { | |
| 451 | return db.used + size; | |
| 452 | }).bind( null, this ); | |
| 453 | this._sh rinkStrate gy = (shri nkStrategy || functi on(db) { | |
| 454 | return initialSi ze; | |
| 455 | }).bind( null, this ); | |
| 456 | this._bu ffer = ini tialSize ? new Buffe r(initialS ize) : nul l; | |
| 457 | this._of fset = 0; | |
| 458 | this._us ed = 0; | |
| 459 | this._ch angeFactor = 0; | |
| 460 | this.__d efineGette r__('size' , function (){ | |
| 461 | return this._buf fer == nul l ? 0 : th is._buffer .length; | |
| 462 | }); | |
| 463 | this.__d efineGette r__('used' , function (){ | |
| 464 | return this._use d; | |
| 465 | }); | |
| 466 | } | |
| 467 | ||
| 468 | BufferPool .prototype .get = fun ction(leng th) { | |
| 469 | if (this ._buffer = = null || this._offs et + lengt h > this._ buffer.len gth) { | |
| 470 | var ne wBuf = new Buffer(th is._growSt rategy(len gth)); | |
| 471 | this._ buffer = n ewBuf; | |
| 472 | this._ offset = 0 ; | |
| 473 | } | |
| 474 | this._us ed += leng th; | |
| 475 | var buf = this._bu ffer.slice (this._off set, this. _offset + length); | |
| 476 | this._of fset += le ngth; | |
| 477 | return b uf; | |
| 478 | } | |
| 479 | ||
| 480 | BufferPool .prototype .reset = f unction(fo rceNewBuff er) { | |
| 481 | var len = this._sh rinkStrate gy(); | |
| 482 | if (len < this.siz e) this._c hangeFacto r -= 1; | |
| 483 | if (forc eNewBuffer || this._ changeFact or < -2) { | |
| 484 | this._ changeFact or = 0; | |
| 485 | this._ buffer = l en ? new B uffer(len) : null; | |
| 486 | } | |
| 487 | this._of fset = 0; | |
| 488 | this._us ed = 0; | |
| 489 | } | |
| 490 | ||
| 491 | module.exp orts = Buf ferPool; | |
| 492 | \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000package /lib/Error Codes.js\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000000644 \x0000000765 \x00000 00024 \x0000000 0001311 \x00001 2461651214 \x0000013700 \x00000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 ustar\x000000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000000000 \x0000 000000 \x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000/*! | |
| 493 | * ws: a n ode.js web socket cli ent | |
| 494 | * Copyrig ht(c) 2011 Einar Ott o Stangvik <einaros@ gmail.com> | |
| 495 | * MIT Lic ensed | |
| 496 | */ | |
| 497 | ||
| 498 | module.exp orts = { | |
| 499 | isValidE rrorCode: function(c ode) { | |
| 500 | return (code >= 1000 && co de <= 1011 && code ! = 1004 && code != 10 05 && code != 1006) || | |
| 501 | ( code >= 30 00 && code <= 4999); | |
| 502 | }, | |
| 503 | 1000: 'n ormal', | |
| 504 | 1001: 'g oing away' , | |
| 505 | 1002: 'p rotocol er ror', | |
| 506 | 1003: 'u nsupported data', | |
| 507 | 1004: 'r eserved', | |
| 508 | 1005: 'r eserved fo r extensio ns', | |
| 509 | 1006: 'r eserved fo r extensio ns', | |
| 510 | 1007: 'i nconsisten t or inval id data', | |
| 511 | 1008: 'p olicy viol ation', | |
| 512 | 1009: 'm essage too big', | |
| 513 | 1010: 'e xtension h andshake m issing', | |
| 514 | 1011: 'a n unexpect ed conditi on prevent ed the req uest from being fulf illed', | |
| 515 | };\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000package /lib/Exten sions.js\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000000644 \x0000000765 \x00000 00024 \x0000000 0003040 \x00001 2461651214 \x0000013771 \x00000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 ustar\x000000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000000000 \x0000 000000 \x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000 | |
| 516 | var util = require(' util'); | |
| 517 | ||
| 518 | /** | |
| 519 | * Module exports. | |
| 520 | */ | |
| 521 | ||
| 522 | exports.pa rse = pars e; | |
| 523 | exports.fo rmat = for mat; | |
| 524 | ||
| 525 | /** | |
| 526 | * Parse e xtensions header val ue | |
| 527 | */ | |
| 528 | ||
| 529 | function p arse(value ) { | |
| 530 | value = value || ' '; | |
| 531 | ||
| 532 | var exte nsions = { }; | |
| 533 | ||
| 534 | value.sp lit(',').f orEach(fun ction(v) { | |
| 535 | var pa rams = v.s plit(';'); | |
| 536 | var to ken = para ms.shift() .trim(); | |
| 537 | var pa ramsList = extension s[token] = extension s[token] | | []; | |
| 538 | var pa rsedParams = {}; | |
| 539 | ||
| 540 | params .forEach(f unction(pa ram) { | |
| 541 | var parts = pa ram.trim() .split('=' ); | |
| 542 | var key = part s[0]; | |
| 543 | var value = pa rts[1]; | |
| 544 | if ( typeof val ue === 'un defined') { | |
| 545 | va lue = true ; | |
| 546 | } el se { | |
| 547 | // unquote v alue | |
| 548 | if (value[0] === '"') { | |
| 549 | value = va lue.slice( 1); | |
| 550 | } | |
| 551 | if (value[va lue.length - 1] === '"') { | |
| 552 | value = va lue.slice( 0, value.l ength - 1) ; | |
| 553 | } | |
| 554 | } | |
| 555 | (par sedParams[ key] = par sedParams[ key] || [] ).push(val ue); | |
| 556 | }); | |
| 557 | ||
| 558 | params List.push( parsedPara ms); | |
| 559 | }); | |
| 560 | ||
| 561 | return e xtensions; | |
| 562 | } | |
| 563 | ||
| 564 | /** | |
| 565 | * Format extensions header va lue | |
| 566 | */ | |
| 567 | ||
| 568 | function f ormat(valu e) { | |
| 569 | return O bject.keys (value).ma p(function (token) { | |
| 570 | var pa ramsList = value[tok en]; | |
| 571 | if (!u til.isArra y(paramsLi st)) { | |
| 572 | para msList = [ paramsList ]; | |
| 573 | } | |
| 574 | return paramsLis t.map(func tion(param s) { | |
| 575 | retu rn [token] .concat(Ob ject.keys( params).ma p(function (k) { | |
| 576 | va r p = para ms[k]; | |
| 577 | if (!util.is Array(p)) p = [p]; | |
| 578 | re turn p.map (function( v) { | |
| 579 | return v = == true ? k : k + '= ' + v; | |
| 580 | }) .join('; ' ); | |
| 581 | })). join('; ') ; | |
| 582 | }).joi n(', '); | |
| 583 | }).join( ', '); | |
| 584 | } | |
| 585 | \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 package/li b/PerMessa geDeflate. js\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 000644 \x000000 0765 \x00000000 24 \x0000000002 2330 \x00001270 2710666\x000001 5162 \x00000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000ust ar\x000000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x00000 00000 \x0000000 000 \x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000 | |
| 586 | var zlib = require(' zlib'); | |
| 587 | ||
| 588 | var AVAILA BLE_WINDOW _BITS = [8 , 9, 10, 1 1, 12, 13, 14, 15]; | |
| 589 | var DEFAUL T_WINDOW_B ITS = 15; | |
| 590 | var DEFAUL T_MEM_LEVE L = 8; | |
| 591 | ||
| 592 | PerMessage Deflate.ex tensionNam e = 'perme ssage-defl ate'; | |
| 593 | ||
| 594 | /** | |
| 595 | * Per-mes sage Compr ession Ext ensions im plementati on | |
| 596 | */ | |
| 597 | ||
| 598 | function P erMessageD eflate(opt ions, isSe rver,maxPa yload) { | |
| 599 | if (this instanceo f PerMessa geDeflate === false) { | |
| 600 | throw new TypeEr ror("Class es can't b e function -called"); | |
| 601 | } | |
| 602 | ||
| 603 | this._op tions = op tions || { }; | |
| 604 | this._is Server = ! !isServer; | |
| 605 | this._in flate = nu ll; | |
| 606 | this._de flate = nu ll; | |
| 607 | this.par ams = null ; | |
| 608 | this._ma xPayload = maxPayloa d || 0; | |
| 609 | } | |
| 610 | ||
| 611 | /** | |
| 612 | * Create extension parameters offer | |
| 613 | * | |
| 614 | * @api pu blic | |
| 615 | */ | |
| 616 | ||
| 617 | PerMessage Deflate.pr ototype.of fer = func tion() { | |
| 618 | var para ms = {}; | |
| 619 | if (this ._options. serverNoCo ntextTakeo ver) { | |
| 620 | params .server_no _context_t akeover = true; | |
| 621 | } | |
| 622 | if (this ._options. clientNoCo ntextTakeo ver) { | |
| 623 | params .client_no _context_t akeover = true; | |
| 624 | } | |
| 625 | if (this ._options. serverMaxW indowBits) { | |
| 626 | params .server_ma x_window_b its = this ._options. serverMaxW indowBits; | |
| 627 | } | |
| 628 | if (this ._options. clientMaxW indowBits) { | |
| 629 | params .client_ma x_window_b its = this ._options. clientMaxW indowBits; | |
| 630 | } else i f (this._o ptions.cli entMaxWind owBits == null) { | |
| 631 | params .client_ma x_window_b its = true ; | |
| 632 | } | |
| 633 | return p arams; | |
| 634 | }; | |
| 635 | ||
| 636 | /** | |
| 637 | * Accept extension offer | |
| 638 | * | |
| 639 | * @api pu blic | |
| 640 | */ | |
| 641 | ||
| 642 | PerMessage Deflate.pr ototype.ac cept = fun ction(para msList) { | |
| 643 | paramsLi st = this. normalizeP arams(para msList); | |
| 644 | ||
| 645 | var para ms; | |
| 646 | if (this ._isServer ) { | |
| 647 | params = this.ac ceptAsServ er(paramsL ist); | |
| 648 | } else { | |
| 649 | params = this.ac ceptAsClie nt(paramsL ist); | |
| 650 | } | |
| 651 | ||
| 652 | this.par ams = para ms; | |
| 653 | return p arams; | |
| 654 | }; | |
| 655 | ||
| 656 | /** | |
| 657 | * Release s all reso urces used by the ex tension | |
| 658 | * | |
| 659 | * @api pu blic | |
| 660 | */ | |
| 661 | ||
| 662 | PerMessage Deflate.pr ototype.cl eanup = fu nction() { | |
| 663 | if (this ._inflate) { | |
| 664 | if (th is._inflat e.writeInP rogress) { | |
| 665 | this ._inflate. pendingClo se = true; | |
| 666 | } else { | |
| 667 | if ( this._infl ate.close) this._inf late.close (); | |
| 668 | this ._inflate = null; | |
| 669 | } | |
| 670 | } | |
| 671 | if (this ._deflate) { | |
| 672 | if (th is._deflat e.writeInP rogress) { | |
| 673 | this ._deflate. pendingClo se = true; | |
| 674 | } else { | |
| 675 | if ( this._defl ate.close) this._def late.close (); | |
| 676 | this ._deflate = null; | |
| 677 | } | |
| 678 | } | |
| 679 | }; | |
| 680 | ||
| 681 | /** | |
| 682 | * Accept extension offer from client | |
| 683 | * | |
| 684 | * @api pr ivate | |
| 685 | */ | |
| 686 | ||
| 687 | PerMessage Deflate.pr ototype.ac ceptAsServ er = funct ion(params List) { | |
| 688 | var acce pted = {}; | |
| 689 | var resu lt = param sList.some (function( params) { | |
| 690 | accept ed = {}; | |
| 691 | if (th is._option s.serverNo ContextTak eover === false && p arams.serv er_no_cont ext_takeov er) { | |
| 692 | retu rn; | |
| 693 | } | |
| 694 | if (th is._option s.serverMa xWindowBit s === fals e && param s.server_m ax_window_ bits) { | |
| 695 | retu rn; | |
| 696 | } | |
| 697 | if (ty peof this. _options.s erverMaxWi ndowBits = == 'number ' && | |
| 698 | ty peof param s.server_m ax_window_ bits === ' number' && | |
| 699 | th is._option s.serverMa xWindowBit s > params .server_ma x_window_b its) { | |
| 700 | retu rn; | |
| 701 | } | |
| 702 | if (ty peof this. _options.c lientMaxWi ndowBits = == 'number ' && !para ms.client_ max_window _bits) { | |
| 703 | retu rn; | |
| 704 | } | |
| 705 | ||
| 706 | if (th is._option s.serverNo ContextTak eover || p arams.serv er_no_cont ext_takeov er) { | |
| 707 | acce pted.serve r_no_conte xt_takeove r = true; | |
| 708 | } | |
| 709 | if (th is._option s.clientNo ContextTak eover) { | |
| 710 | acce pted.clien t_no_conte xt_takeove r = true; | |
| 711 | } | |
| 712 | if (th is._option s.clientNo ContextTak eover !== false && p arams.clie nt_no_cont ext_takeov er) { | |
| 713 | acce pted.clien t_no_conte xt_takeove r = true; | |
| 714 | } | |
| 715 | if (ty peof this. _options.s erverMaxWi ndowBits = == 'number ') { | |
| 716 | acce pted.serve r_max_wind ow_bits = this._opti ons.server MaxWindowB its; | |
| 717 | } else if (typeo f params.s erver_max_ window_bit s === 'num ber') { | |
| 718 | acce pted.serve r_max_wind ow_bits = params.ser ver_max_wi ndow_bits; | |
| 719 | } | |
| 720 | if (ty peof this. _options.c lientMaxWi ndowBits = == 'number ') { | |
| 721 | acce pted.clien t_max_wind ow_bits = this._opti ons.client MaxWindowB its; | |
| 722 | } else if (this. _options.c lientMaxWi ndowBits ! == false & & typeof p arams.clie nt_max_win dow_bits = == 'number ') { | |
| 723 | acce pted.clien t_max_wind ow_bits = params.cli ent_max_wi ndow_bits; | |
| 724 | } | |
| 725 | return true; | |
| 726 | }, this) ; | |
| 727 | ||
| 728 | if (!res ult) { | |
| 729 | throw new Error( 'Doesn\'t support th e offered configurat ion'); | |
| 730 | } | |
| 731 | ||
| 732 | return a ccepted; | |
| 733 | }; | |
| 734 | ||
| 735 | /** | |
| 736 | * Accept extension response f rom server | |
| 737 | * | |
| 738 | * @api pr ivaye | |
| 739 | */ | |
| 740 | ||
| 741 | PerMessage Deflate.pr ototype.ac ceptAsClie nt = funct ion(params List) { | |
| 742 | var para ms = param sList[0]; | |
| 743 | if (this ._options. clientNoCo ntextTakeo ver != nul l) { | |
| 744 | if (th is._option s.clientNo ContextTak eover === false && p arams.clie nt_no_cont ext_takeov er) { | |
| 745 | thro w new Erro r('Invalid value for "client_n o_context_ takeover"' ); | |
| 746 | } | |
| 747 | } | |
| 748 | if (this ._options. clientMaxW indowBits != null) { | |
| 749 | if (th is._option s.clientMa xWindowBit s === fals e && param s.client_m ax_window_ bits) { | |
| 750 | thro w new Erro r('Invalid value for "client_m ax_window_ bits"'); | |
| 751 | } | |
| 752 | if (ty peof this. _options.c lientMaxWi ndowBits = == 'number ' && | |
| 753 | (! params.cli ent_max_wi ndow_bits || params. client_max _window_bi ts > this. _options.c lientMaxWi ndowBits)) { | |
| 754 | thro w new Erro r('Invalid value for "client_m ax_window_ bits"'); | |
| 755 | } | |
| 756 | } | |
| 757 | return p arams; | |
| 758 | }; | |
| 759 | ||
| 760 | /** | |
| 761 | * Normali ze extensi ons parame ters | |
| 762 | * | |
| 763 | * @api pr ivate | |
| 764 | */ | |
| 765 | ||
| 766 | PerMessage Deflate.pr ototype.no rmalizePar ams = func tion(param sList) { | |
| 767 | return p aramsList. map(functi on(params) { | |
| 768 | Object .keys(para ms).forEac h(function (key) { | |
| 769 | var value = pa rams[key]; | |
| 770 | if ( value.leng th > 1) { | |
| 771 | th row new Er ror('Multi ple extens ion parame ters for ' + key); | |
| 772 | } | |
| 773 | ||
| 774 | valu e = value[ 0]; | |
| 775 | ||
| 776 | swit ch (key) { | |
| 777 | case 'server_n o_context_ takeover': | |
| 778 | case 'client_n o_context_ takeover': | |
| 779 | if (value != = true) { | |
| 780 | throw new Error('inv alid exten sion param eter value for ' + k ey + ' (' + value + ')'); | |
| 781 | } | |
| 782 | pa rams[key] = true; | |
| 783 | br eak; | |
| 784 | case 'server_m ax_window_ bits': | |
| 785 | case 'client_m ax_window_ bits': | |
| 786 | if (typeof v alue === ' string') { | |
| 787 | value = pa rseInt(val ue, 10); | |
| 788 | if (!~AVAI LABLE_WIND OW_BITS.in dexOf(valu e)) { | |
| 789 | throw ne w Error('i nvalid ext ension par ameter val ue for ' + key + ' ( ' + value + ')'); | |
| 790 | } | |
| 791 | } | |
| 792 | if (!this._i sServer && value === true) { | |
| 793 | throw new Error('Mis sing exten sion param eter value for ' + k ey); | |
| 794 | } | |
| 795 | pa rams[key] = value; | |
| 796 | br eak; | |
| 797 | defa ult: | |
| 798 | th row new Er ror('Not d efined ext ension par ameter (' + key + ') '); | |
| 799 | } | |
| 800 | }, thi s); | |
| 801 | return params; | |
| 802 | }, this) ; | |
| 803 | }; | |
| 804 | ||
| 805 | /** | |
| 806 | * Decompr ess messag e | |
| 807 | * | |
| 808 | * @api pu blic | |
| 809 | */ | |
| 810 | ||
| 811 | PerMessage Deflate.pr ototype.de compress = function (data, fin , callback ) { | |
| 812 | var endp oint = thi s._isServe r ? 'clien t' : 'serv er'; | |
| 813 | ||
| 814 | if (!thi s._inflate ) { | |
| 815 | var ma xWindowBit s = this.p arams[endp oint + '_m ax_window_ bits']; | |
| 816 | this._ inflate = zlib.creat eInflateRa w({ | |
| 817 | wind owBits: 'n umber' === typeof ma xWindowBit s ? maxWin dowBits : DEFAULT_WI NDOW_BITS | |
| 818 | }); | |
| 819 | } | |
| 820 | this._in flate.writ eInProgres s = true; | |
| 821 | ||
| 822 | var self = this; | |
| 823 | var buff ers = []; | |
| 824 | var cumu lativeBuff erLength=0 ; | |
| 825 | ||
| 826 | this._in flate.on(' error', on Error).on( 'data', on Data); | |
| 827 | this._in flate.writ e(data); | |
| 828 | if (fin) { | |
| 829 | this._ inflate.wr ite(new Bu ffer([0x00 , 0x00, 0x ff, 0xff]) ); | |
| 830 | } | |
| 831 | this._in flate.flus h(function () { | |
| 832 | cleanu p(); | |
| 833 | callba ck(null, B uffer.conc at(buffers )); | |
| 834 | }); | |
| 835 | ||
| 836 | function onError(e rr) { | |
| 837 | cleanu p(); | |
| 838 | callba ck(err); | |
| 839 | } | |
| 840 | ||
| 841 | function onData(da ta) { | |
| 842 | if(s elf._maxPa yload!==un defined && self._max Payload!== null && se lf._maxPay load>0){ | |
| 843 | cumulative BufferLeng th+=data.l ength; | |
| 844 | if(cumulat iveBufferL ength>self ._maxPaylo ad){ | |
| 845 | buffers= []; | |
| 846 | cleanup( ); | |
| 847 | var err= {type:1009 }; | |
| 848 | callback (err); | |
| 849 | return; | |
| 850 | } | |
| 851 | } | |
| 852 | buff ers.push(d ata); | |
| 853 | } | |
| 854 | ||
| 855 | function cleanup() { | |
| 856 | if (!s elf._infla te) return ; | |
| 857 | self._ inflate.re moveListen er('error' , onError) ; | |
| 858 | self._ inflate.re moveListen er('data', onData); | |
| 859 | self._ inflate.wr iteInProgr ess = fals e; | |
| 860 | if ((f in && self .params[en dpoint + ' _no_contex t_takeover ']) || sel f._inflate .pendingCl ose) { | |
| 861 | if ( self._infl ate.close) self._inf late.close (); | |
| 862 | self ._inflate = null; | |
| 863 | } | |
| 864 | } | |
| 865 | }; | |
| 866 | ||
| 867 | /** | |
| 868 | * Compres s message | |
| 869 | * | |
| 870 | * @api pu blic | |
| 871 | */ | |
| 872 | ||
| 873 | PerMessage Deflate.pr ototype.co mpress = f unction (d ata, fin, callback) { | |
| 874 | var endp oint = thi s._isServe r ? 'serve r' : 'clie nt'; | |
| 875 | ||
| 876 | if (!thi s._deflate ) { | |
| 877 | var ma xWindowBit s = this.p arams[endp oint + '_m ax_window_ bits']; | |
| 878 | this._ deflate = zlib.creat eDeflateRa w({ | |
| 879 | flus h: zlib.Z_ SYNC_FLUSH , | |
| 880 | wind owBits: 'n umber' === typeof ma xWindowBit s ? maxWin dowBits : DEFAULT_WI NDOW_BITS, | |
| 881 | memL evel: this ._options. memLevel | | DEFAULT_ MEM_LEVEL | |
| 882 | }); | |
| 883 | } | |
| 884 | this._de flate.writ eInProgres s = true; | |
| 885 | ||
| 886 | var self = this; | |
| 887 | var buff ers = []; | |
| 888 | ||
| 889 | this._de flate.on(' error', on Error).on( 'data', on Data); | |
| 890 | this._de flate.writ e(data); | |
| 891 | this._de flate.flus h(function () { | |
| 892 | cleanu p(); | |
| 893 | var da ta = Buffe r.concat(b uffers); | |
| 894 | if (fi n) { | |
| 895 | data = data.sl ice(0, dat a.length - 4); | |
| 896 | } | |
| 897 | callba ck(null, d ata); | |
| 898 | }); | |
| 899 | ||
| 900 | function onError(e rr) { | |
| 901 | cleanu p(); | |
| 902 | callba ck(err); | |
| 903 | } | |
| 904 | ||
| 905 | function onData(da ta) { | |
| 906 | buffer s.push(dat a); | |
| 907 | } | |
| 908 | ||
| 909 | function cleanup() { | |
| 910 | if (!s elf._defla te) return ; | |
| 911 | self._ deflate.re moveListen er('error' , onError) ; | |
| 912 | self._ deflate.re moveListen er('data', onData); | |
| 913 | self._ deflate.wr iteInProgr ess = fals e; | |
| 914 | if ((f in && self .params[en dpoint + ' _no_contex t_takeover ']) || sel f._deflate .pendingCl ose) { | |
| 915 | if ( self._defl ate.close) self._def late.close (); | |
| 916 | self ._deflate = null; | |
| 917 | } | |
| 918 | } | |
| 919 | }; | |
| 920 | ||
| 921 | module.exp orts = Per MessageDef late; | |
| 922 | \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000pack age/lib/Re ceiver.hix ie.js\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x00000006 44 \x0000000765 \x0000000024 \x0000 0000010204 \x000012702710 666\x0000014510 \x00000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000ustar\x00000 0\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x000000000 0 \x0000000000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000/* ! | |
| 923 | * ws: a n ode.js web socket cli ent | |
| 924 | * Copyrig ht(c) 2011 Einar Ott o Stangvik <einaros@ gmail.com> | |
| 925 | * MIT Lic ensed | |
| 926 | */ | |
| 927 | ||
| 928 | var util = require(' util'); | |
| 929 | ||
| 930 | /** | |
| 931 | * State c onstants | |
| 932 | */ | |
| 933 | ||
| 934 | var EMPTY = 0 | |
| 935 | , BODY = 1; | |
| 936 | var BINARY LENGTH = 2 | |
| 937 | , BINARY BODY = 3; | |
| 938 | ||
| 939 | /** | |
| 940 | * Hixie R eceiver im plementati on | |
| 941 | */ | |
| 942 | ||
| 943 | function R eceiver () { | |
| 944 | if (this instanceo f Receiver === false ) { | |
| 945 | throw new TypeEr ror("Class es can't b e function -called"); | |
| 946 | } | |
| 947 | ||
| 948 | this.sta te = EMPTY ; | |
| 949 | this.buf fers = []; | |
| 950 | this.mes sageEnd = -1; | |
| 951 | this.spa nLength = 0; | |
| 952 | this.dea d = false; | |
| 953 | ||
| 954 | this.one rror = fun ction() {} ; | |
| 955 | this.ont ext = func tion() {}; | |
| 956 | this.onb inary = fu nction() { }; | |
| 957 | this.onc lose = fun ction() {} ; | |
| 958 | this.onp ing = func tion() {}; | |
| 959 | this.onp ong = func tion() {}; | |
| 960 | } | |
| 961 | ||
| 962 | module.exp orts = Rec eiver; | |
| 963 | ||
| 964 | /** | |
| 965 | * Add new data to t he parser. | |
| 966 | * | |
| 967 | * @api pu blic | |
| 968 | */ | |
| 969 | ||
| 970 | Receiver.p rototype.a dd = funct ion(data) { | |
| 971 | if (this .dead) ret urn; | |
| 972 | var self = this; | |
| 973 | function doAdd() { | |
| 974 | if (se lf.state = == EMPTY) { | |
| 975 | if ( data.lengt h == 2 && data[0] == 0xFF && d ata[1] == 0x00) { | |
| 976 | se lf.reset() ; | |
| 977 | se lf.onclose (); | |
| 978 | re turn; | |
| 979 | } | |
| 980 | if ( data[0] == = 0x80) { | |
| 981 | se lf.message End = 0; | |
| 982 | se lf.state = BINARYLEN GTH; | |
| 983 | da ta = data. slice(1); | |
| 984 | } el se { | |
| 985 | ||
| 986 | if ( data[0] != = 0x00) { | |
| 987 | se lf.error(' payload mu st start w ith 0x00 b yte', true ); | |
| 988 | re turn; | |
| 989 | } | |
| 990 | data = data.sl ice(1); | |
| 991 | self .state = B ODY; | |
| 992 | ||
| 993 | } | |
| 994 | } | |
| 995 | if (se lf.state = == BINARYL ENGTH) { | |
| 996 | var i = 0; | |
| 997 | whil e ((i < da ta.length) && (data[ i] & 0x80) ) { | |
| 998 | se lf.message End = 128 * self.mes sageEnd + (data[i] & 0x7f); | |
| 999 | ++ i; | |
| 1000 | } | |
| 1001 | if ( i < data.l ength) { | |
| 1002 | se lf.message End = 128 * self.mes sageEnd + (data[i] & 0x7f); | |
| 1003 | se lf.state = BINARYBOD Y; | |
| 1004 | ++ i; | |
| 1005 | } | |
| 1006 | if ( i > 0) | |
| 1007 | da ta = data. slice(i); | |
| 1008 | } | |
| 1009 | if (se lf.state = == BINARYB ODY) { | |
| 1010 | var dataleft = self.mess ageEnd - s elf.spanLe ngth; | |
| 1011 | if ( data.lengt h >= datal eft) { | |
| 1012 | // consume t he whole b uffer to f inish the frame | |
| 1013 | se lf.buffers .push(data ); | |
| 1014 | se lf.spanLen gth += dat aleft; | |
| 1015 | se lf.message End = data left; | |
| 1016 | re turn self. parse(); | |
| 1017 | } | |
| 1018 | // f rame's not done even if we con sume it al l | |
| 1019 | self .buffers.p ush(data); | |
| 1020 | self .spanLengt h += data. length; | |
| 1021 | retu rn; | |
| 1022 | } | |
| 1023 | self.b uffers.pus h(data); | |
| 1024 | if ((s elf.messag eEnd = buf ferIndex(d ata, 0xFF) ) != -1) { | |
| 1025 | self .spanLengt h += self. messageEnd ; | |
| 1026 | retu rn self.pa rse(); | |
| 1027 | } | |
| 1028 | else s elf.spanLe ngth += da ta.length; | |
| 1029 | } | |
| 1030 | while(da ta) data = doAdd(); | |
| 1031 | }; | |
| 1032 | ||
| 1033 | /** | |
| 1034 | * Release s all reso urces used by the re ceiver. | |
| 1035 | * | |
| 1036 | * @api pu blic | |
| 1037 | */ | |
| 1038 | ||
| 1039 | Receiver.p rototype.c leanup = f unction() { | |
| 1040 | this.dea d = true; | |
| 1041 | this.sta te = EMPTY ; | |
| 1042 | this.buf fers = []; | |
| 1043 | }; | |
| 1044 | ||
| 1045 | /** | |
| 1046 | * Process buffered data. | |
| 1047 | * | |
| 1048 | * @api pu blic | |
| 1049 | */ | |
| 1050 | ||
| 1051 | Receiver.p rototype.p arse = fun ction() { | |
| 1052 | var outp ut = new B uffer(this .spanLengt h); | |
| 1053 | var outp utIndex = 0; | |
| 1054 | for (var bi = 0, b l = this.b uffers.len gth; bi < bl - 1; ++ bi) { | |
| 1055 | var bu ffer = thi s.buffers[ bi]; | |
| 1056 | buffer .copy(outp ut, output Index); | |
| 1057 | output Index += b uffer.leng th; | |
| 1058 | } | |
| 1059 | var last Buffer = t his.buffer s[this.buf fers.lengt h - 1]; | |
| 1060 | if (this .messageEn d > 0) las tBuffer.co py(output, outputInd ex, 0, thi s.messageE nd); | |
| 1061 | if (this .state !== BODY) --t his.messag eEnd; | |
| 1062 | var tail = null; | |
| 1063 | if (this .messageEn d < lastBu ffer.lengt h - 1) { | |
| 1064 | tail = lastBuffe r.slice(th is.message End + 1); | |
| 1065 | } | |
| 1066 | this.res et(); | |
| 1067 | this.ont ext(output .toString( 'utf8')); | |
| 1068 | return t ail; | |
| 1069 | }; | |
| 1070 | ||
| 1071 | /** | |
| 1072 | * Handles an error | |
| 1073 | * | |
| 1074 | * @api pr ivate | |
| 1075 | */ | |
| 1076 | ||
| 1077 | Receiver.p rototype.e rror = fun ction (rea son, termi nate) { | |
| 1078 | if (this .dead) ret urn; | |
| 1079 | this.res et(); | |
| 1080 | if(typeo f reason = = 'string' ){ | |
| 1081 | this.o nerror(new Error(rea son), term inate); | |
| 1082 | } | |
| 1083 | else if( reason.con structor = = Error){ | |
| 1084 | this.o nerror(rea son, termi nate); | |
| 1085 | } | |
| 1086 | else{ | |
| 1087 | this.o nerror(new Error("An error occ ured"),ter minate); | |
| 1088 | } | |
| 1089 | return t his; | |
| 1090 | }; | |
| 1091 | ||
| 1092 | /** | |
| 1093 | * Reset p arser stat e | |
| 1094 | * | |
| 1095 | * @api pr ivate | |
| 1096 | */ | |
| 1097 | ||
| 1098 | Receiver.p rototype.r eset = fun ction (rea son) { | |
| 1099 | if (this .dead) ret urn; | |
| 1100 | this.sta te = EMPTY ; | |
| 1101 | this.buf fers = []; | |
| 1102 | this.mes sageEnd = -1; | |
| 1103 | this.spa nLength = 0; | |
| 1104 | }; | |
| 1105 | ||
| 1106 | /** | |
| 1107 | * Interna l api | |
| 1108 | */ | |
| 1109 | ||
| 1110 | function b ufferIndex (buffer, b yte) { | |
| 1111 | for (var i = 0, l = buffer.l ength; i < l; ++i) { | |
| 1112 | if (bu ffer[i] == = byte) re turn i; | |
| 1113 | } | |
| 1114 | return - 1; | |
| 1115 | } | |
| 1116 | \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 package/li b/BufferUt il.js\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 000644 \x000000 0765 \x00000000 24 \x0000000000 0374 \x00001246 2406655\x000001 3720 \x00000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000ust ar\x000000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x00000 00000 \x0000000 000 \x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000'use str ict'; | |
| 1117 | ||
| 1118 | /*! | |
| 1119 | * ws: a n ode.js web socket cli ent | |
| 1120 | * Copyrig ht(c) 2011 Einar Ott o Stangvik <einaros@ gmail.com> | |
| 1121 | * MIT Lic ensed | |
| 1122 | */ | |
| 1123 | ||
| 1124 | try { | |
| 1125 | module.e xports = r equire('bu fferutil') ; | |
| 1126 | } catch (e ) { | |
| 1127 | module.e xports = r equire('./ BufferUtil .fallback' ); | |
| 1128 | } | |
| 1129 | \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 package/li b/Sender.h ixie.js\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 000644 \x000000 0765 \x00000000 24 \x0000000000 5634 \x00001256 3105043\x000001 4167 \x00000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000ust ar\x000000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x00000 00000 \x0000000 000 \x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000/*! | |
| 1130 | * ws: a n ode.js web socket cli ent | |
| 1131 | * Copyrig ht(c) 2011 Einar Ott o Stangvik <einaros@ gmail.com> | |
| 1132 | * MIT Lic ensed | |
| 1133 | */ | |
| 1134 | ||
| 1135 | var events = require ('events') | |
| 1136 | , util = require(' util') | |
| 1137 | , EventE mitter = e vents.Even tEmitter; | |
| 1138 | ||
| 1139 | /** | |
| 1140 | * Hixie S ender impl ementation | |
| 1141 | */ | |
| 1142 | ||
| 1143 | function S ender(sock et) { | |
| 1144 | if (this instanceo f Sender = == false) { | |
| 1145 | throw new TypeEr ror("Class es can't b e function -called"); | |
| 1146 | } | |
| 1147 | ||
| 1148 | events.E ventEmitte r.call(thi s); | |
| 1149 | ||
| 1150 | this.soc ket = sock et; | |
| 1151 | this.con tinuationF rame = fal se; | |
| 1152 | this.isC losed = fa lse; | |
| 1153 | } | |
| 1154 | ||
| 1155 | module.exp orts = Sen der; | |
| 1156 | ||
| 1157 | /** | |
| 1158 | * Inherit s from Eve ntEmitter. | |
| 1159 | */ | |
| 1160 | ||
| 1161 | util.inher its(Sender , events.E ventEmitte r); | |
| 1162 | ||
| 1163 | /** | |
| 1164 | * Frames and writes data. | |
| 1165 | * | |
| 1166 | * @api pu blic | |
| 1167 | */ | |
| 1168 | ||
| 1169 | Sender.pro totype.sen d = functi on(data, o ptions, cb ) { | |
| 1170 | if (this .isClosed) return; | |
| 1171 | ||
| 1172 | var isSt ring = typ eof data = = 'string' | |
| 1173 | , leng th = isStr ing ? Buff er.byteLen gth(data) : data.len gth | |
| 1174 | , leng thbytes = (length > 127) ? 2 : 1 // assu me less th an 2**14 b ytes | |
| 1175 | , writ eStartMark er = this. continuati onFrame == false | |
| 1176 | , writ eEndMarker = !option s || !(typ eof option s.fin != ' undefined' && !optio ns.fin) | |
| 1177 | , buff er = new B uffer((wri teStartMar ker ? ((op tions && o ptions.bin ary) ? (1 + lengthby tes) : 1) : 0) + len gth + ((wr iteEndMark er && !(op tions && o ptions.bin ary)) ? 1 : 0)) | |
| 1178 | , offs et = write StartMarke r ? 1 : 0; | |
| 1179 | ||
| 1180 | if (writ eStartMark er) { | |
| 1181 | if (op tions && o ptions.bin ary) { | |
| 1182 | buff er.write(' \x80', 'bi nary'); | |
| 1183 | // a ssume leng th less th an 2**14 b ytes | |
| 1184 | if ( lengthbyte s > 1) | |
| 1185 | bu ffer.write (String.fr omCharCode (128+lengt h/128), of fset++, 'b inary'); | |
| 1186 | buff er.write(S tring.from CharCode(l ength&0x7f ), offset+ +, 'binary '); | |
| 1187 | } else | |
| 1188 | buff er.write(' \x00', 'bi nary'); | |
| 1189 | } | |
| 1190 | ||
| 1191 | if (isSt ring) buff er.write(d ata, offse t, 'utf8') ; | |
| 1192 | else dat a.copy(buf fer, offse t, 0); | |
| 1193 | ||
| 1194 | if (writ eEndMarker ) { | |
| 1195 | if (op tions && o ptions.bin ary) { | |
| 1196 | // s ending bin ary, not w riting end marker | |
| 1197 | } else | |
| 1198 | buff er.write(' \xff', off set + leng th, 'binar y'); | |
| 1199 | this.c ontinuatio nFrame = f alse; | |
| 1200 | } | |
| 1201 | else thi s.continua tionFrame = true; | |
| 1202 | ||
| 1203 | try { | |
| 1204 | this.s ocket.writ e(buffer, 'binary', cb); | |
| 1205 | } catch (e) { | |
| 1206 | this.e rror(e.toS tring()); | |
| 1207 | } | |
| 1208 | }; | |
| 1209 | ||
| 1210 | /** | |
| 1211 | * Sends a close ins truction t o the remo te party. | |
| 1212 | * | |
| 1213 | * @api pu blic | |
| 1214 | */ | |
| 1215 | ||
| 1216 | Sender.pro totype.clo se = funct ion(code, data, mask , cb) { | |
| 1217 | if (this .isClosed) return; | |
| 1218 | this.isC losed = tr ue; | |
| 1219 | try { | |
| 1220 | if (th is.continu ationFrame ) this.soc ket.write( new Buffer ([0xff], ' binary')); | |
| 1221 | this.s ocket.writ e(new Buff er([0xff, 0x00]), 'b inary', cb ); | |
| 1222 | } catch (e) { | |
| 1223 | this.e rror(e.toS tring()); | |
| 1224 | } | |
| 1225 | }; | |
| 1226 | ||
| 1227 | /** | |
| 1228 | * Sends a ping mess age to the remote pa rty. Not a vailable f or hixie. | |
| 1229 | * | |
| 1230 | * @api pu blic | |
| 1231 | */ | |
| 1232 | ||
| 1233 | Sender.pro totype.pin g = functi on(data, o ptions) {} ; | |
| 1234 | ||
| 1235 | /** | |
| 1236 | * Sends a pong mess age to the remote pa rty. Not a vailable f or hixie. | |
| 1237 | * | |
| 1238 | * @api pu blic | |
| 1239 | */ | |
| 1240 | ||
| 1241 | Sender.pro totype.pon g = functi on(data, o ptions) {} ; | |
| 1242 | ||
| 1243 | /** | |
| 1244 | * Handles an error | |
| 1245 | * | |
| 1246 | * @api pr ivate | |
| 1247 | */ | |
| 1248 | ||
| 1249 | Sender.pro totype.err or = funct ion (reaso n) { | |
| 1250 | this.emi t('error', reason); | |
| 1251 | return t his; | |
| 1252 | }; | |
| 1253 | \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 package/li b/Sender.j s\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 000644 \x000000 0765 \x00000000 24 \x0000000001 7576 \x00001270 2710666\x000001 3102 \x00000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000ust ar\x000000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x00000 00000 \x0000000 000 \x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000/*! | |
| 1254 | * ws: a n ode.js web socket cli ent | |
| 1255 | * Copyrig ht(c) 2011 Einar Ott o Stangvik <einaros@ gmail.com> | |
| 1256 | * MIT Lic ensed | |
| 1257 | */ | |
| 1258 | ||
| 1259 | var events = require ('events') | |
| 1260 | , util = require(' util') | |
| 1261 | , EventE mitter = e vents.Even tEmitter | |
| 1262 | , ErrorC odes = req uire('./Er rorCodes') | |
| 1263 | , buffer Util = req uire('./Bu fferUtil') .BufferUti l | |
| 1264 | , PerMes sageDeflat e = requir e('./PerMe ssageDefla te'); | |
| 1265 | ||
| 1266 | /** | |
| 1267 | * HyBi Se nder imple mentation | |
| 1268 | */ | |
| 1269 | ||
| 1270 | function S ender(sock et, extens ions) { | |
| 1271 | if (this instanceo f Sender = == false) { | |
| 1272 | throw new TypeEr ror("Class es can't b e function -called"); | |
| 1273 | } | |
| 1274 | ||
| 1275 | events.E ventEmitte r.call(thi s); | |
| 1276 | ||
| 1277 | this._so cket = soc ket; | |
| 1278 | this.ext ensions = extensions || {}; | |
| 1279 | this.fir stFragment = true; | |
| 1280 | this.com press = fa lse; | |
| 1281 | this.mes sageHandle rs = []; | |
| 1282 | this.pro cessing = false; | |
| 1283 | } | |
| 1284 | ||
| 1285 | /** | |
| 1286 | * Inherit s from Eve ntEmitter. | |
| 1287 | */ | |
| 1288 | ||
| 1289 | util.inher its(Sender , events.E ventEmitte r); | |
| 1290 | ||
| 1291 | /** | |
| 1292 | * Sends a close ins truction t o the remo te party. | |
| 1293 | * | |
| 1294 | * @api pu blic | |
| 1295 | */ | |
| 1296 | ||
| 1297 | Sender.pro totype.clo se = funct ion(code, data, mask , cb) { | |
| 1298 | if (type of code != = 'undefin ed') { | |
| 1299 | if (ty peof code !== 'numbe r' || | |
| 1300 | !Err orCodes.is ValidError Code(code) ) throw ne w Error('f irst argum ent must b e a valid error code number'); | |
| 1301 | } | |
| 1302 | code = c ode || 100 0; | |
| 1303 | var data Buffer = n ew Buffer( 2 + (data ? Buffer.b yteLength( data) : 0) ); | |
| 1304 | writeUIn t16BE.call (dataBuffe r, code, 0 ); | |
| 1305 | if (data Buffer.len gth > 2) d ataBuffer. write(data , 2); | |
| 1306 | ||
| 1307 | var self = this; | |
| 1308 | this.mes sageHandle rs.push(fu nction(cal lback) { | |
| 1309 | self.f rameAndSen d(0x8, dat aBuffer, t rue, mask) ; | |
| 1310 | callba ck(); | |
| 1311 | if (ty peof cb == 'function ') cb(); | |
| 1312 | }); | |
| 1313 | this.flu sh(); | |
| 1314 | }; | |
| 1315 | ||
| 1316 | /** | |
| 1317 | * Sends a ping mess age to the remote pa rty. | |
| 1318 | * | |
| 1319 | * @api pu blic | |
| 1320 | */ | |
| 1321 | ||
| 1322 | Sender.pro totype.pin g = functi on(data, o ptions) { | |
| 1323 | var mask = options && option s.mask; | |
| 1324 | var self = this; | |
| 1325 | this.mes sageHandle rs.push(fu nction(cal lback) { | |
| 1326 | self.f rameAndSen d(0x9, dat a || '', t rue, mask) ; | |
| 1327 | callba ck(); | |
| 1328 | }); | |
| 1329 | this.flu sh(); | |
| 1330 | }; | |
| 1331 | ||
| 1332 | /** | |
| 1333 | * Sends a pong mess age to the remote pa rty. | |
| 1334 | * | |
| 1335 | * @api pu blic | |
| 1336 | */ | |
| 1337 | ||
| 1338 | Sender.pro totype.pon g = functi on(data, o ptions) { | |
| 1339 | var mask = options && option s.mask; | |
| 1340 | var self = this; | |
| 1341 | this.mes sageHandle rs.push(fu nction(cal lback) { | |
| 1342 | self.f rameAndSen d(0xa, dat a || '', t rue, mask) ; | |
| 1343 | callba ck(); | |
| 1344 | }); | |
| 1345 | this.flu sh(); | |
| 1346 | }; | |
| 1347 | ||
| 1348 | /** | |
| 1349 | * Sends t ext or bin ary data t o the remo te party. | |
| 1350 | * | |
| 1351 | * @api pu blic | |
| 1352 | */ | |
| 1353 | ||
| 1354 | Sender.pro totype.sen d = functi on(data, o ptions, cb ) { | |
| 1355 | var fina lFragment = options && options .fin === f alse ? fal se : true; | |
| 1356 | var mask = options && option s.mask; | |
| 1357 | var comp ress = opt ions && op tions.comp ress; | |
| 1358 | var opco de = optio ns && opti ons.binary ? 2 : 1; | |
| 1359 | if (this .firstFrag ment === f alse) { | |
| 1360 | opcode = 0; | |
| 1361 | compre ss = false ; | |
| 1362 | } else { | |
| 1363 | this.f irstFragme nt = false ; | |
| 1364 | this.c ompress = compress; | |
| 1365 | } | |
| 1366 | if (fina lFragment) this.firs tFragment = true | |
| 1367 | ||
| 1368 | var comp ressFragme nt = this. compress; | |
| 1369 | ||
| 1370 | var self = this; | |
| 1371 | this.mes sageHandle rs.push(fu nction(cal lback) { | |
| 1372 | self.a pplyExtens ions(data, finalFrag ment, comp ressFragme nt, functi on(err, da ta) { | |
| 1373 | if ( err) { | |
| 1374 | if (typeof c b == 'func tion') cb( err); | |
| 1375 | el se self.em it('error' , err); | |
| 1376 | re turn; | |
| 1377 | } | |
| 1378 | self .frameAndS end(opcode , data, fi nalFragmen t, mask, c ompress, c b); | |
| 1379 | call back(); | |
| 1380 | }); | |
| 1381 | }); | |
| 1382 | this.flu sh(); | |
| 1383 | }; | |
| 1384 | ||
| 1385 | /** | |
| 1386 | * Frames and sends a piece of data acco rding to t he HyBi We bSocket pr otocol. | |
| 1387 | * | |
| 1388 | * @api pr ivate | |
| 1389 | */ | |
| 1390 | ||
| 1391 | Sender.pro totype.fra meAndSend = function (opcode, d ata, final Fragment, maskData, compressed , cb) { | |
| 1392 | var canM odifyData = false; | |
| 1393 | ||
| 1394 | if (!dat a) { | |
| 1395 | try { | |
| 1396 | this ._socket.w rite(new B uffer([opc ode | (fin alFragment ? 0x80 : 0), 0 | (m askData ? 0x80 : 0)] .concat(ma skData ? [ 0, 0, 0, 0 ] : [])), 'binary', cb); | |
| 1397 | } | |
| 1398 | catch (e) { | |
| 1399 | if ( typeof cb == 'functi on') cb(e) ; | |
| 1400 | else this.emit ('error', e); | |
| 1401 | } | |
| 1402 | return ; | |
| 1403 | } | |
| 1404 | ||
| 1405 | if (!Buf fer.isBuff er(data)) { | |
| 1406 | canMod ifyData = true; | |
| 1407 | if (da ta && (typ eof data.b yteLength !== 'undef ined' || t ypeof data .buffer != = 'undefin ed')) { | |
| 1408 | data = getArra yBuffer(da ta); | |
| 1409 | } else { | |
| 1410 | // | |
| 1411 | // I f people w ant to sen d a number , this wou ld allocat e the numb er in | |
| 1412 | // b ytes as me mory size instead of storing t he number as buffer value. So | |
| 1413 | // w e need to transform it to stri ng in orde r to preve nt possibl e | |
| 1414 | // v ulnerabili ties / mem ory attack s. | |
| 1415 | // | |
| 1416 | if ( typeof dat a === 'num ber') data = data.to String(); | |
| 1417 | ||
| 1418 | data = new Buf fer(data); | |
| 1419 | } | |
| 1420 | } | |
| 1421 | ||
| 1422 | var data Length = d ata.length | |
| 1423 | , data Offset = m askData ? 6 : 2 | |
| 1424 | , seco ndByte = d ataLength; | |
| 1425 | ||
| 1426 | if (data Length >= 65536) { | |
| 1427 | dataOf fset += 8; | |
| 1428 | second Byte = 127 ; | |
| 1429 | } | |
| 1430 | else if (dataLengt h > 125) { | |
| 1431 | dataOf fset += 2; | |
| 1432 | second Byte = 126 ; | |
| 1433 | } | |
| 1434 | ||
| 1435 | var merg eBuffers = dataLengt h < 32768 || (maskDa ta && !can ModifyData ); | |
| 1436 | var tota lLength = mergeBuffe rs ? dataL ength + da taOffset : dataOffse t; | |
| 1437 | var outp utBuffer = new Buffe r(totalLen gth); | |
| 1438 | outputBu ffer[0] = finalFragm ent ? opco de | 0x80 : opcode; | |
| 1439 | if (comp ressed) ou tputBuffer [0] |= 0x4 0; | |
| 1440 | ||
| 1441 | switch ( secondByte ) { | |
| 1442 | case 1 26: | |
| 1443 | writ eUInt16BE. call(outpu tBuffer, d ataLength, 2); | |
| 1444 | brea k; | |
| 1445 | case 1 27: | |
| 1446 | writ eUInt32BE. call(outpu tBuffer, 0 , 2); | |
| 1447 | writ eUInt32BE. call(outpu tBuffer, d ataLength, 6); | |
| 1448 | } | |
| 1449 | ||
| 1450 | if (mask Data) { | |
| 1451 | output Buffer[1] = secondBy te | 0x80; | |
| 1452 | var ma sk = getRa ndomMask() ; | |
| 1453 | output Buffer[dat aOffset - 4] = mask[ 0]; | |
| 1454 | output Buffer[dat aOffset - 3] = mask[ 1]; | |
| 1455 | output Buffer[dat aOffset - 2] = mask[ 2]; | |
| 1456 | output Buffer[dat aOffset - 1] = mask[ 3]; | |
| 1457 | if (me rgeBuffers ) { | |
| 1458 | buff erUtil.mas k(data, ma sk, output Buffer, da taOffset, dataLength ); | |
| 1459 | try { | |
| 1460 | th is._socket .write(out putBuffer, 'binary', cb); | |
| 1461 | } | |
| 1462 | catc h (e) { | |
| 1463 | if (typeof c b == 'func tion') cb( e); | |
| 1464 | el se this.em it('error' , e); | |
| 1465 | } | |
| 1466 | } | |
| 1467 | else { | |
| 1468 | buff erUtil.mas k(data, ma sk, data, 0, dataLen gth); | |
| 1469 | try { | |
| 1470 | th is._socket .write(out putBuffer, 'binary') ; | |
| 1471 | th is._socket .write(dat a, 'binary ', cb); | |
| 1472 | } | |
| 1473 | catc h (e) { | |
| 1474 | if (typeof c b == 'func tion') cb( e); | |
| 1475 | el se this.em it('error' , e); | |
| 1476 | } | |
| 1477 | } | |
| 1478 | } | |
| 1479 | else { | |
| 1480 | output Buffer[1] = secondBy te; | |
| 1481 | if (me rgeBuffers ) { | |
| 1482 | data .copy(outp utBuffer, dataOffset ); | |
| 1483 | try { | |
| 1484 | th is._socket .write(out putBuffer, 'binary', cb); | |
| 1485 | } | |
| 1486 | catc h (e) { | |
| 1487 | if (typeof c b == 'func tion') cb( e); | |
| 1488 | el se this.em it('error' , e); | |
| 1489 | } | |
| 1490 | } | |
| 1491 | else { | |
| 1492 | try { | |
| 1493 | th is._socket .write(out putBuffer, 'binary') ; | |
| 1494 | th is._socket .write(dat a, 'binary ', cb); | |
| 1495 | } | |
| 1496 | catc h (e) { | |
| 1497 | if (typeof c b == 'func tion') cb( e); | |
| 1498 | el se this.em it('error' , e); | |
| 1499 | } | |
| 1500 | } | |
| 1501 | } | |
| 1502 | }; | |
| 1503 | ||
| 1504 | /** | |
| 1505 | * Execute message h andler buf fers | |
| 1506 | * | |
| 1507 | * @api pr ivate | |
| 1508 | */ | |
| 1509 | ||
| 1510 | Sender.pro totype.flu sh = funct ion() { | |
| 1511 | if (this .processin g) return; | |
| 1512 | ||
| 1513 | var hand ler = this .messageHa ndlers.shi ft(); | |
| 1514 | if (!han dler) retu rn; | |
| 1515 | ||
| 1516 | this.pro cessing = true; | |
| 1517 | ||
| 1518 | var self = this; | |
| 1519 | ||
| 1520 | handler( function() { | |
| 1521 | self.p rocessing = false; | |
| 1522 | self.f lush(); | |
| 1523 | }); | |
| 1524 | }; | |
| 1525 | ||
| 1526 | /** | |
| 1527 | * Apply e xtensions to message | |
| 1528 | * | |
| 1529 | * @api pr ivate | |
| 1530 | */ | |
| 1531 | ||
| 1532 | Sender.pro totype.app lyExtensio ns = funct ion(data, fin, compr ess, callb ack) { | |
| 1533 | if (comp ress && da ta) { | |
| 1534 | if ((d ata.buffer || data) instanceof ArrayBuff er) { | |
| 1535 | data = getArra yBuffer(da ta); | |
| 1536 | } | |
| 1537 | this.e xtensions[ PerMessage Deflate.ex tensionNam e].compres s(data, fi n, callbac k); | |
| 1538 | } else { | |
| 1539 | callba ck(null, d ata); | |
| 1540 | } | |
| 1541 | }; | |
| 1542 | ||
| 1543 | module.exp orts = Sen der; | |
| 1544 | ||
| 1545 | function w riteUInt16 BE(value, offset) { | |
| 1546 | this[off set] = (va lue & 0xff 00)>>8; | |
| 1547 | this[off set+1] = v alue & 0xf f; | |
| 1548 | } | |
| 1549 | ||
| 1550 | function w riteUInt32 BE(value, offset) { | |
| 1551 | this[off set] = (va lue & 0xff 000000)>>2 4; | |
| 1552 | this[off set+1] = ( value & 0x ff0000)>>1 6; | |
| 1553 | this[off set+2] = ( value & 0x ff00)>>8; | |
| 1554 | this[off set+3] = v alue & 0xf f; | |
| 1555 | } | |
| 1556 | ||
| 1557 | function g etArrayBuf fer(data) { | |
| 1558 | // data is either an ArrayBu ffer or Ar rayBufferV iew. | |
| 1559 | var arra y = new Ui nt8Array(d ata.buffer || data) | |
| 1560 | , l = data.byteL ength || d ata.length | |
| 1561 | , o = data.byteO ffset || 0 | |
| 1562 | , buff er = new B uffer(l); | |
| 1563 | for (var i = 0; i < l; ++i) { | |
| 1564 | buffer [i] = arra y[o+i]; | |
| 1565 | } | |
| 1566 | return b uffer; | |
| 1567 | } | |
| 1568 | ||
| 1569 | function g etRandomMa sk() { | |
| 1570 | return n ew Buffer( [ | |
| 1571 | ~~(Mat h.random() * 255), | |
| 1572 | ~~(Mat h.random() * 255), | |
| 1573 | ~~(Mat h.random() * 255), | |
| 1574 | ~~(Mat h.random() * 255) | |
| 1575 | ]); | |
| 1576 | } | |
| 1577 | \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 package/li b/Validati on.fallbac k.js\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 000644 \x000000 0765 \x00000000 24 \x0000000000 0311 \x00001270 2710666\x000001 5465 \x00000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000ust ar\x000000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x00000 00000 \x0000000 000 \x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000/*! | |
| 1578 | * ws: a n ode.js web socket cli ent | |
| 1579 | * Copyrig ht(c) 2011 Einar Ott o Stangvik <einaros@ gmail.com> | |
| 1580 | * MIT Lic ensed | |
| 1581 | */ | |
| 1582 | ||
| 1583 | exports.Va lidation = { | |
| 1584 | isValidU TF8: funct ion(buffer ) { | |
| 1585 | return true; | |
| 1586 | } | |
| 1587 | }; | |
| 1588 | \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000package/l ib/Validat ion.js\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000000644 \x00000 00765 \x0000000 024 \x000000000 00400 \x0000124 62406655\x00000 13731 \x00000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000us tar\x000000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 000000 \x000000 0000 \x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000'use st rict'; | |
| 1589 | ||
| 1590 | /*! | |
| 1591 | * ws: a n ode.js web socket cli ent | |
| 1592 | * Copyrig ht(c) 2011 Einar Ott o Stangvik <einaros@ gmail.com> | |
| 1593 | * MIT Lic ensed | |
| 1594 | */ | |
| 1595 | ||
| 1596 | try { | |
| 1597 | module.e xports = r equire('ut f-8-valida te'); | |
| 1598 | } catch (e ) { | |
| 1599 | module.e xports = r equire('./ Validation .fallback' ); | |
| 1600 | } | |
| 1601 | \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000pack age/lib/We bSocket.js \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x00000006 44 \x0000000765 \x0000000024 \x0000 0000065744 \x000012702710 666\x0000013550 \x00000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000ustar\x00000 0\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x000000000 0 \x0000000000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000'u se strict' ; | |
| 1602 | ||
| 1603 | /*! | |
| 1604 | * ws: a n ode.js web socket cli ent | |
| 1605 | * Copyrig ht(c) 2011 Einar Ott o Stangvik <einaros@ gmail.com> | |
| 1606 | * MIT Lic ensed | |
| 1607 | */ | |
| 1608 | ||
| 1609 | var url = require('u rl') | |
| 1610 | , util = require(' util') | |
| 1611 | , http = require(' http') | |
| 1612 | , https = require( 'https') | |
| 1613 | , crypto = require ('crypto') | |
| 1614 | , stream = require ('stream') | |
| 1615 | , Ultron = require ('ultron') | |
| 1616 | , Option s = requir e('options ') | |
| 1617 | , Sender = require ('./Sender ') | |
| 1618 | , Receiv er = requi re('./Rece iver') | |
| 1619 | , Sender Hixie = re quire('./S ender.hixi e') | |
| 1620 | , Receiv erHixie = require('. /Receiver. hixie') | |
| 1621 | , Extens ions = req uire('./Ex tensions') | |
| 1622 | , PerMes sageDeflat e = requir e('./PerMe ssageDefla te') | |
| 1623 | , EventE mitter = r equire('ev ents').Eve ntEmitter; | |
| 1624 | ||
| 1625 | /** | |
| 1626 | * Constan ts | |
| 1627 | */ | |
| 1628 | ||
| 1629 | // Default protocol version | |
| 1630 | ||
| 1631 | var protoc olVersion = 13; | |
| 1632 | ||
| 1633 | // Close t imeout | |
| 1634 | ||
| 1635 | var closeT imeout = 3 0 * 1000; // Allow 3 0 seconds to termina te the con nection cl eanly | |
| 1636 | ||
| 1637 | /** | |
| 1638 | * WebSock et impleme ntation | |
| 1639 | * | |
| 1640 | * @constr uctor | |
| 1641 | * @param {String} a ddress Con nection ad dress. | |
| 1642 | * @param {String|Ar ray} proto cols WebSo cket proto cols. | |
| 1643 | * @param {Object} o ptions Add itional co nnection o ptions. | |
| 1644 | * @api pu blic | |
| 1645 | */ | |
| 1646 | function W ebSocket(a ddress, pr otocols, o ptions) { | |
| 1647 | if (this instanceo f WebSocke t === fals e) { | |
| 1648 | return new WebSo cket(addre ss, protoc ols, optio ns); | |
| 1649 | } | |
| 1650 | ||
| 1651 | EventEmi tter.call( this); | |
| 1652 | ||
| 1653 | if (prot ocols && ! Array.isAr ray(protoc ols) && 'o bject' === typeof pr otocols) { | |
| 1654 | // acc ept the "o ptions" Ob ject as th e 2nd argu ment | |
| 1655 | option s = protoc ols; | |
| 1656 | protoc ols = null ; | |
| 1657 | } | |
| 1658 | ||
| 1659 | if ('str ing' === t ypeof prot ocols) { | |
| 1660 | protoc ols = [ pr otocols ]; | |
| 1661 | } | |
| 1662 | ||
| 1663 | if (!Arr ay.isArray (protocols )) { | |
| 1664 | protoc ols = []; | |
| 1665 | } | |
| 1666 | ||
| 1667 | this._so cket = nul l; | |
| 1668 | this._ul tron = nul l; | |
| 1669 | this._cl oseReceive d = false; | |
| 1670 | this.byt esReceived = 0; | |
| 1671 | this.rea dyState = null; | |
| 1672 | this.sup ports = {} ; | |
| 1673 | this.ext ensions = {}; | |
| 1674 | this._bi naryType = 'nodebuff er'; | |
| 1675 | ||
| 1676 | if (Arra y.isArray( address)) { | |
| 1677 | initAs ServerClie nt.apply(t his, addre ss.concat( options)); | |
| 1678 | } else { | |
| 1679 | initAs Client.app ly(this, [ address, p rotocols, options]); | |
| 1680 | } | |
| 1681 | } | |
| 1682 | ||
| 1683 | /** | |
| 1684 | * Inherit s from Eve ntEmitter. | |
| 1685 | */ | |
| 1686 | util.inher its(WebSoc ket, Event Emitter); | |
| 1687 | ||
| 1688 | /** | |
| 1689 | * Ready S tates | |
| 1690 | */ | |
| 1691 | ["CONNECTI NG", "OPEN ", "CLOSIN G", "CLOSE D"].forEac h(function each(stat e, index) { | |
| 1692 | WebSoc ket.protot ype[state] = WebSock et[state] = index; | |
| 1693 | }); | |
| 1694 | ||
| 1695 | /** | |
| 1696 | * Gracefu lly closes the conne ction, aft er sending a descrip tion messa ge to the server | |
| 1697 | * | |
| 1698 | * @param {Object} d ata to be sent to th e server | |
| 1699 | * @api pu blic | |
| 1700 | */ | |
| 1701 | WebSocket. prototype. close = fu nction clo se(code, d ata) { | |
| 1702 | if (this .readyStat e === WebS ocket.CLOS ED) return ; | |
| 1703 | ||
| 1704 | if (this .readyStat e === WebS ocket.CONN ECTING) { | |
| 1705 | this.r eadyState = WebSocke t.CLOSED; | |
| 1706 | return ; | |
| 1707 | } | |
| 1708 | ||
| 1709 | if (this .readyStat e === WebS ocket.CLOS ING) { | |
| 1710 | if (th is._closeR eceived && this._isS erver) { | |
| 1711 | this .terminate (); | |
| 1712 | } | |
| 1713 | return ; | |
| 1714 | } | |
| 1715 | ||
| 1716 | var self = this; | |
| 1717 | try { | |
| 1718 | this.r eadyState = WebSocke t.CLOSING; | |
| 1719 | this._ closeCode = code; | |
| 1720 | this._ closeMessa ge = data; | |
| 1721 | var ma sk = !this ._isServer ; | |
| 1722 | this._ sender.clo se(code, d ata, mask, function( err) { | |
| 1723 | if ( err) self. emit('erro r', err); | |
| 1724 | ||
| 1725 | if ( self._clos eReceived && self._i sServer) { | |
| 1726 | se lf.termina te(); | |
| 1727 | } el se { | |
| 1728 | // ensure th at the con nection is cleaned u p even whe n no respo nse of clo sing hands hake. | |
| 1729 | cl earTimeout (self._clo seTimer); | |
| 1730 | se lf._closeT imer = set Timeout(cl eanupWebso cketResour ces.bind(s elf, true) , closeTim eout); | |
| 1731 | } | |
| 1732 | }); | |
| 1733 | } catch (e) { | |
| 1734 | this.e mit('error ', e); | |
| 1735 | } | |
| 1736 | }; | |
| 1737 | ||
| 1738 | /** | |
| 1739 | * Pause t he client stream | |
| 1740 | * | |
| 1741 | * @api pu blic | |
| 1742 | */ | |
| 1743 | WebSocket. prototype. pause = fu nction pau ser() { | |
| 1744 | if (this .readyStat e !== WebS ocket.OPEN ) throw ne w Error('n ot opened' ); | |
| 1745 | ||
| 1746 | return t his._socke t.pause(); | |
| 1747 | }; | |
| 1748 | ||
| 1749 | /** | |
| 1750 | * Sends a ping | |
| 1751 | * | |
| 1752 | * @param {Object} d ata to be sent to th e server | |
| 1753 | * @param {Object} M embers - m ask: boole an, binary : boolean | |
| 1754 | * @param {boolean} dontFailWh enClosed i ndicates w hether or not to thr ow if the connection isnt open | |
| 1755 | * @api pu blic | |
| 1756 | */ | |
| 1757 | WebSocket. prototype. ping = fun ction ping (data, opt ions, dont FailWhenCl osed) { | |
| 1758 | if (this .readyStat e !== WebS ocket.OPEN ) { | |
| 1759 | if (do ntFailWhen Closed === true) ret urn; | |
| 1760 | throw new Error( 'not opene d'); | |
| 1761 | } | |
| 1762 | ||
| 1763 | options = options || {}; | |
| 1764 | ||
| 1765 | if (type of options .mask === 'undefined ') options .mask = !t his._isSer ver; | |
| 1766 | ||
| 1767 | this._se nder.ping( data, opti ons); | |
| 1768 | }; | |
| 1769 | ||
| 1770 | /** | |
| 1771 | * Sends a pong | |
| 1772 | * | |
| 1773 | * @param {Object} d ata to be sent to th e server | |
| 1774 | * @param {Object} M embers - m ask: boole an, binary : boolean | |
| 1775 | * @param {boolean} dontFailWh enClosed i ndicates w hether or not to thr ow if the connection isnt open | |
| 1776 | * @api pu blic | |
| 1777 | */ | |
| 1778 | WebSocket. prototype. pong = fun ction(data , options, dontFailW henClosed) { | |
| 1779 | if (this .readyStat e !== WebS ocket.OPEN ) { | |
| 1780 | if (do ntFailWhen Closed === true) ret urn; | |
| 1781 | throw new Error( 'not opene d'); | |
| 1782 | } | |
| 1783 | ||
| 1784 | options = options || {}; | |
| 1785 | ||
| 1786 | if (type of options .mask === 'undefined ') options .mask = !t his._isSer ver; | |
| 1787 | ||
| 1788 | this._se nder.pong( data, opti ons); | |
| 1789 | }; | |
| 1790 | ||
| 1791 | /** | |
| 1792 | * Resume the client stream | |
| 1793 | * | |
| 1794 | * @api pu blic | |
| 1795 | */ | |
| 1796 | WebSocket. prototype. resume = f unction re sume() { | |
| 1797 | if (this .readyStat e !== WebS ocket.OPEN ) throw ne w Error('n ot opened' ); | |
| 1798 | ||
| 1799 | return t his._socke t.resume() ; | |
| 1800 | }; | |
| 1801 | ||
| 1802 | /** | |
| 1803 | * Sends a piece of data | |
| 1804 | * | |
| 1805 | * @param {Object} d ata to be sent to th e server | |
| 1806 | * @param {Object} M embers - m ask: boole an, binary : boolean, compress: boolean | |
| 1807 | * @param {function} Optional callback w hich is ex ecuted aft er the sen d complete s | |
| 1808 | * @api pu blic | |
| 1809 | */ | |
| 1810 | ||
| 1811 | WebSocket. prototype. send = fun ction send (data, opt ions, cb) { | |
| 1812 | if (type of options === 'func tion') { | |
| 1813 | cb = o ptions; | |
| 1814 | option s = {}; | |
| 1815 | } | |
| 1816 | ||
| 1817 | if (this .readyStat e !== WebS ocket.OPEN ) { | |
| 1818 | if (ty peof cb == = 'functio n') cb(new Error('no t opened') ); | |
| 1819 | else t hrow new E rror('not opened'); | |
| 1820 | return ; | |
| 1821 | } | |
| 1822 | ||
| 1823 | if (!dat a) data = ''; | |
| 1824 | if (this ._queue) { | |
| 1825 | var se lf = this; | |
| 1826 | this._ queue.push (function( ) { self.s end(data, options, c b); }); | |
| 1827 | return ; | |
| 1828 | } | |
| 1829 | ||
| 1830 | options = options || {}; | |
| 1831 | options. fin = true ; | |
| 1832 | ||
| 1833 | if (type of options .binary == = 'undefin ed') { | |
| 1834 | option s.binary = (data ins tanceof Ar rayBuffer || data in stanceof B uffer || | |
| 1835 | data instanceo f Uint8Arr ay || | |
| 1836 | data instanceo f Uint16Ar ray || | |
| 1837 | data instanceo f Uint32Ar ray || | |
| 1838 | data instanceo f Int8Arra y || | |
| 1839 | data instanceo f Int16Arr ay || | |
| 1840 | data instanceo f Int32Arr ay || | |
| 1841 | data instanceo f Float32A rray || | |
| 1842 | data instanceo f Float64A rray); | |
| 1843 | } | |
| 1844 | ||
| 1845 | if (type of options .mask === 'undefined ') options .mask = !t his._isSer ver; | |
| 1846 | if (type of options .compress === 'undef ined') opt ions.compr ess = true ; | |
| 1847 | if (!thi s.extensio ns[PerMess ageDeflate .extension Name]) { | |
| 1848 | option s.compress = false; | |
| 1849 | } | |
| 1850 | ||
| 1851 | var read able = typ eof stream .Readable === 'funct ion' | |
| 1852 | ? stre am.Readabl e | |
| 1853 | : stre am.Stream; | |
| 1854 | ||
| 1855 | if (data instanceo f readable ) { | |
| 1856 | startQ ueue(this) ; | |
| 1857 | var se lf = this; | |
| 1858 | ||
| 1859 | sendSt ream(this, data, opt ions, func tion send( error) { | |
| 1860 | proc ess.nextTi ck(functio n tock() { | |
| 1861 | ex ecuteQueue Sends(self ); | |
| 1862 | }); | |
| 1863 | ||
| 1864 | if ( typeof cb === 'funct ion') cb(e rror); | |
| 1865 | }); | |
| 1866 | } else { | |
| 1867 | this._ sender.sen d(data, op tions, cb) ; | |
| 1868 | } | |
| 1869 | }; | |
| 1870 | ||
| 1871 | /** | |
| 1872 | * Streams data thro ugh calls to a user supplied f unction | |
| 1873 | * | |
| 1874 | * @param {Object} M embers - m ask: boole an, binary : boolean, compress: boolean | |
| 1875 | * @param {function} 'function (error, s end)' whic h is execu ted on suc cessive ti cks of whi ch send is 'function (data, fi nal)'. | |
| 1876 | * @api pu blic | |
| 1877 | */ | |
| 1878 | WebSocket. prototype. stream = f unction st ream(optio ns, cb) { | |
| 1879 | if (type of options === 'func tion') { | |
| 1880 | cb = o ptions; | |
| 1881 | option s = {}; | |
| 1882 | } | |
| 1883 | ||
| 1884 | var self = this; | |
| 1885 | ||
| 1886 | if (type of cb !== 'function' ) throw ne w Error('c allback mu st be prov ided'); | |
| 1887 | ||
| 1888 | if (this .readyStat e !== WebS ocket.OPEN ) { | |
| 1889 | if (ty peof cb == = 'functio n') cb(new Error('no t opened') ); | |
| 1890 | else t hrow new E rror('not opened'); | |
| 1891 | return ; | |
| 1892 | } | |
| 1893 | ||
| 1894 | if (this ._queue) { | |
| 1895 | this._ queue.push (function () { self. stream(opt ions, cb); }); | |
| 1896 | return ; | |
| 1897 | } | |
| 1898 | ||
| 1899 | options = options || {}; | |
| 1900 | ||
| 1901 | if (type of options .mask === 'undefined ') options .mask = !t his._isSer ver; | |
| 1902 | if (type of options .compress === 'undef ined') opt ions.compr ess = true ; | |
| 1903 | if (!thi s.extensio ns[PerMess ageDeflate .extension Name]) { | |
| 1904 | option s.compress = false; | |
| 1905 | } | |
| 1906 | ||
| 1907 | startQue ue(this); | |
| 1908 | ||
| 1909 | function send(data , final) { | |
| 1910 | try { | |
| 1911 | if ( self.ready State !== WebSocket. OPEN) thro w new Erro r('not ope ned'); | |
| 1912 | opti ons.fin = final === true; | |
| 1913 | self ._sender.s end(data, options); | |
| 1914 | if ( !final) pr ocess.next Tick(cb.bi nd(null, n ull, send) ); | |
| 1915 | else executeQu eueSends(s elf); | |
| 1916 | } catc h (e) { | |
| 1917 | if ( typeof cb === 'funct ion') cb(e ); | |
| 1918 | else { | |
| 1919 | de lete self. _queue; | |
| 1920 | se lf.emit('e rror', e); | |
| 1921 | } | |
| 1922 | } | |
| 1923 | } | |
| 1924 | ||
| 1925 | process. nextTick(c b.bind(nul l, null, s end)); | |
| 1926 | }; | |
| 1927 | ||
| 1928 | /** | |
| 1929 | * Immedia tely shuts down the connection | |
| 1930 | * | |
| 1931 | * @api pu blic | |
| 1932 | */ | |
| 1933 | WebSocket. prototype. terminate = function terminate () { | |
| 1934 | if (this .readyStat e === WebS ocket.CLOS ED) return ; | |
| 1935 | ||
| 1936 | if (this ._socket) { | |
| 1937 | this.r eadyState = WebSocke t.CLOSING; | |
| 1938 | ||
| 1939 | // End the conne ction | |
| 1940 | try { this._sock et.end(); } | |
| 1941 | catch (e) { | |
| 1942 | // S ocket erro r during e nd() call, so just d estroy it right now | |
| 1943 | clea nupWebsock etResource s.call(thi s, true); | |
| 1944 | retu rn; | |
| 1945 | } | |
| 1946 | ||
| 1947 | // Add a timeout to ensure that the connection is comple tely | |
| 1948 | // cle aned up wi thin 30 se conds, eve n if the c lean close procedure | |
| 1949 | // fai ls for wha tever reas on | |
| 1950 | // Fir st cleanup any pre-e xisting ti meout from an earlie r "termina te" call, | |
| 1951 | // if one exists . Otherwi se termina te calls i n quick su ccession w ill leak t imeouts | |
| 1952 | // and hold the program op en for `cl oseTimout` time. | |
| 1953 | if (th is._closeT imer) { cl earTimeout (this._clo seTimer); } | |
| 1954 | this._ closeTimer = setTime out(cleanu pWebsocket Resources. bind(this, true), cl oseTimeout ); | |
| 1955 | } else i f (this.re adyState = == WebSock et.CONNECT ING) { | |
| 1956 | cleanu pWebsocket Resources. call(this, true); | |
| 1957 | } | |
| 1958 | }; | |
| 1959 | ||
| 1960 | /** | |
| 1961 | * Expose bufferedAm ount | |
| 1962 | * | |
| 1963 | * @api pu blic | |
| 1964 | */ | |
| 1965 | Object.def inePropert y(WebSocke t.prototyp e, 'buffer edAmount', { | |
| 1966 | get: fun ction get( ) { | |
| 1967 | var am ount = 0; | |
| 1968 | if (th is._socket ) { | |
| 1969 | amou nt = this. _socket.bu fferSize | | 0; | |
| 1970 | } | |
| 1971 | return amount; | |
| 1972 | } | |
| 1973 | }); | |
| 1974 | ||
| 1975 | /** | |
| 1976 | * Expose binaryType | |
| 1977 | * | |
| 1978 | * This de viates fro m the W3C interface since ws d oesn't sup port the r equired | |
| 1979 | * default "blob" ty pe (instea d we defin e a custom "nodebuff er" type). | |
| 1980 | * | |
| 1981 | * @see ht tp://dev.w 3.org/html 5/websocke ts/#the-we bsocket-in terface | |
| 1982 | * @api pu blic | |
| 1983 | */ | |
| 1984 | Object.def inePropert y(WebSocke t.prototyp e, 'binary Type', { | |
| 1985 | get: fun ction get( ) { | |
| 1986 | return this._bin aryType; | |
| 1987 | }, | |
| 1988 | set: fun ction set( type) { | |
| 1989 | if (ty pe === 'ar raybuffer' || type = == 'nodebu ffer') | |
| 1990 | this ._binaryTy pe = type; | |
| 1991 | else | |
| 1992 | thro w new Synt axError('u nsupported binaryTyp e: must be either "n odebuffer" or "array buffer"'); | |
| 1993 | } | |
| 1994 | }); | |
| 1995 | ||
| 1996 | /** | |
| 1997 | * Emulate s the W3C Browser ba sed WebSoc ket interf ace using function m embers. | |
| 1998 | * | |
| 1999 | * @see ht tp://dev.w 3.org/html 5/websocke ts/#the-we bsocket-in terface | |
| 2000 | * @api pu blic | |
| 2001 | */ | |
| 2002 | ['open', ' error', 'c lose', 'me ssage'].fo rEach(func tion(metho d) { | |
| 2003 | Object.d efinePrope rty(WebSoc ket.protot ype, 'on' + method, { | |
| 2004 | /** | |
| 2005 | * Ret urns the c urrent lis tener | |
| 2006 | * | |
| 2007 | * @re turns {Mix ed} the se t function or undefi ned | |
| 2008 | * @ap i public | |
| 2009 | */ | |
| 2010 | get: f unction ge t() { | |
| 2011 | var listener = this.list eners(meth od)[0]; | |
| 2012 | retu rn listene r ? (liste ner._liste ner ? list ener._list ener : lis tener) : u ndefined; | |
| 2013 | }, | |
| 2014 | ||
| 2015 | /** | |
| 2016 | * Sta rt listeni ng for eve nts | |
| 2017 | * | |
| 2018 | * @pa ram {Funct ion} liste ner the li stener | |
| 2019 | * @re turns {Mix ed} the se t function or undefi ned | |
| 2020 | * @ap i public | |
| 2021 | */ | |
| 2022 | set: f unction se t(listener ) { | |
| 2023 | this .removeAll Listeners( method); | |
| 2024 | this .addEventL istener(me thod, list ener); | |
| 2025 | } | |
| 2026 | }); | |
| 2027 | }); | |
| 2028 | ||
| 2029 | /** | |
| 2030 | * Emulate s the W3C Browser ba sed WebSoc ket interf ace using addEventLi stener. | |
| 2031 | * | |
| 2032 | * @see ht tps://deve loper.mozi lla.org/en /DOM/eleme nt.addEven tListener | |
| 2033 | * @see ht tp://dev.w 3.org/html 5/websocke ts/#the-we bsocket-in terface | |
| 2034 | * @api pu blic | |
| 2035 | */ | |
| 2036 | WebSocket. prototype. addEventLi stener = f unction(me thod, list ener) { | |
| 2037 | var targ et = this; | |
| 2038 | ||
| 2039 | function onMessage (data, fl ags) { | |
| 2040 | if (fl ags.binary && this.b inaryType === 'array buffer') | |
| 2041 | da ta = new U int8Array( data).buff er; | |
| 2042 | listen er.call(ta rget, new MessageEve nt(data, ! !flags.bin ary, targe t)); | |
| 2043 | } | |
| 2044 | ||
| 2045 | function onClose ( code, mess age) { | |
| 2046 | listen er.call(ta rget, new CloseEvent (code, mes sage, targ et)); | |
| 2047 | } | |
| 2048 | ||
| 2049 | function onError ( event) { | |
| 2050 | event. type = 'er ror'; | |
| 2051 | event. target = t arget; | |
| 2052 | listen er.call(ta rget, even t); | |
| 2053 | } | |
| 2054 | ||
| 2055 | function onOpen () { | |
| 2056 | listen er.call(ta rget, new OpenEvent( target)); | |
| 2057 | } | |
| 2058 | ||
| 2059 | if (type of listene r === 'fun ction') { | |
| 2060 | if (me thod === ' message') { | |
| 2061 | // s tore a ref erence so we can ret urn the or iginal fun ction from the | |
| 2062 | // a ddEventLis tener hook | |
| 2063 | onMe ssage._lis tener = li stener; | |
| 2064 | this .on(method , onMessag e); | |
| 2065 | } else if (metho d === 'clo se') { | |
| 2066 | // s tore a ref erence so we can ret urn the or iginal fun ction from the | |
| 2067 | // a ddEventLis tener hook | |
| 2068 | onCl ose._liste ner = list ener; | |
| 2069 | this .on(method , onClose) ; | |
| 2070 | } else if (metho d === 'err or') { | |
| 2071 | // s tore a ref erence so we can ret urn the or iginal fun ction from the | |
| 2072 | // a ddEventLis tener hook | |
| 2073 | onEr ror._liste ner = list ener; | |
| 2074 | this .on(method , onError) ; | |
| 2075 | } else if (metho d === 'ope n') { | |
| 2076 | // s tore a ref erence so we can ret urn the or iginal fun ction from the | |
| 2077 | // a ddEventLis tener hook | |
| 2078 | onOp en._listen er = liste ner; | |
| 2079 | this .on(method , onOpen); | |
| 2080 | } else { | |
| 2081 | this .on(method , listener ); | |
| 2082 | } | |
| 2083 | } | |
| 2084 | }; | |
| 2085 | ||
| 2086 | module.exp orts = Web Socket; | |
| 2087 | module.exp orts.build HostHeader = buildHo stHeader | |
| 2088 | ||
| 2089 | /** | |
| 2090 | * W3C Mes sageEvent | |
| 2091 | * | |
| 2092 | * @see ht tp://www.w 3.org/TR/h tml5/comms .html | |
| 2093 | * @constr uctor | |
| 2094 | * @api pr ivate | |
| 2095 | */ | |
| 2096 | function M essageEven t(dataArg, isBinary, target) { | |
| 2097 | this.typ e = 'messa ge'; | |
| 2098 | this.dat a = dataAr g; | |
| 2099 | this.tar get = targ et; | |
| 2100 | this.bin ary = isBi nary; // n on-standar d. | |
| 2101 | } | |
| 2102 | ||
| 2103 | /** | |
| 2104 | * W3C Clo seEvent | |
| 2105 | * | |
| 2106 | * @see ht tp://www.w 3.org/TR/h tml5/comms .html | |
| 2107 | * @constr uctor | |
| 2108 | * @api pr ivate | |
| 2109 | */ | |
| 2110 | function C loseEvent( code, reas on, target ) { | |
| 2111 | this.typ e = 'close '; | |
| 2112 | this.was Clean = (t ypeof code === 'unde fined' || code === 1 000); | |
| 2113 | this.cod e = code; | |
| 2114 | this.rea son = reas on; | |
| 2115 | this.tar get = targ et; | |
| 2116 | } | |
| 2117 | ||
| 2118 | /** | |
| 2119 | * W3C Ope nEvent | |
| 2120 | * | |
| 2121 | * @see ht tp://www.w 3.org/TR/h tml5/comms .html | |
| 2122 | * @constr uctor | |
| 2123 | * @api pr ivate | |
| 2124 | */ | |
| 2125 | function O penEvent(t arget) { | |
| 2126 | this.typ e = 'open' ; | |
| 2127 | this.tar get = targ et; | |
| 2128 | } | |
| 2129 | ||
| 2130 | // Append port numbe r to Host header, on ly if spec ified in t he url | |
| 2131 | // and non -default | |
| 2132 | function b uildHostHe ader(isSec ure, hostn ame, port) { | |
| 2133 | var head erHost = h ostname; | |
| 2134 | if (host name) { | |
| 2135 | if ((i sSecure && (port != 443)) || ( !isSecure && (port ! = 80))){ | |
| 2136 | head erHost = h eaderHost + ':' + po rt; | |
| 2137 | } | |
| 2138 | } | |
| 2139 | return h eaderHost; | |
| 2140 | } | |
| 2141 | ||
| 2142 | /** | |
| 2143 | * Entirel y private apis, | |
| 2144 | * which m ay or may not be bou nd to a se pcific Web Socket ins tance. | |
| 2145 | */ | |
| 2146 | function i nitAsServe rClient(re q, socket, upgradeHe ad, option s) { | |
| 2147 | options = new Opti ons({ | |
| 2148 | protoc olVersion: protocolV ersion, | |
| 2149 | protoc ol: null, | |
| 2150 | extens ions: {}, | |
| 2151 | maxPay load: 0 | |
| 2152 | }).merge (options); | |
| 2153 | ||
| 2154 | // expos e state pr operties | |
| 2155 | this.pro tocol = op tions.valu e.protocol ; | |
| 2156 | this.pro tocolVersi on = optio ns.value.p rotocolVer sion; | |
| 2157 | this.ext ensions = options.va lue.extens ions; | |
| 2158 | this.sup ports.bina ry = (this .protocolV ersion !== 'hixie-76 '); | |
| 2159 | this.upg radeReq = req; | |
| 2160 | this.rea dyState = WebSocket. CONNECTING ; | |
| 2161 | this._is Server = t rue; | |
| 2162 | this.max Payload = options.va lue.maxPay load; | |
| 2163 | // estab lish conne ction | |
| 2164 | if (opti ons.value. protocolVe rsion === 'hixie-76' ) { | |
| 2165 | establ ishConnect ion.call(t his, Recei verHixie, SenderHixi e, socket, upgradeHe ad); | |
| 2166 | } else { | |
| 2167 | establ ishConnect ion.call(t his, Recei ver, Sende r, socket, upgradeHe ad); | |
| 2168 | } | |
| 2169 | } | |
| 2170 | ||
| 2171 | function i nitAsClien t(address, protocols , options) { | |
| 2172 | options = new Opti ons({ | |
| 2173 | origin : null, | |
| 2174 | protoc olVersion: protocolV ersion, | |
| 2175 | host: null, | |
| 2176 | header s: null, | |
| 2177 | protoc ol: protoc ols.join(' ,'), | |
| 2178 | agent: null, | |
| 2179 | ||
| 2180 | // ssl -related o ptions | |
| 2181 | pfx: n ull, | |
| 2182 | key: n ull, | |
| 2183 | passph rase: null , | |
| 2184 | cert: null, | |
| 2185 | ca: nu ll, | |
| 2186 | cipher s: null, | |
| 2187 | reject Unauthoriz ed: null, | |
| 2188 | perMes sageDeflat e: true, | |
| 2189 | localA ddress: nu ll | |
| 2190 | }).merge (options); | |
| 2191 | ||
| 2192 | if (opti ons.value. protocolVe rsion !== 8 && optio ns.value.p rotocolVer sion !== 1 3) { | |
| 2193 | throw new Error( 'unsupport ed protoco l version' ); | |
| 2194 | } | |
| 2195 | ||
| 2196 | // verif y URL and establish http class | |
| 2197 | var serv erUrl = ur l.parse(ad dress); | |
| 2198 | var isUn ixSocket = serverUrl .protocol === 'ws+un ix:'; | |
| 2199 | if (!ser verUrl.hos t && !isUn ixSocket) throw new Error('inv alid url') ; | |
| 2200 | var isSe cure = ser verUrl.pro tocol === 'wss:' || serverUrl. protocol = == 'https: '; | |
| 2201 | var http Obj = isSe cure ? htt ps : http; | |
| 2202 | var port = serverU rl.port || (isSecure ? 443 : 8 0); | |
| 2203 | var auth = serverU rl.auth; | |
| 2204 | ||
| 2205 | // prepa re extensi ons | |
| 2206 | var exte nsionsOffe r = {}; | |
| 2207 | var perM essageDefl ate; | |
| 2208 | if (opti ons.value. perMessage Deflate) { | |
| 2209 | perMes sageDeflat e = new Pe rMessageDe flate(type of options .value.per MessageDef late !== t rue ? opti ons.value. perMessage Deflate : {}, false) ; | |
| 2210 | extens ionsOffer[ PerMessage Deflate.ex tensionNam e] = perMe ssageDefla te.offer() ; | |
| 2211 | } | |
| 2212 | ||
| 2213 | // expos e state pr operties | |
| 2214 | this._is Server = f alse; | |
| 2215 | this.url = address ; | |
| 2216 | this.pro tocolVersi on = optio ns.value.p rotocolVer sion; | |
| 2217 | this.sup ports.bina ry = (this .protocolV ersion !== 'hixie-76 '); | |
| 2218 | ||
| 2219 | // begin handshake | |
| 2220 | var key = new Buff er(options .value.pro tocolVersi on + '-' + Date.now( )).toStrin g('base64' ); | |
| 2221 | var shas um = crypt o.createHa sh('sha1') ; | |
| 2222 | shasum.u pdate(key + '258EAFA 5-E914-47D A-95CA-C5A B0DC85B11' ); | |
| 2223 | var expe ctedServer Key = shas um.digest( 'base64'); | |
| 2224 | ||
| 2225 | var agen t = option s.value.ag ent; | |
| 2226 | ||
| 2227 | var head erHost = b uildHostHe ader(isSec ure, serve rUrl.hostn ame, port) | |
| 2228 | ||
| 2229 | var requ estOptions = { | |
| 2230 | port: port, | |
| 2231 | host: serverUrl. hostname, | |
| 2232 | header s: { | |
| 2233 | 'Con nection': 'Upgrade', | |
| 2234 | 'Upg rade': 'we bsocket', | |
| 2235 | 'Hos t': header Host, | |
| 2236 | 'Sec -WebSocket -Version': options.v alue.proto colVersion , | |
| 2237 | 'Sec -WebSocket -Key': key | |
| 2238 | } | |
| 2239 | }; | |
| 2240 | ||
| 2241 | // If we have basi c auth. | |
| 2242 | if (auth ) { | |
| 2243 | reques tOptions.h eaders.Aut horization = 'Basic ' + new Bu ffer(auth) .toString( 'base64'); | |
| 2244 | } | |
| 2245 | ||
| 2246 | if (opti ons.value. protocol) { | |
| 2247 | reques tOptions.h eaders['Se c-WebSocke t-Protocol '] = optio ns.value.p rotocol; | |
| 2248 | } | |
| 2249 | ||
| 2250 | if (opti ons.value. host) { | |
| 2251 | reques tOptions.h eaders.Hos t = option s.value.ho st; | |
| 2252 | } | |
| 2253 | ||
| 2254 | if (opti ons.value. headers) { | |
| 2255 | for (v ar header in options .value.hea ders) { | |
| 2256 | if (options.v alue.heade rs.hasOwnP roperty(he ader)) { | |
| 2257 | re questOptio ns.headers [header] = options.v alue.heade rs[header] ; | |
| 2258 | } | |
| 2259 | } | |
| 2260 | } | |
| 2261 | ||
| 2262 | if (Obje ct.keys(ex tensionsOf fer).lengt h) { | |
| 2263 | reques tOptions.h eaders['Se c-WebSocke t-Extensio ns'] = Ext ensions.fo rmat(exten sionsOffer ); | |
| 2264 | } | |
| 2265 | ||
| 2266 | if (opti ons.isDefi nedAndNonN ull('pfx') | |
| 2267 | || opti ons.isDefi nedAndNonN ull('key') | |
| 2268 | || opti ons.isDefi nedAndNonN ull('passp hrase') | |
| 2269 | || opti ons.isDefi nedAndNonN ull('cert' ) | |
| 2270 | || opti ons.isDefi nedAndNonN ull('ca') | |
| 2271 | || opti ons.isDefi nedAndNonN ull('ciphe rs') | |
| 2272 | || opti ons.isDefi nedAndNonN ull('rejec tUnauthori zed')) { | |
| 2273 | ||
| 2274 | if (op tions.isDe finedAndNo nNull('pfx ')) reques tOptions.p fx = optio ns.value.p fx; | |
| 2275 | if (op tions.isDe finedAndNo nNull('key ')) reques tOptions.k ey = optio ns.value.k ey; | |
| 2276 | if (op tions.isDe finedAndNo nNull('pas sphrase')) requestOp tions.pass phrase = o ptions.val ue.passphr ase; | |
| 2277 | if (op tions.isDe finedAndNo nNull('cer t')) reque stOptions. cert = opt ions.value .cert; | |
| 2278 | if (op tions.isDe finedAndNo nNull('ca' )) request Options.ca = options .value.ca; | |
| 2279 | if (op tions.isDe finedAndNo nNull('cip hers')) re questOptio ns.ciphers = options .value.cip hers; | |
| 2280 | if (op tions.isDe finedAndNo nNull('rej ectUnautho rized')) r equestOpti ons.reject Unauthoriz ed = optio ns.value.r ejectUnaut horized; | |
| 2281 | ||
| 2282 | if (!a gent) { | |
| 2283 | // global ag ent ignore s client s ide certif icates | |
| 2284 | ag ent = new httpObj.Ag ent(reques tOptions); | |
| 2285 | } | |
| 2286 | } | |
| 2287 | ||
| 2288 | requestO ptions.pat h = server Url.path | | '/'; | |
| 2289 | ||
| 2290 | if (agen t) { | |
| 2291 | reques tOptions.a gent = age nt; | |
| 2292 | } | |
| 2293 | ||
| 2294 | if (isUn ixSocket) { | |
| 2295 | reques tOptions.s ocketPath = serverUr l.pathname ; | |
| 2296 | } | |
| 2297 | ||
| 2298 | if (opti ons.value. localAddre ss) { | |
| 2299 | reques tOptions.l ocalAddres s = option s.value.lo calAddress ; | |
| 2300 | } | |
| 2301 | ||
| 2302 | if (opti ons.value. origin) { | |
| 2303 | if (op tions.valu e.protocol Version < 13) reques tOptions.h eaders['Se c-WebSocke t-Origin'] = options .value.ori gin; | |
| 2304 | else r equestOpti ons.header s.Origin = options.v alue.origi n; | |
| 2305 | } | |
| 2306 | ||
| 2307 | var self = this; | |
| 2308 | var req = httpObj. request(re questOptio ns); | |
| 2309 | ||
| 2310 | req.on(' error', fu nction one rror(error ) { | |
| 2311 | self.e mit('error ', error); | |
| 2312 | cleanu pWebsocket Resources. call(self, error); | |
| 2313 | }); | |
| 2314 | ||
| 2315 | req.once ('response ', functio n response (res) { | |
| 2316 | var er ror; | |
| 2317 | ||
| 2318 | if (!s elf.emit(' unexpected -response' , req, res )) { | |
| 2319 | erro r = new Er ror('unexp ected serv er respons e (' + res .statusCod e + ')'); | |
| 2320 | req. abort(); | |
| 2321 | self .emit('err or', error ); | |
| 2322 | } | |
| 2323 | ||
| 2324 | cleanu pWebsocket Resources. call(self, error); | |
| 2325 | }); | |
| 2326 | ||
| 2327 | req.once ('upgrade' , function upgrade(r es, socket , upgradeH ead) { | |
| 2328 | if (se lf.readySt ate === We bSocket.CL OSED) { | |
| 2329 | // c lient clos ed before server acc epted conn ection | |
| 2330 | self .emit('clo se'); | |
| 2331 | self .removeAll Listeners( ); | |
| 2332 | sock et.end(); | |
| 2333 | retu rn; | |
| 2334 | } | |
| 2335 | ||
| 2336 | var se rverKey = res.header s['sec-web socket-acc ept']; | |
| 2337 | if (ty peof serve rKey === ' undefined' || server Key !== ex pectedServ erKey) { | |
| 2338 | self .emit('err or', 'inva lid server key'); | |
| 2339 | self .removeAll Listeners( ); | |
| 2340 | sock et.end(); | |
| 2341 | retu rn; | |
| 2342 | } | |
| 2343 | ||
| 2344 | var se rverProt = res.heade rs['sec-we bsocket-pr otocol']; | |
| 2345 | var pr otList = ( options.va lue.protoc ol || ""). split(/, * /); | |
| 2346 | var pr otError = null; | |
| 2347 | ||
| 2348 | if (!o ptions.val ue.protoco l && serve rProt) { | |
| 2349 | prot Error = 's erver sent a subprot ocol even though non e requeste d'; | |
| 2350 | } else if (optio ns.value.p rotocol && !serverPr ot) { | |
| 2351 | prot Error = 's erver sent no subpro tocol even though re quested'; | |
| 2352 | } else if (serve rProt && p rotList.in dexOf(serv erProt) == = -1) { | |
| 2353 | prot Error = 's erver resp onded with an invali d protocol '; | |
| 2354 | } | |
| 2355 | ||
| 2356 | if (pr otError) { | |
| 2357 | self .emit('err or', protE rror); | |
| 2358 | self .removeAll Listeners( ); | |
| 2359 | sock et.end(); | |
| 2360 | retu rn; | |
| 2361 | } else if (serve rProt) { | |
| 2362 | self .protocol = serverPr ot; | |
| 2363 | } | |
| 2364 | ||
| 2365 | var se rverExtens ions = Ext ensions.pa rse(res.he aders['sec -websocket -extension s']); | |
| 2366 | if (pe rMessageDe flate && s erverExten sions[PerM essageDefl ate.extens ionName]) { | |
| 2367 | try { | |
| 2368 | pe rMessageDe flate.acce pt(serverE xtensions[ PerMessage Deflate.ex tensionNam e]); | |
| 2369 | } ca tch (err) { | |
| 2370 | se lf.emit('e rror', 'in valid exte nsion para meter'); | |
| 2371 | se lf.removeA llListener s(); | |
| 2372 | so cket.end() ; | |
| 2373 | re turn; | |
| 2374 | } | |
| 2375 | self .extension s[PerMessa geDeflate. extensionN ame] = per MessageDef late; | |
| 2376 | } | |
| 2377 | ||
| 2378 | establ ishConnect ion.call(s elf, Recei ver, Sende r, socket, upgradeHe ad); | |
| 2379 | ||
| 2380 | // per form clean up on http resources | |
| 2381 | req.re moveAllLis teners(); | |
| 2382 | req = null; | |
| 2383 | agent = null; | |
| 2384 | }); | |
| 2385 | ||
| 2386 | req.end( ); | |
| 2387 | this.rea dyState = WebSocket. CONNECTING ; | |
| 2388 | } | |
| 2389 | ||
| 2390 | function e stablishCo nnection(R eceiverCla ss, Sender Class, soc ket, upgra deHead) { | |
| 2391 | var ultr on = this. _ultron = new Ultron (socket) | |
| 2392 | , call ed = false | |
| 2393 | , self = this; | |
| 2394 | ||
| 2395 | socket.s etTimeout( 0); | |
| 2396 | socket.s etNoDelay( true); | |
| 2397 | ||
| 2398 | this._re ceiver = n ew Receive rClass(thi s.extensio ns,this.ma xPayload); | |
| 2399 | this._so cket = soc ket; | |
| 2400 | ||
| 2401 | // socke t cleanup handlers | |
| 2402 | ultron.o n('end', c leanupWebs ocketResou rces.bind( this)); | |
| 2403 | ultron.o n('close', cleanupWe bsocketRes ources.bin d(this)); | |
| 2404 | ultron.o n('error', cleanupWe bsocketRes ources.bin d(this)); | |
| 2405 | ||
| 2406 | // ensur e that the upgradeHe ad is adde d to the r eceiver | |
| 2407 | function firstHand ler(data) { | |
| 2408 | if (ca lled || se lf.readySt ate === We bSocket.CL OSED) retu rn; | |
| 2409 | ||
| 2410 | called = true; | |
| 2411 | socket .removeLis tener('dat a', firstH andler); | |
| 2412 | ultron .on('data' , realHand ler); | |
| 2413 | ||
| 2414 | if (up gradeHead && upgrade Head.lengt h > 0) { | |
| 2415 | real Handler(up gradeHead) ; | |
| 2416 | upgr adeHead = null; | |
| 2417 | } | |
| 2418 | ||
| 2419 | if (da ta) realHa ndler(data ); | |
| 2420 | } | |
| 2421 | ||
| 2422 | // subse quent pack ets are pu shed strai ght to the receiver | |
| 2423 | function realHandl er(data) { | |
| 2424 | self.b ytesReceiv ed += data .length; | |
| 2425 | self._ receiver.a dd(data); | |
| 2426 | } | |
| 2427 | ||
| 2428 | ultron.o n('data', firstHandl er); | |
| 2429 | ||
| 2430 | // if da ta was pas sed along with the h ttp upgrad e, | |
| 2431 | // this will sched ule a push of that o n to the r eceiver. | |
| 2432 | // this has to be done on ne xt tick, s ince the c aller | |
| 2433 | // hasn' t had a ch ance to se t event ha ndlers on this clien t | |
| 2434 | // objec t yet. | |
| 2435 | process. nextTick(f irstHandle r); | |
| 2436 | ||
| 2437 | // recei ver event handlers | |
| 2438 | self._re ceiver.ont ext = func tion ontex t(data, fl ags) { | |
| 2439 | flags = flags || {}; | |
| 2440 | ||
| 2441 | self.e mit('messa ge', data, flags); | |
| 2442 | }; | |
| 2443 | ||
| 2444 | self._re ceiver.onb inary = fu nction onb inary(data , flags) { | |
| 2445 | flags = flags || {}; | |
| 2446 | ||
| 2447 | flags. binary = t rue; | |
| 2448 | self.e mit('messa ge', data, flags); | |
| 2449 | }; | |
| 2450 | ||
| 2451 | self._re ceiver.onp ing = func tion onpin g(data, fl ags) { | |
| 2452 | flags = flags || {}; | |
| 2453 | ||
| 2454 | self.p ong(data, { | |
| 2455 | mask : !self._i sServer, | |
| 2456 | bina ry: flags. binary === true | |
| 2457 | }, tru e); | |
| 2458 | ||
| 2459 | self.e mit('ping' , data, fl ags); | |
| 2460 | }; | |
| 2461 | ||
| 2462 | self._re ceiver.onp ong = func tion onpon g(data, fl ags) { | |
| 2463 | self.e mit('pong' , data, fl ags || {}) ; | |
| 2464 | }; | |
| 2465 | ||
| 2466 | self._re ceiver.onc lose = fun ction oncl ose(code, data, flag s) { | |
| 2467 | flags = flags || {}; | |
| 2468 | ||
| 2469 | self._ closeRecei ved = true ; | |
| 2470 | self.c lose(code, data); | |
| 2471 | }; | |
| 2472 | ||
| 2473 | self._re ceiver.one rror = fun ction oner ror(reason , errorCod e) { | |
| 2474 | // clo se the con nection wh en the rec eiver repo rts a HyBi error cod e | |
| 2475 | self.c lose(typeo f errorCod e !== 'und efined' ? errorCode : 1002, '' ); | |
| 2476 | self.e mit('error ', (reason instanceo f Error) ? reason : (new Error (reason))) ; | |
| 2477 | }; | |
| 2478 | ||
| 2479 | // final ize the cl ient | |
| 2480 | this._se nder = new SenderCla ss(socket, this.exte nsions); | |
| 2481 | this._se nder.on('e rror', fun ction oner ror(error) { | |
| 2482 | self.c lose(1002, ''); | |
| 2483 | self.e mit('error ', error); | |
| 2484 | }); | |
| 2485 | ||
| 2486 | this.rea dyState = WebSocket. OPEN; | |
| 2487 | this.emi t('open'); | |
| 2488 | } | |
| 2489 | ||
| 2490 | function s tartQueue( instance) { | |
| 2491 | instance ._queue = instance._ queue || [ ]; | |
| 2492 | } | |
| 2493 | ||
| 2494 | function e xecuteQueu eSends(ins tance) { | |
| 2495 | var queu e = instan ce._queue; | |
| 2496 | if (type of queue = == 'undefi ned') retu rn; | |
| 2497 | ||
| 2498 | delete i nstance._q ueue; | |
| 2499 | for (var i = 0, l = queue.le ngth; i < l; ++i) { | |
| 2500 | queue[ i](); | |
| 2501 | } | |
| 2502 | } | |
| 2503 | ||
| 2504 | function s endStream( instance, stream, op tions, cb) { | |
| 2505 | stream.o n('data', function i ncoming(da ta) { | |
| 2506 | if (in stance.rea dyState != = WebSocke t.OPEN) { | |
| 2507 | if ( typeof cb === 'funct ion') cb(n ew Error(' not opened ')); | |
| 2508 | else { | |
| 2509 | de lete insta nce._queue ; | |
| 2510 | in stance.emi t('error', new Error ('not open ed')); | |
| 2511 | } | |
| 2512 | retu rn; | |
| 2513 | } | |
| 2514 | ||
| 2515 | option s.fin = fa lse; | |
| 2516 | instan ce._sender .send(data , options) ; | |
| 2517 | }); | |
| 2518 | ||
| 2519 | stream.o n('end', f unction en d() { | |
| 2520 | if (in stance.rea dyState != = WebSocke t.OPEN) { | |
| 2521 | if ( typeof cb === 'funct ion') cb(n ew Error(' not opened ')); | |
| 2522 | else { | |
| 2523 | de lete insta nce._queue ; | |
| 2524 | in stance.emi t('error', new Error ('not open ed')); | |
| 2525 | } | |
| 2526 | retu rn; | |
| 2527 | } | |
| 2528 | ||
| 2529 | option s.fin = tr ue; | |
| 2530 | instan ce._sender .send(null , options) ; | |
| 2531 | ||
| 2532 | if (ty peof cb == = 'functio n') cb(nul l); | |
| 2533 | }); | |
| 2534 | } | |
| 2535 | ||
| 2536 | function c leanupWebs ocketResou rces(error ) { | |
| 2537 | if (this .readyStat e === WebS ocket.CLOS ED) return ; | |
| 2538 | ||
| 2539 | this.rea dyState = WebSocket. CLOSED; | |
| 2540 | ||
| 2541 | clearTim eout(this. _closeTime r); | |
| 2542 | this._cl oseTimer = null; | |
| 2543 | ||
| 2544 | // If th e connecti on was clo sed abnorm ally (with an error) , or if | |
| 2545 | // the c lose contr ol frame w as not rec eived then the close code | |
| 2546 | // must default to 1006. | |
| 2547 | if (erro r || !this ._closeRec eived) { | |
| 2548 | this._ closeCode = 1006; | |
| 2549 | } | |
| 2550 | this.emi t('close', this._clo seCode || 1000, this ._closeMes sage || '' ); | |
| 2551 | ||
| 2552 | if (this ._socket) { | |
| 2553 | if (th is._ultron ) this._ul tron.destr oy(); | |
| 2554 | this._ socket.on( 'error', f unction on error() { | |
| 2555 | try { this.des troy(); } | |
| 2556 | catc h (e) {} | |
| 2557 | }); | |
| 2558 | ||
| 2559 | try { | |
| 2560 | if ( !error) th is._socket .end(); | |
| 2561 | else this._soc ket.destro y(); | |
| 2562 | } catc h (e) { /* Ignore te rmination errors */ } | |
| 2563 | ||
| 2564 | this._ socket = n ull; | |
| 2565 | this._ ultron = n ull; | |
| 2566 | } | |
| 2567 | ||
| 2568 | if (this ._sender) { | |
| 2569 | this._ sender.rem oveAllList eners(); | |
| 2570 | this._ sender = n ull; | |
| 2571 | } | |
| 2572 | ||
| 2573 | if (this ._receiver ) { | |
| 2574 | this._ receiver.c leanup(); | |
| 2575 | this._ receiver = null; | |
| 2576 | } | |
| 2577 | ||
| 2578 | if (this .extension s[PerMessa geDeflate. extensionN ame]) { | |
| 2579 | this.e xtensions[ PerMessage Deflate.ex tensionNam e].cleanup (); | |
| 2580 | } | |
| 2581 | ||
| 2582 | this.ext ensions = null; | |
| 2583 | ||
| 2584 | this.rem oveAllList eners(); | |
| 2585 | this.on( 'error', f unction on error() {} ); // catc h all erro rs after t his | |
| 2586 | delete t his._queue ; | |
| 2587 | } | |
| 2588 | \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000pa ckage/lib/ BufferUtil .fallback. js\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x000000 0644 \x00000007 65 \x0000000024 \x000000000026 06 \x0000127027 10666\x00000154 53 \x00000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000ustar \x000000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000000 000 \x000000000 0 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 /*! | |
| 2589 | * ws: a n ode.js web socket cli ent | |
| 2590 | * Copyrig ht(c) 2011 Einar Ott o Stangvik <einaros@ gmail.com> | |
| 2591 | * MIT Lic ensed | |
| 2592 | */ | |
| 2593 | ||
| 2594 | exports.Bu fferUtil = { | |
| 2595 | merge: f unction(me rgedBuffer , buffers) { | |
| 2596 | var of fset = 0; | |
| 2597 | for (v ar i = 0, l = buffer s.length; i < l; ++i ) { | |
| 2598 | var buf = buff ers[i]; | |
| 2599 | buf. copy(merge dBuffer, o ffset); | |
| 2600 | offs et += buf. length; | |
| 2601 | } | |
| 2602 | }, | |
| 2603 | mask: fu nction(sou rce, mask, output, o ffset, len gth) { | |
| 2604 | var ma skNum = ma sk.readUIn t32LE(0, t rue); | |
| 2605 | var i = 0; | |
| 2606 | for (; i < lengt h - 3; i + = 4) { | |
| 2607 | var num = mask Num ^ sour ce.readUIn t32LE(i, t rue); | |
| 2608 | if ( num < 0) n um = 42949 67296 + nu m; | |
| 2609 | outp ut.writeUI nt32LE(num , offset + i, true); | |
| 2610 | } | |
| 2611 | switch (length % 4) { | |
| 2612 | case 3: output [offset + i + 2] = s ource[i + 2] ^ mask[ 2]; | |
| 2613 | case 2: output [offset + i + 1] = s ource[i + 1] ^ mask[ 1]; | |
| 2614 | case 1: output [offset + i] = sourc e[i] ^ mas k[0]; | |
| 2615 | case 0:; | |
| 2616 | } | |
| 2617 | }, | |
| 2618 | unmask: function(d ata, mask) { | |
| 2619 | var ma skNum = ma sk.readUIn t32LE(0, t rue); | |
| 2620 | var le ngth = dat a.length; | |
| 2621 | var i = 0; | |
| 2622 | for (; i < lengt h - 3; i + = 4) { | |
| 2623 | var num = mask Num ^ data .readUInt3 2LE(i, tru e); | |
| 2624 | if ( num < 0) n um = 42949 67296 + nu m; | |
| 2625 | data .writeUInt 32LE(num, i, true); | |
| 2626 | } | |
| 2627 | switch (length % 4) { | |
| 2628 | case 3: data[i + 2] = da ta[i + 2] ^ mask[2]; | |
| 2629 | case 2: data[i + 1] = da ta[i + 1] ^ mask[1]; | |
| 2630 | case 1: data[i ] = data[i ] ^ mask[0 ]; | |
| 2631 | case 0:; | |
| 2632 | } | |
| 2633 | } | |
| 2634 | } | |
| 2635 | \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000package/ lib/WebSoc ketServer. js\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000000644 \x0000 000765 \x000000 0024 \x00000000 041032 \x000012 702710666\x0000 014717 \x00000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000u star\x000000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000000000 \x00000 00000 \x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000/*! | |
| 2636 | * ws: a n ode.js web socket cli ent | |
| 2637 | * Copyrig ht(c) 2011 Einar Ott o Stangvik <einaros@ gmail.com> | |
| 2638 | * MIT Lic ensed | |
| 2639 | */ | |
| 2640 | ||
| 2641 | var util = require(' util') | |
| 2642 | , events = require ('events') | |
| 2643 | , http = require(' http') | |
| 2644 | , crypto = require ('crypto') | |
| 2645 | , Option s = requir e('options ') | |
| 2646 | , WebSoc ket = requ ire('./Web Socket') | |
| 2647 | , Extens ions = req uire('./Ex tensions') | |
| 2648 | , PerMes sageDeflat e = requir e('./PerMe ssageDefla te') | |
| 2649 | , tls = require('t ls') | |
| 2650 | , url = require('u rl'); | |
| 2651 | ||
| 2652 | /** | |
| 2653 | * WebSock et Server implementa tion | |
| 2654 | */ | |
| 2655 | ||
| 2656 | function W ebSocketSe rver(optio ns, callba ck) { | |
| 2657 | if (this instanceo f WebSocke tServer == = false) { | |
| 2658 | return new WebSo cketServer (options, callback); | |
| 2659 | } | |
| 2660 | ||
| 2661 | events.E ventEmitte r.call(thi s); | |
| 2662 | ||
| 2663 | options = new Opti ons({ | |
| 2664 | host: '0.0.0.0', | |
| 2665 | port: null, | |
| 2666 | server : null, | |
| 2667 | verify Client: nu ll, | |
| 2668 | handle Protocols: null, | |
| 2669 | path: null, | |
| 2670 | noServ er: false, | |
| 2671 | disabl eHixie: fa lse, | |
| 2672 | client Tracking: true, | |
| 2673 | perMes sageDeflat e: true, | |
| 2674 | maxPay load: null | |
| 2675 | }).merge (options); | |
| 2676 | ||
| 2677 | if (!opt ions.isDef inedAndNon Null('port ') && !opt ions.isDef inedAndNon Null('serv er') && !o ptions.val ue.noServe r) { | |
| 2678 | throw new TypeEr ror('`port ` or a `se rver` must be provid ed'); | |
| 2679 | } | |
| 2680 | ||
| 2681 | var self = this; | |
| 2682 | ||
| 2683 | if (opti ons.isDefi nedAndNonN ull('port' )) { | |
| 2684 | this._ server = h ttp.create Server(fun ction (req , res) { | |
| 2685 | var body = htt p.STATUS_C ODES[426]; | |
| 2686 | res. writeHead( 426, { | |
| 2687 | 'C ontent-Len gth': body .length, | |
| 2688 | 'C ontent-Typ e': 'text/ plain' | |
| 2689 | }); | |
| 2690 | res. end(body); | |
| 2691 | }); | |
| 2692 | this._ server.all owHalfOpen = false; | |
| 2693 | this._ server.lis ten(option s.value.po rt, option s.value.ho st, callba ck); | |
| 2694 | this._ closeServe r = functi on() { if (self._ser ver) self. _server.cl ose(); }; | |
| 2695 | } | |
| 2696 | else if (options.v alue.serve r) { | |
| 2697 | this._ server = o ptions.val ue.server; | |
| 2698 | if (op tions.valu e.path) { | |
| 2699 | // t ake note o f the path , to avoid collision s when mul tiple webs ocket serv ers are | |
| 2700 | // l istening o n the same http serv er | |
| 2701 | if ( this._serv er._webSoc ketPaths & & options. value.serv er._webSoc ketPaths[o ptions.val ue.path]) { | |
| 2702 | th row new Er ror('two i nstances o f WebSocke tServer ca nnot liste n on the s ame http s erver path '); | |
| 2703 | } | |
| 2704 | if ( typeof thi s._server. _webSocket Paths !== 'object') { | |
| 2705 | th is._server ._webSocke tPaths = { }; | |
| 2706 | } | |
| 2707 | this ._server._ webSocketP aths[optio ns.value.p ath] = 1; | |
| 2708 | } | |
| 2709 | } | |
| 2710 | if (this ._server) { | |
| 2711 | this._ onceServer Listening = function () { self. emit('list ening'); } ; | |
| 2712 | this._ server.onc e('listeni ng', this. _onceServe rListening ); | |
| 2713 | } | |
| 2714 | ||
| 2715 | if (type of this._s erver != ' undefined' ) { | |
| 2716 | this._ onServerEr ror = func tion(error ) { self.e mit('error ', error) }; | |
| 2717 | this._ server.on( 'error', t his._onSer verError); | |
| 2718 | this._ onServerUp grade = fu nction(req , socket, upgradeHea d) { | |
| 2719 | //co py upgrade Head to av oid retent ion of lar ge slab bu ffers used in node c ore | |
| 2720 | var head = new Buffer(up gradeHead. length); | |
| 2721 | upgr adeHead.co py(head); | |
| 2722 | ||
| 2723 | self .handleUpg rade(req, socket, he ad, functi on(client) { | |
| 2724 | se lf.emit('c onnection' +req.url, client); | |
| 2725 | se lf.emit('c onnection' , client); | |
| 2726 | }); | |
| 2727 | }; | |
| 2728 | this._ server.on( 'upgrade', this._onS erverUpgra de); | |
| 2729 | } | |
| 2730 | ||
| 2731 | this.opt ions = opt ions.value ; | |
| 2732 | this.pat h = option s.value.pa th; | |
| 2733 | this.cli ents = []; | |
| 2734 | } | |
| 2735 | ||
| 2736 | /** | |
| 2737 | * Inherit s from Eve ntEmitter. | |
| 2738 | */ | |
| 2739 | ||
| 2740 | util.inher its(WebSoc ketServer, events.Ev entEmitter ); | |
| 2741 | ||
| 2742 | /** | |
| 2743 | * Immedia tely shuts down the connection . | |
| 2744 | * | |
| 2745 | * @api pu blic | |
| 2746 | */ | |
| 2747 | ||
| 2748 | WebSocketS erver.prot otype.clos e = functi on(callbac k) { | |
| 2749 | // termi nate all a ssociated clients | |
| 2750 | var erro r = null; | |
| 2751 | try { | |
| 2752 | for (v ar i = 0, l = this.c lients.len gth; i < l ; ++i) { | |
| 2753 | this .clients[i ].terminat e(); | |
| 2754 | } | |
| 2755 | } | |
| 2756 | catch (e ) { | |
| 2757 | error = e; | |
| 2758 | } | |
| 2759 | ||
| 2760 | // remov e path des criptor, i f any | |
| 2761 | if (this .path && t his._serve r._webSock etPaths) { | |
| 2762 | delete this._ser ver._webSo cketPaths[ this.path] ; | |
| 2763 | if (Ob ject.keys( this._serv er._webSoc ketPaths). length == 0) { | |
| 2764 | dele te this._s erver._web SocketPath s; | |
| 2765 | } | |
| 2766 | } | |
| 2767 | ||
| 2768 | // close the http server if it was int ernally cr eated | |
| 2769 | try { | |
| 2770 | if (ty peof this. _closeServ er !== 'un defined') { | |
| 2771 | this ._closeSer ver(); | |
| 2772 | } | |
| 2773 | } | |
| 2774 | finally { | |
| 2775 | if (th is._server ) { | |
| 2776 | this ._server.r emoveListe ner('liste ning', thi s._onceSer verListeni ng); | |
| 2777 | this ._server.r emoveListe ner('error ', this._o nServerErr or); | |
| 2778 | this ._server.r emoveListe ner('upgra de', this. _onServerU pgrade); | |
| 2779 | } | |
| 2780 | delete this._ser ver; | |
| 2781 | } | |
| 2782 | if(callb ack) | |
| 2783 | callba ck(error); | |
| 2784 | else if( error) | |
| 2785 | throw error; | |
| 2786 | } | |
| 2787 | ||
| 2788 | /** | |
| 2789 | * Handle a HTTP Upg rade reque st. | |
| 2790 | * | |
| 2791 | * @api pu blic | |
| 2792 | */ | |
| 2793 | ||
| 2794 | WebSocketS erver.prot otype.hand leUpgrade = function (req, sock et, upgrad eHead, cb) { | |
| 2795 | // check for wrong path | |
| 2796 | if (this .options.p ath) { | |
| 2797 | var u = url.pars e(req.url) ; | |
| 2798 | if (u && u.pathn ame !== th is.options .path) ret urn; | |
| 2799 | } | |
| 2800 | ||
| 2801 | if (type of req.hea ders.upgra de === 'un defined' | | req.head ers.upgrad e.toLowerC ase() !== 'websocket ') { | |
| 2802 | abortC onnection( socket, 40 0, 'Bad Re quest'); | |
| 2803 | return ; | |
| 2804 | } | |
| 2805 | ||
| 2806 | if (req. headers['s ec-websock et-key1']) handleHix ieUpgrade. apply(this , argument s); | |
| 2807 | else han dleHybiUpg rade.apply (this, arg uments); | |
| 2808 | } | |
| 2809 | ||
| 2810 | module.exp orts = Web SocketServ er; | |
| 2811 | ||
| 2812 | /** | |
| 2813 | * Entirel y private apis, | |
| 2814 | * which m ay or may not be bou nd to a se pcific Web Socket ins tance. | |
| 2815 | */ | |
| 2816 | ||
| 2817 | function h andleHybiU pgrade(req , socket, upgradeHea d, cb) { | |
| 2818 | // handl e prematur e socket e rrors | |
| 2819 | var erro rHandler = function( ) { | |
| 2820 | try { socket.des troy(); } catch (e) {} | |
| 2821 | } | |
| 2822 | socket.o n('error', errorHand ler); | |
| 2823 | ||
| 2824 | // verif y key pres ence | |
| 2825 | if (!req .headers[' sec-websoc ket-key']) { | |
| 2826 | abortC onnection( socket, 40 0, 'Bad Re quest'); | |
| 2827 | return ; | |
| 2828 | } | |
| 2829 | ||
| 2830 | // verif y version | |
| 2831 | var vers ion = pars eInt(req.h eaders['se c-websocke t-version' ]); | |
| 2832 | if ([8, 13].indexO f(version) === -1) { | |
| 2833 | abortC onnection( socket, 40 0, 'Bad Re quest'); | |
| 2834 | return ; | |
| 2835 | } | |
| 2836 | ||
| 2837 | // verif y protocol | |
| 2838 | var prot ocols = re q.headers[ 'sec-webso cket-proto col']; | |
| 2839 | ||
| 2840 | // verif y client | |
| 2841 | var orig in = versi on < 13 ? | |
| 2842 | req.he aders['sec -websocket -origin'] : | |
| 2843 | req.he aders['ori gin']; | |
| 2844 | ||
| 2845 | // handl e extensio ns offer | |
| 2846 | var exte nsionsOffe r = Extens ions.parse (req.heade rs['sec-we bsocket-ex tensions'] ); | |
| 2847 | ||
| 2848 | // handl er to call when the connection sequence completes | |
| 2849 | var self = this; | |
| 2850 | var comp leteHybiUp grade2 = f unction(pr otocol) { | |
| 2851 | ||
| 2852 | // cal c key | |
| 2853 | var ke y = req.he aders['sec -websocket -key']; | |
| 2854 | var sh asum = cry pto.create Hash('sha1 '); | |
| 2855 | shasum .update(ke y + "258EA FA5-E914-4 7DA-95CA-C 5AB0DC85B1 1"); | |
| 2856 | key = shasum.dig est('base6 4'); | |
| 2857 | ||
| 2858 | var he aders = [ | |
| 2859 | 'H TTP/1.1 10 1 Switchin g Protocol s' | |
| 2860 | , 'U pgrade: we bsocket' | |
| 2861 | , 'C onnection: Upgrade' | |
| 2862 | , 'S ec-WebSock et-Accept: ' + key | |
| 2863 | ]; | |
| 2864 | ||
| 2865 | if (ty peof proto col != 'un defined') { | |
| 2866 | head ers.push(' Sec-WebSoc ket-Protoc ol: ' + pr otocol); | |
| 2867 | } | |
| 2868 | ||
| 2869 | var ex tensions = {}; | |
| 2870 | try { | |
| 2871 | exte nsions = a cceptExten sions.call (self, ext ensionsOff er); | |
| 2872 | } catc h (err) { | |
| 2873 | abor tConnectio n(socket, 400, 'Bad Request'); | |
| 2874 | retu rn; | |
| 2875 | } | |
| 2876 | ||
| 2877 | if (Ob ject.keys( extensions ).length) { | |
| 2878 | var serverExte nsions = { }; | |
| 2879 | Obje ct.keys(ex tensions). forEach(fu nction(tok en) { | |
| 2880 | se rverExtens ions[token ] = [exten sions[toke n].params] | |
| 2881 | }); | |
| 2882 | head ers.push(' Sec-WebSoc ket-Extens ions: ' + Extensions .format(se rverExtens ions)); | |
| 2883 | } | |
| 2884 | ||
| 2885 | // all ows extern al modific ation/insp ection of handshake headers | |
| 2886 | self.e mit('heade rs', heade rs); | |
| 2887 | ||
| 2888 | socket .setTimeou t(0); | |
| 2889 | socket .setNoDela y(true); | |
| 2890 | try { | |
| 2891 | sock et.write(h eaders.con cat('', '' ).join('\r \n')); | |
| 2892 | } | |
| 2893 | catch (e) { | |
| 2894 | // i f the upgr ade write fails, shu t the conn ection dow n hard | |
| 2895 | try { socket.d estroy(); } catch (e ) {} | |
| 2896 | retu rn; | |
| 2897 | } | |
| 2898 | ||
| 2899 | var cl ient = new WebSocket ([req, soc ket, upgra deHead], { | |
| 2900 | prot ocolVersio n: version , | |
| 2901 | prot ocol: prot ocol, | |
| 2902 | exte nsions: ex tensions, | |
| 2903 | maxP ayload: se lf.options .maxPayloa d | |
| 2904 | }); | |
| 2905 | ||
| 2906 | if (se lf.options .clientTra cking) { | |
| 2907 | self .clients.p ush(client ); | |
| 2908 | clie nt.on('clo se', funct ion() { | |
| 2909 | va r index = self.clien ts.indexOf (client); | |
| 2910 | if (index != -1) { | |
| 2911 | self.clien ts.splice( index, 1); | |
| 2912 | } | |
| 2913 | }); | |
| 2914 | } | |
| 2915 | ||
| 2916 | // sig nal upgrad e complete | |
| 2917 | socket .removeLis tener('err or', error Handler); | |
| 2918 | cb(cli ent); | |
| 2919 | } | |
| 2920 | ||
| 2921 | // optio nally call external protocol s election h andler bef ore | |
| 2922 | // calli ng complet eHybiUpgra de2 | |
| 2923 | var comp leteHybiUp grade1 = f unction() { | |
| 2924 | // cho ose from t he sub-pro tocols | |
| 2925 | if (ty peof self. options.ha ndleProtoc ols == 'fu nction') { | |
| 2926 | va r protList = (protoc ols || "") .split(/, */); | |
| 2927 | va r callback Called = f alse; | |
| 2928 | va r res = se lf.options .handlePro tocols(pro tList, fun ction(resu lt, protoc ol) { | |
| 2929 | callbackCa lled = tru e; | |
| 2930 | if (!resul t) abortCo nnection(s ocket, 401 , 'Unautho rized'); | |
| 2931 | else compl eteHybiUpg rade2(prot ocol); | |
| 2932 | }) ; | |
| 2933 | if (!callbac kCalled) { | |
| 2934 | // the h andleProto cols handl er never c alled our callback | |
| 2935 | abortCon nection(so cket, 501, 'Could no t process protocols' ); | |
| 2936 | } | |
| 2937 | re turn; | |
| 2938 | } else { | |
| 2939 | if (typeof p rotocols ! == 'undefi ned') { | |
| 2940 | complete HybiUpgrad e2(protoco ls.split(/ , */)[0]); | |
| 2941 | } | |
| 2942 | el se { | |
| 2943 | complete HybiUpgrad e2(); | |
| 2944 | } | |
| 2945 | } | |
| 2946 | } | |
| 2947 | ||
| 2948 | // optio nally call external client ver ification handler | |
| 2949 | if (type of this.op tions.veri fyClient = = 'functio n') { | |
| 2950 | var in fo = { | |
| 2951 | orig in: origin , | |
| 2952 | secu re: typeof req.conne ction.auth orized !== 'undefine d' || type of req.con nection.en crypted != = 'undefin ed', | |
| 2953 | req: req | |
| 2954 | }; | |
| 2955 | if (th is.options .verifyCli ent.length == 2) { | |
| 2956 | this .options.v erifyClien t(info, fu nction(res ult, code, name) { | |
| 2957 | if (typeof c ode === 'u ndefined') code = 40 1; | |
| 2958 | if (typeof n ame === 'u ndefined') name = ht tp.STATUS_ CODES[code ]; | |
| 2959 | ||
| 2960 | if (!result) abortConn ection(soc ket, code, name); | |
| 2961 | el se complet eHybiUpgra de1(); | |
| 2962 | }); | |
| 2963 | retu rn; | |
| 2964 | } | |
| 2965 | else i f (!this.o ptions.ver ifyClient( info)) { | |
| 2966 | abor tConnectio n(socket, 401, 'Unau thorized') ; | |
| 2967 | retu rn; | |
| 2968 | } | |
| 2969 | } | |
| 2970 | ||
| 2971 | complete HybiUpgrad e1(); | |
| 2972 | } | |
| 2973 | ||
| 2974 | function h andleHixie Upgrade(re q, socket, upgradeHe ad, cb) { | |
| 2975 | // handl e prematur e socket e rrors | |
| 2976 | var erro rHandler = function( ) { | |
| 2977 | try { socket.des troy(); } catch (e) {} | |
| 2978 | } | |
| 2979 | socket.o n('error', errorHand ler); | |
| 2980 | ||
| 2981 | // bail if options prevent h ixie | |
| 2982 | if (this .options.d isableHixi e) { | |
| 2983 | abortC onnection( socket, 40 1, 'Hixie support di sabled'); | |
| 2984 | return ; | |
| 2985 | } | |
| 2986 | ||
| 2987 | // verif y key pres ence | |
| 2988 | if (!req .headers[' sec-websoc ket-key2'] ) { | |
| 2989 | abortC onnection( socket, 40 0, 'Bad Re quest'); | |
| 2990 | return ; | |
| 2991 | } | |
| 2992 | ||
| 2993 | var orig in = req.h eaders['or igin'] | |
| 2994 | , self = this; | |
| 2995 | ||
| 2996 | // setup handshake completio n to run a fter clien t has been verified | |
| 2997 | var onCl ientVerifi ed = funct ion() { | |
| 2998 | var ws host; | |
| 2999 | if (!r eq.headers ['x-forwar ded-host'] ) | |
| 3000 | ws host = req .headers.h ost; | |
| 3001 | else | |
| 3002 | ws host = req .headers[' x-forwarde d-host']; | |
| 3003 | var lo cation = ( (req.heade rs['x-forw arded-prot o'] === 'h ttps' || s ocket.encr ypted) ? ' wss' : 'ws ') + '://' + wshost + req.url | |
| 3004 | , pr otocol = r eq.headers ['sec-webs ocket-prot ocol']; | |
| 3005 | ||
| 3006 | // bui ld the res ponse head er and ret urn a Buff er | |
| 3007 | var bu ildRespons eHeader = function() { | |
| 3008 | var headers = [ | |
| 3009 | 'HTTP/1.1 101 Switch ing Protoc ols' | |
| 3010 | , 'Upgrade: WebSocket' | |
| 3011 | , 'Connectio n: Upgrade ' | |
| 3012 | , 'Sec-WebSo cket-Locat ion: ' + l ocation | |
| 3013 | ]; | |
| 3014 | if ( typeof pro tocol != ' undefined' ) headers. push('Sec- WebSocket- Protocol: ' + protoc ol); | |
| 3015 | if ( typeof ori gin != 'un defined') headers.pu sh('Sec-We bSocket-Or igin: ' + origin); | |
| 3016 | ||
| 3017 | retu rn new Buf fer(header s.concat(' ', '').joi n('\r\n')) ; | |
| 3018 | }; | |
| 3019 | ||
| 3020 | // sen d handshak e response before re ceiving th e nonce | |
| 3021 | var ha ndshakeRes ponse = fu nction() { | |
| 3022 | ||
| 3023 | sock et.setTime out(0); | |
| 3024 | sock et.setNoDe lay(true); | |
| 3025 | ||
| 3026 | var headerBuff er = build ResponseHe ader(); | |
| 3027 | ||
| 3028 | try { | |
| 3029 | so cket.write (headerBuf fer, 'bina ry', funct ion(err) { | |
| 3030 | // remove listener i f there wa s an error | |
| 3031 | if (err) s ocket.remo veListener ('data', h andler); | |
| 3032 | return; | |
| 3033 | }) ; | |
| 3034 | } ca tch (e) { | |
| 3035 | tr y { socket .destroy() ; } catch (e) {} | |
| 3036 | re turn; | |
| 3037 | }; | |
| 3038 | }; | |
| 3039 | ||
| 3040 | // han dshake com pletion co de to run once nonce has been successful ly retriev ed | |
| 3041 | var co mpleteHand shake = fu nction(non ce, rest, headerBuff er) { | |
| 3042 | // c alculate k ey | |
| 3043 | var k1 = req.h eaders['se c-websocke t-key1'] | |
| 3044 | , k2 = req.h eaders['se c-websocke t-key2'] | |
| 3045 | , md5 = cryp to.createH ash('md5') ; | |
| 3046 | ||
| 3047 | [k1, k2].forEa ch(functio n (k) { | |
| 3048 | va r n = pars eInt(k.rep lace(/[^\d ]/g, '')) | |
| 3049 | , spaces = k.replace (/[^ ]/g, '').length ; | |
| 3050 | if (spaces = == 0 || n % spaces ! == 0){ | |
| 3051 | abortConne ction(sock et, 400, ' Bad Reques t'); | |
| 3052 | return; | |
| 3053 | } | |
| 3054 | n /= spaces; | |
| 3055 | md 5.update(S tring.from CharCode( | |
| 3056 | n >> 24 & 0xFF, | |
| 3057 | n >> 16 & 0xFF, | |
| 3058 | n >> 8 & 0xFF, | |
| 3059 | n & 0xFF)); | |
| 3060 | }); | |
| 3061 | md5. update(non ce.toStrin g('binary' )); | |
| 3062 | ||
| 3063 | sock et.setTime out(0); | |
| 3064 | sock et.setNoDe lay(true); | |
| 3065 | ||
| 3066 | try { | |
| 3067 | va r hashBuff er = new B uffer(md5. digest('bi nary'), 'b inary'); | |
| 3068 | va r handshak eBuffer = new Buffer (headerBuf fer.length + hashBuf fer.length ); | |
| 3069 | he aderBuffer .copy(hand shakeBuffe r, 0); | |
| 3070 | ha shBuffer.c opy(handsh akeBuffer, headerBuf fer.length ); | |
| 3071 | ||
| 3072 | // do a sing le write, which - up on success - causes a new clie nt websock et to be s etup | |
| 3073 | so cket.write (handshake Buffer, 'b inary', fu nction(err ) { | |
| 3074 | if (err) r eturn; // do not cre ate client if an err or happens | |
| 3075 | var client = new Web Socket([re q, socket, rest], { | |
| 3076 | protocol Version: ' hixie-76', | |
| 3077 | protocol : protocol | |
| 3078 | }); | |
| 3079 | if (self.o ptions.cli entTrackin g) { | |
| 3080 | self.cli ents.push( client); | |
| 3081 | client.o n('close', function( ) { | |
| 3082 | var in dex = self .clients.i ndexOf(cli ent); | |
| 3083 | if (in dex != -1) { | |
| 3084 | self .clients.s plice(inde x, 1); | |
| 3085 | } | |
| 3086 | }); | |
| 3087 | } | |
| 3088 | ||
| 3089 | // signal upgrade co mplete | |
| 3090 | socket.rem oveListene r('error', errorHand ler); | |
| 3091 | cb(client) ; | |
| 3092 | }) ; | |
| 3093 | } | |
| 3094 | catc h (e) { | |
| 3095 | tr y { socket .destroy() ; } catch (e) {} | |
| 3096 | re turn; | |
| 3097 | } | |
| 3098 | } | |
| 3099 | ||
| 3100 | // ret rieve nonc e | |
| 3101 | var no nceLength = 8; | |
| 3102 | if (up gradeHead && upgrade Head.lengt h >= nonce Length) { | |
| 3103 | var nonce = up gradeHead. slice(0, n onceLength ); | |
| 3104 | var rest = upg radeHead.l ength > no nceLength ? upgradeH ead.slice( nonceLengt h) : null; | |
| 3105 | comp leteHandsh ake.call(s elf, nonce , rest, bu ildRespons eHeader()) ; | |
| 3106 | } | |
| 3107 | else { | |
| 3108 | // n once not p resent in upgradeHea d | |
| 3109 | var nonce = ne w Buffer(n onceLength ); | |
| 3110 | upgr adeHead.co py(nonce, 0); | |
| 3111 | var received = upgradeHe ad.length; | |
| 3112 | var rest = nul l; | |
| 3113 | var handler = function ( data) { | |
| 3114 | va r toRead = Math.min( data.lengt h, nonceLe ngth - rec eived); | |
| 3115 | if (toRead = == 0) retu rn; | |
| 3116 | da ta.copy(no nce, recei ved, 0, to Read); | |
| 3117 | re ceived += toRead; | |
| 3118 | if (received == nonceL ength) { | |
| 3119 | socket.rem oveListene r('data', handler); | |
| 3120 | if (toRead < data.le ngth) rest = data.sl ice(toRead ); | |
| 3121 | ||
| 3122 | // complet e the hand shake but send empty buffer fo r headers since they have alre ady been s ent | |
| 3123 | completeHa ndshake.ca ll(self, n once, rest , new Buff er(0)); | |
| 3124 | } | |
| 3125 | } | |
| 3126 | ||
| 3127 | // h andle addi tional dat a as we re ceive it | |
| 3128 | sock et.on('dat a', handle r); | |
| 3129 | ||
| 3130 | // s end header response before we have the n once to fi x haproxy buffering | |
| 3131 | hand shakeRespo nse(); | |
| 3132 | } | |
| 3133 | } | |
| 3134 | ||
| 3135 | // verif y client | |
| 3136 | if (type of this.op tions.veri fyClient = = 'functio n') { | |
| 3137 | var in fo = { | |
| 3138 | orig in: origin , | |
| 3139 | secu re: typeof req.conne ction.auth orized !== 'undefine d' || type of req.con nection.en crypted != = 'undefin ed', | |
| 3140 | req: req | |
| 3141 | }; | |
| 3142 | if (th is.options .verifyCli ent.length == 2) { | |
| 3143 | var self = thi s; | |
| 3144 | this .options.v erifyClien t(info, fu nction(res ult, code, name) { | |
| 3145 | if (typeof c ode === 'u ndefined') code = 40 1; | |
| 3146 | if (typeof n ame === 'u ndefined') name = ht tp.STATUS_ CODES[code ]; | |
| 3147 | ||
| 3148 | if (!result) abortConn ection(soc ket, code, name); | |
| 3149 | el se onClien tVerified. apply(self ); | |
| 3150 | }); | |
| 3151 | retu rn; | |
| 3152 | } | |
| 3153 | else i f (!this.o ptions.ver ifyClient( info)) { | |
| 3154 | abor tConnectio n(socket, 401, 'Unau thorized') ; | |
| 3155 | retu rn; | |
| 3156 | } | |
| 3157 | } | |
| 3158 | ||
| 3159 | // no cl ient verif ication re quired | |
| 3160 | onClient Verified() ; | |
| 3161 | } | |
| 3162 | ||
| 3163 | function a cceptExten sions(offe r) { | |
| 3164 | var exte nsions = { }; | |
| 3165 | var opti ons = this .options.p erMessageD eflate; | |
| 3166 | var maxP ayload = t his.option s.maxPaylo ad; | |
| 3167 | if (opti ons && off er[PerMess ageDeflate .extension Name]) { | |
| 3168 | var pe rMessageDe flate = ne w PerMessa geDeflate( options != = true ? o ptions : { }, true, m axPayload) ; | |
| 3169 | perMes sageDeflat e.accept(o ffer[PerMe ssageDefla te.extensi onName]); | |
| 3170 | extens ions[PerMe ssageDefla te.extensi onName] = perMessage Deflate; | |
| 3171 | } | |
| 3172 | return e xtensions; | |
| 3173 | } | |
| 3174 | ||
| 3175 | function a bortConnec tion(socke t, code, n ame) { | |
| 3176 | try { | |
| 3177 | var re sponse = [ | |
| 3178 | 'HTT P/1.1 ' + code + ' ' + name, | |
| 3179 | 'Con tent-type: text/html ' | |
| 3180 | ]; | |
| 3181 | socket .write(res ponse.conc at('', '') .join('\r\ n')); | |
| 3182 | } | |
| 3183 | catch (e ) { /* ign ore errors - we've a borted thi s connecti on */ } | |
| 3184 | finally { | |
| 3185 | // ens ure that a n early ab orted conn ection is shut down completely | |
| 3186 | try { socket.des troy(); } catch (e) {} | |
| 3187 | } | |
| 3188 | } | |
| 3189 | \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000pack age/lib/Re ceiver.js\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x00000006 44 \x0000000765 \x0000000024 \x0000 0000055220 \x000012702710 666\x0000013412 \x00000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000ustar\x00000 0\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x000000000 0 \x0000000000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000/* ! | |
| 3190 | * ws: a n ode.js web socket cli ent | |
| 3191 | * Copyrig ht(c) 2011 Einar Ott o Stangvik <einaros@ gmail.com> | |
| 3192 | * MIT Lic ensed | |
| 3193 | */ | |
| 3194 | ||
| 3195 | var util = require(' util') | |
| 3196 | , Valida tion = req uire('./Va lidation') .Validatio n | |
| 3197 | , ErrorC odes = req uire('./Er rorCodes') | |
| 3198 | , Buffer Pool = req uire('./Bu fferPool') | |
| 3199 | , buffer Util = req uire('./Bu fferUtil') .BufferUti l | |
| 3200 | , PerMes sageDeflat e = requir e('./PerMe ssageDefla te'); | |
| 3201 | ||
| 3202 | /** | |
| 3203 | * HyBi Re ceiver imp lementatio n | |
| 3204 | */ | |
| 3205 | ||
| 3206 | function R eceiver (e xtensions, maxPayload ) { | |
| 3207 | if (this instanceo f Receiver === false ) { | |
| 3208 | throw new TypeEr ror("Class es can't b e function -called"); | |
| 3209 | } | |
| 3210 | if(typeo f extensio ns==='numb er'){ | |
| 3211 | maxPay load=exten sions; | |
| 3212 | extens ions={}; | |
| 3213 | } | |
| 3214 | ||
| 3215 | ||
| 3216 | // memor y pool for fragmente d messages | |
| 3217 | var frag mentedPool PrevUsed = -1; | |
| 3218 | this.fra gmentedBuf ferPool = new Buffer Pool(1024, function( db, length ) { | |
| 3219 | return db.used + length; | |
| 3220 | }, funct ion(db) { | |
| 3221 | return fragmente dPoolPrevU sed = frag mentedPool PrevUsed > = 0 ? | |
| 3222 | Math .ceil((fra gmentedPoo lPrevUsed + db.used) / 2) : | |
| 3223 | db.u sed; | |
| 3224 | }); | |
| 3225 | ||
| 3226 | // memor y pool for unfragmen ted messag es | |
| 3227 | var unfr agmentedPo olPrevUsed = -1; | |
| 3228 | this.unf ragmentedB ufferPool = new Buff erPool(102 4, functio n(db, leng th) { | |
| 3229 | return db.used + length; | |
| 3230 | }, funct ion(db) { | |
| 3231 | return unfragmen tedPoolPre vUsed = un fragmented PoolPrevUs ed >= 0 ? | |
| 3232 | Math .ceil((unf ragmentedP oolPrevUse d + db.use d) / 2) : | |
| 3233 | db.u sed; | |
| 3234 | }); | |
| 3235 | this.ext ensions = extensions || {}; | |
| 3236 | this.max Payload = maxPayload || 0; | |
| 3237 | this.cur rentPayloa dLength = 0; | |
| 3238 | this.sta te = { | |
| 3239 | active Fragmented Operation: null, | |
| 3240 | lastFr agment: fa lse, | |
| 3241 | masked : false, | |
| 3242 | opcode : 0, | |
| 3243 | fragme ntedOperat ion: false | |
| 3244 | }; | |
| 3245 | this.ove rflow = [] ; | |
| 3246 | this.hea derBuffer = new Buff er(10); | |
| 3247 | this.exp ectOffset = 0; | |
| 3248 | this.exp ectBuffer = null; | |
| 3249 | this.exp ectHandler = null; | |
| 3250 | this.cur rentMessag e = []; | |
| 3251 | this.cur rentMessag eLength = 0; | |
| 3252 | this.mes sageHandle rs = []; | |
| 3253 | this.exp ectHeader( 2, this.pr ocessPacke t); | |
| 3254 | this.dea d = false; | |
| 3255 | this.pro cessing = false; | |
| 3256 | ||
| 3257 | this.one rror = fun ction() {} ; | |
| 3258 | this.ont ext = func tion() {}; | |
| 3259 | this.onb inary = fu nction() { }; | |
| 3260 | this.onc lose = fun ction() {} ; | |
| 3261 | this.onp ing = func tion() {}; | |
| 3262 | this.onp ong = func tion() {}; | |
| 3263 | } | |
| 3264 | ||
| 3265 | module.exp orts = Rec eiver; | |
| 3266 | ||
| 3267 | /** | |
| 3268 | * Add new data to t he parser. | |
| 3269 | * | |
| 3270 | * @api pu blic | |
| 3271 | */ | |
| 3272 | ||
| 3273 | Receiver.p rototype.a dd = funct ion(data) { | |
| 3274 | if (this .dead) ret urn; | |
| 3275 | var data Length = d ata.length ; | |
| 3276 | if (data Length == 0) return; | |
| 3277 | if (this .expectBuf fer == nul l) { | |
| 3278 | this.o verflow.pu sh(data); | |
| 3279 | return ; | |
| 3280 | } | |
| 3281 | var toRe ad = Math. min(dataLe ngth, this .expectBuf fer.length - this.ex pectOffset ); | |
| 3282 | fastCopy (toRead, d ata, this. expectBuff er, this.e xpectOffse t); | |
| 3283 | this.exp ectOffset += toRead; | |
| 3284 | if (toRe ad < dataL ength) { | |
| 3285 | this.o verflow.pu sh(data.sl ice(toRead )); | |
| 3286 | } | |
| 3287 | while (t his.expect Buffer && this.expec tOffset == this.expe ctBuffer.l ength) { | |
| 3288 | var bu fferForHan dler = thi s.expectBu ffer; | |
| 3289 | this.e xpectBuffe r = null; | |
| 3290 | this.e xpectOffse t = 0; | |
| 3291 | this.e xpectHandl er.call(th is, buffer ForHandler ); | |
| 3292 | } | |
| 3293 | }; | |
| 3294 | ||
| 3295 | /** | |
| 3296 | * Release s all reso urces used by the re ceiver. | |
| 3297 | * | |
| 3298 | * @api pu blic | |
| 3299 | */ | |
| 3300 | ||
| 3301 | Receiver.p rototype.c leanup = f unction() { | |
| 3302 | this.dea d = true; | |
| 3303 | this.ove rflow = nu ll; | |
| 3304 | this.hea derBuffer = null; | |
| 3305 | this.exp ectBuffer = null; | |
| 3306 | this.exp ectHandler = null; | |
| 3307 | this.unf ragmentedB ufferPool = null; | |
| 3308 | this.fra gmentedBuf ferPool = null; | |
| 3309 | this.sta te = null; | |
| 3310 | this.cur rentMessag e = null; | |
| 3311 | this.one rror = nul l; | |
| 3312 | this.ont ext = null ; | |
| 3313 | this.onb inary = nu ll; | |
| 3314 | this.onc lose = nul l; | |
| 3315 | this.onp ing = null ; | |
| 3316 | this.onp ong = null ; | |
| 3317 | }; | |
| 3318 | ||
| 3319 | /** | |
| 3320 | * Waits f or a certa in amount of header bytes to b e availabl e, then fi res a call back. | |
| 3321 | * | |
| 3322 | * @api pr ivate | |
| 3323 | */ | |
| 3324 | ||
| 3325 | Receiver.p rototype.e xpectHeade r = functi on(length, handler) { | |
| 3326 | if (leng th == 0) { | |
| 3327 | handle r(null); | |
| 3328 | return ; | |
| 3329 | } | |
| 3330 | this.exp ectBuffer = this.hea derBuffer. slice(this .expectOff set, this. expectOffs et + lengt h); | |
| 3331 | this.exp ectHandler = handler ; | |
| 3332 | var toRe ad = lengt h; | |
| 3333 | while (t oRead > 0 && this.ov erflow.len gth > 0) { | |
| 3334 | var fr omOverflow = this.ov erflow.pop (); | |
| 3335 | if (to Read < fro mOverflow. length) th is.overflo w.push(fro mOverflow. slice(toRe ad)); | |
| 3336 | var re ad = Math. min(fromOv erflow.len gth, toRea d); | |
| 3337 | fastCo py(read, f romOverflo w, this.ex pectBuffer , this.exp ectOffset) ; | |
| 3338 | this.e xpectOffse t += read; | |
| 3339 | toRead -= read; | |
| 3340 | } | |
| 3341 | }; | |
| 3342 | ||
| 3343 | /** | |
| 3344 | * Waits f or a certa in amount of data by tes to be available, then fire s a callba ck. | |
| 3345 | * | |
| 3346 | * @api pr ivate | |
| 3347 | */ | |
| 3348 | ||
| 3349 | Receiver.p rototype.e xpectData = function (length, h andler) { | |
| 3350 | if (leng th == 0) { | |
| 3351 | handle r(null); | |
| 3352 | return ; | |
| 3353 | } | |
| 3354 | this.exp ectBuffer = this.all ocateFromP ool(length , this.sta te.fragmen tedOperati on); | |
| 3355 | this.exp ectHandler = handler ; | |
| 3356 | var toRe ad = lengt h; | |
| 3357 | while (t oRead > 0 && this.ov erflow.len gth > 0) { | |
| 3358 | var fr omOverflow = this.ov erflow.pop (); | |
| 3359 | if (to Read < fro mOverflow. length) th is.overflo w.push(fro mOverflow. slice(toRe ad)); | |
| 3360 | var re ad = Math. min(fromOv erflow.len gth, toRea d); | |
| 3361 | fastCo py(read, f romOverflo w, this.ex pectBuffer , this.exp ectOffset) ; | |
| 3362 | this.e xpectOffse t += read; | |
| 3363 | toRead -= read; | |
| 3364 | } | |
| 3365 | }; | |
| 3366 | ||
| 3367 | /** | |
| 3368 | * Allocat es memory from the b uffer pool . | |
| 3369 | * | |
| 3370 | * @api pr ivate | |
| 3371 | */ | |
| 3372 | ||
| 3373 | Receiver.p rototype.a llocateFro mPool = fu nction(len gth, isFra gmented) { | |
| 3374 | return ( isFragment ed ? this. fragmented BufferPool : this.un fragmented BufferPool ).get(leng th); | |
| 3375 | }; | |
| 3376 | ||
| 3377 | /** | |
| 3378 | * Start p rocessing a new pack et. | |
| 3379 | * | |
| 3380 | * @api pr ivate | |
| 3381 | */ | |
| 3382 | ||
| 3383 | Receiver.p rototype.p rocessPack et = funct ion (data) { | |
| 3384 | if (this .extension s[PerMessa geDeflate. extensionN ame]) { | |
| 3385 | if ((d ata[0] & 0 x30) != 0) { | |
| 3386 | this .error('re served fie lds (2, 3) must be e mpty', 100 2); | |
| 3387 | retu rn; | |
| 3388 | } | |
| 3389 | } else { | |
| 3390 | if ((d ata[0] & 0 x70) != 0) { | |
| 3391 | this .error('re served fie lds must b e empty', 1002); | |
| 3392 | retu rn; | |
| 3393 | } | |
| 3394 | } | |
| 3395 | this.sta te.lastFra gment = (d ata[0] & 0 x80) == 0x 80; | |
| 3396 | this.sta te.masked = (data[1] & 0x80) = = 0x80; | |
| 3397 | var comp ressed = ( data[0] & 0x40) == 0 x40; | |
| 3398 | var opco de = data[ 0] & 0xf; | |
| 3399 | if (opco de === 0) { | |
| 3400 | if (co mpressed) { | |
| 3401 | this .error('co ntinuation frame can not have t he Per-mes sage Compr essed bits ', 1002); | |
| 3402 | retu rn; | |
| 3403 | } | |
| 3404 | // con tinuation frame | |
| 3405 | this.s tate.fragm entedOpera tion = tru e; | |
| 3406 | this.s tate.opcod e = this.s tate.activ eFragmente dOperation ; | |
| 3407 | if (!( this.state .opcode == 1 || this .state.opc ode == 2)) { | |
| 3408 | this .error('co ntinuation frame can not follow current o pcode', 10 02); | |
| 3409 | retu rn; | |
| 3410 | } | |
| 3411 | } | |
| 3412 | else { | |
| 3413 | if (op code < 3 & & this.sta te.activeF ragmentedO peration ! = null) { | |
| 3414 | this .error('da ta frames after the initial da ta frame m ust have o pcode 0', 1002); | |
| 3415 | retu rn; | |
| 3416 | } | |
| 3417 | if (op code >= 8 && compres sed) { | |
| 3418 | this .error('co ntrol fram es cannot have the P er-message Compresse d bits', 1 002); | |
| 3419 | retu rn; | |
| 3420 | } | |
| 3421 | this.s tate.compr essed = co mpressed; | |
| 3422 | this.s tate.opcod e = opcode ; | |
| 3423 | if (th is.state.l astFragmen t === fals e) { | |
| 3424 | this .state.fra gmentedOpe ration = t rue; | |
| 3425 | this .state.act iveFragmen tedOperati on = opcod e; | |
| 3426 | } | |
| 3427 | else t his.state. fragmented Operation = false; | |
| 3428 | } | |
| 3429 | var hand ler = opco des[this.s tate.opcod e]; | |
| 3430 | if (type of handler == 'undef ined') thi s.error('n o handler for opcode ' + this. state.opco de, 1002); | |
| 3431 | else { | |
| 3432 | handle r.start.ca ll(this, d ata); | |
| 3433 | } | |
| 3434 | }; | |
| 3435 | ||
| 3436 | /** | |
| 3437 | * Endproc essing a p acket. | |
| 3438 | * | |
| 3439 | * @api pr ivate | |
| 3440 | */ | |
| 3441 | ||
| 3442 | Receiver.p rototype.e ndPacket = function( ) { | |
| 3443 | if (this .dead) ret urn; | |
| 3444 | if (!thi s.state.fr agmentedOp eration) t his.unfrag mentedBuff erPool.res et(true); | |
| 3445 | else if (this.stat e.lastFrag ment) this .fragmente dBufferPoo l.reset(tr ue); | |
| 3446 | this.exp ectOffset = 0; | |
| 3447 | this.exp ectBuffer = null; | |
| 3448 | this.exp ectHandler = null; | |
| 3449 | if (this .state.las tFragment && this.st ate.opcode === this. state.acti veFragment edOperatio n) { | |
| 3450 | // end current f ragmented operation | |
| 3451 | this.s tate.activ eFragmente dOperation = null; | |
| 3452 | } | |
| 3453 | this.cur rentPayloa dLength = 0; | |
| 3454 | this.sta te.lastFra gment = fa lse; | |
| 3455 | this.sta te.opcode = this.sta te.activeF ragmentedO peration ! = null ? t his.state. activeFrag mentedOper ation : 0; | |
| 3456 | this.sta te.masked = false; | |
| 3457 | this.exp ectHeader( 2, this.pr ocessPacke t); | |
| 3458 | }; | |
| 3459 | ||
| 3460 | /** | |
| 3461 | * Reset t he parser state. | |
| 3462 | * | |
| 3463 | * @api pr ivate | |
| 3464 | */ | |
| 3465 | ||
| 3466 | Receiver.p rototype.r eset = fun ction() { | |
| 3467 | if (this .dead) ret urn; | |
| 3468 | this.sta te = { | |
| 3469 | active Fragmented Operation: null, | |
| 3470 | lastFr agment: fa lse, | |
| 3471 | masked : false, | |
| 3472 | opcode : 0, | |
| 3473 | fragme ntedOperat ion: false | |
| 3474 | }; | |
| 3475 | this.fra gmentedBuf ferPool.re set(true); | |
| 3476 | this.unf ragmentedB ufferPool. reset(true ); | |
| 3477 | this.exp ectOffset = 0; | |
| 3478 | this.exp ectBuffer = null; | |
| 3479 | this.exp ectHandler = null; | |
| 3480 | this.ove rflow = [] ; | |
| 3481 | this.cur rentMessag e = []; | |
| 3482 | this.cur rentMessag eLength = 0; | |
| 3483 | this.mes sageHandle rs = []; | |
| 3484 | this.cur rentPayloa dLength = 0; | |
| 3485 | }; | |
| 3486 | ||
| 3487 | /** | |
| 3488 | * Unmask received d ata. | |
| 3489 | * | |
| 3490 | * @api pr ivate | |
| 3491 | */ | |
| 3492 | ||
| 3493 | Receiver.p rototype.u nmask = fu nction (ma sk, buf, b inary) { | |
| 3494 | if (mask != null & & buf != n ull) buffe rUtil.unma sk(buf, ma sk); | |
| 3495 | if (bina ry) return buf; | |
| 3496 | return b uf != null ? buf.toS tring('utf 8') : ''; | |
| 3497 | }; | |
| 3498 | ||
| 3499 | /** | |
| 3500 | * Handles an error | |
| 3501 | * | |
| 3502 | * @api pr ivate | |
| 3503 | */ | |
| 3504 | ||
| 3505 | Receiver.p rototype.e rror = fun ction (rea son, proto colErrorCo de) { | |
| 3506 | if (this .dead) ret urn; | |
| 3507 | this.res et(); | |
| 3508 | if(typeo f reason = = 'string' ){ | |
| 3509 | this.o nerror(new Error(rea son), prot ocolErrorC ode); | |
| 3510 | } | |
| 3511 | else if( reason.con structor = = Error){ | |
| 3512 | this.o nerror(rea son, proto colErrorCo de); | |
| 3513 | } | |
| 3514 | else{ | |
| 3515 | this.o nerror(new Error("An error occ ured"),pro tocolError Code); | |
| 3516 | } | |
| 3517 | return t his; | |
| 3518 | }; | |
| 3519 | ||
| 3520 | /** | |
| 3521 | * Execute message h andler buf fers | |
| 3522 | * | |
| 3523 | * @api pr ivate | |
| 3524 | */ | |
| 3525 | ||
| 3526 | Receiver.p rototype.f lush = fun ction() { | |
| 3527 | if (this .processin g || this. dead) retu rn; | |
| 3528 | ||
| 3529 | var hand ler = this .messageHa ndlers.shi ft(); | |
| 3530 | if (!han dler) retu rn; | |
| 3531 | ||
| 3532 | this.pro cessing = true; | |
| 3533 | var self = this; | |
| 3534 | ||
| 3535 | handler( function() { | |
| 3536 | self.p rocessing = false; | |
| 3537 | self.f lush(); | |
| 3538 | }); | |
| 3539 | }; | |
| 3540 | ||
| 3541 | /** | |
| 3542 | * Apply e xtensions to message | |
| 3543 | * | |
| 3544 | * @api pr ivate | |
| 3545 | */ | |
| 3546 | ||
| 3547 | Receiver.p rototype.a pplyExtens ions = fun ction(mess ageBuffer, fin, comp ressed, ca llback) { | |
| 3548 | var self = this; | |
| 3549 | if (comp ressed) { | |
| 3550 | this.e xtensions[ PerMessage Deflate.ex tensionNam e].decompr ess(messag eBuffer, f in, functi on(err, bu ffer) { | |
| 3551 | if ( self.dead) return; | |
| 3552 | if ( err) { | |
| 3553 | ca llback(new Error('in valid comp ressed dat a')); | |
| 3554 | re turn; | |
| 3555 | } | |
| 3556 | call back(null, buffer); | |
| 3557 | }); | |
| 3558 | } else { | |
| 3559 | callba ck(null, m essageBuff er); | |
| 3560 | } | |
| 3561 | }; | |
| 3562 | ||
| 3563 | /** | |
| 3564 | * Checks p ayload siz e, disconn ects socke t when it exceeds ma xPayload | |
| 3565 | * | |
| 3566 | * @api pri vate | |
| 3567 | */ | |
| 3568 | Receiver.p rototype.m axPayloadE xceeded = function(l ength) { | |
| 3569 | if (this .maxPayloa d=== undef ined || th is.maxPayl oad === nu ll || this .maxPayloa d < 1) { | |
| 3570 | return false; | |
| 3571 | } | |
| 3572 | var full Length = t his.curren tPayloadLe ngth + len gth; | |
| 3573 | if (full Length < t his.maxPay load) { | |
| 3574 | this.c urrentPayl oadLength = fullLeng th; | |
| 3575 | return false; | |
| 3576 | } | |
| 3577 | this.err or('payloa d cannot e xceed ' + this.maxPa yload + ' bytes', 10 09); | |
| 3578 | this.mes sageBuffer =[]; | |
| 3579 | this.cle anup(); | |
| 3580 | ||
| 3581 | return t rue; | |
| 3582 | }; | |
| 3583 | ||
| 3584 | /** | |
| 3585 | * Buffer utilities | |
| 3586 | */ | |
| 3587 | ||
| 3588 | function r eadUInt16B E(start) { | |
| 3589 | return ( this[start ]<<8) + | |
| 3590 | t his[start+ 1]; | |
| 3591 | } | |
| 3592 | ||
| 3593 | function r eadUInt32B E(start) { | |
| 3594 | return ( this[start ]<<24) + | |
| 3595 | ( this[start +1]<<16) + | |
| 3596 | ( this[start +2]<<8) + | |
| 3597 | t his[start+ 3]; | |
| 3598 | } | |
| 3599 | ||
| 3600 | function f astCopy(le ngth, srcB uffer, dst Buffer, ds tOffset) { | |
| 3601 | switch ( length) { | |
| 3602 | defaul t: srcBuff er.copy(ds tBuffer, d stOffset, 0, length) ; break; | |
| 3603 | case 1 6: dstBuff er[dstOffs et+15] = s rcBuffer[1 5]; | |
| 3604 | case 1 5: dstBuff er[dstOffs et+14] = s rcBuffer[1 4]; | |
| 3605 | case 1 4: dstBuff er[dstOffs et+13] = s rcBuffer[1 3]; | |
| 3606 | case 1 3: dstBuff er[dstOffs et+12] = s rcBuffer[1 2]; | |
| 3607 | case 1 2: dstBuff er[dstOffs et+11] = s rcBuffer[1 1]; | |
| 3608 | case 1 1: dstBuff er[dstOffs et+10] = s rcBuffer[1 0]; | |
| 3609 | case 1 0: dstBuff er[dstOffs et+9] = sr cBuffer[9] ; | |
| 3610 | case 9 : dstBuffe r[dstOffse t+8] = src Buffer[8]; | |
| 3611 | case 8 : dstBuffe r[dstOffse t+7] = src Buffer[7]; | |
| 3612 | case 7 : dstBuffe r[dstOffse t+6] = src Buffer[6]; | |
| 3613 | case 6 : dstBuffe r[dstOffse t+5] = src Buffer[5]; | |
| 3614 | case 5 : dstBuffe r[dstOffse t+4] = src Buffer[4]; | |
| 3615 | case 4 : dstBuffe r[dstOffse t+3] = src Buffer[3]; | |
| 3616 | case 3 : dstBuffe r[dstOffse t+2] = src Buffer[2]; | |
| 3617 | case 2 : dstBuffe r[dstOffse t+1] = src Buffer[1]; | |
| 3618 | case 1 : dstBuffe r[dstOffse t] = srcBu ffer[0]; | |
| 3619 | } | |
| 3620 | } | |
| 3621 | ||
| 3622 | function c lone(obj) { | |
| 3623 | var clon ed = {}; | |
| 3624 | for (var k in obj) { | |
| 3625 | if (ob j.hasOwnPr operty(k)) { | |
| 3626 | clon ed[k] = ob j[k]; | |
| 3627 | } | |
| 3628 | } | |
| 3629 | return c loned; | |
| 3630 | } | |
| 3631 | ||
| 3632 | /** | |
| 3633 | * Opcode handlers | |
| 3634 | */ | |
| 3635 | ||
| 3636 | var opcode s = { | |
| 3637 | // text | |
| 3638 | '1': { | |
| 3639 | start: function( data) { | |
| 3640 | var self = thi s; | |
| 3641 | // d ecode leng th | |
| 3642 | var firstLengt h = data[1 ] & 0x7f; | |
| 3643 | if ( firstLengt h < 126) { | |
| 3644 | if (self.max PayloadExc eeded(firs tLength)){ | |
| 3645 | self.error ('Maximump ayload exc eeded in c ompressed text messa ge. Aborti ng...', 10 09); | |
| 3646 | return; | |
| 3647 | } | |
| 3648 | op codes['1'] .getData.c all(self, firstLengt h); | |
| 3649 | } | |
| 3650 | else if (first Length == 126) { | |
| 3651 | se lf.expectH eader(2, f unction(da ta) { | |
| 3652 | var length = readUIn t16BE.call (data, 0); | |
| 3653 | if (self.m axPayloadE xceeded(le ngth)){ | |
| 3654 | self.err or('Maximu mpayload e xceeded in compresse d text mes sage. Abor ting...', 1009); | |
| 3655 | return; | |
| 3656 | } | |
| 3657 | opcodes['1 '].getData .call(self , length); | |
| 3658 | }) ; | |
| 3659 | } | |
| 3660 | else if (first Length == 127) { | |
| 3661 | se lf.expectH eader(8, f unction(da ta) { | |
| 3662 | if (readUI nt32BE.cal l(data, 0) != 0) { | |
| 3663 | self.err or('packet s with len gth spanni ng more th an 32 bit is current ly not sup ported', 1 008); | |
| 3664 | return; | |
| 3665 | } | |
| 3666 | var length = readUIn t32BE.call (data, 4); | |
| 3667 | if (self.m axPayloadE xceeded(le ngth)){ | |
| 3668 | self.err or('Maximu mpayload e xceeded in compresse d text mes sage. Abor ting...', 1009); | |
| 3669 | return; | |
| 3670 | } | |
| 3671 | opcodes['1 '].getData .call(self , readUInt 32BE.call( data, 4)); | |
| 3672 | }) ; | |
| 3673 | } | |
| 3674 | }, | |
| 3675 | getDat a: functio n(length) { | |
| 3676 | var self = thi s; | |
| 3677 | if ( self.state .masked) { | |
| 3678 | se lf.expectH eader(4, f unction(da ta) { | |
| 3679 | var mask = data; | |
| 3680 | self.expec tData(leng th, functi on(data) { | |
| 3681 | opcodes[ '1'].finis h.call(sel f, mask, d ata); | |
| 3682 | }); | |
| 3683 | }) ; | |
| 3684 | } | |
| 3685 | else { | |
| 3686 | se lf.expectD ata(length , function (data) { | |
| 3687 | opcodes['1 '].finish. call(self, null, dat a); | |
| 3688 | }) ; | |
| 3689 | } | |
| 3690 | }, | |
| 3691 | finish : function (mask, dat a) { | |
| 3692 | var self = thi s; | |
| 3693 | var packet = t his.unmask (mask, dat a, true) | | new Buff er(0); | |
| 3694 | var state = cl one(this.s tate); | |
| 3695 | this .messageHa ndlers.pus h(function (callback) { | |
| 3696 | se lf.applyEx tensions(p acket, sta te.lastFra gment, sta te.compres sed, funct ion(err, b uffer) { | |
| 3697 | if (err) { | |
| 3698 | if(err.t ype===1009 ){ | |
| 3699 | retu rn self.er ror('Maxim umpayload exceeded i n compress ed text me ssage. Abo rting...', 1009); | |
| 3700 | } | |
| 3701 | return s elf.error( err.messag e, 1007); | |
| 3702 | } | |
| 3703 | if (buffer != null) { | |
| 3704 | if( self .maxPayloa d==0 || (s elf.maxPay load > 0 & & (self.cu rrentMessa geLength + buffer.le ngth) < se lf.maxPayl oad) ){ | |
| 3705 | self.c urrentMess age.push(b uffer); | |
| 3706 | } | |
| 3707 | else{ | |
| 3708 | self .currentMe ssage=null ; | |
| 3709 | self .currentMe ssage = [] ; | |
| 3710 | self .currentMe ssageLengt h = 0; | |
| 3711 | self .error(new Error('Ma ximum payl oad exceed ed. maxPay load: '+se lf.maxPayl oad), 1009 ); | |
| 3712 | retu rn; | |
| 3713 | } | |
| 3714 | self.cur rentMessag eLength += buffer.le ngth; | |
| 3715 | } | |
| 3716 | if (state. lastFragme nt) { | |
| 3717 | var mess ageBuffer = Buffer.c oncat(self .currentMe ssage); | |
| 3718 | self.cur rentMessag e = []; | |
| 3719 | self.cur rentMessag eLength = 0; | |
| 3720 | if (!Val idation.is ValidUTF8( messageBuf fer)) { | |
| 3721 | self.e rror('inva lid utf8 s equence', 1007); | |
| 3722 | return ; | |
| 3723 | } | |
| 3724 | self.ont ext(messag eBuffer.to String('ut f8'), {mas ked: state .masked, b uffer: mes sageBuffer }); | |
| 3725 | } | |
| 3726 | callback() ; | |
| 3727 | }) ; | |
| 3728 | }); | |
| 3729 | this .flush(); | |
| 3730 | this .endPacket (); | |
| 3731 | } | |
| 3732 | }, | |
| 3733 | // binar y | |
| 3734 | '2': { | |
| 3735 | start: function( data) { | |
| 3736 | var self = thi s; | |
| 3737 | // d ecode leng th | |
| 3738 | var firstLengt h = data[1 ] & 0x7f; | |
| 3739 | if ( firstLengt h < 126) { | |
| 3740 | if (self.m axPayloadE xceeded(fi rstLength) ){ | |
| 3741 | self.err or('Max pa yload exce eded in co mpressed t ext messag e. Abortin g...', 100 9); | |
| 3742 | return; | |
| 3743 | } | |
| 3744 | op codes['2'] .getData.c all(self, firstLengt h); | |
| 3745 | } | |
| 3746 | else if (first Length == 126) { | |
| 3747 | se lf.expectH eader(2, f unction(da ta) { | |
| 3748 | var length = readUIn t16BE.call (data, 0); | |
| 3749 | if (self.m axPayloadE xceeded(le ngth)){ | |
| 3750 | self.err or('Max pa yload exce eded in co mpressed t ext messag e. Abortin g...', 100 9); | |
| 3751 | return; | |
| 3752 | } | |
| 3753 | opcodes['2 '].getData .call(self , length); | |
| 3754 | }) ; | |
| 3755 | } | |
| 3756 | else if (first Length == 127) { | |
| 3757 | se lf.expectH eader(8, f unction(da ta) { | |
| 3758 | if (readUI nt32BE.cal l(data, 0) != 0) { | |
| 3759 | self.err or('packet s with len gth spanni ng more th an 32 bit is current ly not sup ported', 1 008); | |
| 3760 | return; | |
| 3761 | } | |
| 3762 | var length = readUIn t32BE.call (data, 4, true); | |
| 3763 | if (self.m axPayloadE xceeded(le ngth)){ | |
| 3764 | self.err or('Max pa yload exce eded in co mpressed t ext messag e. Abortin g...', 100 9); | |
| 3765 | return; | |
| 3766 | } | |
| 3767 | opcodes['2 '].getData .call(self , length); | |
| 3768 | }) ; | |
| 3769 | } | |
| 3770 | }, | |
| 3771 | getDat a: functio n(length) { | |
| 3772 | var self = thi s; | |
| 3773 | if ( self.state .masked) { | |
| 3774 | se lf.expectH eader(4, f unction(da ta) { | |
| 3775 | var mask = data; | |
| 3776 | self.expec tData(leng th, functi on(data) { | |
| 3777 | opcodes[ '2'].finis h.call(sel f, mask, d ata); | |
| 3778 | }); | |
| 3779 | }) ; | |
| 3780 | } | |
| 3781 | else { | |
| 3782 | se lf.expectD ata(length , function (data) { | |
| 3783 | opcodes['2 '].finish. call(self, null, dat a); | |
| 3784 | }) ; | |
| 3785 | } | |
| 3786 | }, | |
| 3787 | finish : function (mask, dat a) { | |
| 3788 | var self = thi s; | |
| 3789 | var packet = t his.unmask (mask, dat a, true) | | new Buff er(0); | |
| 3790 | var state = cl one(this.s tate); | |
| 3791 | this .messageHa ndlers.pus h(function (callback) { | |
| 3792 | se lf.applyEx tensions(p acket, sta te.lastFra gment, sta te.compres sed, funct ion(err, b uffer) { | |
| 3793 | if (err) { | |
| 3794 | if(err.t ype===1009 ){ | |
| 3795 | retu rn self.er ror('Max p ayload exc eeded in c ompressed binary mes sage. Abor ting...', 1009); | |
| 3796 | } | |
| 3797 | return s elf.error( err.messag e, 1007); | |
| 3798 | } | |
| 3799 | if (buffer != null) { | |
| 3800 | if( self .maxPayloa d==0 || (s elf.maxPay load > 0 & & (self.cu rrentMessa geLength + buffer.le ngth) < se lf.maxPayl oad) ){ | |
| 3801 | self.c urrentMess age.push(b uffer); | |
| 3802 | } | |
| 3803 | else{ | |
| 3804 | self .currentMe ssage=null ; | |
| 3805 | self .currentMe ssage = [] ; | |
| 3806 | self .currentMe ssageLengt h = 0; | |
| 3807 | self .error(new Error('Ma ximum payl oad exceed ed'), 1009 ); | |
| 3808 | retu rn; | |
| 3809 | } | |
| 3810 | self.cur rentMessag eLength += buffer.le ngth; | |
| 3811 | } | |
| 3812 | if (state. lastFragme nt) { | |
| 3813 | var mess ageBuffer = Buffer.c oncat(self .currentMe ssage); | |
| 3814 | self.cur rentMessag e = []; | |
| 3815 | self.cur rentMessag eLength = 0; | |
| 3816 | self.onb inary(mess ageBuffer, {masked: state.mask ed, buffer : messageB uffer}); | |
| 3817 | } | |
| 3818 | callback() ; | |
| 3819 | }) ; | |
| 3820 | }); | |
| 3821 | this .flush(); | |
| 3822 | this .endPacket (); | |
| 3823 | } | |
| 3824 | }, | |
| 3825 | // close | |
| 3826 | '8': { | |
| 3827 | start: function( data) { | |
| 3828 | var self = thi s; | |
| 3829 | if ( self.state .lastFragm ent == fal se) { | |
| 3830 | se lf.error(' fragmented close is not suppor ted', 1002 ); | |
| 3831 | re turn; | |
| 3832 | } | |
| 3833 | ||
| 3834 | // d ecode leng th | |
| 3835 | var firstLengt h = data[1 ] & 0x7f; | |
| 3836 | if ( firstLengt h < 126) { | |
| 3837 | op codes['8'] .getData.c all(self, firstLengt h); | |
| 3838 | } | |
| 3839 | else { | |
| 3840 | se lf.error(' control fr ames canno t have mor e than 125 bytes of data', 100 2); | |
| 3841 | } | |
| 3842 | }, | |
| 3843 | getDat a: functio n(length) { | |
| 3844 | var self = thi s; | |
| 3845 | if ( self.state .masked) { | |
| 3846 | se lf.expectH eader(4, f unction(da ta) { | |
| 3847 | var mask = data; | |
| 3848 | self.expec tData(leng th, functi on(data) { | |
| 3849 | opcodes[ '8'].finis h.call(sel f, mask, d ata); | |
| 3850 | }); | |
| 3851 | }) ; | |
| 3852 | } | |
| 3853 | else { | |
| 3854 | se lf.expectD ata(length , function (data) { | |
| 3855 | opcodes['8 '].finish. call(self, null, dat a); | |
| 3856 | }) ; | |
| 3857 | } | |
| 3858 | }, | |
| 3859 | finish : function (mask, dat a) { | |
| 3860 | var self = thi s; | |
| 3861 | data = self.un mask(mask, data, tru e); | |
| 3862 | ||
| 3863 | var state = cl one(this.s tate); | |
| 3864 | this .messageHa ndlers.pus h(function () { | |
| 3865 | if (data && data.lengt h == 1) { | |
| 3866 | self.error ('close pa ckets with data must be at lea st two byt es long', 1002); | |
| 3867 | return; | |
| 3868 | } | |
| 3869 | va r code = d ata && dat a.length > 1 ? readU Int16BE.ca ll(data, 0 ) : 1000; | |
| 3870 | if (!ErrorCo des.isVali dErrorCode (code)) { | |
| 3871 | self.error ('invalid error code ', 1002); | |
| 3872 | return; | |
| 3873 | } | |
| 3874 | va r message = ''; | |
| 3875 | if (data && data.lengt h > 2) { | |
| 3876 | var messag eBuffer = data.slice (2); | |
| 3877 | if (!Valid ation.isVa lidUTF8(me ssageBuffe r)) { | |
| 3878 | self.err or('invali d utf8 seq uence', 10 07); | |
| 3879 | return; | |
| 3880 | } | |
| 3881 | message = messageBuf fer.toStri ng('utf8') ; | |
| 3882 | } | |
| 3883 | se lf.onclose (code, mes sage, {mas ked: state .masked}); | |
| 3884 | se lf.reset() ; | |
| 3885 | }); | |
| 3886 | this .flush(); | |
| 3887 | }, | |
| 3888 | }, | |
| 3889 | // ping | |
| 3890 | '9': { | |
| 3891 | start: function( data) { | |
| 3892 | var self = thi s; | |
| 3893 | if ( self.state .lastFragm ent == fal se) { | |
| 3894 | se lf.error(' fragmented ping is n ot support ed', 1002) ; | |
| 3895 | re turn; | |
| 3896 | } | |
| 3897 | ||
| 3898 | // d ecode leng th | |
| 3899 | var firstLengt h = data[1 ] & 0x7f; | |
| 3900 | if ( firstLengt h < 126) { | |
| 3901 | op codes['9'] .getData.c all(self, firstLengt h); | |
| 3902 | } | |
| 3903 | else { | |
| 3904 | se lf.error(' control fr ames canno t have mor e than 125 bytes of data', 100 2); | |
| 3905 | } | |
| 3906 | }, | |
| 3907 | getDat a: functio n(length) { | |
| 3908 | var self = thi s; | |
| 3909 | if ( self.state .masked) { | |
| 3910 | se lf.expectH eader(4, f unction(da ta) { | |
| 3911 | var mask = data; | |
| 3912 | self.expec tData(leng th, functi on(data) { | |
| 3913 | opcodes[ '9'].finis h.call(sel f, mask, d ata); | |
| 3914 | }); | |
| 3915 | }) ; | |
| 3916 | } | |
| 3917 | else { | |
| 3918 | se lf.expectD ata(length , function (data) { | |
| 3919 | opcodes['9 '].finish. call(self, null, dat a); | |
| 3920 | }) ; | |
| 3921 | } | |
| 3922 | }, | |
| 3923 | finish : function (mask, dat a) { | |
| 3924 | var self = thi s; | |
| 3925 | data = this.un mask(mask, data, tru e); | |
| 3926 | var state = cl one(this.s tate); | |
| 3927 | this .messageHa ndlers.pus h(function (callback) { | |
| 3928 | se lf.onping( data, {mas ked: state .masked, b inary: tru e}); | |
| 3929 | ca llback(); | |
| 3930 | }); | |
| 3931 | this .flush(); | |
| 3932 | this .endPacket (); | |
| 3933 | } | |
| 3934 | }, | |
| 3935 | // pong | |
| 3936 | '10': { | |
| 3937 | start: function( data) { | |
| 3938 | var self = thi s; | |
| 3939 | if ( self.state .lastFragm ent == fal se) { | |
| 3940 | se lf.error(' fragmented pong is n ot support ed', 1002) ; | |
| 3941 | re turn; | |
| 3942 | } | |
| 3943 | ||
| 3944 | // d ecode leng th | |
| 3945 | var firstLengt h = data[1 ] & 0x7f; | |
| 3946 | if ( firstLengt h < 126) { | |
| 3947 | op codes['10' ].getData. call(self, firstLeng th); | |
| 3948 | } | |
| 3949 | else { | |
| 3950 | se lf.error(' control fr ames canno t have mor e than 125 bytes of data', 100 2); | |
| 3951 | } | |
| 3952 | }, | |
| 3953 | getDat a: functio n(length) { | |
| 3954 | var self = thi s; | |
| 3955 | if ( this.state .masked) { | |
| 3956 | th is.expectH eader(4, f unction(da ta) { | |
| 3957 | var mask = data; | |
| 3958 | self.expec tData(leng th, functi on(data) { | |
| 3959 | opcodes[ '10'].fini sh.call(se lf, mask, data); | |
| 3960 | }); | |
| 3961 | }) ; | |
| 3962 | } | |
| 3963 | else { | |
| 3964 | th is.expectD ata(length , function (data) { | |
| 3965 | opcodes['1 0'].finish .call(self , null, da ta); | |
| 3966 | }) ; | |
| 3967 | } | |
| 3968 | }, | |
| 3969 | finish : function (mask, dat a) { | |
| 3970 | var self = thi s; | |
| 3971 | data = self.un mask(mask, data, tru e); | |
| 3972 | var state = cl one(this.s tate); | |
| 3973 | this .messageHa ndlers.pus h(function (callback) { | |
| 3974 | se lf.onpong( data, {mas ked: state .masked, b inary: tru e}); | |
| 3975 | ca llback(); | |
| 3976 | }); | |
| 3977 | this .flush(); | |
| 3978 | this .endPacket (); | |
| 3979 | } | |
| 3980 | } | |
| 3981 | } | |
| 3982 | \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000\x0000 \x0000\x0000 |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.