diff --git a/ezy-client.js b/ezy-client.js index 461cd21..c0ed4a8 100644 --- a/ezy-client.js +++ b/ezy-client.js @@ -1,10 +1,10 @@ -import Const from './ezy-constants' -import Util from './ezy-util' -import Event from './ezy-events' -import Manager from './ezy-managers' -import Socket from './ezy-sockets' -import EzySetup from './ezy-setup' -import EzyEventMessageHandler from './ezy-event-message-handler' +import Const from './ezy-constants'; +import Util from './ezy-util'; +import Event from './ezy-events'; +import Manager from './ezy-managers'; +import Socket from './ezy-sockets'; +import EzySetup from './ezy-setup'; +import EzyEventMessageHandler from './ezy-event-message-handler'; /** * Wrapper for JS built-in WebSocket to communicate with websocket server @@ -29,17 +29,21 @@ class EzyConnector { connect(client, url) { this.disconnectReason = null; this.ws = new WebSocket(url); - var thiz = this; + let that = this; var failed = false; - var pingManager = client.pingManager; - var eventMessageHandler = client.eventMessageHandler; + let pingManager = client.pingManager; + let eventMessageHandler = client.eventMessageHandler; this.ws.onerror = function (e) { - Util.EzyLogger.console('connect to: ' + url + ' error : ' + JSON.stringify(e)); + Util.EzyLogger.console( + 'connect to: ' + url + ' error : ' + JSON.stringify(e) + ); failed = true; - var event = new Event.EzyConnectionFailureEvent(Const.EzyConnectionFailedReason.UNKNOWN); + var event = new Event.EzyConnectionFailureEvent( + Const.EzyConnectionFailedReason.UNKNOWN + ); eventMessageHandler.handleEvent(event); - } + }; this.ws.onopen = function (e) { Util.EzyLogger.console('connected to: ' + url); @@ -47,29 +51,29 @@ class EzyConnector { client.status = Const.EzyConnectionStatus.CONNECTED; var event = new Event.EzyConnectionSuccessEvent(); eventMessageHandler.handleEvent(event); - } + }; this.ws.onclose = function (e) { - if (failed) - return; - if (thiz.destroyed) - return; + if (failed) return; + if (that.destroyed) return; if (client.isConnected()) { - var reason = thiz.disconnectReason || Const.EzyDisconnectReason.UNKNOWN; + var reason = + that.disconnectReason || Const.EzyDisconnectReason.UNKNOWN; eventMessageHandler.handleDisconnection(reason); } else { - Util.EzyLogger.console('connection to: ' + url + " has disconnected before"); + Util.EzyLogger.console( + 'connection to: ' + url + ' has disconnected before' + ); } - } + }; this.ws.onmessage = function (event) { - if (thiz.destroyed) - return; + if (that.destroyed) return; pingManager.lostPingCount = 0; var data = event.data; var message = JSON.parse(data); eventMessageHandler.handleMessage(message); - } + }; } /** @@ -124,7 +128,10 @@ class EzyClient { this.pingSchedule = new Socket.EzyPingSchedule(this); this.handlerManager = new Manager.EzyHandlerManager(this); this.setup = new EzySetup(this.handlerManager); - this.unloggableCommands = [Const.EzyCommand.PING, Const.EzyCommand.PONG]; + this.unloggableCommands = [ + Const.EzyCommand.PING, + Const.EzyCommand.PONG, + ]; this.eventMessageHandler = new EzyEventMessageHandler(this); this.pingSchedule.eventMessageHandler = this.eventMessageHandler; } @@ -151,17 +158,13 @@ class EzyClient { reconnect() { var reconnectConfig = this.config.reconnect; var maxReconnectCount = reconnectConfig.maxReconnectCount; - if (this.reconnectCount >= maxReconnectCount) - return false; + if (this.reconnectCount >= maxReconnectCount) return false; this.preconnect(); this.status = Const.EzyConnectionStatus.RECONNECTING; - this.reconnectTimeout = setTimeout( - () => { - this.connector = new EzyConnector(); - this.connector.connect(this, this.url); - }, - reconnectConfig.reconnectPeriod - ); + this.reconnectTimeout = setTimeout(() => { + this.connector = new EzyConnector(); + this.connector.connect(this, this.url); + }, reconnectConfig.reconnectPeriod); this.reconnectCount++; var event = new Event.EzyTryConnectEvent(this.reconnectCount); this.eventMessageHandler.handleEvent(event); @@ -174,10 +177,8 @@ class EzyClient { this.zone = null; this.me = null; this.appsById = {}; - if (this.connector) - this.connector.destroy(); - if (this.reconnectTimeout) - clearTimeout(this.reconnectTimeout); + if (this.connector) this.connector.destroy(); + if (this.reconnectTimeout) clearTimeout(this.reconnectTimeout); } /** @@ -194,8 +195,7 @@ class EzyClient { } internalDisconnect(reason) { - if (this.connector) - this.connector.disconnect(reason); + if (this.connector) this.connector.disconnect(reason); } /** @@ -203,7 +203,7 @@ class EzyClient { * @param data */ send(cmd, data) { - this.sendRequest(cmd, data) + this.sendRequest(cmd, data); } /** @@ -213,7 +213,9 @@ class EzyClient { */ sendRequest(cmd, data) { if (!this.unloggableCommands.includes(cmd)) { - Util.EzyLogger.console('send cmd: ' + cmd.name + ", data: " + JSON.stringify(data)); + Util.EzyLogger.console( + 'send cmd: ' + cmd.name + ', data: ' + JSON.stringify(data) + ); } var request = [cmd.id, data]; this.connector.send(request); @@ -234,7 +236,7 @@ class EzyClient { * @returns {boolean} Whether or not the status is CONNECTED */ isConnected() { - var connected = (this.status == Const.EzyConnectionStatus.CONNECTED); + var connected = this.status === Const.EzyConnectionStatus.CONNECTED; return connected; } @@ -242,7 +244,7 @@ class EzyClient { * Get first app from this client zone * @returns {EzyApp} Queried app */ - getApp() { + getApp() { if (!this.zone) return null; var appManager = this.zone.appManager; return appManager.getApp(); @@ -270,6 +272,10 @@ class EzyClient { return pluginManager.getPluginById(pluginId); } + newAppManager(zoneName) { + return new Manager.EzyAppManager(zoneName); + } + /** * Get the app manager of this client zone * @returns {EzyAppManager} App manager of current client zone @@ -279,6 +285,10 @@ class EzyClient { return this.zone.appManager; } + newPluginManager(zoneName) { + return new Manager.EzyPluginManager(zoneName); + } + /** * Get the plugin manager of this client zone * @returns {EzyPluginManager} Plugin manager of current client zone @@ -289,4 +299,4 @@ class EzyClient { } } -export default EzyClient +export default EzyClient; diff --git a/ezy-clients.js b/ezy-clients.js index bd9973a..79caec3 100644 --- a/ezy-clients.js +++ b/ezy-clients.js @@ -1,4 +1,4 @@ -import EzyClient from './ezy-client' +import EzyClient from './ezy-client'; /** * Singleton object to manage all clients of a server. @@ -8,7 +8,7 @@ import EzyClient from './ezy-client' class EzyClients { constructor() { this.clients = {}; - this.defaultClientName = ""; + this.defaultClientName = ''; } /** @@ -30,8 +30,7 @@ class EzyClients { newClient(config) { var client = new EzyClient(config); this.addClient(client); - if (this.defaultClientName == "") - this.defaultClientName = client.name; + if (this.defaultClientName === '') this.defaultClientName = client.name; return client; } @@ -72,4 +71,4 @@ class EzyClients { } } -export default EzyClients +export default EzyClients; diff --git a/ezy-configs.js b/ezy-configs.js index 340e222..0e1ddf4 100644 --- a/ezy-configs.js +++ b/ezy-configs.js @@ -1,7 +1,7 @@ class EzyClientConfig { constructor() { - this.zoneName = ""; - this.clientName = ""; + this.zoneName = ''; + this.clientName = ''; this.reconnect = new EzyReconnectConfig(); } @@ -10,8 +10,7 @@ class EzyClientConfig { * @returns {string} Client name */ getClientName() { - if (this.clientName == "") - return this.zoneName; + if (this.clientName === '') return this.zoneName; return this.clientName; } } @@ -24,4 +23,4 @@ class EzyReconnectConfig { } } -export default {EzyClientConfig} +export default { EzyClientConfig }; diff --git a/ezy-constants.js b/ezy-constants.js index 9ff59d1..e48d4d0 100644 --- a/ezy-constants.js +++ b/ezy-constants.js @@ -1,20 +1,20 @@ -export const EzyCommand = { - ERROR : {id: 10, name: "ERROR"}, - HANDSHAKE : {id: 11, name: "HANDSHAKE"}, - PING : {id: 12, name: "PING"}, - PONG : {id: 13, name: "PONG"}, - DISCONNECT : {id: 14, name: "DISCONNECT"}, - LOGIN : {id: 20, name: "LOGIN"}, - LOGIN_ERROR : {id: 21, name: "LOGIN_ERROR"}, - LOGOUT : {id: 22, name: "LOGOUT"}, - APP_ACCESS : {id: 30, name: "APP_ACCESS"}, - APP_REQUEST : {id: 31, name: "APP_REQUEST"}, - APP_EXIT : {id: 33, name: "APP_EXIT"}, - APP_ACCESS_ERROR : {id: 34, name: "APP_ACCESS_ERROR"}, - APP_REQUEST_ERROR: {id: 35, name: "APP_REQUEST_ERROR"}, - PLUGIN_INFO : {id: 40, name: "PLUGIN_INFO"}, - PLUGIN_REQUEST : {id: 41, name: "PLUGIN_REQUEST"} -} +export const EzyCommand = { + ERROR: { id: 10, name: 'ERROR' }, + HANDSHAKE: { id: 11, name: 'HANDSHAKE' }, + PING: { id: 12, name: 'PING' }, + PONG: { id: 13, name: 'PONG' }, + DISCONNECT: { id: 14, name: 'DISCONNECT' }, + LOGIN: { id: 20, name: 'LOGIN' }, + LOGIN_ERROR: { id: 21, name: 'LOGIN_ERROR' }, + LOGOUT: { id: 22, name: 'LOGOUT' }, + APP_ACCESS: { id: 30, name: 'APP_ACCESS' }, + APP_REQUEST: { id: 31, name: 'APP_REQUEST' }, + APP_EXIT: { id: 33, name: 'APP_EXIT' }, + APP_ACCESS_ERROR: { id: 34, name: 'APP_ACCESS_ERROR' }, + APP_REQUEST_ERROR: { id: 35, name: 'APP_REQUEST_ERROR' }, + PLUGIN_INFO: { id: 40, name: 'PLUGIN_INFO' }, + PLUGIN_REQUEST: { id: 41, name: 'PLUGIN_REQUEST' }, +}; export var EzyCommands = EzyCommands || {}; EzyCommands[EzyCommand.ERROR.id] = EzyCommand.ERROR; @@ -23,9 +23,9 @@ EzyCommands[EzyCommand.PING.id] = EzyCommand.PING; EzyCommands[EzyCommand.PONG.id] = EzyCommand.PONG; EzyCommands[EzyCommand.DISCONNECT.id] = EzyCommand.DISCONNECT; EzyCommands[EzyCommand.LOGIN.id] = EzyCommand.LOGIN; -EzyCommands[EzyCommand.LOGIN_ERROR.id] = EzyCommand.LOGIN_ERROR; -EzyCommands[EzyCommand.LOGOUT.id] = EzyCommand.LOGOUT; -EzyCommands[EzyCommand.APP_ACCESS.id] = EzyCommand.APP_ACCESS; +EzyCommands[EzyCommand.LOGIN_ERROR.id] = EzyCommand.LOGIN_ERROR; +EzyCommands[EzyCommand.LOGOUT.id] = EzyCommand.LOGOUT; +EzyCommands[EzyCommand.APP_ACCESS.id] = EzyCommand.APP_ACCESS; EzyCommands[EzyCommand.APP_REQUEST.id] = EzyCommand.APP_REQUEST; EzyCommands[EzyCommand.APP_EXIT.id] = EzyCommand.APP_EXIT; EzyCommands[EzyCommand.APP_ACCESS_ERROR.id] = EzyCommand.APP_ACCESS_ERROR; @@ -36,73 +36,76 @@ EzyCommands[EzyCommand.PLUGIN_REQUEST.id] = EzyCommand.PLUGIN_REQUEST; Object.freeze(EzyCommands); export const EzyEventType = { - CONNECTION_SUCCESS: "CONNECTION_SUCCESS", - CONNECTION_FAILURE: "CONNECTION_FAILURE", - DISCONNECTION : "DISCONNECTION", - LOST_PING : "LOST_PING", - TRY_CONNECT : "TRY_CONNECT" -} + CONNECTION_SUCCESS: 'CONNECTION_SUCCESS', + CONNECTION_FAILURE: 'CONNECTION_FAILURE', + DISCONNECTION: 'DISCONNECTION', + LOST_PING: 'LOST_PING', + TRY_CONNECT: 'TRY_CONNECT', +}; export const EzyConnectionStatus = { - NULL: "NULL", - CONNECTING: "CONNECTING", - CONNECTED: "CONNECTED", - DISCONNECTED: "DISCONNECTED", - FAILURE: "FAILURE", - RECONNECTING: "RECONNECTING" -} + NULL: 'NULL', + CONNECTING: 'CONNECTING', + CONNECTED: 'CONNECTED', + DISCONNECTED: 'DISCONNECTED', + FAILURE: 'FAILURE', + RECONNECTING: 'RECONNECTING', +}; -export const EzyConnectionFailedReason = { - NETWORK_UNREACHABLE: "NETWORK_UNREACHABLE", - UNKNOWN_HOST: "UNKNOWN_HOST", - CONNECTION_REFUSED: "CONNECTION_REFUSED", - UNKNOWN: "UNKNOWN" -} +export const EzyConnectionFailedReason = { + NETWORK_UNREACHABLE: 'NETWORK_UNREACHABLE', + UNKNOWN_HOST: 'UNKNOWN_HOST', + CONNECTION_REFUSED: 'CONNECTION_REFUSED', + UNKNOWN: 'UNKNOWN', +}; export const EzyDisconnectReason = { CLOSE: -1, - UNKNOWN : 0, - IDLE : 1, - NOT_LOGGED_IN : 2, - ANOTHER_SESSION_LOGIN : 3, - ADMIN_BAN : 4, - ADMIN_KICK : 5, - MAX_REQUEST_PER_SECOND : 6, - MAX_REQUEST_SIZE : 7, - SERVER_ERROR : 8, - SERVER_NOT_RESPONDING : 400, - UNAUTHORIZED: 401 -} + UNKNOWN: 0, + IDLE: 1, + NOT_LOGGED_IN: 2, + ANOTHER_SESSION_LOGIN: 3, + ADMIN_BAN: 4, + ADMIN_KICK: 5, + MAX_REQUEST_PER_SECOND: 6, + MAX_REQUEST_SIZE: 7, + SERVER_ERROR: 8, + SERVER_NOT_RESPONDING: 400, + UNAUTHORIZED: 401, +}; export var EzyDisconnectReasonNames = EzyDisconnectReasonNames || {}; -EzyDisconnectReasonNames[EzyDisconnectReason.CLOSE] = "CLOSE"; -EzyDisconnectReasonNames[EzyDisconnectReason.UNKNOWN] = "UNKNOWN"; -EzyDisconnectReasonNames[EzyDisconnectReason.IDLE] = "IDLE"; -EzyDisconnectReasonNames[EzyDisconnectReason.NOT_LOGGED_IN] = "NOT_LOGGED_IN"; -EzyDisconnectReasonNames[EzyDisconnectReason.ANOTHER_SESSION_LOGIN] = "ANOTHER_SESSION_LOGIN"; -EzyDisconnectReasonNames[EzyDisconnectReason.ADMIN_BAN] = "ADMIN_BAN"; -EzyDisconnectReasonNames[EzyDisconnectReason.ADMIN_KICK] = "ADMIN_KICK"; -EzyDisconnectReasonNames[EzyDisconnectReason.MAX_REQUEST_PER_SECOND] = "MAX_REQUEST_PER_SECOND"; -EzyDisconnectReasonNames[EzyDisconnectReason.MAX_REQUEST_SIZE] = "MAX_REQUEST_SIZE"; -EzyDisconnectReasonNames[EzyDisconnectReason.SERVER_ERROR] = "SERVER_ERROR"; -EzyDisconnectReasonNames[EzyDisconnectReason.SERVER_NOT_RESPONDING] = "SERVER_NOT_RESPONSE"; -EzyDisconnectReasonNames[EzyDisconnectReason.UNAUTHORIZED] = "UNAUTHORIZED"; +EzyDisconnectReasonNames[EzyDisconnectReason.CLOSE] = 'CLOSE'; +EzyDisconnectReasonNames[EzyDisconnectReason.UNKNOWN] = 'UNKNOWN'; +EzyDisconnectReasonNames[EzyDisconnectReason.IDLE] = 'IDLE'; +EzyDisconnectReasonNames[EzyDisconnectReason.NOT_LOGGED_IN] = 'NOT_LOGGED_IN'; +EzyDisconnectReasonNames[EzyDisconnectReason.ANOTHER_SESSION_LOGIN] = + 'ANOTHER_SESSION_LOGIN'; +EzyDisconnectReasonNames[EzyDisconnectReason.ADMIN_BAN] = 'ADMIN_BAN'; +EzyDisconnectReasonNames[EzyDisconnectReason.ADMIN_KICK] = 'ADMIN_KICK'; +EzyDisconnectReasonNames[EzyDisconnectReason.MAX_REQUEST_PER_SECOND] = + 'MAX_REQUEST_PER_SECOND'; +EzyDisconnectReasonNames[EzyDisconnectReason.MAX_REQUEST_SIZE] = + 'MAX_REQUEST_SIZE'; +EzyDisconnectReasonNames[EzyDisconnectReason.SERVER_ERROR] = 'SERVER_ERROR'; +EzyDisconnectReasonNames[EzyDisconnectReason.SERVER_NOT_RESPONDING] = + 'SERVER_NOT_RESPONSE'; +EzyDisconnectReasonNames[EzyDisconnectReason.UNAUTHORIZED] = 'UNAUTHORIZED'; -EzyDisconnectReasonNames.parse = function(reasonId) { +EzyDisconnectReasonNames.parse = function (reasonId) { const answer = EzyDisconnectReasonNames[reasonId]; - if(answer) - return answer; + if (answer) return answer; return reasonId.toString(); -} +}; Object.freeze(EzyDisconnectReasonNames); export default { - EzyCommand, - EzyCommands, - EzyEventType, - EzyConnectionStatus, + EzyCommand, + EzyCommands, + EzyEventType, + EzyConnectionStatus, EzyConnectionFailedReason, EzyDisconnectReason, - EzyDisconnectReasonNames -} \ No newline at end of file + EzyDisconnectReasonNames, +}; diff --git a/ezy-data-handlers.js b/ezy-data-handlers.js index 30517f0..5f616f7 100644 --- a/ezy-data-handlers.js +++ b/ezy-data-handlers.js @@ -1,6 +1,6 @@ -import Const from './ezy-constants' -import Util from './ezy-util' -import Entity from './ezy-entities' +import Const from './ezy-constants'; +import Util from './ezy-util'; +import Entity from './ezy-entities'; /** * A listener which fires when client receives Const.EzyCommand.HANDSHAKE command from server. @@ -31,32 +31,30 @@ import Entity from './ezy-entities' * ``` */ export class EzyHandshakeHandler { - /** * Automatically call this function when client receives HANDSHAKE command * from server. * @param data [encryptedServerPublicKey, token, sessionId] */ - handle(data) { - this.startPing(); - this.handleLogin(); - this.postHandle(data); - } + handle(data) { + this.startPing(); + this.handleLogin(); + this.postHandle(data); + } /** * This function need to be manually defined to specify * what to do after sending login request * @param data: [encryptedServerPublicKey, token, sessionId] */ - postHandle(data) { - } + postHandle(data) {} /** * Send loginRequest to server */ - handleLogin() { - var loginRequest = this.getLoginRequest(); - this.client.sendRequest(Const.EzyCommand.LOGIN, loginRequest); + handleLogin() { + var loginRequest = this.getLoginRequest(); + this.client.sendRequest(Const.EzyCommand.LOGIN, loginRequest); } /** @@ -65,15 +63,15 @@ export class EzyHandshakeHandler { * @returns [zonename, username, password, data] */ getLoginRequest() { - return ["test", "test", "test", []]; - } + return ['test', 'test', 'test', []]; + } /** * Start sending ping request */ - startPing() { - this.client.pingSchedule.start(); - } + startPing() { + this.client.pingSchedule.start(); + } } //====================================== @@ -106,7 +104,9 @@ export class EzyLoginSuccessHandler { this.client.me = user; this.client.zone = zone; this.handleLoginSuccess(responseData); - Util.EzyLogger.console("user: " + user.name + " logged in successfully"); + Util.EzyLogger.console( + 'user: ' + user.name + ' logged in successfully' + ); } /** @@ -114,8 +114,7 @@ export class EzyLoginSuccessHandler { * do after successful login * @param responseData Additional data received from server */ - handleLoginSuccess(responseData) { - } + handleLoginSuccess(responseData) {} } //====================================== @@ -146,8 +145,7 @@ export class EzyLoginErrorHandler { * do after unsuccessful login * @param data [errorId, errorMessage] */ - handleLoginError(data) { - } + handleLoginError(data) {} } //====================================== @@ -175,7 +173,7 @@ export class EzyAppAccessHandler { var app = this.newApp(zone, data); appManager.addApp(app); this.postHandle(app, data); - Util.EzyLogger.console("access app: " + app.name + " successfully"); + Util.EzyLogger.console('access app: ' + app.name + ' successfully'); } /** @@ -197,8 +195,7 @@ export class EzyAppAccessHandler { * @param app {EzyApp} App has just been created * @param data {array} [appId, appName, data=[]] */ - postHandle(app, data) { - } + postHandle(app, data) {} } //====================================== @@ -220,13 +217,15 @@ export class EzyAppExitHandler { */ handle(data) { var zone = this.client.zone; - var appManager = zone.appManager + var appManager = zone.appManager; var appId = data[0]; var reasonId = data[1]; var app = appManager.removeApp(appId); - if(app) { + if (app) { this.postHandle(app, data); - Util.EzyLogger.console("user exit app: " + app.name + ", reason: " + reasonId); + Util.EzyLogger.console( + 'user exit app: ' + app.name + ', reason: ' + reasonId + ); } } @@ -236,9 +235,7 @@ export class EzyAppExitHandler { * @param app {EzyApp} App has just been removed * @param data {array} [appId, reasonId] */ - postHandle(app, data) { - } - + postHandle(app, data) {} } //====================================== @@ -263,15 +260,18 @@ export class EzyAppResponseHandler { var commandData = responseData[1]; var app = this.client.getAppById(appId); - if(!app) { - Util.EzyLogger.console("receive message when has not joined app yet"); + if (!app) { + Util.EzyLogger.console( + 'receive message when has not joined app yet' + ); return; } var handler = app.getDataHandler(cmd); - if(handler) - handler(app, commandData); + if (handler) handler(app, commandData); else - Util.EzyLogger.console("app: " + app.name + " has no handler for command: " + cmd); + Util.EzyLogger.console( + 'app: ' + app.name + ' has no handler for command: ' + cmd + ); } } @@ -299,7 +299,9 @@ export class EzyPluginInfoHandler { var plugin = this.newPlugin(zone, data); pluginManager.addPlugin(plugin); this.postHandle(plugin, data); - Util.EzyLogger.console("request plugin: " + plugin.name + " info successfully"); + Util.EzyLogger.console( + 'request plugin: ' + plugin.name + ' info successfully' + ); } /** * Create an EzyPlugin entity for client @@ -310,7 +312,12 @@ export class EzyPluginInfoHandler { newPlugin(zone, data) { var pluginId = data[0]; var pluginName = data[1]; - var plugin = new Entity.EzyPlugin(this.client, zone, pluginId, pluginName); + var plugin = new Entity.EzyPlugin( + this.client, + zone, + pluginId, + pluginName + ); return plugin; } @@ -320,8 +327,7 @@ export class EzyPluginInfoHandler { * @param plugin {EzyPlugin} Plugin has just been created * @param data {array} [pluginId, pluginName, data=[]] */ - postHandle(plugin, data) { - } + postHandle(plugin, data) {} } //====================================== @@ -347,10 +353,11 @@ export class EzyPluginResponseHandler { var plugin = this.client.getPluginById(pluginId); var handler = plugin.getDataHandler(cmd); - if(handler) - handler(plugin, commandData); + if (handler) handler(plugin, commandData); else - Util.EzyLogger.console("plugin: " + plugin.name + " has no handler for command: " + cmd); + Util.EzyLogger.console( + 'plugin: ' + plugin.name + ' has no handler for command: ' + cmd + ); } } @@ -360,8 +367,7 @@ export class EzyPluginResponseHandler { * from server */ export class EzyPongHandler { - handle(client) { - } + handle(client) {} } //====================================== @@ -406,9 +412,8 @@ export class EzyDataHandlers { * Manager class of all data handlers of an app */ export class EzyAppDataHandlers { - constructor() { - this.handlers = {} + this.handlers = {}; } /** @@ -429,7 +434,6 @@ export class EzyAppDataHandlers { var handler = this.handlers[cmd]; return handler; } - } //====================================== @@ -437,9 +441,8 @@ export class EzyAppDataHandlers { * Manager class of all data handlers of a plugin. */ export class EzyPluginDataHandlers { - constructor() { - this.handlers = {} + this.handlers = {}; } /** @@ -460,7 +463,6 @@ export class EzyPluginDataHandlers { var handler = this.handlers[cmd]; return handler; } - } //====================================== @@ -477,5 +479,5 @@ export default { EzyPongHandler, EzyAppDataHandlers, EzyPluginDataHandlers, - EzyDataHandlers -} + EzyDataHandlers, +}; diff --git a/ezy-entities.js b/ezy-entities.js index b0339b2..74181d9 100644 --- a/ezy-entities.js +++ b/ezy-entities.js @@ -1,5 +1,4 @@ -import Const from './ezy-constants' -import Manager from './ezy-managers' +import Const from './ezy-constants'; //=================================================== @@ -17,8 +16,8 @@ export class EzyZone { this.id = id; this.name = name; this.client = client; - this.appManager = new Manager.EzyAppManager(name); - this.pluginManager = new Manager.EzyPluginManager(name); + this.appManager = client.newAppManager(name); + this.pluginManager = client.newPluginManager(name); } } @@ -39,8 +38,7 @@ export class EzyApp { sendRequest(cmd, data) { var validData = data; - if(!validData) - validData = {}; + if (!validData) validData = {}; var requestData = [this.id, [cmd, validData]]; this.client.sendRequest(Const.EzyCommand.APP_REQUEST, requestData); } @@ -68,8 +66,7 @@ export class EzyPlugin { sendRequest(cmd, data) { var validData = data; - if(!validData) - validData = {}; + if (!validData) validData = {}; var requestData = [this.id, [cmd, validData]]; this.client.sendRequest(Const.EzyCommand.PLUGIN_REQUEST, requestData); } @@ -82,4 +79,4 @@ export class EzyPlugin { //=================================================== -export default {EzyUser, EzyZone, EzyApp, EzyPlugin} \ No newline at end of file +export default { EzyUser, EzyZone, EzyApp, EzyPlugin }; diff --git a/ezy-event-handlers.js b/ezy-event-handlers.js index 07fa031..4adf694 100644 --- a/ezy-event-handlers.js +++ b/ezy-event-handlers.js @@ -1,11 +1,10 @@ -import Const from './ezy-constants' -import Util from './ezy-util' +import Const from './ezy-constants'; +import Util from './ezy-util'; export class EzyConnectionSuccessHandler { - constructor() { - this.clientType = "JSEMACS6"; - this.clientVersion = "1.0.0"; + this.clientType = 'JSEMACS6'; + this.clientVersion = '1.2.0'; } handle() { @@ -13,8 +12,7 @@ export class EzyConnectionSuccessHandler { this.postHandle(); } - postHandle() { - } + postHandle() {} sendHandshakeRequest() { var request = this.newHandshakeRequest(); @@ -24,14 +22,21 @@ export class EzyConnectionSuccessHandler { newHandshakeRequest() { var clientId = this.getClientId(); var clientKey = this.getClientKey(); - var enableEncryption = this.isEnableEncryption(); + var enableEncryption = false; var token = this.getStoredToken(); - var request = [clientId, clientKey, this.clientType, this.clientVersion, enableEncryption, token]; + var request = [ + clientId, + clientKey, + this.clientType, + this.clientVersion, + enableEncryption, + token, + ]; return request; } getClientKey() { - return ""; + return ''; } getClientId() { @@ -39,42 +44,42 @@ export class EzyConnectionSuccessHandler { return guid; } - isEnableEncryption() { - return false; - } - getStoredToken() { - return ""; + return ''; } - } //====================================== export class EzyConnectionFailureHandler { - handle(event) { - Util.EzyLogger.console("connection failure, reason = " + event.reason); + Util.EzyLogger.console('connection failure, reason = ' + event.reason); var config = this.client.config; var reconnectConfig = config.reconnect; var should = this.shouldReconnect(event); var must = reconnectConfig.enable && should; var reconnecting = false; this.client.status = Const.EzyConnectionStatus.FAILURE; - if(must) + if (must) { reconnecting = this.client.reconnect(); - if(!reconnecting) { - this.control(event); } + if (reconnecting) { + this.onReconnecting(event); + } else { + this.onDisconnected(event); + } + this.postHandle(event); } shouldReconnect(event) { return true; } - control(event) { - } + onReconnecting(event) {} + + onDisconnected(event) {} + postHandle(event) {} } //====================================== @@ -83,40 +88,43 @@ export class EzyDisconnectionHandler { handle(event) { var reason = event.reason; const reasonName = Const.EzyDisconnectReasonNames.parse(reason); - Util.EzyLogger.console("handle disconnection, reason = " + reasonName); + Util.EzyLogger.console('handle disconnection, reason = ' + reasonName); this.preHandle(event); var config = this.client.config; var reconnectConfig = config.reconnect; var should = this.shouldReconnect(event); - var mustReconnect = reconnectConfig.enable && - reason != Const.EzyDisconnectReason.UNAUTHORIZED && - reason != Const.EzyDisconnectReason.CLOSE && + var mustReconnect = + reconnectConfig.enable && + reason !== Const.EzyDisconnectReason.UNAUTHORIZED && + reason !== Const.EzyDisconnectReason.CLOSE && should; var reconnecting = false; this.client.status = Const.EzyConnectionStatus.DISCONNECTED; - if(mustReconnect) + if (mustReconnect) { reconnecting = this.client.reconnect(); - if(!reconnecting) { - this.control(event); + } + if (reconnecting) { + this.onReconnecting(event); + } else { + this.onDisconnected(event); } this.postHandle(event); } - preHandle(event) { - } + preHandle(event) {} shouldReconnect(event) { var reason = event.reason; - if(reason == Const.EzyDisconnectReason.ANOTHER_SESSION_LOGIN) + if (reason === Const.EzyDisconnectReason.ANOTHER_SESSION_LOGIN) return false; return true; } - control(event) { - } + onReconnecting(event) {} - postHandle(event) { - } + onDisconnected(event) {} + + postHandle(event) {} } //====================================== @@ -144,5 +152,5 @@ export default { EzyConnectionSuccessHandler, EzyConnectionFailureHandler, EzyDisconnectionHandler, - EzyEventHandlers -} \ No newline at end of file + EzyEventHandlers, +}; diff --git a/ezy-event-message-handler.js b/ezy-event-message-handler.js index ea9256c..95f838c 100644 --- a/ezy-event-message-handler.js +++ b/ezy-event-message-handler.js @@ -1,9 +1,8 @@ -import Const from './ezy-constants' -import Util from './ezy-util' -import Event from './ezy-events' +import Const from './ezy-constants'; +import Util from './ezy-util'; +import Event from './ezy-events'; class EzyEventMessageHandler { - constructor(client) { this.client = client; this.handlerManager = client.handlerManager; @@ -12,10 +11,11 @@ class EzyEventMessageHandler { handleEvent(event) { var eventHandler = this.handlerManager.getEventHandler(event.getType()); - if(eventHandler) - eventHandler.handle(event); + if (eventHandler) eventHandler.handle(event); else - Util.EzyLogger.console('has no handler with event: ' + event.getType()); + Util.EzyLogger.console( + 'has no handler with event: ' + event.getType() + ); } handleDisconnection(reason) { @@ -27,12 +27,13 @@ class EzyEventMessageHandler { handleMessage(message) { var cmd = Const.EzyCommands[message[0]]; var data = message.length > 1 ? message[1] : []; - if(!this.unloggableCommands.includes(cmd)) - Util.EzyLogger.console('received cmd: ' + cmd.name + ", data: " + JSON.stringify(data)); - if(cmd === Const.EzyCommand.DISCONNECT) + if (!this.unloggableCommands.includes(cmd)) + Util.EzyLogger.console( + 'received cmd: ' + cmd.name + ', data: ' + JSON.stringify(data) + ); + if (cmd === Const.EzyCommand.DISCONNECT) this.handleDisconnectionData(data); - else - this.handleResponseData(cmd, data); + else this.handleResponseData(cmd, data); } handleDisconnectionData(resonseData) { @@ -42,11 +43,9 @@ class EzyEventMessageHandler { handleResponseData(cmd, responseData) { var handler = this.handlerManager.getDataHandler(cmd); - if(handler) - handler.handle(responseData); - else - Util.EzyLogger.console("has no handler with command: " + cmd.name); + if (handler) handler.handle(responseData); + else Util.EzyLogger.console('has no handler with command: ' + cmd.name); } } -export default EzyEventMessageHandler \ No newline at end of file +export default EzyEventMessageHandler; diff --git a/ezy-events.js b/ezy-events.js index 4e1b9fb..0253b11 100644 --- a/ezy-events.js +++ b/ezy-events.js @@ -1,11 +1,9 @@ -import Const from './ezy-constants' +import Const from './ezy-constants'; export class EzyConnectionSuccessEvent { - getType() { return Const.EzyEventType.CONNECTION_SUCCESS; } - } export class EzyTryConnectEvent { @@ -19,7 +17,6 @@ export class EzyTryConnectEvent { } export class EzyConnectionFailureEvent { - constructor(reason) { this.reason = reason; } @@ -27,7 +24,6 @@ export class EzyConnectionFailureEvent { getType() { return Const.EzyEventType.CONNECTION_FAILURE; } - } export class EzyLostPingEvent { @@ -41,7 +37,6 @@ export class EzyLostPingEvent { } export class EzyDisconnectionEvent { - constructor(reason) { this.reason = reason; } @@ -49,7 +44,6 @@ export class EzyDisconnectionEvent { getType() { return Const.EzyEventType.DISCONNECTION; } - } export default { @@ -57,5 +51,5 @@ export default { EzyTryConnectEvent, EzyConnectionFailureEvent, EzyLostPingEvent, - EzyDisconnectionEvent -} \ No newline at end of file + EzyDisconnectionEvent, +}; diff --git a/ezy-managers.js b/ezy-managers.js index 8acb478..90bb813 100644 --- a/ezy-managers.js +++ b/ezy-managers.js @@ -1,10 +1,9 @@ -import Const from './ezy-constants' -import Util from './ezy-util' -import DataHandler from './ezy-data-handlers' -import EventHandler from './ezy-event-handlers' +import Const from './ezy-constants'; +import Util from './ezy-util'; +import DataHandler from './ezy-data-handlers'; +import EventHandler from './ezy-event-handlers'; export class EzyAppManager { - constructor(zoneName) { this.zoneName = zoneName; this.appList = []; @@ -14,10 +13,8 @@ export class EzyAppManager { getApp() { var app = null; - if(this.appList.length > 0) - app = this.appList[0]; - else - Util.EzyLogger.console('has no app in zone: ' + this.zoneName); + if (this.appList.length > 0) app = this.appList[0]; + else Util.EzyLogger.console('has no app in zone: ' + this.zoneName); return app; } @@ -29,10 +26,10 @@ export class EzyAppManager { removeApp(appId) { var app = this.appsById[appId]; - if(app) { + if (app) { delete this.appsById[appId]; delete this.appsByName[app.name]; - this.appList = this.appList.filter(item => item.id != appId); + this.appList = this.appList.filter((item) => item.id !== appId); } return app; } @@ -51,7 +48,6 @@ export class EzyAppManager { //====================================== export class EzyPluginManager { - constructor(zoneName) { this.zoneName = zoneName; this.pluginList = []; @@ -61,10 +57,8 @@ export class EzyPluginManager { getPlugin() { var plugin = null; - if(this.pluginList.length > 0) - plugin = this.pluginList[0]; - else - Util.EzyLogger.console('has no plugin in zone: ' + this.zoneName); + if (this.pluginList.length > 0) plugin = this.pluginList[0]; + else Util.EzyLogger.console('has no plugin in zone: ' + this.zoneName); return plugin; } @@ -95,41 +89,76 @@ export class EzyPingManager { } increaseLostPingCount() { - return (++ this.lostPingCount); + return ++this.lostPingCount; } } //====================================== export class EzyHandlerManager { - constructor(client) { this.client = client; this.dataHandlers = this.newDataHandlers(); this.eventHandlers = this.newEventHandlers(); - this.appDataHandlerss = {}; - this.pluginDataHandlerss = {}; + this.appDataHandlersByName = {}; + this.pluginDataHandlersByName = {}; } newEventHandlers() { var handlers = new EventHandler.EzyEventHandlers(this.client); - handlers.addHandler(Const.EzyEventType.CONNECTION_SUCCESS, new EventHandler.EzyConnectionSuccessHandler()); - handlers.addHandler(Const.EzyEventType.CONNECTION_FAILURE, new EventHandler.EzyConnectionFailureHandler()); - handlers.addHandler(Const.EzyEventType.DISCONNECTION, new EventHandler.EzyDisconnectionHandler()); + handlers.addHandler( + Const.EzyEventType.CONNECTION_SUCCESS, + new EventHandler.EzyConnectionSuccessHandler() + ); + handlers.addHandler( + Const.EzyEventType.CONNECTION_FAILURE, + new EventHandler.EzyConnectionFailureHandler() + ); + handlers.addHandler( + Const.EzyEventType.DISCONNECTION, + new EventHandler.EzyDisconnectionHandler() + ); return handlers; } newDataHandlers() { var handlers = new DataHandler.EzyDataHandlers(this.client); - handlers.addHandler(Const.EzyCommand.PONG, new DataHandler.EzyPongHandler()); - handlers.addHandler(Const.EzyCommand.HANDSHAKE, new DataHandler.EzyHandshakeHandler()); - handlers.addHandler(Const.EzyCommand.LOGIN, new DataHandler.EzyLoginSuccessHandler()); - handlers.addHandler(Const.EzyCommand.LOGIN_ERROR, new DataHandler.EzyLoginErrorHandler()); - handlers.addHandler(Const.EzyCommand.APP_ACCESS, new DataHandler.EzyAppAccessHandler()); - handlers.addHandler(Const.EzyCommand.APP_REQUEST, new DataHandler.EzyAppResponseHandler()); - handlers.addHandler(Const.EzyCommand.APP_EXIT, new DataHandler.EzyAppExitHandler()); - handlers.addHandler(Const.EzyCommand.PLUGIN_INFO, new DataHandler.EzyPluginInfoHandler()); - handlers.addHandler(Const.EzyCommand.PLUGIN_REQUEST, new DataHandler.EzyPluginResponseHandler()); + handlers.addHandler( + Const.EzyCommand.PONG, + new DataHandler.EzyPongHandler() + ); + handlers.addHandler( + Const.EzyCommand.HANDSHAKE, + new DataHandler.EzyHandshakeHandler() + ); + handlers.addHandler( + Const.EzyCommand.LOGIN, + new DataHandler.EzyLoginSuccessHandler() + ); + handlers.addHandler( + Const.EzyCommand.LOGIN_ERROR, + new DataHandler.EzyLoginErrorHandler() + ); + handlers.addHandler( + Const.EzyCommand.APP_ACCESS, + new DataHandler.EzyAppAccessHandler() + ); + handlers.addHandler( + Const.EzyCommand.APP_REQUEST, + new DataHandler.EzyAppResponseHandler() + ); + handlers.addHandler( + Const.EzyCommand.APP_EXIT, + new DataHandler.EzyAppExitHandler() + ); + handlers.addHandler( + Const.EzyCommand.PLUGIN_INFO, + new DataHandler.EzyPluginInfoHandler() + ); + handlers.addHandler( + Const.EzyCommand.PLUGIN_REQUEST, + new DataHandler.EzyPluginResponseHandler() + ); return handlers; } @@ -144,25 +173,25 @@ export class EzyHandlerManager { } getAppDataHandlers(appName) { - var answer = this.appDataHandlerss[appName]; - if(!answer) { + var answer = this.appDataHandlersByName[appName]; + if (!answer) { answer = new DataHandler.EzyAppDataHandlers(); - this.appDataHandlerss[appName] = answer; + this.appDataHandlersByName[appName] = answer; } return answer; } getPluginDataHandlers(pluginName) { - var answer = this.pluginDataHandlerss[pluginName]; - if(!answer) { + var answer = this.pluginDataHandlersByName[pluginName]; + if (!answer) { answer = new DataHandler.EzyPluginDataHandlers(); - this.pluginDataHandlerss[pluginName] = answer; + this.pluginDataHandlersByName[pluginName] = answer; } return answer; } addDataHandler(cmd, dataHandler) { - this.dataHandlers.addHandler(cmd, dataHandler); + this.dataHandlers.addHandler(cmd, dataHandler); } addEventHandler(eventType, eventHandler) { @@ -170,4 +199,9 @@ export class EzyHandlerManager { } } -export default {EzyAppManager, EzyPluginManager, EzyPingManager, EzyHandlerManager} \ No newline at end of file +export default { + EzyAppManager, + EzyPluginManager, + EzyPingManager, + EzyHandlerManager, +}; diff --git a/ezy-setup.js b/ezy-setup.js index b6e795a..902bf6d 100644 --- a/ezy-setup.js +++ b/ezy-setup.js @@ -17,8 +17,9 @@ class EzySetup { setupApp(appName) { var appSetup = this.appSetups[appName]; - if(!appSetup) { - var appDataHandlers = this.handlerManager.getAppDataHandlers(appName); + if (!appSetup) { + var appDataHandlers = + this.handlerManager.getAppDataHandlers(appName); appSetup = new EzyAppSetup(appDataHandlers, this); this.appSetups[appName] = appSetup; } @@ -27,8 +28,9 @@ class EzySetup { setupPlugin(pluginName) { var pluginSetup = this.pluginSetups[pluginName]; - if(!pluginSetup) { - var pluginDataHandlers = this.handlerManager.getPluginDataHandlers(pluginName); + if (!pluginSetup) { + var pluginDataHandlers = + this.handlerManager.getPluginDataHandlers(pluginName); pluginSetup = new EzyPluginSetup(pluginDataHandlers, this); this.pluginSetups[pluginName] = pluginSetup; } @@ -37,7 +39,6 @@ class EzySetup { } class EzyAppSetup { - constructor(dataHandlers, parent) { this.parent = parent; this.dataHandlers = dataHandlers; @@ -54,7 +55,6 @@ class EzyAppSetup { } class EzyPluginSetup { - constructor(dataHandlers, parent) { this.parent = parent; this.dataHandlers = dataHandlers; @@ -70,5 +70,4 @@ class EzyPluginSetup { } } - -export default EzySetup \ No newline at end of file +export default EzySetup; diff --git a/ezy-sockets.js b/ezy-sockets.js index 8a29525..29fdb4a 100644 --- a/ezy-sockets.js +++ b/ezy-sockets.js @@ -1,7 +1,6 @@ -import Const from './ezy-constants' +import Const from './ezy-constants'; class EzyPingSchedule { - constructor(client) { this.client = client; this.pingManager = client.pingManager; @@ -9,15 +8,12 @@ class EzyPingSchedule { } start() { - var startPingNow = function(thiz) { - var pingInterval = setInterval( - () => { - thiz.sendPingRequest(); - }, - thiz.pingManager.pingPeriod - ); + var startPingNow = function (thiz) { + var pingInterval = setInterval(() => { + thiz.sendPingRequest(); + }, thiz.pingManager.pingPeriod); return pingInterval; - } + }; this.stop(); this.pingInterval = startPingNow(this); } @@ -25,19 +21,17 @@ class EzyPingSchedule { sendPingRequest() { const maxLostPingCount = this.pingManager.maxLostPingCount; const lostPingCount = this.pingManager.increaseLostPingCount(); - if(lostPingCount >= maxLostPingCount) { + if (lostPingCount >= maxLostPingCount) { var reason = Const.EzyDisconnectReason.SERVER_NOT_RESPONDING; this.eventMessageHandler.handleDisconnection(reason); - } - else { + } else { this.client.sendRequest(Const.EzyCommand.PING, []); } } stop() { - if(this.pingInterval) - clearInterval(this.pingInterval); + if (this.pingInterval) clearInterval(this.pingInterval); } } -export default {EzyPingSchedule} \ No newline at end of file +export default { EzyPingSchedule }; diff --git a/ezy-util.js b/ezy-util.js index f812180..e4bfff0 100644 --- a/ezy-util.js +++ b/ezy-util.js @@ -1,11 +1,24 @@ export class EzyGuid { static generate() { function s4() { - return Math.floor((1 + Math.random()) * 0x10000) - .toString(16) - .substring(1); + return Math.floor((1 + Math.random()) * 0x10000) + .toString(16) + .substring(1); } - return s4() + s4() + '-' + s4() + '-' + s4() + '-' + s4() + '-' + s4() + s4() + s4(); + return ( + s4() + + s4() + + '-' + + s4() + + '-' + + s4() + + '-' + + s4() + + '-' + + s4() + + s4() + + s4() + ); } } @@ -15,9 +28,8 @@ export class EzyLogger { } static console(message) { - if(EzyLogger.debug()) - console.log(message); + if (EzyLogger.debug()) console.log(message); } } -export default {EzyGuid, EzyLogger} \ No newline at end of file +export default { EzyGuid, EzyLogger }; diff --git a/index.js b/index.js index ab0950b..e89be41 100644 --- a/index.js +++ b/index.js @@ -1,40 +1,40 @@ -import Util from './ezy-util' -import Entity from './ezy-entities' -import Const from './ezy-constants' -import Config from './ezy-configs' -import EventHandler from './ezy-event-handlers' -import DataHandler from './ezy-data-handlers' -import EzyClient from './ezy-client' -import EzyClients from './ezy-clients' +import Util from './ezy-util'; +import Entity from './ezy-entities'; +import Const from './ezy-constants'; +import Config from './ezy-configs'; +import EventHandler from './ezy-event-handlers'; +import DataHandler from './ezy-data-handlers'; +import EzyClient from './ezy-client'; +import EzyClients from './ezy-clients'; const Ezy = { - Guid : Util.EzyGuid, - Logger : Util.EzyLogger, - App : Entity.EzyApp, - User : Entity.EzyUser, - Zone : Entity.EzyZone, - Command : Const.EzyCommand, - Commands : Const.EzyCommands, - DisconnectReason : Const.EzyDisconnectReason, - DisconnectReasonNames : Const.EzyDisconnectReasonNames, - ConnectionFailedReason : Const.EzyConnectionFailedReason, - ConnectionStatus : Const.EzyConnectionStatus, - EventType : Const.EzyEventType, - ClientConfig : Config.EzyClientConfig, - ConnectionSuccessHandler : EventHandler.EzyConnectionSuccessHandler, - ConnectionFailureHandler : EventHandler.EzyConnectionFailureHandler, - DisconnectionHandler : EventHandler.EzyDisconnectionHandler, - HandshakeHandler : DataHandler.EzyHandshakeHandler, - LoginSuccessHandler : DataHandler.EzyLoginSuccessHandler, - LoginErrorHandler : DataHandler.EzyLoginErrorHandler, - AppAccessHandler : DataHandler.EzyAppAccessHandler, - AppExitHandler : DataHandler.EzyAppExitHandler, - AppResponseHandler : DataHandler.EzyAppResponseHandler, - PluginInfoHandler : DataHandler.EzyPluginInfoHandler, - PluginResponseHandler : DataHandler.EzyPluginResponseHandler, - PongHandler : DataHandler.EzyPongHandler, - Client : EzyClient, - Clients : EzyClients -} + Guid: Util.EzyGuid, + Logger: Util.EzyLogger, + App: Entity.EzyApp, + User: Entity.EzyUser, + Zone: Entity.EzyZone, + Command: Const.EzyCommand, + Commands: Const.EzyCommands, + DisconnectReason: Const.EzyDisconnectReason, + DisconnectReasonNames: Const.EzyDisconnectReasonNames, + ConnectionFailedReason: Const.EzyConnectionFailedReason, + ConnectionStatus: Const.EzyConnectionStatus, + EventType: Const.EzyEventType, + ClientConfig: Config.EzyClientConfig, + ConnectionSuccessHandler: EventHandler.EzyConnectionSuccessHandler, + ConnectionFailureHandler: EventHandler.EzyConnectionFailureHandler, + DisconnectionHandler: EventHandler.EzyDisconnectionHandler, + HandshakeHandler: DataHandler.EzyHandshakeHandler, + LoginSuccessHandler: DataHandler.EzyLoginSuccessHandler, + LoginErrorHandler: DataHandler.EzyLoginErrorHandler, + AppAccessHandler: DataHandler.EzyAppAccessHandler, + AppExitHandler: DataHandler.EzyAppExitHandler, + AppResponseHandler: DataHandler.EzyAppResponseHandler, + PluginInfoHandler: DataHandler.EzyPluginInfoHandler, + PluginResponseHandler: DataHandler.EzyPluginResponseHandler, + PongHandler: DataHandler.EzyPongHandler, + Client: EzyClient, + Clients: EzyClients, +}; -export default Ezy \ No newline at end of file +export default Ezy; diff --git a/package.json b/package.json index 5629d09..f5de5ed 100644 --- a/package.json +++ b/package.json @@ -1,10 +1,11 @@ { "name": "ezyfox-es6-client", - "version": "1.1.9", + "version": "1.2.0", "description": "ezyfox client use ECMAScript 6", "main": "index.js", "scripts": { - "test": "test" + "test": "test", + "lint": "eslint \"**/*.{js,ts,tsx}\"" }, "repository": { "type": "git", @@ -19,5 +20,55 @@ "url": "https://github.com/youngmonkeys/ezyfox-server-es6-client/issues" }, "homepage": "https://github.com/youngmonkeys/ezyfox-server-es6-client#readme", - "dependencies": {} + "dependencies": {}, + "devDependencies": { + "@commitlint/config-conventional": "^11.0.0", + "@react-native-community/eslint-config": "^2.0.0", + "commitlint": "^11.0.0", + "eslint": "^7.2.0", + "eslint-config-prettier": "^7.0.0", + "eslint-plugin-prettier": "^3.1.3", + "husky": "^4.2.5" + }, + "husky": { + "hooks": { + "commit-msg": "commitlint -E HUSKY_GIT_PARAMS", + "pre-commit": "yarn lint" + } + }, + "commitlint": { + "extends": [ + "@commitlint/config-conventional" + ] + }, + "eslintConfig": { + "root": true, + "extends": [ + "@react-native-community", + "prettier" + ], + "rules": { + "prettier/prettier": [ + "error", + { + "quoteProps": "consistent", + "singleQuote": true, + "tabWidth": 4, + "trailingComma": "es5", + "useTabs": false + } + ] + } + }, + "eslintIgnore": [ + "node_modules/", + "lib/" + ], + "prettier": { + "quoteProps": "consistent", + "singleQuote": true, + "tabWidth": 4, + "trailingComma": "es5", + "useTabs": false + } }