Skip to content

Commit 41413d9

Browse files
committed
deno fmt (lol)
1 parent 433485f commit 41413d9

File tree

4 files changed

+34
-18
lines changed

4 files changed

+34
-18
lines changed

client-module.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
import SocketClient from "./client.js"
1+
import SocketClient from "./client.js";
22

33
export { SocketClient };

client.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ class SocketClient {
103103
_reconnectSuccessful(previousId) {
104104
this.reconnectCount += 1;
105105
// server can react if needed to this connection id
106-
this.to('reconnect', {
106+
this.to("reconnect", {
107107
previousId,
108108
id: this.connection.id,
109109
reconnectCount: this.reconnectCount,
@@ -136,7 +136,7 @@ class SocketClient {
136136
});
137137
this.connection.addEventListener("error", (event) => {
138138
// send error message to server
139-
this.to('error', event);
139+
this.to("error", event);
140140
});
141141
this.connection.addEventListener("close", () => {
142142
this._connectToSocketServer(true);
@@ -152,9 +152,9 @@ class SocketClient {
152152
* information about the Body mixin.
153153
*/
154154
_handleEncodedMessage(message) {
155-
if (typeof message === 'string' && 'ping') {
155+
if (typeof message === "string" && "ping") {
156156
this._pongServer();
157-
} else if (typeof message === 'object') {
157+
} else if (typeof message === "object") {
158158
message.arrayBuffer().then((buffer) => {
159159
const decodedMessage = this.decoder.decode(buffer);
160160
const parsedMessage = JSON.parse(decodedMessage);
@@ -190,6 +190,6 @@ class SocketClient {
190190
* Send pong message to server.
191191
*/
192192
_pongServer() {
193-
this.connection.send('pong')
193+
this.connection.send("pong");
194194
}
195195
}

src/server.ts

+18-5
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,10 @@ export default class SocketServer extends EventEmitter {
7171
*
7272
* @return Promise<DenoServer>
7373
*/
74-
public async run(options: HTTPOptions, transmitterOptions: any = {}): Promise<DenoServer> {
74+
public async run(
75+
options: HTTPOptions,
76+
transmitterOptions: any = {},
77+
): Promise<DenoServer> {
7578
if (options.hostname) {
7679
this.hostname = options.hostname;
7780
}
@@ -103,20 +106,30 @@ export default class SocketServer extends EventEmitter {
103106

104107
try {
105108
for await (const ev of socket) {
106-
if (ev === 'pong') {
107-
this.transmitter.handleReservedEventNames('pong', clientId, socket);
109+
if (ev === "pong") {
110+
this.transmitter.handleReservedEventNames(
111+
"pong",
112+
clientId,
113+
socket,
114+
);
108115
} else if (ev instanceof Uint8Array) {
109116
await this.transmitter.checkEvent(ev, clientId);
110117
} else if (isWebSocketCloseEvent(ev)) {
111118
await super.removeClient(clientId);
112-
this.transmitter.handleReservedEventNames("disconnect", clientId);
119+
this.transmitter.handleReservedEventNames(
120+
"disconnect",
121+
clientId,
122+
);
113123
}
114124
}
115125
} catch (e) {
116126
if (!socket.isClosed) {
117127
await socket.close(1000).catch(console.error);
118128
await super.removeClient(clientId);
119-
this.transmitter.handleReservedEventNames("disconnect", clientId);
129+
this.transmitter.handleReservedEventNames(
130+
"disconnect",
131+
clientId,
132+
);
120133
}
121134
}
122135
})

src/transmitter.ts

+10-7
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { MESSAGE_TYPE } from "./io_types.ts";
22
import { RESERVED_EVENT_NAMES } from "./reserved_event_names.ts";
33

44
export default class Transmitter {
5-
65
/**
76
* @description
87
* A property to determine number of ms to wait for a pong event before closing a client connection.
@@ -28,7 +27,7 @@ export default class Transmitter {
2827
// FILE MARKER - CONSTRUCTOR /////////////////////////////////////////////////
2928

3029
constructor(server: any, options: any = {}) {
31-
if ('reconnect' in options) {
30+
if ("reconnect" in options) {
3231
this.reconnect = options.reconnect;
3332
}
3433

@@ -87,7 +86,11 @@ export default class Transmitter {
8786
*
8887
* @return void
8988
*/
90-
public handleReservedEventNames(eventName: string, clientId: number, socket?: any): void {
89+
public handleReservedEventNames(
90+
eventName: string,
91+
clientId: number,
92+
socket?: any,
93+
): void {
9194
switch (eventName) {
9295
case "connection":
9396
case "disconnect":
@@ -98,8 +101,8 @@ export default class Transmitter {
98101
}
99102
break;
100103
case "reconnect":
101-
// do something on an reconnect event
102-
// could be useful to add a flag to this client
104+
// do something on an reconnect event
105+
// could be useful to add a flag to this client
103106
break;
104107
case "pong":
105108
if (!this.server.clients[clientId]) {
@@ -111,7 +114,7 @@ export default class Transmitter {
111114
break;
112115
case "error":
113116
// do something when client errors
114-
break;
117+
break;
115118
default:
116119
this.server.addListener(eventName, clientId);
117120
break;
@@ -162,7 +165,7 @@ export default class Transmitter {
162165
if (this.server.clients[clientId]) {
163166
const client = this.server.clients[clientId];
164167
if (client.pong_received) {
165-
client.socket.send('ping');
168+
client.socket.send("ping");
166169
client.pong_received = false;
167170
} else {
168171
setTimeout(() => this._timeoutPing(clientId), this.pingTimeout);

0 commit comments

Comments
 (0)