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 2 months 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 3 years ago)
- Default Branch: master
- Last Pushed: 2025-05-01T20:59:07.000Z (about 1 year ago)
- Last Synced: 2025-05-01T21:49:46.598Z (about 1 year 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
[](https://github.com/giovannicalo/js-wrtc-ws-api-client/actions/workflows/build.yml)
[](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.