### Install webConnect.js via NPM
Source: https://github.com/nuzulul/webconnect.js/blob/main/README.md
Install webconnect.js using npm and import it for use in your project.
```javascript
npm install webconnect
//Browserify
const webconnect = require('webconnect')
//ES Module
import webconnect from 'webconnect'
```
--------------------------------
### Initialize webConnect.js
Source: https://github.com/nuzulul/webconnect.js/blob/main/README.md
Create an instance of the webconnect object to start using its functionalities.
```javascript
const connect = webconnect()
```
--------------------------------
### Connect using NPM
Source: https://github.com/nuzulul/webconnect.js/blob/main/README.md
Install and import WebConnect.js using NPM for use in Node.js or bundled frontend projects. This is the standard method for project integration.
```javascript
import webconnect from 'webconnect'
const connect = webconnect()
connect.onConnect(async(attribute)=>{
console.log("Connect",attribute)
connect.Send("hello",{connectId:attribute.connectId})
console.log(await connect.Ping({connectId:attribute.connectId}))
connect.getConnection((attribute)=>{
console.log("Connection",attribute)
})
})
connect.onDisconnect((attribute)=>{
console.log("Disconnect",attribute)
})
connect.onReceive((data,attribute) =>{
console.log(data,attribute)
})
```
--------------------------------
### Install webConnect.js via CDN
Source: https://github.com/nuzulul/webconnect.js/blob/main/README.md
Include the webconnect.js script from a CDN for browser usage.
```html
```
--------------------------------
### Get All Connection IDs
Source: https://github.com/nuzulul/webconnect.js/blob/main/README.md
Retrieve a list of all currently connected peer IDs.
```javascript
connect.getConnection((attribute) => console.log(`${attribute.connection}`))
```
--------------------------------
### Get Own Connection ID
Source: https://github.com/nuzulul/webconnect.js/blob/main/README.md
Retrieve and log your own unique connection ID.
```javascript
connect.getMyId((attribute) => console.log(`${attribute.connectId}`))
```
--------------------------------
### Get All Connection Id
Source: https://github.com/nuzulul/webconnect.js/blob/main/README.md
Retrieves a list of all currently active connection IDs.
```APIDOC
## Get All Connection Id
### Description
Retrieves a list of all currently active connection IDs.
### Method
```javascript
connect.getConnection(callback)
```
### Parameters
- **callback** (function) - Function to execute with the connection list. Receives an `attribute` object containing a `connection` array of IDs.
### Request Example
```javascript
connect.getConnection((attribute) => console.log('Active connections:', attribute.connection))
```
```
--------------------------------
### Get self connection identity
Source: https://github.com/nuzulul/webconnect.js/blob/main/README.md
Retrieves the unique identifier for the current connection.
```APIDOC
## Get self connection identity
### Description
Retrieves the unique identifier for the current connection.
### Method
```javascript
getMyId((attribute) => {})
```
### Parameters
#### attribute
- **connectId** (String) - The unique identifier for the self connection.
```
--------------------------------
### Get My Connection Id
Source: https://github.com/nuzulul/webconnect.js/blob/main/README.md
Retrieves the unique connection ID of the current client.
```APIDOC
## Get My Connection Id
### Description
Retrieves the unique connection ID of the current client.
### Method
```javascript
connect.getMyId(callback)
```
### Parameters
- **callback** (function) - Function to execute with the connection ID. Receives an `attribute` object containing `connectId`.
### Request Example
```javascript
connect.getMyId((attribute) => console.log(`${attribute.connectId}`))
```
```
--------------------------------
### Get All Connection Identities
Source: https://github.com/nuzulul/webconnect.js/blob/main/README.md
Retrieve all connection identities within a channel. The 'attribute' object contains 'connection' (excluding self) and 'connections' (RTCPeerConnection objects).
```javascript
getConnection((attribute) => {})
```
--------------------------------
### Get self connection identity
Source: https://github.com/nuzulul/webconnect.js/blob/main/README.md
Retrieve the unique identifier for the current connection. The identity is provided in a callback attribute.
```javascript
getMyId((attribute) => {})
```
--------------------------------
### Get Connection Latency
Source: https://github.com/nuzulul/webconnect.js/blob/main/README.md
Measure the latency of a specific connection. This function returns a promise that resolves to the latency in milliseconds. The 'attribute' object requires the 'connectId' of the target connection.
```javascript
Ping(attribute)
```
--------------------------------
### Initialization
Source: https://github.com/nuzulul/webconnect.js/blob/main/README.md
Initializes the webConnect instance. This is the first step to using the library.
```APIDOC
## Initialization
### Description
Initializes the webConnect instance. This is the first step to using the library.
### Method
```javascript
webconnect()
```
### Endpoint
N/A (Client-side library)
### Parameters
None
### Request Example
```javascript
const connect = webconnect()
```
### Response
Returns an initialized webconnect object.
```
--------------------------------
### Connect to a channel with options
Source: https://github.com/nuzulul/webconnect.js/blob/main/README.md
Initialize a connection to a specific channel using optional configuration parameters. This allows customization of connection behavior and network settings.
```javascript
const options = {appName,channelName,connectPassword,iceConfiguration,torrentTrackers,nostrRelays,mqttBrokers}
webconnect(options)
```
--------------------------------
### Initialize and Use WebConnect.js
Source: https://github.com/nuzulul/webconnect.js/blob/main/demo/index.html
Initializes WebConnect.js and sets up event listeners for connection, disconnection, and message reception. It also demonstrates sending a message and pinging a connection.
```javascript
import webconnect from 'https://cdn.jsdelivr.net/npm/webconnect/dist/esm/webconnect.js'
const connect = webconnect()
connect.getMyId((attribute) => write('My connectId is '+attribute.connectId))
connect.onConnect(async(attribute)=>{
write(attribute.connectId+' is connected')
console.log("Connect",attribute)
write('Say hello to '+attribute.connectId)
connect.Send("hello",{connectId:attribute.connectId})
write('Latency '+attribute.connectId+' is '+await connect.Ping({connectId:attribute.connectId})+' ms')
})
connect.onDisconnect((attribute)=>{
write(attribute.connectId+' is disconnected')
console.log("Disconnect",attribute)
})
connect.onReceive((data,attribute) =>{
write(attribute.connectId+' say : '+data)
console.log(data,attribute)
})
function write(input){
const node = document.createElement("li")
const textnode = document.createTextNode(input)
node.appendChild(textnode)
document.getElementById("myList").appendChild(node)
}
```
--------------------------------
### Listen for New Connections
Source: https://github.com/nuzulul/webconnect.js/blob/main/README.md
Set up a callback to log the connectId when a new peer connects.
```javascript
connect.onConnect((attribute) => console.log(`${attribute.connectId} connected`))
```
--------------------------------
### Basic WebConnect UMD Initialization and Usage
Source: https://github.com/nuzulul/webconnect.js/blob/main/test/umd.html
This snippet shows how to initialize WebConnect, set up event listeners for connection, disconnection, and receiving messages, and send a message and a ping. It's suitable for direct use in an HTML file.
```javascript
void async function main() {
const w = webconnect()
w.onConnect(async(data)=>{
console.log(data)
w.Send("hello",{connectId:data.connectId})
console.log(await w.Ping({connectId:data.connectId}))
w.getConnection((data)=>{
console.log(data)
})
})
w.onDisconnect((connectId)=>{
console.log(connectId)
w.Disconnect()
})
w.onReceive((data,connectId) =>{
console.log(data)
})
}()
```
--------------------------------
### Open Streaming Connection
Source: https://github.com/nuzulul/webconnect.js/blob/main/README.md
Initiate a streaming connection to a peer, optionally with metadata.
```javascript
const attribute = {connectId,metadata:{name:'Meeting'}}
connect.openStreaming(stream,attribute)
```
--------------------------------
### Listen for Receiving Progress
Source: https://github.com/nuzulul/webconnect.js/blob/main/README.md
Set up a callback to monitor the progress of data being received from a specific peer.
```javascript
connect.onReceiveProgress((attribute) => console.log(`Receiving progress : ${attribute.percent} from ${attribute.connectId}`))
```
--------------------------------
### Listen for Incoming Streaming Data
Source: https://github.com/nuzulul/webconnect.js/blob/main/README.md
Set up a callback to handle incoming media streams and assign them to a video element.
```javascript
connect.onStreaming((stream,attribute) => Elements[attribute.connectId].video.srcObject = stream )
```
--------------------------------
### Connect using CDN
Source: https://github.com/nuzulul/webconnect.js/blob/main/README.md
Include the WebConnect.js library via CDN and initialize a connection. This is suitable for quick integration or environments where NPM is not available.
```javascript
```
--------------------------------
### Listen for Sending Progress
Source: https://github.com/nuzulul/webconnect.js/blob/main/README.md
Set up a callback to monitor the progress of data being sent to a specific peer.
```javascript
connect.onSendProgress((attribute) => console.log(`Sending progress : ${attribute.percent} to ${attribute.connectId}`))
```
--------------------------------
### Connect to a channel
Source: https://github.com/nuzulul/webconnect.js/blob/main/README.md
Establishes a connection to a specified channel with optional configuration parameters.
```APIDOC
## Connect to a channel
### Description
Establishes a connection to a specified channel with optional configuration parameters.
### Method
```javascript
webconnect(options)
```
### Parameters
#### Options Object
- **appName** (String) - Your app identity
- **channelName** (String) - Channel to connect
- **connectPassword** (String) - Password to encrypt connection initialization
- **iceConfiguration** (Object) - Custom [iceConfiguration](https://webrtc.org/getting-started/turn-server)
- **torrentTrackers** (Array) - Custom list of TORRENT trackers
- **nostrRelays** (Array) - Custom list of NOSTR relays
- **mqttBrokers** (Array) - Custom list of MQTT brokers
```
--------------------------------
### Listen to new connections
Source: https://github.com/nuzulul/webconnect.js/blob/main/README.md
Register a callback function to be executed whenever a new client successfully connects to the channel. The callback receives connection attributes.
```javascript
onConnect((attribute)=>{})
```
--------------------------------
### Open streaming connection
Source: https://github.com/nuzulul/webconnect.js/blob/main/README.md
Initiate a streaming connection using a MediaStream. Specify the target connection and optional metadata for the stream.
```javascript
openStreaming(stream,attribute)
```
--------------------------------
### Connect and Interact with WebConnect.js (ESM)
Source: https://github.com/nuzulul/webconnect.js/blob/main/test/esm.html
This snippet shows how to import and initialize WebConnect.js in an ESM environment. It includes event handlers for connection, disconnection, and receiving data, as well as sending a message and pinging the server.
```javascript
import webconnect from './../public/bundle/webconnect.esm.js' //void async function main() { const w = webconnect() w.onConnect(async(data)=>{ console.log(data) w.Send("hello",{connectId:data.connectId}) console.log(await w.Ping({connectId:data.connectId})) w.getConnection((data)=>{ console.log(data) }) }) w.onDisconnect((data)=>{ console.log(data) w.Disconnect() }) w.onReceive((data,metadata) =>{ console.log(data,metadata) }) //}()
```
--------------------------------
### Listen to send progress
Source: https://github.com/nuzulul/webconnect.js/blob/main/README.md
Implement a callback to monitor the progress of binary data being sent. Provides percentage completion and the target connection ID.
```javascript
onSendProgress((attribute) => {})
```
--------------------------------
### Listen to receive progress for binary data
Source: https://github.com/nuzulul/webconnect.js/blob/main/README.md
Implement a callback to track the progress of incoming binary data. Provides percentage completion and the origin connection ID.
```javascript
onReceiveProgress((attribute) => {})
```
--------------------------------
### Open streaming connection
Source: https://github.com/nuzulul/webconnect.js/blob/main/README.md
Initiates a streaming connection using a MediaStream.
```APIDOC
## Open streaming connection
### Description
Initiates a streaming connection using a MediaStream.
### Method
```javascript
openStreaming(stream, attribute)
```
### Parameters
#### stream
- **stream** (MediaStream) - A MediaStream with audio and/or video.
#### attribute
- **connectId** (String) - The target connection identifier.
- **metadata** (Object) - Optional object describing the stream.
```
--------------------------------
### Open Streaming
Source: https://github.com/nuzulul/webconnect.js/blob/main/README.md
Initiates a media stream to a specific peer connection.
```APIDOC
## Open Streaming
### Description
Initiates a media stream to a specific peer connection.
### Method
```javascript
connect.openStreaming(stream, attribute)
```
### Parameters
- **stream** (MediaStream) - The media stream to send.
- **attribute** (object) - An object containing connection details and metadata.
- **connectId** (string) - The ID of the target peer.
- **metadata** (object) - Optional metadata for the stream (e.g., `{ name: 'Meeting' }`).
### Request Example
```javascript
const attribute = { connectId: 'some_connection_id', metadata: { name: 'Meeting' } }
// Assume 'stream' is a valid MediaStream object
connect.openStreaming(stream, attribute)
```
```
--------------------------------
### Listen to every new connection
Source: https://github.com/nuzulul/webconnect.js/blob/main/README.md
Registers a callback function to be executed whenever a new connection is established.
```APIDOC
## Listen to every new connection
### Description
Registers a callback function to be executed whenever a new connection is established.
### Method
```javascript
onConnect((attribute) => {})
```
### Parameters
#### attribute
- **connectId** (String) - The unique identifier for the origin connection.
```
--------------------------------
### Listen for Incoming Data
Source: https://github.com/nuzulul/webconnect.js/blob/main/README.md
Set up a callback to process received data and log the sender's connectId.
```javascript
connect.onReceive((data,attribute) => console.log(`${data} from ${attribute.connectId}`))
```
--------------------------------
### Listen to incoming streaming connection
Source: https://github.com/nuzulul/webconnect.js/blob/main/README.md
Registers a callback function to handle incoming streaming connections.
```APIDOC
## Listen to incoming streaming connection
### Description
Registers a callback function to handle incoming streaming connections.
### Method
```javascript
onStreaming((stream, attribute) => {})
```
### Parameters
#### stream
- **stream** (MediaStream) - A MediaStream with audio and/or video.
#### attribute
- **connectId** (String) - The identifier of the origin connection.
- **metadata** (Object) - Optional object describing the stream.
```
--------------------------------
### Listen to incoming streaming connection
Source: https://github.com/nuzulul/webconnect.js/blob/main/README.md
Register a callback to handle incoming streaming connections. The callback receives the MediaStream and origin connection attributes.
```javascript
onStreaming((stream,attribute) => {})
```
--------------------------------
### Listen to receiving progress for binary data
Source: https://github.com/nuzulul/webconnect.js/blob/main/README.md
Registers a callback function to monitor the progress of binary data downloads.
```APIDOC
## Listen to receiving progress for binary data
### Description
Registers a callback function to monitor the progress of binary data downloads.
### Method
```javascript
onReceiveProgress((attribute) => {})
```
### Parameters
#### attribute
- **percent** (Number) - The percentage of completion, ranging from 0 to 1.
- **connectId** (String) - The identifier of the origin connection.
```
--------------------------------
### Listen for Disconnect Events
Source: https://github.com/nuzulul/webconnect.js/blob/main/README.md
Set up a callback to log the connectId when a peer disconnects.
```javascript
connect.onDisconnect((attribute) => console.log(`${attribute.connectId} disconnected`))
```
--------------------------------
### Listen to sending progress for binary data
Source: https://github.com/nuzulul/webconnect.js/blob/main/README.md
Registers a callback function to monitor the progress of binary data uploads.
```APIDOC
## Listen to sending progress for binary data
### Description
Registers a callback function to monitor the progress of binary data uploads.
### Method
```javascript
onSendProgress((attribute) => {})
```
### Parameters
#### attribute
- **percent** (Number) - The percentage of completion, ranging from 0 to 1.
- **connectId** (String) - The identifier of the target connection.
```
--------------------------------
### Import webConnect.js as ES Module via CDN
Source: https://github.com/nuzulul/webconnect.js/blob/main/README.md
Import the webconnect.js library as an ES Module directly from a CDN.
```javascript
```
--------------------------------
### Listen to receiving data
Source: https://github.com/nuzulul/webconnect.js/blob/main/README.md
Register a callback to handle incoming data, which can be strings, objects, or ArrayBuffers. Includes origin connection ID and metadata for binary data.
```javascript
onReceive((data,attribute) => {})
```
--------------------------------
### Send Binary Data with Metadata
Source: https://github.com/nuzulul/webconnect.js/blob/main/README.md
Send binary data, such as files, along with metadata like filename and type.
```javascript
const attribute = {connectId,metadata:{name: 'Report', type: 'application/pdf'}}
connect.Send(buffer,attribute)
```
--------------------------------
### Send Binary
Source: https://github.com/nuzulul/webconnect.js/blob/main/README.md
Sends binary data, such as files, to a specific peer connection with metadata.
```APIDOC
## Send Binary
### Description
Sends binary data, such as files, to a specific peer connection with metadata.
### Method
```javascript
connect.Send(buffer, attribute)
```
### Parameters
- **buffer** (ArrayBuffer or similar) - The binary data to send.
- **attribute** (object) - An object containing connection details and metadata.
- **connectId** (string) - The ID of the target peer.
- **metadata** (object) - Optional metadata for the binary data.
- **name** (string) - The name of the file or data.
- **type** (string) - The MIME type of the data (e.g., 'application/pdf').
### Request Example
```javascript
const buffer = new Uint8Array([1, 2, 3]) // Example binary data
const attribute = { connectId: 'some_connection_id', metadata: { name: 'Report', type: 'application/pdf' } }
connect.Send(buffer, attribute)
```
```
--------------------------------
### Event Listeners
Source: https://github.com/nuzulul/webconnect.js/blob/main/README.md
Provides methods to listen for various events such as new connections, disconnections, data reception, and streaming.
```APIDOC
## Event Listeners
### Description
Provides methods to listen for various events such as new connections, disconnections, data reception, and streaming.
### Methods
#### `onConnect(callback)`
Listens for new connections.
- **callback** (function) - Function to execute when a connection is established. Receives an `attribute` object with `connectId`.
#### `onDisconnect(callback)`
Listens for disconnections.
- **callback** (function) - Function to execute when a connection is lost. Receives an `attribute` object with `connectId`.
#### `onReceive(callback)`
Listens for incoming data.
- **callback** (function) - Function to execute when data is received. Receives `data` and an `attribute` object with `connectId`.
#### `onSendProgress(callback)`
Listens for data sending progress.
- **callback** (function) - Function to execute during data sending. Receives an `attribute` object with `percent` and `connectId`.
#### `onReceiveProgress(callback)`
Listens for data receiving progress.
- **callback** (function) - Function to execute during data receiving. Receives an `attribute` object with `percent` and `connectId`.
#### `onStreaming(callback)`
Listens for incoming media streams.
- **callback** (function) - Function to execute when a stream is received. Receives `stream` and an `attribute` object with `connectId`.
### Request Example
```javascript
connect.onConnect((attribute) => console.log(`${attribute.connectId} connected`))
connect.onReceive((data, attribute) => console.log(`${data} from ${attribute.connectId}`))
connect.onStreaming((stream, attribute) => Elements[attribute.connectId].video.srcObject = stream)
```
```
--------------------------------
### Listen to receiving data
Source: https://github.com/nuzulul/webconnect.js/blob/main/README.md
Registers a callback function to handle incoming data, which can be string, object, or ArrayBuffer.
```APIDOC
## Listen to receiving data
### Description
Registers a callback function to handle incoming data, which can be string, object, or ArrayBuffer.
### Method
```javascript
onReceive((data, attribute) => {})
```
### Parameters
#### data
- **data** (String or Object or ArrayBuffer) - The received data.
#### attribute
- **connectId** (String) - The identifier of the origin connection.
- **metadata** (Object) - An object describing the ArrayBuffer, if applicable.
```
--------------------------------
### Connect using CDN ESM
Source: https://github.com/nuzulul/webconnect.js/blob/main/README.md
Integrate WebConnect.js using CDN with ES Module support. This method is preferred for modern JavaScript projects using module systems.
```javascript
```
--------------------------------
### Send binary data to connection
Source: https://github.com/nuzulul/webconnect.js/blob/main/README.md
Sends binary data (ArrayBuffer) to a specified connection or all connections, with optional metadata.
```APIDOC
## Send binary data to connection
### Description
Sends binary data (ArrayBuffer) to a specified connection or all connections, with optional metadata.
### Method
```javascript
Send(ArrayBuffer, attribute)
```
### Parameters
#### ArrayBuffer
- **ArrayBuffer** (ArrayBuffer) - The binary data to be sent.
#### attribute
- **connectId** (String or Array or null) - The target connection identifier. Can be a single `connectId`, an array of `connectId`s, or `null` to target all connections in the channel.
- **metadata** (Object) - Optional metadata object, such as filename or file type.
```
--------------------------------
### Send binary data with metadata
Source: https://github.com/nuzulul/webconnect.js/blob/main/README.md
Transmit binary data (ArrayBuffer) along with optional metadata to a specific connection or all connections. Useful for file transfers.
```javascript
Send(ArrayBuffer,attribute)
```
--------------------------------
### Ping a Connection
Source: https://github.com/nuzulul/webconnect.js/blob/main/README.md
Measure the latency to a specific peer by sending a ping and receiving the round-trip time in milliseconds.
```javascript
const attribute = {connectId}
console.log(`${await connect.Ping(attribute)} ms`)
```
--------------------------------
### Listen to disconnections
Source: https://github.com/nuzulul/webconnect.js/blob/main/README.md
Register a callback function to be executed when a client disconnects from the channel. The callback receives connection attributes.
```javascript
onDisconnect((attribute)=>{})
```
--------------------------------
### Listen to every disconnection
Source: https://github.com/nuzulul/webconnect.js/blob/main/README.md
Registers a callback function to be executed whenever a connection is terminated.
```APIDOC
## Listen to every disconnection
### Description
Registers a callback function to be executed whenever a connection is terminated.
### Method
```javascript
onDisconnect((attribute) => {})
```
### Parameters
#### attribute
- **connectId** (String) - The unique identifier for the origin connection.
```
--------------------------------
### getConnection
Source: https://github.com/nuzulul/webconnect.js/blob/main/README.md
Retrieves all connection identities within the current channel. It provides a callback with connection details.
```APIDOC
## getConnection
### Description
Retrieves all connection identities in the channel, excluding the self connection identity. It also provides access to the RTCPeerConnection objects.
### Method
JavaScript Function Call
### Function Signature
`getConnection(callback)`
### Parameters
#### Callback Function Parameters
- **attribute** (object) - Required - An object containing connection information.
- **connection** (Array) - An array of all connection identities excluding the self connection identity.
- **connections** (RTCPeerConnection) - An object containing RTCPeerConnection instances.
### Request Example
```javascript
getConnection((attribute) => {
// Handle connection attributes
});
```
### Response
#### Callback Invocation
The provided callback function is invoked with the `attribute` object containing connection details.
```
--------------------------------
### Send data to a connection
Source: https://github.com/nuzulul/webconnect.js/blob/main/README.md
Send string or object data to a specific connection or all connections in the channel. Use `connectId` to target specific clients.
```javascript
Send(data,attribute)
```
--------------------------------
### Send data to connection
Source: https://github.com/nuzulul/webconnect.js/blob/main/README.md
Sends string or object data to a specified connection or all connections in the channel.
```APIDOC
## Send data to connection
### Description
Sends string or object data to a specified connection or all connections in the channel.
### Method
```javascript
Send(data, attribute)
```
### Parameters
#### data
- **data** (String or Object) - The data to be sent.
#### attribute
- **connectId** (String or Array or null) - The target connection identifier. Can be a single `connectId`, an array of `connectId`s, or `null` to target all connections in the channel.
```
--------------------------------
### Send Data
Source: https://github.com/nuzulul/webconnect.js/blob/main/README.md
Sends data to a specific peer connection.
```APIDOC
## Send Data
### Description
Sends data to a specific peer connection.
### Method
```javascript
connect.Send(data, attribute)
```
### Parameters
- **data** (any) - The data to send.
- **attribute** (object) - An object containing connection details. Must include `connectId`.
- **connectId** (string) - The ID of the target peer.
### Request Example
```javascript
const attribute = { connectId: 'some_connection_id' }
connect.Send('Hello, peer!', attribute)
```
```
--------------------------------
### Disconnect All Peers
Source: https://github.com/nuzulul/webconnect.js/blob/main/README.md
Close all active connections to peers.
```javascript
connect.Disconnect()
```
--------------------------------
### Send Data to a Peer
Source: https://github.com/nuzulul/webconnect.js/blob/main/README.md
Send data to a specific peer identified by their connectId.
```javascript
const attribute = {connectId}
connect.Send(data,attribute)
```
--------------------------------
### Disconnect from Channel
Source: https://github.com/nuzulul/webconnect.js/blob/main/README.md
Terminate the connection to the current channel.
```javascript
Disconnect()
```
--------------------------------
### Ping
Source: https://github.com/nuzulul/webconnect.js/blob/main/README.md
Measures the latency to a specific connection by sending a ping request. Returns a promise that resolves with the latency in milliseconds.
```APIDOC
## Ping
### Description
Calculates the latency to a specified connection. This function returns a promise that resolves with the latency in milliseconds.
### Method
JavaScript Function Call
### Function Signature
`Ping(attribute)`
### Parameters
#### attribute (object) - Required
- **connectId** (string) - The identifier of the target connection to ping.
### Request Example
```javascript
Ping({ connectId: 'someConnectionId' })
.then(latency => {
console.log(`Latency: ${latency}ms`);
});
```
### Response
#### Success Response (Promise resolves)
- **latency** (number) - The latency in milliseconds to the target connection.
```
--------------------------------
### Ping Connection
Source: https://github.com/nuzulul/webconnect.js/blob/main/README.md
Checks the latency to a specific peer connection.
```APIDOC
## Ping Connection
### Description
Checks the latency to a specific peer connection.
### Method
```javascript
connect.Ping(attribute)
```
### Parameters
- **attribute** (object) - An object containing connection details.
- **connectId** (string) - The ID of the target peer.
### Request Example
```javascript
const attribute = { connectId: 'some_connection_id' }
console.log(`Ping response time: ${await connect.Ping(attribute)} ms`)
```
### Response
- **(number)** - The round-trip time in milliseconds.
```
--------------------------------
### Close Streaming Connection
Source: https://github.com/nuzulul/webconnect.js/blob/main/README.md
Terminate an active streaming connection to a peer.
```javascript
const attribute = {connectId}
connect.closeStreaming(stream,attribute)
```
--------------------------------
### Close Streaming
Source: https://github.com/nuzulul/webconnect.js/blob/main/README.md
Terminates an ongoing media stream to a specific peer connection.
```APIDOC
## Close Streaming
### Description
Terminates an ongoing media stream to a specific peer connection.
### Method
```javascript
connect.closeStreaming(stream, attribute)
```
### Parameters
- **stream** (MediaStream) - The media stream to close (optional, depending on implementation).
- **attribute** (object) - An object containing connection details.
- **connectId** (string) - The ID of the target peer.
### Request Example
```javascript
const attribute = { connectId: 'some_connection_id' }
// Assume 'stream' is the MediaStream object previously opened
connect.closeStreaming(stream, attribute)
```
```
--------------------------------
### Disconnect
Source: https://github.com/nuzulul/webconnect.js/blob/main/README.md
Terminates the current connection to the channel.
```APIDOC
## Disconnect
### Description
Closes the connection to the current channel.
### Method
JavaScript Function Call
### Function Signature
`Disconnect()`
### Parameters
None
### Request Example
```javascript
Disconnect();
```
### Response
None explicitly documented.
```
--------------------------------
### Disconnect
Source: https://github.com/nuzulul/webconnect.js/blob/main/README.md
Disconnects all active peer connections.
```APIDOC
## Disconnect
### Description
Disconnects all active peer connections.
### Method
```javascript
connect.Disconnect()
```
### Parameters
None
### Request Example
```javascript
connect.Disconnect()
```
```
--------------------------------
### Close streaming connection
Source: https://github.com/nuzulul/webconnect.js/blob/main/README.md
Terminates an active streaming connection.
```APIDOC
## Close streaming connection
### Description
Terminates an active streaming connection.
### Method
```javascript
closeStreaming(stream, attribute)
```
### Parameters
#### stream
- **stream** (MediaStream) - A previously opened MediaStream.
#### attribute
- **connectId** (String) - The target connection identifier.
```
--------------------------------
### Close streaming connection
Source: https://github.com/nuzulul/webconnect.js/blob/main/README.md
Terminate an active streaming connection. Requires the MediaStream object and the target connection ID.
```javascript
closeStreaming(stream,attribute)
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.