Teleport static

Namespace available in the global context of the page after connecting the javascript library to the page.

Example: console.log(window.teleport.version)

Properties

Name Type Description
version string Teleport SDK version
Quality enum Enumeration of video qualities
SegmentType enum Enumeration of segment types
PeeringMode enum Enumeration of peering modes

Methods

Name Type Description
options ITeleportFactoryOptions initialization options

Example:

let tlprt = await teleport.initialize({
    apiKey: "APIKEY",
    loader: {
        type: "player plugin ID",
        params: {player: player}
    }
});

await player.load("manifest url");

ITeleportInstance

Events

  • onPeeringModeChanged

    Fired when peering mode has been changed.

    Callback: (mode: PeeringMode) => void

    Example:

    tlprt.onPeeringModeChanged = (mode) => console.log(`current peering mode: ${teleport.PeeringMode[mode]}`);
    
  • onPeerConnectionOpened

    Fired when connection with new peer has been established.

    Callback: (peerId: string) => void

    Example:

    tlprt.onPeerConnectionOpened = (peerId) => console.log(`peer connected: ${peerId}`);
    
  • onPeerConnectionClosed

    Fired when connection with peer has been closed.

    Callback: (peerId: string) => void

    Example:

    tlprt.onPeerConnectionOpened = (peerId) => console.log(`peer disconnected: ${peerId}`);
    
  • onSegmentLoaded

    Fired when after video segment has been loaded.

    Callback: (segment: ISegment) => void

    Example:

    tlprt.onSegmentLoaded = (segment) => console.log(`segment loaded:`, segment);
    
  • onSegmentUploaded

    Fired when video segment has been uploaded to P2P network.

    Callback: (segment: ISegment) => void

    Example:

    tlprt.onSegmentUploaded = (segment) => console.log(`segment uploaded:`, segment);
    

Properties

Name Type Readonly Description
version string true Teleport SDK version
apiKey string true API key for the access to peering. You can get in in the Teleport client area
connectionId string true Peer ID
connected boolean true Connection status
peeringMode PeeringMode false Peering mode

Methods

  • buffering()

    Reports the buffering event state to the Teleport server.

  • getStatTotals()

    Gives aggregated statistics on the downloaded segments from the media server and from the P2P network.

    Return type: IStatTotals

    Example:

    console.log(tlprt.getStatTotals())
    
  • getStatDetails()

    Gives detailed statistics on the downloaded segments from the media server and from the P2P network.

    Return type: IStatDetails

    Example:

    console.log(tlprt.getStatDetails())
    
  • dispose()

    Should be called to free used resources and destroy Teleport instance.

    Return type: Promise<void>

  • getLoader()

    Return API for current loader. The API is not available for all loaders. If it's not present then undefined will be returned.

    Return type: any

Enums

List of enumerations in namespace Teleport.

Quality

Enumeration of the qualities of the video stream.

Values:

  • Q144P
  • Q240P
  • Q360P
  • Q480P
  • Q720P
  • Q1080P
  • Q4K
  • Other

SegmentType

Enumeration of segment types.

Values:

  • Unknown
  • Video
  • Audio
  • Caption
  • Other

PeeringMode

Enumeration of peer-to-peer modes.

Values:

  • Off - Peer to peer connection is disabled.
  • Download - The peer can only download from Teleport PDN.
  • Upload - The peer can only upload from Teleport PDN.
  • Full - The peer can download and upload from Teleport PDN.

Example:

tlrpt.peeringMode = teleport.PeeringMode.Download;

Interfaces

ITeleportFactoryOptions

Name Type Description
apiKey string API key for the access to peering. You can get in in the Teleport client area
loader IPluginOptions Options for integration with the video player

IPluginOptions

Name Type Description
type string Plugin ID for the integration with the player (shaka, hlsjs, videojs-hls, clappr-dash, clappr-hls)
params IPluginIntegrationOptions Options for integration with the video player

IPluginIntegrationOptions

Parameters for configuring plugins.

Name Type Description
manifestAcceptor (url: string) => boolean Function for enabling manifest loading
segmentAcceptor (url: string) => boolean Function for enabling video segment loading
urlCleaner (url: string) => string Function to convert an URL to a manifest file and segment URLs. Teleport groups peers by the manifest URL. In case you use different servers to upload the manifest, transfer in the value of the parameter a function that turns the manifest from different url addresses to the same form.
qualityGetter (segmentUrl: string) => Quality Function to identity the quality of the active video stream
segmentTypeGetter (segmentUrl: string) => SegmentType Function to identity the type of the segment being loaded
bufferSizeGetter () => number Function for reading the current buffer size of the player
durationGetter (segmentUrl: string) => number Function for reading the length of the requested video segment

ISegment

Segment info data.

Name Type Description
timestamp number Segment load time, timestamp
result ISegmentResult Segment load result
request ISegmentRequest Segment request params
timings ISegmentTimings Segment download statistics

ISegmentResult

Name Type Description
segmentId string Segment ID
sourceId CDN|PDN Source of segment
targetId string|undefined Peer ID from which the segment was downloaded, if sourceId = PDN
range string|undefined Range of downloaded segment bytes
flags number Download flag
haves number Peer count with this segment in swarm
waitTimeout number Wait timeout from Teleport PDN
downloadTimeout number Download timeout from Teleport PDN
size number Segment size, byte
swarmSize number Swarm size
connected boolean Connection status
mode PeeringMode Peering mode
active boolean Flag of Teleport PDN activity

ISegmentRequest

Name Type Description
url string Raw segment URL
uri string Modified segment URI, after processing by urlCleaner
quality Quality Current video quality
type SegmentType Segment type
duration number Segment duration, second
bufferSize number Player buffer size, second

ISegmentTimings

Name Type Description
req_start number Request start time, timestamp
tthave number Delta of segment wait time from Teleport PDN
ttsent number Delta of load initialization time
ttfb number Delta of waiting for the first chunk
ttlb number Delta end of download segment
ttfinish number Delta end of segment processing and data transfer to the player

IStatTotals

Name Type Description
cdn ITraffic Download statistics from CDN
pdn ITraffic Download statistics from Teleport PDN
upload ITraffic Upload statistics to Teleport PDN

IStatDetails

Name Type Description
totals IStatTotals Total download statistics
details

IStatDetailsRow

Name Type Description
id string peer ID
download ITraffic Download statistics from peer
upload ITraffic Upload statistics from peer

ITraffic

Name Type Description
size number Traffic size, byte
count number Segments count
time number Download time, msec
speed number Upload speed, Mbit/s

Customization

Parameters for improving the quality of peer-to-peer network operation.

manifestAcceptor

To find the necessary connections, Teleport uses the URL video stream. By default Teleport defines manifest for extension: .m3u8, .mpd.

If your media server issues specific URL to the manifest, you need to define a function to search for the manifest.

Example:

let tlprt = await teleport.initialize({
    apiKey: "YOUR_API_KEY",
    loader: {
        type: "PLUGIN_ID",
        params: {
            manifestAcceptor: url => url.indexOf(".m3u8") > -1
        }
    }
});

segmentAcceptor

In order for the data transfer to begin in Teleport PDN, it is necessary to determine that this request is downloading the video segment. By default, Teleport determines the video segments for extensions: .ts, .mp4, .m4s.

If your media server issues specific url for video segments, you need to define a function for searching for segments.

Example:

let tlprt = await teleport.initialize({
    apiKey: "YOUR_API_KEY",
    loader: {
        type: "PLUGIN_ID",
        params: {
            segmentAcceptor: url => url.indexOf(".mp4") > -1
        }
    }
});

urlCleaner

For correct operation of Teleport PDN, it is necessary to delete unique information from the URL of a video segment or manifest.

Example:

let tlprt = await teleport.initialize({
    apiKey: "YOUR_API_KEY",
    loader: {
        type: "PLUGIN_ID",
        params: {
            urlCleaner: url => (new URL(url)).pathname
        }
    }
});

qualityGetter

To improve the performance of Teleport PDN, it is recommended to specify a function to identify the active quality of the video stream.

Example:

let player = new shaka.Player(video);
let videoIdToQuality = {};

videoId2Quality["1"] = teleport.Quality.Q1080P;
videoId2Quality["2"] = teleport.Quality.Q720P;
videoId2Quality["3"] = teleport.Quality.Q480P;

let tlprt = await teleport.initialize({
    apiKey: "YOUR_API_KEY",
    loader: {
        type: "PLUGIN_ID",
        params: {
            qualityGetter: () => {
                let t = player.getVariantTracks().find(x => x && x.active);

                return t && t.videoId && videoId2Quality[t.videoId] || teleport.Quality.Unknown;
            }
        }
    }
});

segmentTypeGetter

To improve the performance of Teleport PDN, it is recommended to specify a function for identifying the segment type.

Example:

let tlprt = await teleport.initialize({
    apiKey: "YOUR_API_KEY",
    loader: {
        type: "PLUGIN_ID",
        params: {
            segmentTypeGetter: url => url.indexOf('caption') > -1 ? teleport.SegmentType.Caption : teleport.SegmentType.Video
        }
    }
});

bufferSizeGetter

To improve the performance of Teleport PDN, it is recommended to specify a function to identify the buffer size of the player.

Example:

let player = new shaka.Player(video);
let tlprt = await teleport.initialize({
    apiKey: "YOUR_API_KEY",
    loader: {
        type: "PLUGIN_ID",
        params: {
            bufferSizeGetter: () => {
                let playhead = p.getPlayheadTimeAsDate().getTime();
                let presentation = p.getPresentationStartTimeAsDate().getTime();
                let start = (playhead - presentation) / 1000;

                let buf = p.getBufferedInfo();
                let end = buf && buf.video && buf.video[0] && buf.video[0].end || 0;

                return end > start ? end - start : 0;
            }
        }
    }
});

durationGetter

To improve the performance of Teleport PDN, it is recommended to specify a function to identify the segment duration.

Example:

let tlprt = await teleport.initialize({
    apiKey: "YOUR_API_KEY",
    loader: {
        type: "PLUGIN_ID",
        params: {
            durationGetter: () => 5
        }
    }
});