@axonkit/client-sdk-js 0.1.1 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +87 -66
- package/dist/Room.d.ts +11 -7
- package/dist/axonkit-client.esm.js +1 -1
- package/dist/axonkit-client.umd.js +1 -1
- package/dist/events.d.ts +71 -46
- package/dist/index.d.ts +2 -2
- package/dist/participant/LocalParticipant.d.ts +2 -6
- package/dist/participant/Participant.d.ts +1 -1
- package/dist/protocol/types.d.ts +2 -2
- package/dist/room/DefaultReconnectPolicy.d.ts +17 -1
- package/dist/room/options.d.ts +27 -1
- package/dist/track/options.d.ts +0 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,10 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
>
|
|
6
|
-
>
|
|
7
|
-
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="assets/banner.svg" alt="AxonKit" width="480">
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
<p align="center">
|
|
6
|
+
<strong>AxonKit JavaScript/TypeScript client SDK</strong> for real-time communication,<br/>
|
|
7
|
+
built on <a href="https://github.com/versatica/mediasoup-client">mediasoup-client</a> with a
|
|
8
|
+
<a href="https://livekit.io">LiveKit</a>-compatible API surface.
|
|
9
|
+
</p>
|
|
10
|
+
|
|
11
|
+
<p align="center">
|
|
12
|
+
<a href="https://github.com/axonkit/client-sdk-js/actions/workflows/publish.yml"><img alt="CI" src="https://github.com/axonkit/client-sdk-js/actions/workflows/publish.yml/badge.svg"></a>
|
|
13
|
+
<a href="https://www.npmjs.com/package/@axonkit/client-sdk-js"><img alt="npm version" src="https://img.shields.io/npm/v/@axonkit/client-sdk-js"></a>
|
|
14
|
+
<a href="https://www.npmjs.com/package/@axonkit/client-sdk-js"><img alt="npm downloads" src="https://img.shields.io/npm/dm/@axonkit/client-sdk-js"></a>
|
|
15
|
+
</p>
|
|
8
16
|
|
|
9
17
|
## Installation
|
|
10
18
|
|
|
@@ -15,94 +23,105 @@ pnpm add @axonkit/client-sdk-js
|
|
|
15
23
|
## Quick Start
|
|
16
24
|
|
|
17
25
|
```typescript
|
|
18
|
-
import {
|
|
26
|
+
import {
|
|
27
|
+
Room,
|
|
28
|
+
RoomEvent,
|
|
29
|
+
ConnectionState,
|
|
30
|
+
setLogLevel,
|
|
31
|
+
LogLevel,
|
|
32
|
+
} from '@axonkit/client-sdk-js';
|
|
19
33
|
|
|
20
34
|
setLogLevel(LogLevel.INFO);
|
|
21
35
|
|
|
22
36
|
const room = new Room({
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
adaptiveStream: true,
|
|
37
|
+
dynacast: true, // pause simulcast layers with no subscribers
|
|
38
|
+
adaptiveStream: true, // adapt subscription quality to element size/visibility
|
|
26
39
|
});
|
|
27
40
|
|
|
28
|
-
//
|
|
41
|
+
// Subscribe to events before connecting
|
|
42
|
+
room
|
|
43
|
+
.on(RoomEvent.ParticipantConnected, (participant) => {
|
|
44
|
+
console.log(`${participant.identity} joined`);
|
|
45
|
+
})
|
|
46
|
+
.on(RoomEvent.ParticipantDisconnected, (participant) => {
|
|
47
|
+
console.log(`${participant.identity} left`);
|
|
48
|
+
})
|
|
49
|
+
.on(RoomEvent.TrackSubscribed, (track, publication, participant) => {
|
|
50
|
+
const element = track.attach();
|
|
51
|
+
if (track.kind === 'video') {
|
|
52
|
+
document.getElementById('remote-videos')?.appendChild(element);
|
|
53
|
+
} else {
|
|
54
|
+
element.play();
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
// Connect (token is optional when the server allows anonymous joins —
|
|
59
|
+
// pass roomName in RoomOptions instead)
|
|
29
60
|
await room.connect('https://your-server.com', 'your-jwt-token');
|
|
30
61
|
|
|
31
62
|
// Publish camera and microphone
|
|
32
63
|
await room.localParticipant.setCameraEnabled(true);
|
|
33
64
|
await room.localParticipant.setMicrophoneEnabled(true);
|
|
34
65
|
|
|
35
|
-
//
|
|
36
|
-
room.on('trackSubscribed', (track, publication, participant) => {
|
|
37
|
-
if (track.kind === 'video') {
|
|
38
|
-
const element = track.attach();
|
|
39
|
-
document.getElementById('remote-videos')?.appendChild(element);
|
|
40
|
-
} else {
|
|
41
|
-
const element = track.attach();
|
|
42
|
-
element.play();
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
// Listen for participants
|
|
47
|
-
room.on('participantJoined', (participant) => {
|
|
48
|
-
console.log(`${participant.identity} joined`);
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
room.on('participantLeft', (participant) => {
|
|
52
|
-
console.log(`${participant.identity} left`);
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
// Disconnect
|
|
66
|
+
// Later
|
|
56
67
|
await room.disconnect();
|
|
57
68
|
```
|
|
58
69
|
|
|
59
70
|
## Features
|
|
60
71
|
|
|
61
|
-
- **
|
|
62
|
-
- **
|
|
63
|
-
- **
|
|
64
|
-
- **
|
|
65
|
-
- **
|
|
66
|
-
- **
|
|
67
|
-
- **
|
|
72
|
+
- **LiveKit-compatible API** — familiar `Room` / `Participant` / `Track` model, events, and options
|
|
73
|
+
- **mediasoup-client transport** — WebRTC media over mediasoup send/receive transports
|
|
74
|
+
- **DataChannel RPC** — Axon Protocol for signaling over DataChannel after the initial HTTP join
|
|
75
|
+
- **Auto Subscribe** — server-side subscription management with no media loss
|
|
76
|
+
- **Simulcast / SVC** — simulcast layers, scalability modes, backup codec policies
|
|
77
|
+
- **Dynacast** — dynamically pause video encodings with no subscribers
|
|
78
|
+
- **Adaptive Stream** — visibility and size-based subscription management
|
|
79
|
+
- **Reconnection** — automatic reconnect with pluggable reconnect policy and state sync
|
|
80
|
+
- **Data streams & RPC** — sendText/streamText/sendFile/streamBytes and typed RPC between participants
|
|
81
|
+
- **Groups** — breakout-room style participant grouping with pin/move
|
|
82
|
+
- **Room shared state** — server-backed key/value state with offline catch-up
|
|
68
83
|
|
|
69
84
|
## API Reference
|
|
70
85
|
|
|
71
86
|
### Room
|
|
72
87
|
|
|
73
|
-
| Method
|
|
74
|
-
|
|
|
75
|
-
| `connect(url, token)` | Connect to a room
|
|
76
|
-
| `disconnect()`
|
|
77
|
-
| `
|
|
88
|
+
| Method | Description |
|
|
89
|
+
| --- | --- |
|
|
90
|
+
| `connect(url, token?, options?)` | Connect to a room (token optional for anonymous servers) |
|
|
91
|
+
| `disconnect(stopTracks?)` | Disconnect and optionally stop local tracks |
|
|
92
|
+
| `switchActiveDevice(kind, deviceId)` | Switch camera / microphone / output device |
|
|
93
|
+
| `startAudio()` | Resume audio playback (autoplay policy) |
|
|
78
94
|
|
|
79
95
|
### LocalParticipant
|
|
80
96
|
|
|
81
|
-
| Method
|
|
82
|
-
|
|
|
83
|
-
| `setCameraEnabled(enabled)`
|
|
84
|
-
| `setMicrophoneEnabled(enabled)`
|
|
85
|
-
| `setScreenShareEnabled(enabled)` | Toggle screen share
|
|
86
|
-
| `publishTrack(track, options?)`
|
|
87
|
-
| `unpublishTrack(track)`
|
|
88
|
-
| `publishData(data, options?)`
|
|
89
|
-
| `
|
|
90
|
-
| `
|
|
97
|
+
| Method | Description |
|
|
98
|
+
| --- | --- |
|
|
99
|
+
| `setCameraEnabled(enabled)` | Toggle camera |
|
|
100
|
+
| `setMicrophoneEnabled(enabled)` | Toggle microphone |
|
|
101
|
+
| `setScreenShareEnabled(enabled)` | Toggle screen share |
|
|
102
|
+
| `publishTrack(track, options?)` | Publish a local track |
|
|
103
|
+
| `unpublishTrack(track, stopOnUnpublish?)` | Unpublish a track |
|
|
104
|
+
| `publishData(data, options?)` | Send data via DataChannel |
|
|
105
|
+
| `setMetadata(metadata)` | Update participant metadata |
|
|
106
|
+
| `setName(name)` | Update participant display name |
|
|
91
107
|
|
|
92
108
|
### Events
|
|
93
109
|
|
|
110
|
+
Subscribe with the `RoomEvent` enum (values are camelCase, matching LiveKit):
|
|
111
|
+
|
|
94
112
|
```typescript
|
|
95
|
-
room.on(
|
|
96
|
-
room.on(
|
|
97
|
-
room.on(
|
|
98
|
-
room.on(
|
|
99
|
-
room.on(
|
|
100
|
-
room.on(
|
|
101
|
-
room.on(
|
|
102
|
-
room.on(
|
|
103
|
-
room.on('activeSpeakersChanged', (speakers) => {});
|
|
113
|
+
room.on(RoomEvent.Connected, () => {});
|
|
114
|
+
room.on(RoomEvent.Disconnected, (reason) => {});
|
|
115
|
+
room.on(RoomEvent.Reconnecting, () => {});
|
|
116
|
+
room.on(RoomEvent.ParticipantConnected, (participant) => {});
|
|
117
|
+
room.on(RoomEvent.ParticipantDisconnected, (participant, reason) => {});
|
|
118
|
+
room.on(RoomEvent.TrackSubscribed, (track, publication, participant) => {});
|
|
119
|
+
room.on(RoomEvent.TrackUnsubscribed, (track, publication, participant) => {});
|
|
120
|
+
room.on(RoomEvent.ActiveSpeakersChanged, (speakers) => {});
|
|
104
121
|
```
|
|
105
122
|
|
|
123
|
+
Full API documentation is generated with TypeDoc: `pnpm run docs`.
|
|
124
|
+
|
|
106
125
|
## Building
|
|
107
126
|
|
|
108
127
|
```bash
|
|
@@ -118,8 +137,10 @@ Outputs:
|
|
|
118
137
|
|
|
119
138
|
## Demo
|
|
120
139
|
|
|
121
|
-
Open `examples/demo/index.html` in a browser after building. Requires a running AxonKit server.
|
|
140
|
+
Open `examples/demo/index.html` in a browser after building. Requires a running [AxonKit server](https://github.com/axonkit/axonkit).
|
|
122
141
|
|
|
123
142
|
## License
|
|
124
143
|
|
|
125
|
-
|
|
144
|
+
This SDK is proprietary software licensed exclusively for use with the AxonKit
|
|
145
|
+
Service. See [LICENSE](./LICENSE) for the full terms. For commercial inquiries,
|
|
146
|
+
contact <jiyeyuran@gmail.com>.
|
package/dist/Room.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { RemoteParticipant } from './participant/RemoteParticipant';
|
|
|
4
4
|
import { Participant } from './participant/Participant';
|
|
5
5
|
import { LocalTrackPublication } from './participant/LocalTrackPublication';
|
|
6
6
|
import type { RemoteTrackPublication } from './participant/RemoteTrackPublication';
|
|
7
|
-
import {
|
|
7
|
+
import { ConnectionState, DisconnectReason, StreamState, type ServerInfo, type GroupInfo, ConnectionQuality } from './protocol/types';
|
|
8
8
|
import type { RoomOptions, RoomConnectOptions } from './room/options';
|
|
9
9
|
import { Track } from './track/Track';
|
|
10
10
|
import { RoomEvent } from './events';
|
|
@@ -14,12 +14,12 @@ export type RoomEvents = {
|
|
|
14
14
|
[RoomEvent.Disconnected]: (reason?: DisconnectReason) => void;
|
|
15
15
|
[RoomEvent.Reconnecting]: () => void;
|
|
16
16
|
[RoomEvent.Reconnected]: () => void;
|
|
17
|
-
[RoomEvent.ConnectionStateChanged]: (state:
|
|
17
|
+
[RoomEvent.ConnectionStateChanged]: (state: ConnectionState) => void;
|
|
18
18
|
[RoomEvent.SignalReconnecting]: () => void;
|
|
19
19
|
[RoomEvent.MediaDevicesChanged]: () => void;
|
|
20
20
|
[RoomEvent.MediaDevicesError]: (error: Error) => void;
|
|
21
|
-
[RoomEvent.
|
|
22
|
-
[RoomEvent.
|
|
21
|
+
[RoomEvent.ParticipantConnected]: (participant: RemoteParticipant) => void;
|
|
22
|
+
[RoomEvent.ParticipantDisconnected]: (participant: RemoteParticipant, reason?: DisconnectReason) => void;
|
|
23
23
|
[RoomEvent.ParticipantUpdated]: (participant: RemoteParticipant) => void;
|
|
24
24
|
[RoomEvent.ParticipantMetadataChanged]: (prevMetadata: string | undefined, participant: Participant) => void;
|
|
25
25
|
[RoomEvent.ParticipantNameChanged]: (name: string, participant: Participant) => void;
|
|
@@ -35,11 +35,15 @@ export type RoomEvents = {
|
|
|
35
35
|
[RoomEvent.LocalTrackUnpublished]: (publication: LocalTrackPublication, participant: LocalParticipant) => void;
|
|
36
36
|
[RoomEvent.LocalAudioSilenceDetected]: () => void;
|
|
37
37
|
[RoomEvent.ActiveSpeakersChanged]: (speakers: Participant[]) => void;
|
|
38
|
-
[RoomEvent.
|
|
39
|
-
[RoomEvent.DataReceived]: (
|
|
38
|
+
[RoomEvent.RoomMetadataChanged]: (metadata: string | undefined) => void;
|
|
39
|
+
[RoomEvent.DataReceived]: (payload: Uint8Array, participant?: RemoteParticipant) => void;
|
|
40
40
|
[RoomEvent.ConnectionQualityChanged]: (quality: ConnectionQuality, participant: Participant) => void;
|
|
41
41
|
[RoomEvent.AudioPlaybackStatusChanged]: (canPlayback: boolean) => void;
|
|
42
42
|
[RoomEvent.VideoPlaybackStatusChanged]: (canPlayback: boolean) => void;
|
|
43
|
+
[RoomEvent.SignalConnected]: () => void;
|
|
44
|
+
[RoomEvent.ActiveDeviceChanged]: (kind: MediaDeviceKind, deviceId: string) => void;
|
|
45
|
+
[RoomEvent.RecordingStatusChanged]: (recording: boolean) => void;
|
|
46
|
+
[RoomEvent.ParticipantPermissionsChanged]: (prevPermissions: import('./protocol/types').ParticipantPermission | undefined, participant: Participant) => void;
|
|
43
47
|
[RoomEvent.ChatMessage]: (message: Message, participant?: Participant) => void;
|
|
44
48
|
[RoomEvent.MessageDeleted]: (ids: string[], type?: string) => void;
|
|
45
49
|
[RoomEvent.StateUpdated]: (key: string, value: string, participantSid?: string, participantIdentity?: string) => void;
|
|
@@ -88,7 +92,7 @@ export declare class Room extends TypedEmitter<RoomEvents> {
|
|
|
88
92
|
private _lastMessageTimestamp;
|
|
89
93
|
private _connectOptions;
|
|
90
94
|
constructor(options?: RoomOptions);
|
|
91
|
-
get state():
|
|
95
|
+
get state(): ConnectionState;
|
|
92
96
|
get name(): string;
|
|
93
97
|
get sid(): string;
|
|
94
98
|
get serverInfo(): ServerInfo | undefined;
|