npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@detox/transport

v0.38.3

Published

Transport layer implementation for Detox project

Downloads

16

Readme

Detox transport Travis CI

Transport layer implementation for Detox project.

This library provides transport layer implementation with simple API that:

  • ensures constant data rate on connection
  • supports sending numeric commands with payload
  • compresses payloads of some commands

How to install

npm install @detox/transport

How to use

Node.js:

var detox_transport = require('@detox/transport')

detox_transport.ready(function () {
    // Do stuff
});

Browser:

requirejs(['@detox/transport'], function (detox_transport) {
    detox_transport.ready(function () {
        // Do stuff
    });
})

API

detox_transport.P2P_transport(id : Uint8Array, peer_id : Uint8Array, initiator : boolean, ice_servers : Object[], packets_per_second : number, uncompressed_commands_offset : number) : detox_transport.P2P_transport

Constructor for peer-to-peer transport between 2 nodes in Detox network.

  • id - own ID
  • peer_id - ID of a peer
  • initiator - whether current node initiates connection
  • ice_servers - array of objects as in RTCPeerConnection constructor
  • packets_per_second - packets are sent at constant rate (which together with fixed packet size of 512 bytes can be used to identify bandwidth requirements for specific connection), 1 is minimal supported rate, actual rate is negotiated between 2 nodes on connection
  • uncompressed_commands_offset - commands with number less than this will be compressed/decompressed with zlib

detox_transport.P2P_transport.signal(signal : Uint8Array)

  • signal - as generated by signal event

detox_transport.P2P_transport.update_peer_id(peer_id : Uint8Array)

Allows to change old peer ID to new one, is useful when connection needs to be initialized, but peer's ID is not yet known, so that random ID can be used and then updated to correct one.

detox_transport.P2P_transport.send(command : number, data : Uint8Array)

Send command with some payload to the remote node.

  • command - command from range [0, 255]
  • data - command payload, up to detox_transport.MAX_COMPRESSED_DATA_SIZE bytes for commands below uncompressed_commands_offset and up to detox_transport.MAX_DATA_SIZE bytes for other commands

detox_transport.P2P_transport.destroy()

Destroy instance, disconnect from the remote node.

detox_transport.P2P_transport.on(event: string, callback: Function) : detox_transport.P2P_transport

Register event handler.

detox_transport.P2P_transport.once(event: string, callback: Function) : detox_transport.P2P_transport

Register one-time event handler (just on() + off() under the hood).

detox_transport.P2P_transport.off(event: string[, callback: Function]) : detox_transport.P2P_transport

Unregister event handler.

Event: signal

Payload consists of single Uint8Array argument signal.

Event is fired when signaling data is available and should be sent to remote node.

Event: connected

Event is fired when new remote node is connected.

Event: disconnected

Event is fired when new remote node is disconnected.

Event: data

Payload consists of two arguments: command (number) and data (Uint8Array). Event is fired when new remote node have sent data using send() method.

detox_transport.Transport(id : Uint8Array, ice_servers : Object[], packets_per_second : number, uncompressed_commands_offset : number, connect_timeout : number) : detox_transport.Transport

Constructor for transport object that encapsulates multiple P2P connections and uses P2P_transport under the hood.

  • id - own ID
  • ice_servers - array of objects as in RTCPeerConnection constructor
  • packets_per_second - packets are sent at constant rate (which together with fixed packet size of 512 bytes can be used to identify bandwidth requirements for specific connection), 1 is minimal supported rate, actual rate is negotiated between 2 nodes on connection
  • uncompressed_commands_offset - commands with number less than this will be compressed/decompressed with zlib
  • connect_timeout - how many seconds since signal generation to wait for connection before failing

detox_transport.Transport.create_connection(initiator : boolean, peer_id : Uint8Array) : detox_transport.P2P_transport

Create new connection for peer_id as initiator or responder.

Returns instance of P2P_transport on success.

detox_transport.Transport.get_connection(peer_id : Uint8Array) : detox_transport.P2P_transport

Get connection for peer_id that was already created.

Returns instance of P2P_transport if it was already created or null otherwise.

detox_transport.Transport.update_peer_id(old_peer_id : Uint8Array, new_peer_id : Uint8Array) : boolean

Allows to change old peer ID to new one, is useful when connection needs to be initialized, but peer's ID is not yet known, so that random ID can be used and then updated to correct one.

Returns true if update succeeded (will fail when connection to peer with new_peer_id already exists).

detox_transport.Transport.destroy_connection(peer_id : Uint8Array)

Destroy connection for peer_id.

detox_transport.Transport.signal(peer_id : Uint8Array, signal : Uint8Array)

  • peer_id - as generated by signal event
  • signal - as generated by signal event

detox_transport.Transport.send(peer_id : Uint8Array, command : number, data : Uint8Array)

Send command with some payload to the remote node.

  • peer_id - peer to which sent command
  • command - command from range [0, 255]
  • data - command payload, up to detox_transport.MAX_COMPRESSED_DATA_SIZE bytes for commands below uncompressed_commands_offset and up to detox_transport.MAX_DATA_SIZE bytes for other commands

detox_transport.Transport.destroy()

Destroy instance, disconnect from all of the peers.

detox_transport.Transport.on(event: string, callback: Function) : detox_transport.Transport

Register event handler.

detox_transport.Transport.once(event: string, callback: Function) : detox_transport.Transport

Register one-time event handler (just on() + off() under the hood).

detox_transport.Transport.off(event: string[, callback: Function]) : detox_transport.Transport

Unregister event handler.

Event: signal

Payload consists of two Uint8Array arguments: peer_id and signal.

Event is fired when signaling data is available and should be sent to remote node.

Event: connected

Payload consists of single Uint8Array argument peer_id.

Event is fired when new remote node is connected.

Event: disconnected

Payload consists of single Uint8Array argument peer_id.

Event is fired when new remote node is disconnected.

Event: data

Payload consists of three arguments: peer_id (Uint8Array), command (number) and data (Uint8Array).

Event is fired when new remote node have sent data using send() method.

detox_transport.MAX_DATA_SIZE : number

Constant that defines max data size supported for sending for non-compressed commands (controlled by uncompressed_commands_offset option).

detox_transport.MAX_COMPRESSED_DATA_SIZE : number

Constant that defines max data size supported for sending for compressed commands (controlled by uncompressed_commands_offset option).

Contribution

Feel free to create issues and send pull requests (for big changes create an issue first and link it from the PR), they are highly appreciated!

When reading LiveScript code make sure to configure 1 tab to be 4 spaces (GitHub uses 8 by default), otherwise code might be hard to read.

License

Free Public License 1.0.0 / Zero Clause BSD License

https://opensource.org/licenses/FPL-1.0.0

https://tldrlegal.com/license/bsd-0-clause-license