mirror of
https://github.com/PrismarineJS/node-minecraft-protocol.git
synced 2024-11-29 18:55:40 -05:00
use es6 properties for client.js
see https://github.com/jeffmo/es-class-properties and http://odetocode.com/blogs/scott/archive/2014/10/14/features-of-es6-part-9-classes.aspx
This commit is contained in:
parent
6e399122bf
commit
bbde23bb02
1 changed files with 30 additions and 28 deletions
|
@ -13,39 +13,41 @@ var packetIndexes = readPackets(packets, states);
|
|||
|
||||
class Client extends EventEmitter
|
||||
{
|
||||
packetsToParse={};
|
||||
serializer;
|
||||
compressor=null;
|
||||
framer=framing.createFramer();
|
||||
cipher=null;
|
||||
decipher=null;
|
||||
splitter=framing.createSplitter();
|
||||
decompressor=null;
|
||||
deserializer;
|
||||
isServer;
|
||||
|
||||
get state(){
|
||||
return this.serializer.protocolState;
|
||||
}
|
||||
|
||||
set state(newProperty) {
|
||||
var oldProperty = this.serializer.protocolState;
|
||||
this.serializer.protocolState = newProperty;
|
||||
this.deserializer.protocolState = newProperty;
|
||||
this.emit('state', newProperty, oldProperty);
|
||||
}
|
||||
|
||||
get compressionThreshold() {
|
||||
return this.compressor == null ? -2 : this.compressor.compressionThreshold;
|
||||
}
|
||||
|
||||
set compressionThreshold(threshold) {
|
||||
this.setCompressionThreshold(threshold);
|
||||
}
|
||||
|
||||
constructor(isServer) {
|
||||
super();
|
||||
|
||||
var socket;
|
||||
this.packetsToParse = {};
|
||||
|
||||
this.serializer = serializer.createSerializer({ isServer });
|
||||
this.compressor = null;
|
||||
this.framer = framing.createFramer();
|
||||
this.cipher = null;
|
||||
|
||||
this.decipher = null;
|
||||
this.splitter = framing.createSplitter();
|
||||
this.decompressor = null;
|
||||
this.deserializer = serializer.createDeserializer({ isServer, packetsToParse: this.packetsToParse });
|
||||
|
||||
this._state = states.HANDSHAKING;
|
||||
Object.defineProperty(this, "state", {
|
||||
get: function() {
|
||||
return this.serializer.protocolState;
|
||||
},
|
||||
set: function(newProperty) {
|
||||
var oldProperty = this.serializer.protocolState;
|
||||
this.serializer.protocolState = newProperty;
|
||||
this.deserializer.protocolState = newProperty;
|
||||
this.emit('state', newProperty, oldProperty);
|
||||
}
|
||||
});
|
||||
Object.defineProperty(this, "compressionThreshold", {
|
||||
get: () => this.compressor == null ? -2 : this.compressor.compressionThreshold,
|
||||
set: (threshold) => this.setCompressionThreshold(threshold)
|
||||
});
|
||||
|
||||
this.isServer = !!isServer;
|
||||
|
||||
this.on('newListener', function(event, listener) {
|
||||
|
|
Loading…
Reference in a new issue