@w3stream/nodejs-client
v1.0.5
Published
w3stream nodejs API client
Downloads
823
Maintainers
Readme
W3Stream is the video infrastructure for product builders. Lightning fast video APIs for integrating, scaling, and managing on-demand & low latency live streaming features in your app.
Project description
W3Stream's Node.js is a lightweight client built in TypeScript
that streamlines the coding process. Chunking files is handled for you, as is pagination and refreshing your tokens.
Getting started
Installation
With npm
:
npm install @w3stream/nodejs-client
...or with yarn
:
yarn add @w3stream/nodejs-client
Development
To build and compile the typescript sources to javascript use:
npm install
npm run build
Code sample
import W3StreamClient from "@w3stream/nodejs-client";
(async () => {
try {
const client = new W3StreamClient({
publicKey: "YOUR_PUBLIC_KEY",
secretKey: "YOUR_SECRET_KEY",
});
const videoCreationPayload = {
title: "First video", // The title of your new video.
description: "A new video.", // A brief description of your video.
};
const video = await client.video.create(videoCreationPayload);
if (!video.data) {
throw new Error("Failed to create video");
}
if (!video.data.id) {
throw new Error("Failed to create video");
}
// Option 1: Use client upload with videoId
// await client.uploadVideo(video.data.id, "./path/to/video.mp4");
// console.log("Upload successfully");
// Option 2: Upload parts yourself
const uploadResult = await client.video.uploadPart(
video.data.id,
"./path/to/video.mp4",
);
console.log(uploadResult);
const checkResult = await client.video.uploadVideoComplete(video.data.id);
// Check if the video upload is complete
console.log(checkResult);
} catch (e) {
console.error(e);
}
})();
Documentation
API endpoints
API key
Method | Description | HTTP request
------------- | ------------- | -------------
create() | Create API key | POST /api_keys
update() | Rename API key | PATCH /api_keys/{id}
delete() | Delete API key | DELETE /api_keys/{id}
list() | Get list API keys | GET /api_keys
Live stream
Method | Description | HTTP request
------------- | ------------- | -------------
createLiveStreamKey() | Create live stream key | POST /live_streams
createStreaming() | Create a new live stream video | POST /live_streams/{id}/streamings
deleteLiveStreamKey() | Delete live stream key | DELETE /live_streams/{id}
deleteLiveStreamVideo() | Delete live stream video | DELETE /live_streams/{id}/videos
getLiveStreamKey() | Get live stream key | GET /live_streams/{id}
getLiveStreamKeys() | Get live stream key list | GET /live_streams
getLiveStreamPlayerInfo() | Get live stream video public | GET /live_streams/player/{id}/videos
getLiveStreamVideo() | Get live stream video | GET /live_streams/{id}/videos
getLiveStreamVideos() | Get live stream videos | POST /live_streams/{id}/videos
getStreaming() | Get live stream video streaming | GET /live_streams/{id}/streamings/{stream_id}
getStreamings() | Get live stream video streamings | GET /live_streams/{id}/streamings
updateLiveStreamKey() | Update live stream key | PUT /live_streams/{id}
updateLiveStreamVideo() | Update live stream video | PUT /live_streams/{id}/streamings
Players
Method | Description | HTTP request
------------- | ------------- | -------------
create() | Create a player theme | POST /players
get() | Get a player theme by ID | GET /players/{id}
update() | Update a player theme by ID | PATCH /players/{id}
delete() | Delete a player theme by ID | DELETE /players/{id}
list() | List all player themes | GET /players
uploadLogo() | Upload a logo for a player theme by ID | POST /players/{id}/logo
deleteLogo() | Delete a logo for a player theme by ID | DELETE /players/{id}/logo
addPlayer() | Add a player theme to a video | POST /players/add-player
removePlayer() | Remove a player theme from a video | POST /players/remove-player
Playlist
Method | Description | HTTP request
------------- | ------------- | -------------
deleteThumbnail() | Delete a playlist thumbnail | DELETE /playlists/{id}/thumbnail
addItem() | Add a video to a playlist | POST /playlists/{id}/items
createPlaylist() | Create a new playlist | POST /playlists/create
deleteItem() | Remove a video from a playlist | DELETE /playlists/{id}/items/{item_id}
deletePlaylist() | Delete a playlist by ID | DELETE /playlists/{id}
getPlaylistById() | Get playlist by ID | GET /playlists/{id}
getPlaylistInfo() | Get a playlist public | GET /playlists/{id}/player.json
getPlaylists() | Get user's playlists | POST /playlists
moveItems() | Move a video within a playlist | PUT /playlists/{id}/items
updatePlaylist() | Update a playlist | PATCH /playlists/{id}
Video
Method | Description | HTTP request
------------- | ------------- | -------------
create() | Create video object | POST /videos/create
update() | update video info | PATCH /videos/{id}
delete() | Delete video | DELETE /videos/{id}
uploadThumbnail() | Upload video thumbnail | POST /videos/{id}/thumbnail
createCaption() | Create a new video caption | POST /videos/{id}/captions/{lan}
deleteCaption() | Delete a video caption | DELETE /videos/{id}/captions/{lan}
getCaptions() | Get video captions | GET /videos/{id}/captions
getCost() | get video transcoding cost | GET /videos/cost
getDetail() | get video detail | GET /videos/{id}
getVideoList() | Get user videos list | POST /videos
getVideoPlayerInfo() | Get video player info | GET /videos/{id}/player.json
setCaption() | Set default video caption | PATCH /videos/{id}/captions/{lan}
uploadPart() | Upload part of video | POST /videos/{id}/part
uploadVideoComplete() | Get upload video when complete | GET /videos/{id}/complete
Video chapter
Method | Description | HTTP request
------------- | ------------- | -------------
create() | Create a video chapter | POST /videos/{id}/chapters/{lan}
get() | Get video chapters | GET /videos/{id}/chapters
delete() | Delete a video chapter | DELETE /videos/{id}/chapters/{lan}
Watermark
Method | Description | HTTP request
------------- | ------------- | -------------
upload() | Create a new watermark | POST /watermarks
delete() | Delete a watermark by ID | DELETE /watermarks/{id}
list() | List all watermarks | GET /watermarks
Webhook
Method | Description | HTTP request
------------- | ------------- | -------------
create() | Create webhook | POST /webhooks
get() | Get user's webhook by id | GET /webhooks/{id}
update() | Update event webhook | PATCH /webhooks/{id}
delete() | Delete webhook | DELETE /webhooks/{id}
list() | Get list webhooks | GET /webhooks
check() | Check webhook by id | POST /webhooks/check/{id}
Models
- AddPlayerThemesToVideoRequest
- AddVideoToPlaylistRequest
- ApiKey
- Asset
- Controls
- CreateApiKeyData
- CreateApiKeyRequest
- CreateApiKeyResponse
- CreateLiveStreamKeyRequest
- CreateLiveStreamKeyResponse
- CreatePlayerThemeRequest
- CreatePlayerThemesData
- CreatePlayerThemesResponse
- CreatePlaylistData
- CreatePlaylistRequest
- CreatePlaylistResponse
- CreateStreamingRequest
- CreateStreamingResponse
- CreateVideoCaptionData
- CreateVideoCaptionResponse
- CreateVideoChapterData
- CreateVideoChapterResponse
- CreateVideoRequest
- CreateVideoResponse
- CreateWatermarkData
- CreateWatermarkResponse
- CreateWebhookData
- CreateWebhookRequest
- CreateWebhookResponse
- GetAllWatermarkData
- GetAllWatermarkResponse
- GetApiKeysData
- GetApiKeysResponse
- GetLiveStreamKeyData
- GetLiveStreamKeyResponse
- GetLiveStreamKeysListData
- GetLiveStreamKeysListResponse
- GetLiveStreamVideoPublicResponse
- GetLiveStreamVideoResponse
- GetLiveStreamVideosRequest
- GetLiveStreamVideosResponse
- GetPlayerThemeByIdData
- GetPlayerThemeByIdResponse
- GetPlayerThemeData
- GetPlayerThemeResponse
- GetPlaylistByIdData
- GetPlaylistByIdResponse
- GetPlaylistListData
- GetPlaylistListRequest
- GetPlaylistListResponse
- GetStreamingResponse
- GetStreamingsResponse
- GetTranscodeCostData
- GetTranscodeCostResponse
- GetUserWebhookData
- GetUserWebhookResponse
- GetVideoCaptionsData
- GetVideoCaptionsResponse
- GetVideoChaptersData
- GetVideoChaptersResponse
- GetVideoDetailResponse
- GetVideoListData
- GetVideoListRequest
- GetVideoListResponse
- GetVideoPlayerInfoResponse
- GetWebhooksListData
- GetWebhooksListResponse
- LiveStreamAssets
- LiveStreamKeyData
- LiveStreamVideoData
- LiveStreamVideoResponse
- LiveStreamVideosResponse
- Metadata
- MoveVideoInPlaylistRequest
- PlayerTheme
- Playlist
- PlaylistItem
- PlaylistItemVideo
- PublicPlaylistObject
- QualityObject
- RemovePlayerThemesFromVideoRequest
- RenameAPIKeyRequest
- ResponseError
- ResponseSuccess
- SetDefaultCaptionRequest
- Theme
- UpdateLiveStreamKeyData
- UpdateLiveStreamKeyRequest
- UpdateLiveStreamKeyResponse
- UpdateLiveStreamVideoRequest
- UpdatePlayerThemeRequest
- UpdatePlayerThemeResponse
- UpdateVideoInfoRequest
- UpdateWebhookRequest
- UploadLogoByIdResponse
- Video
- VideoAssets
- VideoCaption
- VideoChapter
- VideoWatermark
- Watermark
- Webhook
Rate Limiting
W3Stream implements rate limiting to ensure fair usage and stability of the service. The API provides the rate limit values in the response headers for any API requests you make.
In this Node.js client, you can access these headers by using the *WithResponseHeaders()
versions of the methods. These methods return both the response body and the headers, allowing you to check the X-RateLimit-Limit
, X-RateLimit-Remaining
, and X-RateLimit-Retry-After
headers to understand your current rate limit status.
Here is an example of how to use these methods:
const client = new W3StreamClient({
secretKey: "YOUR_SECRET_KEY",
publicKey: "YOUR_PUBLIC_KEY"
});
const { headers, body } = const webhook = await client.webhook.listWithResponseHeaders();
Authorization
API key and public key
All endpoints required to be authenticated using the API key and public key mechanism described in our documentation.
All you have to do is provide an API key and public key when instantiating the W3StreamClient:
const client = new W3StreamClient({
secretKey: "YOUR_SECRET_KEY",
publicKey: "YOUR_PUBLIC_KEY"
});
Have you gotten use from this API client?
Please take a moment to leave a star on the client ⭐
This helps other users to find the clients and also helps us understand which clients are most popular. Thank you!