Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/giovannicalo/js-wrtc-ws-api-client
JavaScript WebRTC WebSocket Signaling API Client
https://github.com/giovannicalo/js-wrtc-ws-api-client
api client signaling webrtc websocket
Last synced: about 1 month ago
JSON representation
JavaScript WebRTC WebSocket Signaling API Client
- Host: GitHub
- URL: https://github.com/giovannicalo/js-wrtc-ws-api-client
- Owner: giovannicalo
- License: mit
- Created: 2022-09-30T22:40:38.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2024-08-15T00:44:02.000Z (5 months ago)
- Last Synced: 2024-08-15T01:53:08.764Z (5 months ago)
- Topics: api, client, signaling, webrtc, websocket
- Language: JavaScript
- Homepage:
- Size: 33.2 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
# JavaScript WebRTC WebSocket Signaling API Client
[![Build Status](https://github.com/giovannicalo/js-wrtc-ws-api-client/actions/workflows/build.yml/badge.svg)](https://github.com/giovannicalo/js-wrtc-ws-api-client/actions/workflows/build.yml)
[![Coverage Status](https://coveralls.io/repos/github/giovannicalo/js-wrtc-ws-api-client/badge.svg?branch=master)](https://coveralls.io/github/giovannicalo/js-wrtc-ws-api-client?branch=master)## Installation
```bash
npm install giovannicalo/js-wrtc-ws-api-client
```> Not yet published to NPM. This will install it from GitHub.
## Usage
```javascript
import Client from "wrtc-ws-api-client";const client = new Client("ws://localhost:8080");
client.addEventListener("foo", ({ data: { bar } }) => {
// Do something
});client.send({ data: { bar: 42 }, event: "foo" });
```## API
### `new Client(url: string, options?: Options)`
Creates a WebSocket client and uses it to connect to the server running at `url`. Extends [`EventTarget`](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget).
Options are:
* `getAuthenticationData?(): { [key: string]: JsonSerializable }`: a function that returns data required for authentication, e.g. a token, which will be sent to the server upon connection, defaults to `undefined`.
* `log?(level: string, message: string): void`: a logging function that will be called when certain events occur, defaults to `undefined`.
* `reconnectionInterval?: number`: the interval between reconnection attempts, in milliseconds, defaults to `1000`.
* `role?: string`: the client's role, which will be sent to the server upon connection, defaults to `client`.#### `close(): void`
Permanently closes the connection.
#### `id: null | number | string`
The `Client`'s ID, returned by the server upon successful authentication.
#### `send(message: JsonSerializable): void`
Sends a `message` to the server.