| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
parent directory.. | ||||
This is the JavaScript parser for the engine.io protocol encoding, shared by both engine.io-client and engine.io.
The parser can encode/decode packets, payloads, and payloads as binary with the following methods: encodePacket, decodePacket, encodePayload, decodePayload, encodePayloadAsBinary, decodePayloadAsBinary.
The browser-side parser also includes encodePayloadAsArrayBuffer and encodePayloadAsBlob.
Example:
var parser = require('engine.io-parser');
var data = new Buffer(5);
for (var i = 0; i < data.length; i++) { data[i] = i; }
parser.encodePacket({ type: 'message', data: data }, function(encoded) {
var decodedData = parser.decodePacket(encoded); // { type: 'message', data: data }
});Engine.IO Parser is a commonjs module, which means you can include it by using require on the browser and package using browserify:
install the parser package
npm install engine.io-parserwrite your app code
var parser = require('engine.io-parser');
var testBuffer = new Int8Array(10);
for (var i = 0; i < testBuffer.length; i++) testBuffer[i] = i;
var packets = [{ type: 'message', data: testBuffer.buffer }, { type: 'message', data: 'hello' }];
parser.encodePayload(packets, function(encoded) {
parser.decodePayload(encoded,
function(packet, index, total) {
var isLast = index + 1 == total;
if (!isLast) {
var buffer = new Int8Array(packet.data); // testBuffer
} else {
var message = packet.data; // 'hello'
}
});
});build your app bundle
$ browserify app.js > bundle.jsinclude on your page
<script src="/path/to/bundle.js"></script>Note: cb(type) means the type is a callback function that contains a parameter of type type when called.
encodePacket
decodePacket
encodeBase64Packet
decodeBase64Packet
encodePayload
decodePayload
encodePayloadAsBinary
decodePayloadAsBinary
Standalone tests can be run with make test which will run both node.js and browser tests.
Browser tests are run using zuul. (You must have zuul setup with a saucelabs account.)
You can run the tests locally using the following command:
./node_modules/.bin/zuul --local 8080 -- test/index.js
The support channels for engine.io-parser are the same as socket.io:
To contribute patches, run tests or benchmarks, make sure to clone the repository:
git clone git://github.com/LearnBoost/engine.io-parser.gitThen:
cd engine.io-parser
npm installSee the Tests section above for how to run tests before submitting any patches.
MIT
| Back | FazBrowse Home | New Git URL |