Commit ec49adc6 authored by Dima's avatar Dima

Update Teleport guide.md

parent 9fb092c9
......@@ -73,12 +73,16 @@ $ index.html
## Events
To receive feedback from teleport.js in real time, you need to subscribe to the events generated in the window.teleport.events method.
It takes the following parameters:
**eventName** (string) — API event name
| Parameter | Description |
| ------------- | ------------- |
| **eventName** (string) | API event name |
| **callback** (function) | The function where the received result will be sent, after the event is completed. |
**callback** (function) — the function where the received result will be sent, after the event is completed.
**Example**
```html
$ skeleton
<script>
......@@ -89,64 +93,61 @@ $ skeleton
$ To restrict an access to unauthorized media content users, initialize the script only after authorization.
```
#### Events
Event Name: **noWebrtc**
Arguments: *number* **performance.now()**
The browser does not support WebRTC.
#### Events list:
| Event Name | Arguments | Description |
| ------------- | ------------- | ------------- |
| **noWebrtc** | *number* **performance.now()** |The browser does not support WebRTC. |
*Example:*
```javascript
window.teleport.events.on('noWebrtc',(date) => console.log('change your IE', date))
```
Event Name: **peerConnected**
Arguments: *string* **userId**, *number* **performance.now()**
A WebRTC connection has been established. userId - is the unique ID of the peer.
------------
| Event Name | Arguments | Description |
| ------------- | ------------- | ------------- |
| **peerConnected**| *string* **userId**, *number* **performance.now()** |A WebRTC connection has been established. userId - is the unique ID of the peer. |
*Example:*
```javascript
window.teleport.events.on('peerConnected', (userId, date) => console.log('New peer connected.', userId, date))
```
Event Name: **peerDisconnected**
Arguments: *string* **userId**, *number* **performance.now()**
WebRTC connection is broken.
------------
| Event Name | Arguments | Description |
| ------------- | ------------- | ------------- |
| **peerDisconnected**| *string* **userId**, *number* **performance.now()** |WebRTC connection is broken. |
*Example:*
```javascript
window.teleport.events.on('peerDisconnected', (userId, date) => console.log('peerDisconnected', userId, date))
```
------------
Event Name: **statSegment**
Arguments: *string* **targetId**('cdn' | PeerTargetId), *string* **segmentId**, *int* **byteLength**, *int* **loadTime**, *number* **performance.now()**
Video file segment is loaded. If the segment file is loaded from CDN targetId === 'cdn'.
| Event Name | Arguments | Description |
| ------------- | ------------- | ------------- |
| **statSegment**| *string* **targetId**('cdn'/ PeerTargetId), *string* **segmentId**, *int* **byteLength**, *int* **loadTime**, *number* **performance.now()**|Video file segment is loaded. If the segment file is loaded from CDN targetId === 'cdn'. |
*Example:*
```javascript
window.teleport.events.on('statSegment', (targetId, segmentId, byteLength, loadTime, date) => console.log('New segment loaded:', segmentId))
```
#### Methods
**window.teleport.api.getSegment(url:String, quality:number, callback?:(Promise<res>)=>void):Promise** - performs a segment request, where: 'url' - is the segment URL, 'quality' - segment quality id.
**window.teleport.api.getSegmentIdByUrl(url: string):string** - returns a unique segment identifier by URL.
**window.teleport.api.abort(url: string, callback?:()=>void):void** - cancels a segment request, where 'url' - is the URL of the segment.
------------
**window.teleport.api.buffering(): void** - informs the Teleport server about the buffering events.
**window.teleport.api.setUploadState(true|false): void** - switches On and Off the upload of the segments in the P2P. The status of the current state can be found in the uploadState property of the getStats method.
#### Methods list:
**window.teleport.api.segmentInfo(url|segmentId, callback?:()=>void): string** - returns the source of segment load ('cdn' | targetId | 'Segment not loaded')
| Event Name | Arguments |
| ------------- | ------------- |
| **window.teleport.api.getSegment(url:String, quality:number, callback?:(Promise<res>)=>void):Promise** | performs a segment request, where: 'url' - is the segment URL, 'quality' - segment quality id. |
| **window.teleport.api.getSegmentIdByUrl(url: string):string** | returns a unique segment identifier by URL.|
| **window.teleport.api.abort(url: string, callback?:()=>void):void**|cancels a segment request, where 'url' - is the URL of the segment.|
| **window.teleport.api.buffering(): void**|informs the Teleport server about the buffering events.|
| **window.teleport.api.setUploadState(true/false): void**|switches On and Off the upload of the segments in the P2P. The status of the current state can be found in the uploadState property of the getStats method.|
|**window.teleport.api.segmentInfo(url/segmentId, callback?:()=>void): string**| returns the source of segment load ('cdn' / targetId / 'Segment not loaded')|
*Example:*
```javascript
$ javascript
...
......@@ -160,8 +161,14 @@ $ console output example
"Segment not loaded"
```
**window.teleport.api.getStats (): Object** returns aggregated statistics on the downloaded segments from the media server and from the P2P.
------------
| Event Name | Arguments |
| ------------- | ------------- |
|**window.teleport.api.getStats (): Object**| returns aggregated statistics on the downloaded segments from the media server and from the P2P.|
*Example:*
```javascript
$ javascript
...
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment