https://github.com/ionorg/ion-sdk-js
ion javascript sdk
https://github.com/ionorg/ion-sdk-js
Last synced: 11 months ago
JSON representation
ion javascript sdk
- Host: GitHub
- URL: https://github.com/ionorg/ion-sdk-js
- Owner: ionorg
- License: mit
- Created: 2020-05-04T03:08:01.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2023-03-27T21:39:15.000Z (about 3 years ago)
- Last Synced: 2025-05-15T16:49:22.649Z (about 1 year ago)
- Language: JavaScript
- Size: 1.4 MB
- Stars: 104
- Watchers: 11
- Forks: 73
- Open Issues: 33
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# ion-sdk-js
Frontend sdk for the Ion backend.
## Installation
`npm install ion-sdk-js`
## Usage
```ts
import { Client, LocalStream, RemoteStream } from 'ion-sdk-js';
import { IonSFUJSONRPCSignal } from 'ion-sdk-js/lib/signal/json-rpc-impl';
const signal = new IonSFUJSONRPCSignal("wss://ion-sfu:7000/ws");
const client = new Client(signal);
signal.onopen = () => client.join("test session", "test uid")
// Setup handlers
client.ontrack = (track: MediaStreamTrack, stream: RemoteStream) => {
// mute a remote stream
stream.mute()
// unmute a remote stream
stream.unmute()
if (track.kind === "video") {
// prefer a layer
stream.preferLayer("low" | "medium" | "high")
}
});
// Get a local stream
const local = await LocalStream.getUserMedia({
audio: true,
video: true,
simulcast: true, // enable simulcast
});
// Publish stream
client.publish(local);
// mute local straem
local.mute()
// unmute local stream
local.unmute()
// create a datachannel
const dc = client.createDataChannel("data")
dc.onopen = () => dc.send("hello world")
// Close client connection
client.close();
```