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.
console.log(window.teleport.version); // Example of accessing propertiesteleport Properties (Static Properties)
| Name | Data Type | Description |
|---|---|---|
version | string | Version of the loaded Teleport SDK. |
Quality | enum | Enumeration of video quality values. |
SegmentType | enum | Enumeration of segment type values. |
PeeringMode | enum | Enumeration of peering mode values. |
teleport Methods (Static Methods)
initialize(options)
Initializes a Teleport SDK instance.
Return Type: Promise<ITeleportInstance>
Arguments:
| Name | Data Type | Description |
|---|---|---|
options | ITeleportFactoryOptions | Teleport SDK initialization parameters. |
Example:
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:
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:
tlrpt.onPeerConnectionOpened = (peerId) => console.log(`peer connected: ${peerId}`);onPeerConnectionClosed
Event triggered when a connection with a peer is terminated.
Signature: (peerId: string) => void
Example:
tlrpt.onPeerConnectionClosed = (peerId) => console.log(`peer disconnected: ${peerId}`);onSegmentLoaded
Event triggered when a new video segment is loaded.
Signature: (segment: ISegment) => void
Example:
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:
tlrpt.onSegmentUploaded = (segment) => console.log(`segment uploaded:`, segment);ITeleportInstance Properties
| Name | Data Type | Readonly | Description |
|---|---|---|---|
version | string | true | Version of the loaded Teleport SDK. |
apiKey | string | true | API Key with which Teleport was initialized. |
connectionId | string | true | Identifier of the current peer. |
connected | boolean | true | Flag indicating active connection to the Teleport signaling server. |
peeringMode | PeeringMode | false | Current 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:
console.log(tlprt.getStatTotals());getStatDetails()
Returns detailed traffic statistics broken down by WebRTC connections for the current Teleport instance.
Return Type: IStatDetails
Example:
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:
Q144PQ240PQ360PQ480PQ720PQ1080PQ4KOther
SegmentType
Enumeration of segment types.
Available values:
UnknownVideoAudioCaptionMixedOther
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:
tlrpt.peeringMode = teleport.PeeringMode.Download;Interfaces
Description of available TypeScript/JavaScript interfaces.
ITeleportFactoryOptions
Parameters for the teleport.initialize() method.
| Name | Data Type | Description |
|---|---|---|
apiKey | string | API key for Teleport access. Can be obtained in the personal account. |
loader | IPluginOptions | Parameters for video player integration. |
IPluginOptions
Parameters for configuring the player loader.
| Name | Data Type | Description |
|---|---|---|
type | string | Plugin identifier for player integration (e.g., shaka, hls-js, video-js, jwplayer, uppod-html5, clappr-dash, clappr-hls, sw). |
params | IPluginIntegrationOptions | Additional parameters for video player integration. |
IPluginIntegrationOptions
Parameters for customizing the behavior of player plugins.
| Name | Data Type | Description |
|---|---|---|
manifestAcceptor | (url: string) => boolean | Function to identify an HTTP request with a video stream manifest. |
segmentAcceptor | (url: string) => boolean | Function to identify an HTTP request with a video segment. |
urlCleaner | (url: string) => string | Function 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 | () => number | Function to read the current buffer size of the player. |
durationGetter | (segmentUrl: string) => number | Function to read the duration of the requested video segment. |
ISegment
JavaScript object containing data about a video segment.
| Name | Data Type | Description |
|---|---|---|
timestamp | number | UNIX timestamp of segment load time. |
result | ISegmentResult | Property with segment load result data. |
request | ISegmentRequest | Property with requested segment data. |
timings | ISegmentTimings | Property with measured load timings data. |
ISegmentResult
Video segment load result.
| Name | Data Type | Description |
|---|---|---|
segmentId | string | Segment identifier. |
sourceId | CDN | PDN | Source from which the segment was downloaded (CDN or PDN). |
targetId | string | undefined | Peer identifier from which the segment was downloaded, if sourceId = PDN. |
range | string | undefined | Range of downloaded bytes of the segment. |
flags | number | Load flags. |
haves | number | Number of peers with the specified segment in the swarm. |
waitTimeout | number | Timeout for waiting from Teleport PDN. |
downloadTimeout | number | Timeout for downloading from Teleport PDN. |
size | number | Segment size in bytes. |
swarmSize | number | Swarm size (number of active peers in the network). |
connected | boolean | Flag indicating active connection to the Teleport signaling server. |
mode | PeeringMode | Current peering mode. |
active | boolean | Flag indicating Teleport PDN activity. |
ISegmentRequest
Data about the requested video segment.
| Name | Data Type | Description |
|---|---|---|
url | string | Original URL of the segment. |
uri | string | Unified URI of the segment after urlCleaner processing. |
quality | Quality | Current video stream quality. |
type | SegmentType | Segment type. |
duration | number | Segment duration in seconds. |
bufferSize | number | Player buffer size in seconds. |
ISegmentTimings
Measured timings of video segment loading.
| Name | Data Type | Description |
|---|---|---|
req_start | number | UNIX timestamp of segment request time by player (request start). |
tthave | number | Delta of segment waiting from Teleport PDN (time until first peer response). |
ttsent | number | Delta of load initialization time (time until request sent). |
ttfb | number | Delta of first chunk waiting (Time To First Byte). |
ttlb | number | Delta of segment load completion (Time To Last Byte). |
ttfinish | number | Delta of segment processing completion and data transfer to player. |
IStatTotals
Aggregated traffic statistics.
| Name | Data Type | Description |
|---|---|---|
cdn | ITraffic | CDN download statistics. |
pdn | ITraffic | Teleport PDN download statistics. |
upload | ITraffic | Teleport PDN upload statistics. |
IStatDetails
Detailed traffic statistics by WebRTC connections.
| Name | Data Type | Description |
|---|---|---|
totals | IStatTotals | Aggregated download statistics. |
details | Array<[IStatDetailsRow](#interfaces-istatdetailsrow)> | Download statistics by WebRTC connections. |
IStatDetailsRow
Detailed statistics row for each peer.
| Name | Data Type | Description |
|---|---|---|
id | string | Peer identifier. |
download | ITraffic | Peer download statistics. |
upload | ITraffic | Peer upload statistics. |
ITraffic
Traffic statistics data.
| Name | Data Type | Description |
|---|---|---|
size | number | Traffic volume in bytes. |
count | number | Number of segments. |
time | number | Download time in milliseconds. |
speed | number | Download speed in megabits per second. |