Skip to content

Commit

Permalink
feat: add options for controlling buffer usage
Browse files Browse the repository at this point in the history
  • Loading branch information
ejose19 committed Nov 27, 2020
1 parent b3de861 commit 890f728
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
22 changes: 22 additions & 0 deletions lib/manager.ts
Expand Up @@ -257,6 +257,18 @@ export interface ManagerOptions extends EngineOptions {
* the parser to use. Defaults to an instance of the Parser that ships with socket.io.
*/
parser: any;

/**
* Should we buffer receive events if socket is not connected
* @default true
*/
enableReceiveBuffer: boolean;

/**
* Should we buffer send events if socket is not connected
* @default true
*/
enableSendBuffer: boolean;
}

export class Manager extends Emitter {
Expand All @@ -278,6 +290,14 @@ export class Manager extends Emitter {
* @private
*/
_reconnecting: boolean;
/**
* @private
*/
_enableReceiveBuffer: boolean;
/**
* @private
*/
_enableSendBuffer: boolean;

private readonly uri: string;
private readonly opts: object;
Expand Down Expand Up @@ -333,6 +353,8 @@ export class Manager extends Emitter {
this.encoder = new _parser.Encoder();
this.decoder = new _parser.Decoder();
this._autoConnect = opts.autoConnect !== false;
this._enableReceiveBuffer = opts.enableReceiveBuffer !== false;
this._enableSendBuffer = opts.enableSendBuffer !== false;
if (this._autoConnect) this.open();
}

Expand Down
4 changes: 2 additions & 2 deletions lib/socket.ts
Expand Up @@ -162,7 +162,7 @@ export class Socket extends Emitter {
debug("discard packet as the transport is not currently writable");
} else if (this.connected) {
this.packet(packet);
} else {
} else if (this.io._enableSendBuffer) {
this.sendBuffer.push(packet);
}

Expand Down Expand Up @@ -275,7 +275,7 @@ export class Socket extends Emitter {

if (this.connected) {
this.emitEvent(args);
} else {
} else if (this.io._enableReceiveBuffer) {
this.receiveBuffer.push(args);
}
}
Expand Down

0 comments on commit 890f728

Please sign in to comment.