1.0.8 • Published 7 months ago

@w3stream/nodejs-client v1.0.8

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

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

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

ApiKeyApi

MethodDescriptionHTTP request
create()Create API keyPOST /api_keys
update()Rename api keyPATCH /api_keys/{id}
delete()Delete API keyDELETE /api_keys/{id}
list()Get list API keysGET /api_keys

LiveStreamApi

MethodDescriptionHTTP request
createLiveStreamKey()Create live stream keyPOST /live_streams
createStreaming()Create a new live stream videoPOST /live_streams/{id}/streamings
deleteLiveStreamKey()Delete live stream keyDELETE /live_streams/{id}
deleteStreaming()Delete live stream videoDELETE /live_streams/{id}/streamings/{stream_id}
getLiveStreamKey()Get live stream keyGET /live_streams/{id}
getLiveStreamKeys()Get live stream key listGET /live_streams
getLiveStreamPlayerInfo()Get live stream video publicGET /live_streams/player/{id}/videos
getLiveStreamVideo()Get live stream videoGET /live_streams/{id}/videos
getLiveStreamVideos()Get live stream videosPOST /live_streams/{id}/videos
getStreaming()Get live stream video streamingGET /live_streams/{id}/streamings/{stream_id}
getStreamings()Get live stream video streamingsGET /live_streams/{id}/streamings
updateLiveStreamKey()Update live stream keyPUT /live_streams/{id}
updateLiveStreamVideo()Update live stream videoPUT /live_streams/{id}/streamings

PlayersApi

MethodDescriptionHTTP request
create()Create a player themePOST /players
get()Get a player theme by IDGET /players/{id}
update()Update a player theme by IDPATCH /players/{id}
delete()Delete a player theme by IDDELETE /players/{id}
list()List all player themesGET /players
uploadLogo()Upload a logo for a player theme by IDPOST /players/{id}/logo
deleteLogo()Delete a logo for a player theme by IDDELETE /players/{id}/logo
addPlayer()Add a player theme to a videoPOST /players/add-player
removePlayer()Remove a player theme from a videoPOST /players/remove-player

PlaylistApi

MethodDescriptionHTTP request
addVideoToPlaylist()Add a video to a playlistPOST /playlists/{id}/items
createPlaylist()Create a playlistPOST /playlists/create
deletePlaylistById()Delete a playlist by IDDELETE /playlists/{id}
deletePlaylistThumbnail()Delete a playlist thumbnailDELETE /playlists/{id}/thumbnail
getPlaylistById()Get playlist by IDGET /playlists/{id}
getPlaylistPublicInfo()Get a playlist publicGET /playlists/{id}/player.json
getPlaylists()Get user's playlistsPOST /playlists
moveVideoInPlaylist()Move a video in a playlistPUT /playlists/{id}/items
removeVideoFromPlaylist()Remove a video from a playlistDELETE /playlists/{id}/items/{item_id}
updatePlaylist()Update a playlistPATCH /playlists/{id}

VideoApi

MethodDescriptionHTTP request
create()Create video objectPOST /videos/create
update()update video infoPATCH /videos/{id}
delete()Delete videoDELETE /videos/{id}
uploadThumbnail()Upload video thumbnailPOST /videos/{id}/thumbnail
createCaption()Create a new video captionPOST /videos/{id}/captions/{lan}
deleteCaption()Delete a video captionDELETE /videos/{id}/captions/{lan}
getCaptions()Get video captionsGET /videos/{id}/captions
getCost()get video transcoding costGET /videos/cost
getDetail()get video detailGET /videos/{id}
getVideoList()Get user videos listPOST /videos
getVideoPlayerInfo()Get video player infoGET /videos/{id}/player.json
setDefaultCaption()Set default captionPATCH /videos/{id}/captions/{lan}
uploadPart()Upload part of videoPOST /videos/{id}/part
uploadVideoComplete()Get upload video when completeGET /videos/{id}/complete

VideoChapterApi

MethodDescriptionHTTP request
create()Create a video chapterPOST /videos/{id}/chapters/{lan}
get()Get video chaptersGET /videos/{id}/chapters
delete()Delete a video chapterDELETE /videos/{id}/chapters/{lan}

WebhookApi

MethodDescriptionHTTP request
create()Create webhookPOST /webhooks
get()Get user's webhook by idGET /webhooks/{id}
update()Update event webhookPATCH /webhooks/{id}
delete()Delete webhookDELETE /webhooks/{id}
list()Get list webhooksGET /webhooks
check()Check webhook by idPOST /webhooks/check/{id}

Models

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!

1.0.8

7 months ago

1.0.7

8 months ago

1.0.6

8 months ago

1.0.5

9 months ago

1.0.4

10 months ago

1.0.3

10 months ago

1.0.2

11 months ago

1.0.1

11 months ago

1.0.0

11 months ago