GithubHelp home page GithubHelp logo

dekryptor / platform-sdk-js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from webtor-io/platform-sdk-js

0.0 0.0 0.0 416 KB

Webtor.io platform SDK for online torrent streaming

Home Page: https://webtor.io

License: MIT License

JavaScript 99.88% HTML 0.12%

platform-sdk-js's Introduction

platform-sdk-js

SDK for online torrent streaming

Features

  1. Online torrent content streaming without waiting for full download
  2. On-the-fly content transcoding
  3. Downloading torrent as ZIP-archive (coming soon)
  4. Subtitle transcoding, srt to vtt (coming soon)

Supported formats

  • Video: avi, mkv, mp4, webm, m4v
  • Audio: mp3, wav, ogg, flac, m4a
  • Images: png, gif, jpg, jpeg
  • Subtitles: srt, vtt

Prerequisites

Before moving further we must be sure that webtor backend api is already installed. Just follow this guide to setup all the things.

Installation

npm install @webtor/platform-sdk-js

or

yarn add @webtor/platform-sdk-js

Basic usage

Just a simple example of fetching torrent by magnet-uri, getting streaming url and stats:

import webtor from '@webtor/platform-sdk-js';

const sdk = webtor({
  apiUrl: '...',
});

const magnetUri = '...';

const torrent = await sdk.magnet.fetchTorrent(magnetUri);

const expire = 60*60*24;

await sdk.torrent.push(torrent, expire);

const seeder = sdk.seeder.get(torrent.infoHash);

const filePath = torrent.files[0].path;

const url = await seeder.streamUrl(filePath);
console.log(url);

// NOTE: stats will become available only after content url access
seeder.stats(filePath, (path, data) => {
  console.log(data);
});

You can find fully working example here!

API

const sdk = webtor(options)

options should be the following:

{
  apiUrl: String,              // API url (required)
  downloadUrl: String,         // All download urls will contain this location
  tokenUrl: String,            // API will get access-token from this location
  tokenRenewInterval: Number,  // Renews access-token after specific period in ms
  grpcDebug: Boolean,          // If enabled shows grpc-web debug output
  statsRetryInterval: Number,  // If stats not available for this file it will retry after specific period in ms (default=3000)
  getToken: function() Promise // If defined custom token-function will be used 
}

sdk.torrent.fromUrl(url)

Fetches parsed torrent from specific url. Be sure that appropriate CORS-headers are set on server-side in case of cross-site request (Access-Control-Allow-Origin: *).

sdk.torrent.pull(infoHash)

Pulls parsed torrent by infoHash from torrent-store.

sdk.torrent.push(torrent, expire)

Pushes parsed torrent to torrent-store with specific expiration time in seconds. We can use any parsed torrent generated by parse-torrent there.

sdk.torrent.touch(torrent, expire)

Just renews expiration date of torrent-file.

sdk.magnet.fetchTorrent(magnet)

Fetches parsed torrent by magnet-uri.

const seeder = sdk.seeder.get(infoHash)

Returns seeder instance for the specific torrent stored in torrent-store.

seeder.streamUrl(path, viewSettings = {})

viewSettings should be provided only in case of content trnascoding. Possible viewSettings:

{
  a: Number,   // Selected audio channel
  s: Number,   // Selected subtitle channel
}

seeder.mediaInfo(path)

Returns FFmpeg probing data. If content should not be transcoded only empty object {} will be returned.

seeder.downloadUrl(path)

Returns download url.

const statClient = seeder.stats(path, function(path, data) { ... })

Receives status of specific file. Possible data:

{
  total: Number     // Number of total bytes
  completed: Number // Number of completed bytes
  peers: Number     // Total number of peers
  piecesList: []    // Array of pieces
}

Also returns instance of stat client.

statClient.close()

Closes stat client

platform-sdk-js's People

Contributors

vintikzzz avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.