Created
June 1, 2013 06:57
-
-
Save adammw/5689522 to your computer and use it in GitHub Desktop.
Code excerpt. (not working - data skips S0 Parser and goes directly into the input of S1 Parser)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
var stream = require('stream'); | |
var debug = require('debug')('rtmp:handshake:parser') | |
var S0 = require('./s0'); | |
var S1 = require('./s1'); | |
var S2 = require('./s2'); | |
var HandshakeParserStream = module.exports = function(options) { | |
if (!(this instanceof HandshakeParserStream)) | |
return new HandshakeParserStream(options); | |
stream.Transform.call(this, options); | |
// todo: client/server option | |
//this.server = options.server || false; | |
this._handshakeDone = false; | |
this._s0Stream = new S0.ParserStream(); | |
this._s1Stream = new S1.ParserStream(); | |
this._s2Stream = new S2.ParserStream(); | |
this._s0Stream.pipe(this._s1Stream); | |
this._s1Stream.pipe(this._s2Stream); | |
this._s0Stream.on('s0', this._onS0Recieved.bind(this)); | |
this._s1Stream.on('s1', this._onS1Recieved.bind(this)); | |
this._s2Stream.on('s2', this._onS2Recieved.bind(this)); | |
this._s2Stream.on('readable', this._onS2Readable.bind(this)); | |
}; | |
HandshakeParserStream.prototype = Object.create( | |
stream.Transform.prototype, | |
{ constructor: { value: HandshakeParserStream }} | |
); | |
HandshakeParserStream.prototype._transform = function(chunk, encoding, done) { | |
debug('HandshakeParserStream Transform', chunk) | |
if (!this._handshakeDone) { | |
this._s0Stream.push(chunk); | |
} else { | |
this.push(chunk); | |
} | |
done(); | |
}; | |
HandshakeParserStream.prototype._onS0Recieved = function(s0) { | |
debug('S0 Recieved', s0); | |
}; | |
HandshakeParserStream.prototype._onS1Recieved = function(s1) { | |
debug('S1 Recieved', s1); | |
}; | |
HandshakeParserStream.prototype._onS2Recieved = function(s2) { | |
debug('S2 Recieved', s2); | |
this.emit('handshake'); | |
this._handshakeDone = true; | |
}; | |
HandshakeParserStream.prototype._onS2Readable = function(s2) { | |
debug('S2 readable'); | |
this.push(this._s2Stream.read()); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment