Skip to content

Commit

Permalink
refactor: add types to socket.send()
Browse files Browse the repository at this point in the history
Related: #645
  • Loading branch information
darrachequesne committed Dec 5, 2022
1 parent 3d28229 commit 6d87a40
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions lib/socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class Socket extends EventEmitter {
private upgrading: boolean;
private upgraded: boolean;
private writeBuffer: Packet[];
private packetsFn: any[];
private packetsFn: Array<() => void>;
private sentCallbackFn: any[];
private cleanupFn: any[];
private checkIntervalTimer;
Expand Down Expand Up @@ -431,12 +431,27 @@ export class Socket extends EventEmitter {
* @return {Socket} for chaining
* @api public
*/
public send(data, options, callback?) {
public send(
data: RawData,
options?: { compress: boolean },
callback?: () => void
) {
this.sendPacket("message", data, options, callback);
return this;
}

public write(data, options, callback?) {
/**
* Alias of {@link send}.
*
* @param data
* @param options
* @param callback
*/
public write(
data: RawData,
options?: { compress: boolean },
callback?: () => void
) {
this.sendPacket("message", data, options, callback);
return this;
}
Expand All @@ -451,15 +466,17 @@ export class Socket extends EventEmitter {
*
* @api private
*/
private sendPacket(type: PacketType, data?: RawData, options?, callback?) {
private sendPacket(
type: PacketType,
data?: RawData,
options: { compress: boolean } = { compress: true },
callback?: () => void
) {
if ("function" === typeof options) {
callback = options;
options = null;
}

options = options || {};
options.compress = false !== options.compress;

if ("closing" !== this.readyState && "closed" !== this.readyState) {
debug('sending packet "%s" (%s)', type, data);

Expand Down

0 comments on commit 6d87a40

Please sign in to comment.