Skip to content

Commit

Permalink
Remove unnecessary this qualifier (#15)
Browse files Browse the repository at this point in the history
* Remove unnecessary this qualifier

* Update format code
  • Loading branch information
namanh11611 committed Sep 10, 2023
1 parent 5b29c57 commit 2979025
Show file tree
Hide file tree
Showing 9 changed files with 188 additions and 243 deletions.
59 changes: 28 additions & 31 deletions lib/ezy_client.dart
@@ -1,10 +1,10 @@
import 'dart:typed_data';

import 'ezy_config.dart';
import 'ezy_managers.dart';
import 'ezy_constants.dart';
import 'ezy_entities.dart';
import 'ezy_logger.dart';
import 'ezy_managers.dart';
import 'ezy_proxy.dart';
import 'ezy_setup.dart';

Expand All @@ -22,19 +22,18 @@ class EzyClient {
late String? sessionToken;
late Uint8List? sessionKey;

EzyClient(EzyConfig config) {
EzyClient(this.config) {
EzyProxy.run("init", config.toMap());
this.config = config;
this.name = config.getClientName();
this.enableSSL = config.enableSSL;
this.enableDebug = config.enableDebug;
this.handlerManager = EzyHandlerManager.create(this);
this.setup = EzySetup(handlerManager);
name = config.getClientName();
enableSSL = config.enableSSL;
enableDebug = config.enableDebug;
handlerManager = EzyHandlerManager.create(this);
setup = EzySetup(handlerManager);
}

void connect(String host, int port) {
this.privateKey = null;
this.sessionKey = null;
privateKey = null;
sessionKey = null;
var params = Map();
params["clientName"] = name;
params["host"] = host;
Expand All @@ -43,8 +42,8 @@ class EzyClient {
}

Future reconnect() {
this.privateKey = null;
this.sessionKey = null;
privateKey = null;
sessionKey = null;
var params = Map();
params["clientName"] = name;
return EzyProxy.run("reconnect", params);
Expand All @@ -56,21 +55,20 @@ class EzyClient {
params["reason"] = reason;
EzyProxy.run("disconnect", params);
}

void close() {
disconnect();
}

void send(String cmd, dynamic data, [bool encrypted = false]) {
var shouldEncrypted = encrypted;
if(encrypted && sessionKey == null) {
if(enableDebug) {
if (encrypted && sessionKey == null) {
if (enableDebug) {
shouldEncrypted = false;
}
else {
} else {
EzyLogger.error(
"can not send command: $cmd, you must enable SSL "
"or enable debug mode by configuration when you create the client"
"can not send command: $cmd, you must enable SSL "
"or enable debug mode by configuration when you create the client",
);
return;
}
Expand All @@ -84,20 +82,20 @@ class EzyClient {
params["request"] = requestParams;
EzyProxy.run("send", params);
}

void startPingSchedule() {
var params = Map();
params["clientName"] = name;
EzyProxy.run("startPingSchedule", params);
}

void setStatus(String status) {
var params = Map();
params["clientName"] = name;
params["status"] = status;
EzyProxy.run("setStatus", params);
}

void setSessionKey(Uint8List sessionKey) {
this.sessionKey = sessionKey;
var params = Map();
Expand All @@ -107,7 +105,7 @@ class EzyClient {
}

EzyApp? getApp() {
if(zone != null) {
if (zone != null) {
var appManager = zone!.appManager;
var app = appManager.getApp();
return app;
Expand All @@ -116,22 +114,21 @@ class EzyClient {
}

EzyApp? getAppById(int appId) {
if(zone != null) {
if (zone != null) {
var appManager = zone!.appManager;
var app = appManager.getAppById(appId);
return app;
}
return null;
}

void handleEvent(String eventType, Map data) {
var eventHandlers = this.handlerManager.eventHandlers;
var eventHandlers = handlerManager.eventHandlers;
eventHandlers.handle(eventType, data);
}
void handleData(String command, List data) {
var dataHandlers = this.handlerManager.dataHandlers;

void handleData(String command, List data) {
var dataHandlers = handlerManager.dataHandlers;
dataHandlers.handle(command, data);
}
}

24 changes: 11 additions & 13 deletions lib/ezy_clients.dart
@@ -1,5 +1,3 @@
import 'ezy_proxy.dart';

import 'ezy_client.dart';
import 'ezy_config.dart';

Expand All @@ -9,39 +7,39 @@ class EzyClients {
static final EzyClients _INSTANCE = EzyClients._();

EzyClients._() {
this.defaultClientName = "";
this.clients = Map();
defaultClientName = "";
clients = <String, EzyClient>{};
}

static EzyClients getInstance() {
return _INSTANCE;
}

EzyClient newClient(EzyConfig config) {
var client = EzyClient(config);
this.addClient(client);
if(defaultClientName == "") {
var client = EzyClient(config);
addClient(client);
if (defaultClientName == "") {
defaultClientName = client.name;
}
return client;
}

EzyClient newDefaultClient(EzyConfig config) {
var client = this.newClient(config);
this.defaultClientName = client.name;
var client = newClient(config);
defaultClientName = client.name;
return client;
}

void addClient(EzyClient client) {
this.clients[client.name] = client;
clients[client.name] = client;
}

EzyClient getClient(String clientName) {
var client = this.clients[clientName]!;
var client = clients[clientName]!;
return client;
}

EzyClient getDefaultClient() {
return this.clients[defaultClientName]!;
return clients[defaultClientName]!;
}
}
5 changes: 1 addition & 4 deletions lib/ezy_codec.dart
Expand Up @@ -6,10 +6,7 @@ class EzyKeyPairProxy {
late String publicKey;
late Uint8List privateKey;

EzyKeyPairProxy(String publicKey, Uint8List privateKey) {
this.publicKey = publicKey;
this.privateKey = privateKey;
}
EzyKeyPairProxy(this.publicKey, this.privateKey);
}

class EzyRSAProxy {
Expand Down
26 changes: 8 additions & 18 deletions lib/ezy_entities.dart
Expand Up @@ -11,11 +11,8 @@ class EzyZone {
late EzyClient client;
late EzyAppManager appManager;

EzyZone(EzyClient client, int id, String name) {
this.client = client;
this.id = id;
this.name = name;
this.appManager = EzyAppManager(name);
EzyZone(this.client, this.id, this.name) {
appManager = EzyAppManager(name);
}

EzyApp? getApp() {
Expand All @@ -31,35 +28,28 @@ class EzyApp {
late EzyAppDataHandlers dataHandlers;
static const Map EMPTY_MAP = {};

EzyApp(EzyClient client, EzyZone zone, int id, String name) {
this.id = id;
this.name = name;
this.client = client;
this.zone = zone;
this.dataHandlers = client.handlerManager.getAppDataHandlers(name);
EzyApp(this.client, this.zone, this.id, this.name) {
dataHandlers = client.handlerManager.getAppDataHandlers(name);
}

void send(String cmd, [dynamic data = EMPTY_MAP, bool encrypted = false]) {
var requestData = [];
requestData.add(this.id);
requestData.add(id);
var requestParams = [];
requestParams.add(cmd);
requestParams.add(data);
requestData.add(requestParams);
this.client.send(EzyCommand.APP_REQUEST, requestData, encrypted);
client.send(EzyCommand.APP_REQUEST, requestData, encrypted);
}

EzyAppDataHandler? getDataHandler(String cmd) {
return this.dataHandlers.getHandler(cmd);
return dataHandlers.getHandler(cmd);
}
}

class EzyUser {
late int id;
late String name;

EzyUser(int id, String name) {
this.id = id;
this.name = name;
}
EzyUser(this.id, this.name);
}

0 comments on commit 2979025

Please sign in to comment.