shardy
Version:
Framework for online games and applications on Node.js
101 lines • 3.77 kB
JavaScript
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Client = void 0;
const Commander_1 = require("./Commander");
class Client {
constructor(connection, id, log, service, options, mode = Commander_1.CommanderMode.Service) {
this.connection = connection;
this.id = id;
this.log = log;
this.service = service;
this.options = options;
this.mode = mode;
this.onDisconnect = () => { };
this.onReady = () => { };
this.isConnected = true;
this.commander = new Commander_1.Commander(this.id, this.connection, this.service, this.options, this.log, this.mode);
this.commander.onDisconnect = (reason) => {
this.isConnected = false;
this.onDisconnect(this.id, reason);
};
this.commander.onReady = () => this.onReady();
this.connection.setLogger(this.log);
}
command(command, data) {
return __awaiter(this, void 0, void 0, function* () {
this.commander.command(command, data);
});
}
fetch(request, data) {
return __awaiter(this, void 0, void 0, function* () {
return this.commander.fetch(request, data);
});
}
request(request, callback, data) {
return __awaiter(this, void 0, void 0, function* () {
return this.commander.request(request, callback, data);
});
}
response(request, data) {
return __awaiter(this, void 0, void 0, function* () {
this.commander.response(request, data);
});
}
disconnect() {
return __awaiter(this, void 0, void 0, function* () {
this.commander.disconnect();
});
}
kick(reason) {
return __awaiter(this, void 0, void 0, function* () {
this.commander.kick(reason);
});
}
handshake(body) {
return __awaiter(this, void 0, void 0, function* () {
this.commander.handshake(this.options.validator.handshake(body));
});
}
cancel(id) {
return __awaiter(this, void 0, void 0, function* () {
this.commander.cancelRequest(id);
});
}
on(command, callback) {
return __awaiter(this, void 0, void 0, function* () {
this.commander.addCommand(command, callback);
});
}
off(command, callback) {
return __awaiter(this, void 0, void 0, function* () {
this.commander.cancelCommand(command, callback);
});
}
onRequest(request, callback) {
return __awaiter(this, void 0, void 0, function* () {
this.commander.addOnRequest(request, callback);
});
}
offRequest(request) {
return __awaiter(this, void 0, void 0, function* () {
this.commander.cancelOnRequest(request);
});
}
destroy() {
return __awaiter(this, void 0, void 0, function* () {
this.commander.destroy();
this.log.destroy();
});
}
}
exports.Client = Client;
//# sourceMappingURL=Client.js.map