Class MockRTCRuleBuilder

Rule builders allow you to combine sets of matchers, progressively building a set of matching conditions, before defining the resulting behaviour that will be applied to matching traffic.

Hierarchy

  • MockRTCRuleBuilder

Implements

Steps

createDataChannel: ((channelLabel) => MockRTCHandlerBuilder<void>) = ...

Type declaration

send: {
    (message): MockRTCHandlerBuilder<void>;
    (channel, message): MockRTCHandlerBuilder<void>;
} = ...

Type declaration

    • (message): MockRTCHandlerBuilder<void>
    • Send a message or buffer on the connection's data channels.

      This can take one or two arguments. If only one is provided, it is used as a message that's sent on all open data channels. If two arguments are provided, the first must be the data channel label, and the message (the second) will be sent only to data channel(s) with that label.

      If no matching channels are open, this is a no-op. Use waitForChannel() to ensure the channels you're expecting are open first if necessary.

      Parameters

      • message: string | Buffer

      Returns MockRTCHandlerBuilder<void>

    • (channel, message): MockRTCHandlerBuilder<void>
    • Parameters

      • channel: undefined | string
      • message: string | Buffer

      Returns MockRTCHandlerBuilder<void>

sleep: ((duration) => MockRTCHandlerBuilder<void>) = ...

Type declaration

waitForChannel: ((channelLabel?) => MockRTCHandlerBuilder<void>) = ...

Type declaration

waitForNextMedia: (() => MockRTCHandlerBuilder<void>) = ...

Type declaration

    • (): MockRTCHandlerBuilder<void>
    • Wait until the remote client next sends media data on a media track.

      This waits for new media, ignoring any media already consumed by previous steps.

      Returns MockRTCHandlerBuilder<void>

waitForNextMessage: (() => MockRTCHandlerBuilder<void>) = ...

Type declaration

    • (): MockRTCHandlerBuilder<void>
    • Wait until the remote client next sends a message to us on any DataChannel.

      This looks for new messages, ignoring any messages already consumed by previous steps.

      Returns MockRTCHandlerBuilder<void>

waitForNextMessageOnChannel: ((channelLabel) => MockRTCHandlerBuilder<void>) = ...

Type declaration

    • (channelLabel): MockRTCHandlerBuilder<void>
    • Wait until the remote client sends a message to us on a specific DataChannel.

      This looks for new messages, ignoring any messages already consumed by previous steps.

      Parameters

      • channelLabel: string

      Returns MockRTCHandlerBuilder<void>

waitForTrack: (() => MockRTCHandlerBuilder<void>) = ...

Type declaration

Final Steps

thenClose: (() => Promise<void>) = ...

Type declaration

    • (): Promise<void>
    • Immediately close the connection.

      This defines a final step, and will then create a mock peer from the full set of steps you've defined, and return it wrapped in a promise. As soon as the promise resolves the peer is ready to use.

      Returns Promise<void>

thenEcho: (() => Promise<void>) = ...

Type declaration

    • (): Promise<void>
    • Echo all incoming data channel messages until the other peer closes the connection.

      This defines a final step, and will then create a mock peer from the full set of steps you've defined, and return it wrapped in a promise. As soon as the promise resolves the peer is ready to use.

      Returns Promise<void>

thenForwardTo: ((peer) => Promise<void>) = ...

Type declaration

    • (peer): Promise<void>
    • Creates a new external connection to the given remote peer connection, matching the existing mocked connection, and then proxies all traffic through to that peer.

      This defines a final step, and will then create a mock peer from the full set of steps you've defined, and return it wrapped in a promise. As soon as the promise resolves the peer is ready to use.

      Parameters

      • peer: RTCPeerConnection

      Returns Promise<void>

thenPassThrough: (() => Promise<void>) = ...

Type declaration

    • (): Promise<void>
    • Proxy this connection dynamically to the 'real' target peer, whoever that may be.

      This assumes that you have an existing external connection already set up and attached to this mock connection.

      You can do that either by using hookWebRTCConnection or hookAllWebRTC to hook your connection during normal setup to automatically create an external offer to the real remote peer, or you can do so manually using createExternalOffer or answerExternalOffer and then passing the connection id as here.

      This defines a final step, and will then create a mock peer from the full set of steps you've defined, and return it wrapped in a promise. As soon as the promise resolves the peer is ready to use.

      Returns Promise<void>

thenSend: {
    (message): Promise<void>;
    (channel, message): Promise<void>;
} = ...

Type declaration

    • (message): Promise<void>
    • Send a message or buffer on the connection's data channels, then close the connection. This is equivalent to .send() then .thenClose().

      This defines a final step, and will then create a mock peer from the full set of steps you've defined, and return it wrapped in a promise. As soon as the promise resolves the peer is ready to use.

      Parameters

      • message: string | Buffer

      Returns Promise<void>

    • (channel, message): Promise<void>
    • Parameters

      • channel: string
      • message: string | Buffer

      Returns Promise<void>

Matcher

  • Match RTC connections made from hooked JavaScript running on a given hostname.

    This only matches connections with explicit sourceURL metadata, which must be either added automatically (by using the hookAllWebRTC or hookWebRTCConnection methods) or manually (by providing metadata: { sourceURL: '...' } options during mock connection setup).

    Parameters

    • hostname: string

    Returns MockRTCRuleBuilder

  • Match RTC connections made from hooked JavaScript running on a matching URL.

    This only matches connections with explicit sourceURL metadata, which must be either added automatically (by using the hookAllWebRTC or hookWebRTCConnection methods) or manually (by providing metadata: { sourceURL: '...' } options during mock connection setup).

    Parameters

    • urlRegex: RegExp

    Returns MockRTCRuleBuilder

  • Match RTC connections made by hooked JavaScript running within a browser with a matching user agent string.

    This only matches connections with explicit userAgent metadata, which must be either added automatically (by using the hookAllWebRTC or hookWebRTCConnection methods) or manually (by providing metadata: { userAgent: '...' } options during mock connection setup).

    Parameters

    • userAgentRegEx: RegExp

    Returns MockRTCRuleBuilder

Other

Generated using TypeDoc