mudb
Version:
Real-time database for multiplayer games
30 lines • 1.14 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var protocol_1 = require("./protocol");
var stream_1 = require("../stream");
var MuDeltaServer = (function () {
function MuDeltaServer(spec) {
var _this = this;
this._schema = spec.schema;
this._protocol = spec.server.protocol(protocol_1.muDeltaSchema(spec.schema));
this._state = spec.schema.clone(spec.initial || spec.schema.identity);
this._protocol.configure({
message: {},
connect: function (client) {
client.message.reset(_this._state);
},
});
this._initialPacketSize = spec.packetSizeGuess || 1024;
}
MuDeltaServer.prototype.publish = function (state) {
var out = new stream_1.MuWriteStream(this._initialPacketSize);
if (this._schema.diff(this._state, state, out)) {
this._schema.assign(this._state, state);
this._protocol.broadcastRaw(out.bytes());
}
out.destroy();
};
return MuDeltaServer;
}());
exports.MuDeltaServer = MuDeltaServer;
//# sourceMappingURL=server.js.map