Skip to content

Commit

Permalink
refactor: add additional types
Browse files Browse the repository at this point in the history
Merged from #630
  • Loading branch information
darrachequesne committed Jan 18, 2022
1 parent 3f1e312 commit e122e4b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 34 deletions.
22 changes: 13 additions & 9 deletions lib/socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { IncomingMessage } from "http";
import { Transport } from "./transport";
import { Server } from "./server";
import { setTimeout, clearTimeout } from "timers";
import { Packet, PacketType, RawData } from "engine.io-parser";

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

Expand All @@ -18,7 +19,7 @@ export class Socket extends EventEmitter {
private server: Server;
private upgrading: boolean;
private upgraded: boolean;
private writeBuffer: any[];
private writeBuffer: Packet[];
private packetsFn: any[];
private sentCallbackFn: any[];
private cleanupFn: any[];
Expand Down Expand Up @@ -116,7 +117,7 @@ export class Socket extends EventEmitter {
* @param {Object} packet
* @api private
*/
private onPacket(packet) {
private onPacket(packet: Packet) {
if ("open" !== this.readyState) {
return debug("packet received with closed socket");
}
Expand Down Expand Up @@ -417,7 +418,7 @@ export class Socket extends EventEmitter {
/**
* Sends a message packet.
*
* @param {String} message
* @param {Object} data
* @param {Object} options
* @param {Function} callback
* @return {Socket} for chaining
Expand All @@ -436,12 +437,14 @@ export class Socket extends EventEmitter {
/**
* Sends a packet.
*
* @param {String} packet type
* @param {String} optional, data
* @param {String} type - packet type
* @param {String} data
* @param {Object} options
* @param {Function} callback
*
* @api private
*/
private sendPacket(type, data?, options?, callback?) {
private sendPacket(type: PacketType, data?: RawData, options?, callback?) {
if ("function" === typeof options) {
callback = options;
options = null;
Expand All @@ -453,10 +456,11 @@ export class Socket extends EventEmitter {
if ("closing" !== this.readyState && "closed" !== this.readyState) {
debug('sending packet "%s" (%s)', type, data);

const packet: any = {
type: type,
options: options
const packet: Packet = {
type,
options
};

if (data) packet.data = data;

// exports packetCreate event
Expand Down
3 changes: 2 additions & 1 deletion lib/transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as parser_v4 from "engine.io-parser";
import * as parser_v3 from "./parser-v3/index";
import debugModule from "debug";
import { IncomingMessage } from "http";
import { Packet } from "engine.io-parser";

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

Expand Down Expand Up @@ -111,7 +112,7 @@ export abstract class Transport extends EventEmitter {
* @param {Object} packet
* @api protected
*/
protected onPacket(packet) {
protected onPacket(packet: Packet) {
this.emit("packet", packet);
}

Expand Down
46 changes: 22 additions & 24 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e122e4b

Please sign in to comment.