Skip to content

Commit e122e4b

Browse files
refactor: add additional types
Merged from #630
1 parent 3f1e312 commit e122e4b

File tree

3 files changed

+37
-34
lines changed

3 files changed

+37
-34
lines changed

lib/socket.ts

+13-9
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { IncomingMessage } from "http";
44
import { Transport } from "./transport";
55
import { Server } from "./server";
66
import { setTimeout, clearTimeout } from "timers";
7+
import { Packet, PacketType, RawData } from "engine.io-parser";
78

89
const debug = debugModule("engine:socket");
910

@@ -18,7 +19,7 @@ export class Socket extends EventEmitter {
1819
private server: Server;
1920
private upgrading: boolean;
2021
private upgraded: boolean;
21-
private writeBuffer: any[];
22+
private writeBuffer: Packet[];
2223
private packetsFn: any[];
2324
private sentCallbackFn: any[];
2425
private cleanupFn: any[];
@@ -116,7 +117,7 @@ export class Socket extends EventEmitter {
116117
* @param {Object} packet
117118
* @api private
118119
*/
119-
private onPacket(packet) {
120+
private onPacket(packet: Packet) {
120121
if ("open" !== this.readyState) {
121122
return debug("packet received with closed socket");
122123
}
@@ -417,7 +418,7 @@ export class Socket extends EventEmitter {
417418
/**
418419
* Sends a message packet.
419420
*
420-
* @param {String} message
421+
* @param {Object} data
421422
* @param {Object} options
422423
* @param {Function} callback
423424
* @return {Socket} for chaining
@@ -436,12 +437,14 @@ export class Socket extends EventEmitter {
436437
/**
437438
* Sends a packet.
438439
*
439-
* @param {String} packet type
440-
* @param {String} optional, data
440+
* @param {String} type - packet type
441+
* @param {String} data
441442
* @param {Object} options
443+
* @param {Function} callback
444+
*
442445
* @api private
443446
*/
444-
private sendPacket(type, data?, options?, callback?) {
447+
private sendPacket(type: PacketType, data?: RawData, options?, callback?) {
445448
if ("function" === typeof options) {
446449
callback = options;
447450
options = null;
@@ -453,10 +456,11 @@ export class Socket extends EventEmitter {
453456
if ("closing" !== this.readyState && "closed" !== this.readyState) {
454457
debug('sending packet "%s" (%s)', type, data);
455458

456-
const packet: any = {
457-
type: type,
458-
options: options
459+
const packet: Packet = {
460+
type,
461+
options
459462
};
463+
460464
if (data) packet.data = data;
461465

462466
// exports packetCreate event

lib/transport.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as parser_v4 from "engine.io-parser";
33
import * as parser_v3 from "./parser-v3/index";
44
import debugModule from "debug";
55
import { IncomingMessage } from "http";
6+
import { Packet } from "engine.io-parser";
67

78
const debug = debugModule("engine:transport");
89

@@ -111,7 +112,7 @@ export abstract class Transport extends EventEmitter {
111112
* @param {Object} packet
112113
* @api protected
113114
*/
114-
protected onPacket(packet) {
115+
protected onPacket(packet: Packet) {
115116
this.emit("packet", packet);
116117
}
117118

package-lock.json

+22-24
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)