Skip to content

Teleport JavaScript API

INFO

This section contains a detailed description of the Teleport SDK JavaScript API, available after connecting the library to your web page.

Global Namespace teleport

The global teleport object is available in the window context after successfully connecting the Teleport JavaScript library.

js
console.log(window.teleport.version); // Example of accessing properties

teleport Properties (Static Properties)

NameData TypeDescription
versionstringVersion of the loaded Teleport SDK.
QualityenumEnumeration of video quality values.
SegmentTypeenumEnumeration of segment type values.
PeeringModeenumEnumeration of peering mode values.

teleport Methods (Static Methods)

initialize(options)

Initializes a Teleport SDK instance.

Return Type: Promise<ITeleportInstance>

Arguments:

NameData TypeDescription
optionsITeleportFactoryOptionsTeleport SDK initialization parameters.

Example:

js
let tlprt = await teleport.initialize({
    apiKey: "APIKEY", // Your API key
    loader: {
        type: "player plugin ID", // Player plugin identifier
        params: {player: player} // Player instance
    }
});

await player.load("manifest url");

ITeleportInstance Interface

The ITeleportInstance instance is returned by the teleport.initialize() method and provides access to managing the peer-to-peer network, obtaining statistics, and other SDK functions.

ITeleportInstance Events

onPeeringModeChanged

Event triggered when the peering mode changes.

Signature: (mode: PeeringMode) => void

Example:

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

onPeerConnectionOpened

Event triggered when a connection with a new peer is established.

Signature: (peerId: string) => void

Example:

js
tlrpt.onPeerConnectionOpened = (peerId) => console.log(`peer connected: ${peerId}`);

onPeerConnectionClosed

Event triggered when a connection with a peer is terminated.

Signature: (peerId: string) => void

Example:

js
tlrpt.onPeerConnectionClosed = (peerId) => console.log(`peer disconnected: ${peerId}`);

onSegmentLoaded

Event triggered when a new video segment is loaded.

Signature: (segment: ISegment) => void

Example:

js
tlrpt.onSegmentLoaded = (segment) => console.log(`segment loaded:`, segment);

onSegmentUploaded

Event triggered when a video segment is uploaded to the peer-to-peer network.

Signature: (segment: ISegment) => void

Example:

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

ITeleportInstance Properties

NameData TypeReadonlyDescription
versionstringtrueVersion of the loaded Teleport SDK.
apiKeystringtrueAPI Key with which Teleport was initialized.
connectionIdstringtrueIdentifier of the current peer.
connectedbooleantrueFlag indicating active connection to the Teleport signaling server.
peeringModePeeringModefalseCurrent peering mode.

ITeleportInstance Methods

buffering()

Method signaling Teleport about buffering occurring in the video player.

getStatTotals()

Returns aggregated traffic statistics for the current Teleport instance.

Return Type: IStatTotals

Example:

js
console.log(tlprt.getStatTotals());

getStatDetails()

Returns detailed traffic statistics broken down by WebRTC connections for the current Teleport instance.

Return Type: IStatDetails

Example:

js
console.log(tlprt.getStatDetails());

dispose()

Method that destroys the Teleport instance, correctly releasing all resources.

Return Type: Promise<void>

getLoader()

Returns the API of the current loader. Not all loaders have an API; undefined is returned if it's absent.

Return Type: any

Enumerations (Enums)

List of available enumerations in the global teleport namespace.

Quality

Enumeration of video stream qualities.

Available values:

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

SegmentType

Enumeration of segment types.

Available values:

  • Unknown
  • Video
  • Audio
  • Caption
  • Mixed
  • Other

PeeringMode

Enumeration of peering modes for Teleport SDK operation.

Available values:

  • Off - Peering is disabled.
  • Download - Peer can only download content from Teleport PDN (Peer-to-Peer Delivery Network).
  • Upload - Peer can only upload content to Teleport PDN.
  • Full - Peer operates in full mode: downloads and uploads content.

Example:

js
tlrpt.peeringMode = teleport.PeeringMode.Download;

Interfaces

Description of available TypeScript/JavaScript interfaces.

ITeleportFactoryOptions

Parameters for the teleport.initialize() method.

NameData TypeDescription
apiKeystringAPI key for Teleport access. Can be obtained in the personal account.
loaderIPluginOptionsParameters for video player integration.

IPluginOptions

Parameters for configuring the player loader.

NameData TypeDescription
typestringPlugin identifier for player integration (e.g., shaka, hls-js, video-js, jwplayer, uppod-html5, clappr-dash, clappr-hls, sw).
paramsIPluginIntegrationOptionsAdditional parameters for video player integration.

IPluginIntegrationOptions

Parameters for customizing the behavior of player plugins.

NameData TypeDescription
manifestAcceptor(url: string) => booleanFunction to identify an HTTP request with a video stream manifest.
segmentAcceptor(url: string) => booleanFunction to identify an HTTP request with a video segment.
urlCleaner(url: string) => stringFunction to unify URL addresses of video segments and manifests.
qualityGetter(segmentUrl: string) => [Quality](#enums-quality)Function to determine the quality of the active video stream.
segmentTypeGetter(segmentUrl: string) => [SegmentType](#enums-segmenttype)Function to determine the type of the loaded segment.
bufferSizeGetter() => numberFunction to read the current buffer size of the player.
durationGetter(segmentUrl: string) => numberFunction to read the duration of the requested video segment.

ISegment

JavaScript object containing data about a video segment.

NameData TypeDescription
timestampnumberUNIX timestamp of segment load time.
resultISegmentResultProperty with segment load result data.
requestISegmentRequestProperty with requested segment data.
timingsISegmentTimingsProperty with measured load timings data.

ISegmentResult

Video segment load result.

NameData TypeDescription
segmentIdstringSegment identifier.
sourceIdCDN | PDNSource from which the segment was downloaded (CDN or PDN).
targetIdstring | undefinedPeer identifier from which the segment was downloaded, if sourceId = PDN.
rangestring | undefinedRange of downloaded bytes of the segment.
flagsnumberLoad flags.
havesnumberNumber of peers with the specified segment in the swarm.
waitTimeoutnumberTimeout for waiting from Teleport PDN.
downloadTimeoutnumberTimeout for downloading from Teleport PDN.
sizenumberSegment size in bytes.
swarmSizenumberSwarm size (number of active peers in the network).
connectedbooleanFlag indicating active connection to the Teleport signaling server.
modePeeringModeCurrent peering mode.
activebooleanFlag indicating Teleport PDN activity.

ISegmentRequest

Data about the requested video segment.

NameData TypeDescription
urlstringOriginal URL of the segment.
uristringUnified URI of the segment after urlCleaner processing.
qualityQualityCurrent video stream quality.
typeSegmentTypeSegment type.
durationnumberSegment duration in seconds.
bufferSizenumberPlayer buffer size in seconds.

ISegmentTimings

Measured timings of video segment loading.

NameData TypeDescription
req_startnumberUNIX timestamp of segment request time by player (request start).
tthavenumberDelta of segment waiting from Teleport PDN (time until first peer response).
ttsentnumberDelta of load initialization time (time until request sent).
ttfbnumberDelta of first chunk waiting (Time To First Byte).
ttlbnumberDelta of segment load completion (Time To Last Byte).
ttfinishnumberDelta of segment processing completion and data transfer to player.

IStatTotals

Aggregated traffic statistics.

NameData TypeDescription
cdnITrafficCDN download statistics.
pdnITrafficTeleport PDN download statistics.
uploadITrafficTeleport PDN upload statistics.

IStatDetails

Detailed traffic statistics by WebRTC connections.

NameData TypeDescription
totalsIStatTotalsAggregated download statistics.
detailsArray<[IStatDetailsRow](#interfaces-istatdetailsrow)>Download statistics by WebRTC connections.

IStatDetailsRow

Detailed statistics row for each peer.

NameData TypeDescription
idstringPeer identifier.
downloadITrafficPeer download statistics.
uploadITrafficPeer upload statistics.

ITraffic

Traffic statistics data.

NameData TypeDescription
sizenumberTraffic volume in bytes.
countnumberNumber of segments.
timenumberDownload time in milliseconds.
speednumberDownload speed in megabits per second.