Skip to content

Http2Session

[<Interface>]
type Http2Session =
    abstract member alpnProtocol: string option
    abstract member closed: bool
    abstract member connecting: bool
    abstract member destroyed: bool
    abstract member encrypted: bool option
    abstract member localSettings: Settings
    abstract member originSet: string array option
    abstract member pendingSettingsAck: bool
    abstract member remoteSettings: Settings
    abstract member socket: U2<Socket,TLSSocket>
    abstract member state: SessionState
    abstract member type: float
    abstract member addListener (event: U2<string,Symbol>, listener: obj array -> unit) : Http2Session
    abstract member addListenerClose (listener: unit -> unit) : Http2Session
    abstract member addListenerError (listener: exn -> unit) : Http2Session
    abstract member addListenerFrameError (listener: Listener) : Http2Session
    abstract member addListenerGoaway (listener: Listener2) : Http2Session
    abstract member addListenerLocalSettings (listener: Settings -> unit) : Http2Session
    abstract member addListenerPing (listener: unit -> unit) : Http2Session
    abstract member addListenerRemoteSettings (listener: Settings -> unit) : Http2Session
    abstract member addListenerTimeout (listener: unit -> unit) : Http2Session
    abstract member close (?callback: (unit -> unit)) : unit
    abstract member destroy (?error: exn, ?code: float) : unit
    abstract member emit (event: U2<string,Symbol>, args: obj array) : bool
    abstract member emitClose () : bool
    abstract member emitError (err: exn) : bool
    abstract member emitFrameError (frameType: float, errorCode: float, id: float) : bool
    abstract member emitGoaway (errorCode: float, lastStreamID: float, ?opaqueData: NonSharedBuffer) : bool
    abstract member emitLocalSettings (settings: Settings) : bool
    abstract member emitPing () : bool
    abstract member emitRemoteSettings (settings: Settings) : bool
    abstract member emitTimeout () : bool
    abstract member eventNames () : U2<string,Symbol> array
    abstract member goaway (?code: float, ?lastStreamID: float, ?opaqueData: U12<BigInt64Array<U2<ArrayBuffer,SharedArrayBuffer>>,BigUint64Array<U2<ArrayBuffer,SharedArrayBuffer>>,DataView<U2<ArrayBuffer,SharedArrayBuffer>>,Float32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Float64Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int16Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int8Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint16Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint8Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint8ClampedArray<U2<ArrayBuffer,SharedArrayBuffer>>>) : unit
    abstract member listenerCount (eventName: U2<string,Symbol>, ?listener: Function) : float
    abstract member listeners (eventName: U2<string,Symbol>) : Function array
    abstract member off (eventName: U2<string,Symbol>, listener: obj array -> unit) : Http2Session
    abstract member on (event: U2<string,Symbol>, listener: obj array -> unit) : Http2Session
    abstract member onClose (listener: unit -> unit) : Http2Session
    abstract member onError (listener: exn -> unit) : Http2Session
    abstract member onFrameError (listener: Listener) : Http2Session
    abstract member onGoaway (listener: Listener2) : Http2Session
    abstract member onLocalSettings (listener: Settings -> unit) : Http2Session
    abstract member onPing (listener: unit -> unit) : Http2Session
    abstract member onRemoteSettings (listener: Settings -> unit) : Http2Session
    abstract member onTimeout (listener: unit -> unit) : Http2Session
    abstract member once (event: U2<string,Symbol>, listener: obj array -> unit) : Http2Session
    abstract member onceClose (listener: unit -> unit) : Http2Session
    abstract member onceError (listener: exn -> unit) : Http2Session
    abstract member onceFrameError (listener: Listener) : Http2Session
    abstract member onceGoaway (listener: Listener2) : Http2Session
    abstract member onceLocalSettings (listener: Settings -> unit) : Http2Session
    abstract member oncePing (listener: unit -> unit) : Http2Session
    abstract member onceRemoteSettings (listener: Settings -> unit) : Http2Session
    abstract member onceTimeout (listener: unit -> unit) : Http2Session
    abstract member ping (payload: U12<BigInt64Array<U2<ArrayBuffer,SharedArrayBuffer>>,BigUint64Array<U2<ArrayBuffer,SharedArrayBuffer>>,DataView<U2<ArrayBuffer,SharedArrayBuffer>>,Float32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Float64Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int16Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int8Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint16Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint8Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint8ClampedArray<U2<ArrayBuffer,SharedArrayBuffer>>>, callback: Callback2) : bool
    abstract member ping (callback: Callback) : bool
    abstract member prependListener (event: U2<string,Symbol>, listener: obj array -> unit) : Http2Session
    abstract member prependListenerClose (listener: unit -> unit) : Http2Session
    abstract member prependListenerError (listener: exn -> unit) : Http2Session
    abstract member prependListenerFrameError (listener: Listener) : Http2Session
    abstract member prependListenerGoaway (listener: Listener2) : Http2Session
    abstract member prependListenerLocalSettings (listener: Settings -> unit) : Http2Session
    abstract member prependListenerPing (listener: unit -> unit) : Http2Session
    abstract member prependListenerRemoteSettings (listener: Settings -> unit) : Http2Session
    abstract member prependListenerTimeout (listener: unit -> unit) : Http2Session
    abstract member prependOnceListener (event: U2<string,Symbol>, listener: obj array -> unit) : Http2Session
    abstract member prependOnceListenerClose (listener: unit -> unit) : Http2Session
    abstract member prependOnceListenerError (listener: exn -> unit) : Http2Session
    abstract member prependOnceListenerFrameError (listener: Listener) : Http2Session
    abstract member prependOnceListenerGoaway (listener: Listener2) : Http2Session
    abstract member prependOnceListenerLocalSettings (listener: Settings -> unit) : Http2Session
    abstract member prependOnceListenerPing (listener: unit -> unit) : Http2Session
    abstract member prependOnceListenerRemoteSettings (listener: Settings -> unit) : Http2Session
    abstract member prependOnceListenerTimeout (listener: unit -> unit) : Http2Session
    abstract member rawListeners (eventName: U2<string,Symbol>) : Function array
    abstract member ref () : unit
    abstract member removeAllListeners (?eventName: U2<string,Symbol>) : Http2Session
    abstract member removeListener (eventName: U2<string,Symbol>, listener: obj array -> unit) : Http2Session
    abstract member setLocalWindowSize (windowSize: float) : unit
    abstract member setMaxListeners (n: float) : Http2Session
    abstract member setTimeout (msecs: float, ?callback: (unit -> unit)) : unit
    abstract member settings (settings: Settings, ?callback: Callback) : unit
    abstract member unref () : unit
AssemblyXantham.Fable.Node
ImplementsEventEmitter<unit array>

Declared inside

AddListener
On
Once
Ping
PrependListener
PrependOnceListener
Settings

Properties

abstract member alpnProtocol: string option

Value will be undefined if the Http2Session is not yet connected to a socket, h2c if the Http2Session is not connected to a TLSSocket, or will return the value of the connected TLSSocket's own alpnProtocol property.

@since v9.4.0

abstract member closed: bool

Will be true if this Http2Session instance has been closed, otherwise false.

@since v9.4.0

abstract member connecting: bool

Will be true if this Http2Session instance is still connecting, will be set to false before emitting connect event and/or calling the http2.connect callback.

@since v10.0.0

abstract member destroyed: bool

Will be true if this Http2Session instance has been destroyed and must no longer be used, otherwise false.

@since v8.4.0

abstract member encrypted: bool option

Value is undefined if the Http2Session session socket has not yet been connected, true if the Http2Session is connected with a TLSSocket, and false if the Http2Session is connected to any other kind of socket or stream.

@since v9.4.0

abstract member localSettings: Settings

A prototype-less object describing the current local settings of this Http2Session. The local settings are local to thisHttp2Session instance.

@since v8.4.0

abstract member originSet: string array option

If the Http2Session is connected to a TLSSocket, the originSet property will return an Array of origins for which the Http2Session may be considered authoritative.

The originSet property is only available when using a secure TLS connection.

@since v9.4.0

abstract member pendingSettingsAck: bool

Indicates whether the Http2Session is currently waiting for acknowledgment of a sent SETTINGS frame. Will be true after calling the http2session.settings() method. Will be false once all sent SETTINGS frames have been acknowledged.

@since v8.4.0

abstract member remoteSettings: Settings

A prototype-less object describing the current remote settings of thisHttp2Session. The remote settings are set by the connected HTTP/2 peer.

@since v8.4.0

abstract member socket: U2<Socket,TLSSocket>

Returns a Proxy object that acts as a net.Socket (or tls.TLSSocket) but limits available methods to ones safe to use with HTTP/2.

destroy, emit, end, pause, read, resume, and write will throw an error with code ERR_HTTP2_NO_SOCKET_MANIPULATION. See Http2Session and Sockets for more information.

setTimeout method will be called on this Http2Session.

All other interactions will be routed directly to the socket.

@since v8.4.0

abstract member state: SessionState

Provides miscellaneous information about the current state of theHttp2Session.

An object describing the current status of this Http2Session.

@since v8.4.0

abstract member type: float

The http2session.type will be equal to http2.constants.NGHTTP2_SESSION_SERVER if this Http2Session instance is a server, and http2.constants.NGHTTP2_SESSION_CLIENT if the instance is a client.

@since v8.4.0

Methods

abstract member addListener (event: U2<string,Symbol>, listener: obj array -> unit) : Http2Session

Alias for emitter.on(eventName, listener).

abstract member addListenerClose (listener: unit -> unit) : Http2Session
addListener(event: "close", listener: () => void): this
abstract member addListenerError (listener: exn -> unit) : Http2Session
addListener(event: "error", listener: (err: Error) => void): this
abstract member addListenerFrameError (listener: Listener) : Http2Session
addListener(event: "frameError", listener: (frameType: number, errorCode: number, id: number) => void): this
abstract member addListenerGoaway (listener: Listener2) : Http2Session
addListener(event: "goaway", listener: (errorCode: number, lastStreamID: number, opaqueData?: NonSharedBuffer) => void): this
abstract member addListenerLocalSettings (listener: Settings -> unit) : Http2Session
addListener(event: "localSettings", listener: (settings: Settings) => void): this
abstract member addListenerPing (listener: unit -> unit) : Http2Session
addListener(event: "ping", listener: () => void): this
abstract member addListenerRemoteSettings (listener: Settings -> unit) : Http2Session
addListener(event: "remoteSettings", listener: (settings: Settings) => void): this
abstract member addListenerTimeout (listener: unit -> unit) : Http2Session
addListener(event: "timeout", listener: () => void): this
abstract member close (?callback: (unit -> unit)) : unit

Gracefully closes the Http2Session, allowing any existing streams to complete on their own and preventing new Http2Stream instances from being created. Once closed, http2session.destroy()might be called if there are no open Http2Stream instances.

If specified, the callback function is registered as a handler for the'close' event.

@since v9.4.0

abstract member destroy (?error: exn, ?code: float) : unit

Immediately terminates the Http2Session and the associated net.Socket or tls.TLSSocket.

Once destroyed, the Http2Session will emit the 'close' event. If error is not undefined, an 'error' event will be emitted immediately before the 'close' event.

If there are any remaining open Http2Streams associated with the Http2Session, those will also be destroyed.

@since v8.4.0

Parameter
errorAn Error object if the Http2Session is being destroyed due to an error.
codeThe HTTP/2 error code to send in the final GOAWAY frame. If unspecified, and error is not undefined, the default is INTERNAL_ERROR, otherwise defaults to NO_ERROR.
abstract member emit (event: U2<string,Symbol>, args: obj array) : bool

Synchronously calls each of the listeners registered for the event named eventName, in the order they were registered, passing the supplied arguments to each.

Returns true if the event had listeners, false otherwise.

import { EventEmitter } from 'node:events';
const myEmitter = new EventEmitter();

// First listener
myEmitter.on('event', function firstListener() {
console.log('Helloooo! first listener');
});
// Second listener
myEmitter.on('event', function secondListener(arg1, arg2) {
console.log(`event with parameters ${arg1}, ${arg2} in second listener`);
});
// Third listener
myEmitter.on('event', function thirdListener(...args) {
const parameters = args.join(', ');
console.log(`event with parameters ${parameters} in third listener`);
});

console.log(myEmitter.listeners('event'));

myEmitter.emit('event', 1, 2, 3, 4, 5);

// Prints:
// [
//   [Function: firstListener],
//   [Function: secondListener],
//   [Function: thirdListener]
// ]
// Helloooo! first listener
// event with parameters 1, 2 in second listener
// event with parameters 1, 2, 3, 4, 5 in third listener
abstract member emitClose () : bool
emit(event: "close"): boolean
abstract member emitError (err: exn) : bool
emit(event: "error", err: Error): boolean
abstract member emitFrameError (frameType: float, errorCode: float, id: float) : bool
emit(event: "frameError", frameType: number, errorCode: number, id: number): boolean
abstract member emitGoaway (errorCode: float, lastStreamID: float, ?opaqueData: NonSharedBuffer) : bool
emit(event: "goaway", errorCode: number, lastStreamID: number, opaqueData?: NonSharedBuffer): boolean
abstract member emitLocalSettings (settings: Settings) : bool
emit(event: "localSettings", settings: Settings): boolean
abstract member emitPing () : bool
emit(event: "ping"): boolean
abstract member emitRemoteSettings (settings: Settings) : bool
emit(event: "remoteSettings", settings: Settings): boolean
abstract member emitTimeout () : bool
emit(event: "timeout"): boolean
abstract member eventNames () : U2<string,Symbol> array

Returns an array listing the events for which the emitter has registered listeners. The values in the array are strings or Symbols.

import { EventEmitter } from 'node:events';

const myEE = new EventEmitter();
myEE.on('foo', () => {});
myEE.on('bar', () => {});

const sym = Symbol('symbol');
myEE.on(sym, () => {});

console.log(myEE.eventNames());
// Prints: [ 'foo', 'bar', Symbol(symbol) ]

@since v6.0.0

abstract member goaway (?code: float, ?lastStreamID: float, ?opaqueData: U12<BigInt64Array<U2<ArrayBuffer,SharedArrayBuffer>>,BigUint64Array<U2<ArrayBuffer,SharedArrayBuffer>>,DataView<U2<ArrayBuffer,SharedArrayBuffer>>,Float32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Float64Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int16Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int8Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint16Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint8Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint8ClampedArray<U2<ArrayBuffer,SharedArrayBuffer>>>) : unit

Transmits a GOAWAY frame to the connected peer without shutting down theHttp2Session.

@since v9.4.0

Parameter
codeAn HTTP/2 error code
lastStreamIDThe numeric ID of the last processed Http2Stream
opaqueDataA TypedArray or DataView instance containing additional data to be carried within the GOAWAY frame.
abstract member listenerCount (eventName: U2<string,Symbol>, ?listener: Function) : float

Returns the number of listeners listening for the event named eventName. If listener is provided, it will return how many times the listener is found in the list of the listeners of the event.

@since v3.2.0

Parameter
eventNameThe name of the event being listened for
listenerThe event handler function
abstract member listeners (eventName: U2<string,Symbol>) : Function array

Returns a copy of the array of listeners for the event named eventName.

server.on('connection', (stream) => {
console.log('someone connected!');
});
console.log(util.inspect(server.listeners('connection')));
// Prints: [ [Function] ]

@since v0.1.26

abstract member off (eventName: U2<string,Symbol>, listener: obj array -> unit) : Http2Session

Alias for emitter.removeListener().

@since v10.0.0

abstract member on (event: U2<string,Symbol>, listener: obj array -> unit) : Http2Session

Adds the listener function to the end of the listeners array for the event named eventName. No checks are made to see if the listener has already been added. Multiple calls passing the same combination of eventName and listener will result in the listener being added, and called, multiple times.

server.on('connection', (stream) => {
console.log('someone connected!');
});

Returns a reference to the EventEmitter, so that calls can be chained.

By default, event listeners are invoked in the order they are added. The emitter.prependListener() method can be used as an alternative to add the event listener to the beginning of the listeners array.

import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.on('foo', () => console.log('a'));
myEE.prependListener('foo', () => console.log('b'));
myEE.emit('foo');
// Prints:
//   b
//   a
abstract member onClose (listener: unit -> unit) : Http2Session
on(event: "close", listener: () => void): this
abstract member onError (listener: exn -> unit) : Http2Session
on(event: "error", listener: (err: Error) => void): this
abstract member onFrameError (listener: Listener) : Http2Session
on(event: "frameError", listener: (frameType: number, errorCode: number, id: number) => void): this
abstract member onGoaway (listener: Listener2) : Http2Session
on(event: "goaway", listener: (errorCode: number, lastStreamID: number, opaqueData?: NonSharedBuffer) => void): this
abstract member onLocalSettings (listener: Settings -> unit) : Http2Session
on(event: "localSettings", listener: (settings: Settings) => void): this
abstract member onPing (listener: unit -> unit) : Http2Session
on(event: "ping", listener: () => void): this
abstract member onRemoteSettings (listener: Settings -> unit) : Http2Session
on(event: "remoteSettings", listener: (settings: Settings) => void): this
abstract member onTimeout (listener: unit -> unit) : Http2Session
on(event: "timeout", listener: () => void): this
abstract member once (event: U2<string,Symbol>, listener: obj array -> unit) : Http2Session

Adds a one-timelistener function for the event named eventName. The next time eventName is triggered, this listener is removed and then invoked.

server.once('connection', (stream) => {
console.log('Ah, we have our first user!');
});

Returns a reference to the EventEmitter, so that calls can be chained.

By default, event listeners are invoked in the order they are added. The emitter.prependOnceListener() method can be used as an alternative to add the event listener to the beginning of the listeners array.

import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.once('foo', () => console.log('a'));
myEE.prependOnceListener('foo', () => console.log('b'));
myEE.emit('foo');
// Prints:
//   b
//   a
abstract member onceClose (listener: unit -> unit) : Http2Session
once(event: "close", listener: () => void): this
abstract member onceError (listener: exn -> unit) : Http2Session
once(event: "error", listener: (err: Error) => void): this
abstract member onceFrameError (listener: Listener) : Http2Session
once(event: "frameError", listener: (frameType: number, errorCode: number, id: number) => void): this
abstract member onceGoaway (listener: Listener2) : Http2Session
once(event: "goaway", listener: (errorCode: number, lastStreamID: number, opaqueData?: NonSharedBuffer) => void): this
abstract member onceLocalSettings (listener: Settings -> unit) : Http2Session
once(event: "localSettings", listener: (settings: Settings) => void): this
abstract member oncePing (listener: unit -> unit) : Http2Session
once(event: "ping", listener: () => void): this
abstract member onceRemoteSettings (listener: Settings -> unit) : Http2Session
once(event: "remoteSettings", listener: (settings: Settings) => void): this
abstract member onceTimeout (listener: unit -> unit) : Http2Session
once(event: "timeout", listener: () => void): this
abstract member ping (payload: U12<BigInt64Array<U2<ArrayBuffer,SharedArrayBuffer>>,BigUint64Array<U2<ArrayBuffer,SharedArrayBuffer>>,DataView<U2<ArrayBuffer,SharedArrayBuffer>>,Float32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Float64Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int16Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int8Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint16Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint8Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint8ClampedArray<U2<ArrayBuffer,SharedArrayBuffer>>>, callback: Callback2) : bool

Sends a PING frame to the connected HTTP/2 peer. A callback function must be provided. The method will return true if the PING was sent, false otherwise.

The maximum number of outstanding (unacknowledged) pings is determined by the maxOutstandingPings configuration option. The default maximum is 10.

If provided, the payload must be a Buffer, TypedArray, or DataView containing 8 bytes of data that will be transmitted with the PING and returned with the ping acknowledgment.

The callback will be invoked with three arguments: an error argument that will be null if the PING was successfully acknowledged, a duration argument that reports the number of milliseconds elapsed since the ping was sent and the acknowledgment was received, and a Buffer containing the 8-byte PING payload.

session.ping(Buffer.from('abcdefgh'), (err, duration, payload) => {
if (!err) {
console.log(`Ping acknowledged in ${duration} milliseconds`);
console.log(`With payload '${payload.toString()}'`);
}
});

If the payload argument is not specified, the default payload will be the 64-bit timestamp (little endian) marking the start of the PING duration.

@since v8.9.3

Parameter
payloadOptional ping payload.
abstract member ping (callback: Callback) : bool

Sends a PING frame to the connected HTTP/2 peer. A callback function must be provided. The method will return true if the PING was sent, false otherwise.

The maximum number of outstanding (unacknowledged) pings is determined by the maxOutstandingPings configuration option. The default maximum is 10.

If provided, the payload must be a Buffer, TypedArray, or DataView containing 8 bytes of data that will be transmitted with the PING and returned with the ping acknowledgment.

The callback will be invoked with three arguments: an error argument that will be null if the PING was successfully acknowledged, a duration argument that reports the number of milliseconds elapsed since the ping was sent and the acknowledgment was received, and a Buffer containing the 8-byte PING payload.

session.ping(Buffer.from('abcdefgh'), (err, duration, payload) => {
if (!err) {
console.log(`Ping acknowledged in ${duration} milliseconds`);
console.log(`With payload '${payload.toString()}'`);
}
});

If the payload argument is not specified, the default payload will be the 64-bit timestamp (little endian) marking the start of the PING duration.

@since v8.9.3

Parameter
payloadOptional ping payload.
abstract member prependListener (event: U2<string,Symbol>, listener: obj array -> unit) : Http2Session

Adds the listener function to the beginning of the listeners array for the event named eventName. No checks are made to see if the listener has already been added. Multiple calls passing the same combination of eventName and listener will result in the listener being added, and called, multiple times.

server.prependListener('connection', (stream) => {
console.log('someone connected!');
});

Returns a reference to the EventEmitter, so that calls can be chained.

abstract member prependListenerClose (listener: unit -> unit) : Http2Session
prependListener(event: "close", listener: () => void): this
abstract member prependListenerError (listener: exn -> unit) : Http2Session
prependListener(event: "error", listener: (err: Error) => void): this
abstract member prependListenerFrameError (listener: Listener) : Http2Session
prependListener(event: "frameError", listener: (frameType: number, errorCode: number, id: number) => void): this
abstract member prependListenerGoaway (listener: Listener2) : Http2Session
prependListener(event: "goaway", listener: (errorCode: number, lastStreamID: number, opaqueData?: NonSharedBuffer) => void): this
abstract member prependListenerLocalSettings (listener: Settings -> unit) : Http2Session
prependListener(event: "localSettings", listener: (settings: Settings) => void): this
abstract member prependListenerPing (listener: unit -> unit) : Http2Session
prependListener(event: "ping", listener: () => void): this
abstract member prependListenerRemoteSettings (listener: Settings -> unit) : Http2Session
prependListener(event: "remoteSettings", listener: (settings: Settings) => void): this
abstract member prependListenerTimeout (listener: unit -> unit) : Http2Session
prependListener(event: "timeout", listener: () => void): this
abstract member prependOnceListener (event: U2<string,Symbol>, listener: obj array -> unit) : Http2Session

Adds a one-timelistener function for the event named eventName to the beginning of the listeners array. The next time eventName is triggered, this listener is removed, and then invoked.

server.prependOnceListener('connection', (stream) => {
console.log('Ah, we have our first user!');
});

Returns a reference to the EventEmitter, so that calls can be chained.

abstract member prependOnceListenerClose (listener: unit -> unit) : Http2Session
prependOnceListener(event: "close", listener: () => void): this
abstract member prependOnceListenerError (listener: exn -> unit) : Http2Session
prependOnceListener(event: "error", listener: (err: Error) => void): this
abstract member prependOnceListenerFrameError (listener: Listener) : Http2Session
prependOnceListener(event: "frameError", listener: (frameType: number, errorCode: number, id: number) => void): this
abstract member prependOnceListenerGoaway (listener: Listener2) : Http2Session
prependOnceListener(event: "goaway", listener: (errorCode: number, lastStreamID: number, opaqueData?: NonSharedBuffer) => void): this
abstract member prependOnceListenerLocalSettings (listener: Settings -> unit) : Http2Session
prependOnceListener(event: "localSettings", listener: (settings: Settings) => void): this
abstract member prependOnceListenerPing (listener: unit -> unit) : Http2Session
prependOnceListener(event: "ping", listener: () => void): this
abstract member prependOnceListenerRemoteSettings (listener: Settings -> unit) : Http2Session
prependOnceListener(event: "remoteSettings", listener: (settings: Settings) => void): this
abstract member prependOnceListenerTimeout (listener: unit -> unit) : Http2Session
prependOnceListener(event: "timeout", listener: () => void): this
abstract member rawListeners (eventName: U2<string,Symbol>) : Function array

Returns a copy of the array of listeners for the event named eventName, including any wrappers (such as those created by .once()).

import { EventEmitter } from 'node:events';
const emitter = new EventEmitter();
emitter.once('log', () => console.log('log once'));

// Returns a new Array with a function `onceWrapper` which has a property
// `listener` which contains the original listener bound above
const listeners = emitter.rawListeners('log');
const logFnWrapper = listeners[0];

// Logs "log once" to the console and does not unbind the `once` event
logFnWrapper.listener();

// Logs "log once" to the console and removes the listener
logFnWrapper();

emitter.on('log', () => console.log('log persistently'));
// Will return a new Array with a single function bound by `.on()` above
const newListeners = emitter.rawListeners('log');

// Logs "log persistently" twice
newListeners[0]();
emitter.emit('log');

@since v9.4.0

abstract member ref () : unit

Calls ref() on this Http2Session instance's underlying net.Socket.

@since v9.4.0

abstract member removeAllListeners (?eventName: U2<string,Symbol>) : Http2Session

Removes all listeners, or those of the specified eventName.

It is bad practice to remove listeners added elsewhere in the code, particularly when the EventEmitter instance was created by some other component or module (e.g. sockets or file streams).

Returns a reference to the EventEmitter, so that calls can be chained.

@since v0.1.26

abstract member removeListener (eventName: U2<string,Symbol>, listener: obj array -> unit) : Http2Session

Removes the specified listener from the listener array for the event named eventName.

const callback = (stream) => {
console.log('someone connected!');
};
server.on('connection', callback);
// ...
server.removeListener('connection', callback);

removeListener() will remove, at most, one instance of a listener from the listener array. If any single listener has been added multiple times to the listener array for the specified eventName, then removeListener() must be called multiple times to remove each instance.

Once an event is emitted, all listeners attached to it at the time of emitting are called in order. This implies that any removeListener() or removeAllListeners() calls after emitting and before the last listener finishes execution will not remove them fromemit() in progress. Subsequent events behave as expected.

import { EventEmitter } from 'node:events';
class MyEmitter extends EventEmitter {}
const myEmitter = new MyEmitter();

const callbackA = () => {
console.log('A');
myEmitter.removeListener('event', callbackB);
};

const callbackB = () => {
console.log('B');
};

myEmitter.on('event', callbackA);

myEmitter.on('event', callbackB);

// callbackA removes listener callbackB but it will still be called.
// Internal listener array at time of emit [callbackA, callbackB]
myEmitter.emit('event');
// Prints:
//   A
//   B

// callbackB is now removed.
// Internal listener array [callbackA]
myEmitter.emit('event');
// Prints:
//   A

Because listeners are managed using an internal array, calling this will change the position indices of any listener registered after the listener being removed. This will not impact the order in which listeners are called, but it means that any copies of the listener array as returned by the emitter.listeners() method will need to be recreated.

When a single function has been added as a handler multiple times for a single event (as in the example below), removeListener() will remove the most recently added instance. In the example the once('ping') listener is removed:

import { EventEmitter } from 'node:events';
const ee = new EventEmitter();

function pong() {
console.log('pong');
}

ee.on('ping', pong);
ee.once('ping', pong);
ee.removeListener('ping', pong);

ee.emit('ping');
ee.emit('ping');

Returns a reference to the EventEmitter, so that calls can be chained.

@since v0.1.26

abstract member setLocalWindowSize (windowSize: float) : unit

Sets the local endpoint's window size. The windowSize is the total window size to set, not the delta.

import http2 from 'node:http2';

const server = http2.createServer();
const expectedWindowSize = 2 ** 20;
server.on('connect', (session) => {

// Set local window size to be 2 ** 20
session.setLocalWindowSize(expectedWindowSize);
});

@since v15.3.0, v14.18.0

abstract member setMaxListeners (n: float) : Http2Session

By default EventEmitters will print a warning if more than 10 listeners are added for a particular event. This is a useful default that helps finding memory leaks. The emitter.setMaxListeners() method allows the limit to be modified for this specific EventEmitter instance. The value can be set to Infinity (or 0) to indicate an unlimited number of listeners.

Returns a reference to the EventEmitter, so that calls can be chained.

@since v0.3.5

abstract member setTimeout (msecs: float, ?callback: (unit -> unit)) : unit

Used to set a callback function that is called when there is no activity on the Http2Session after msecs milliseconds. The given callback is registered as a listener on the 'timeout' event.

@since v8.4.0

abstract member settings (settings: Settings, ?callback: Callback) : unit

Updates the current local settings for this Http2Session and sends a new SETTINGS frame to the connected HTTP/2 peer.

Once called, the http2session.pendingSettingsAck property will be true while the session is waiting for the remote peer to acknowledge the new settings.

The new settings will not become effective until the SETTINGS acknowledgment is received and the 'localSettings' event is emitted. It is possible to send multiple SETTINGS frames while acknowledgment is still pending.

@since v8.4.0

Parameter
callbackCallback that is called once the session is connected or right away if the session is already connected.
abstract member unref () : unit

Calls unref() on this Http2Sessioninstance's underlying net.Socket.

@since v9.4.0