ermis-wt
v9.0.0
Published
A starter for creating a TypeScript package.
Readme
ErmisWT (WebTransport Publisher SDK)
A TypeScript SDK for managing livestream sessions and publishing high-quality video/audio data using the WebTransport protocol.
Core Flow
- Initialize Session: Create a new livestream session to obtain a
stream_id. - Activate Stream: Activate the
stream_idto get thestream_url(for WebTransport publishing) and thelink(for HLS playback). - Publish Data: Use
WtPublisherto encode and send media data from the camera/microphone via thestream_url. - Playback: View the livestream using the HLS player link in any supported browser or video player.
1. Session Management (ErmisWT)
Use the ErmisWT class to interact with the backend API for session control.
import { ErmisWT } from 'ermis-wt';
const client = new ErmisWT({
token: 'YOUR_ACCESS_TOKEN',
origin: 'https://api.your-service.com', // API Base URL
prefix: '/stream-gate', // (Optional) API Prefix
appName: 'my-app' // (Optional) Application Name
});
// 1. Create a new session
const streamId = await client.createLiveStreamSession('My-Livestream-Title');
// 2. Activate and retrieve connection info
const streamInfo = await client.activeStream(streamId);
console.log('Stream ID:', streamInfo.stream_id);
console.log('Stream Name:', streamInfo.stream_name);
console.log('Publish URL:', streamInfo.stream_url);
console.log('Player URL:', streamInfo.link);
// 3. Get list of all streams
const streams = await client.getListStream();
console.log('My Streams:', streams);
// 4. Deactivate when finished
// await client.deactivateStream(streamId);2. Media Publishing (WtPublisher)
The WtPublisher class leverages the WebCodecs API for efficient encoding and WebTransport for ultra-low latency data transmission.
import { WtPublisher } from 'ermis-wt';
const publisher = new WtPublisher({
streamUrl: streamInfo.stream_url, // Obtained from the activation step
streamId: streamId, // The ID of the stream
videoCodec: 'avc1', // 'avc1' (H.264) or 'hev1' (H.265)
resolution: { width: 1280, height: 720 },
onStatus: (status) => {
console.log('Status:', status);
},
onLog: (msg, type) => {
console.log(`[${type}] ${msg}`);
},
onStats: (stats) => {
console.log(`Stats - Bytes: ${stats.bytes}, Frames: ${stats.frames}, GOPs: ${stats.gops}, Audio: ${stats.audio}`);
}
});
// Start capturing and publishing
await publisher.start();
// Stop publishing
// publisher.stop();API Reference
1. ErmisWT (Session Management)
| Method | Parameters | Returns | Description |
| :--- | :--- | :--- | :--- |
| createLiveStreamSession | streamName: string | Promise<string> | Creates a session and returns the stream_id. |
| activeStream | streamId: string | Promise<ErmisWtStream> | Activates the stream and returns connection details. |
| getListStream | - | Promise<ErmisWtStream[]> | Fetches the list of all streams for the current token. |
| deactivateStream | streamId: string | Promise<void> | Stops the stream session on the server. |
| setToken | token: string | void | Updates the authorization token. |
ErmisWtStream object:
stream_id: (string) The unique ID of the stream.stream_name: (string) The name of the stream.stream_url: (string) The WebTransport URL for publishing.link: (string) The HLS URL for the video player.
2. WtPublisher (Media Streaming)
| Method | Parameters | Returns | Description |
| :--- | :--- | :--- | :--- |
| start | - | Promise<void> | Starts media capture (camera/mic) and connects to WebTransport. |
| stop | - | void | Stops publishing and releases all media tracks and connections. |
| getMediaStream | - | MediaStream | Returns the local MediaStream object for preview. |
Important Notes:
- The browser must support both WebTransport and WebCodecs.
- WebTransport requires a secure context (HTTPS), except for
localhost. - Call
getMediaStream()afterstart()has resolved.
