@vkontakte/videoplayer-core 2.0.69 → 2.0.70

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vkontakte/videoplayer-core",
3
- "version": "2.0.69",
3
+ "version": "2.0.70",
4
4
  "author": "vk.com",
5
5
  "description": "Videoplayer core library based on the vk.com platform",
6
6
  "homepage": "https://vk.com",
@@ -0,0 +1,9 @@
1
+ import { IError, ISubject } from '@vkontakte/videoplayer-shared';
2
+ /**
3
+ * WebRTCLiveClient options description
4
+ */
5
+ export interface WebRTCLiveClientOptions {
6
+ stunServerList: string[];
7
+ maxRetryNumber: number;
8
+ errorChanel: ISubject<IError> | null;
9
+ }
package/player/types.d.ts CHANGED
@@ -319,6 +319,7 @@ export interface ISources {
319
319
  [VideoFormat.HLS]?: IHLSSource;
320
320
  [VideoFormat.HLS_ONDEMAND]?: IHLSSource;
321
321
  [VideoFormat.HLS_LIVE]?: IHLSLiveSource;
322
+ [VideoFormat.WEB_RTC_LIVE]?: URLSource;
322
323
  }
323
324
  export interface IMetadata {
324
325
  title?: string;
@@ -361,7 +362,8 @@ export declare enum VideoFormat {
361
362
  HLS_ONDEMAND = "HLS_ONDEMAND",
362
363
  /** @deprecated Используйте HLS */
363
364
  HLS_JS = "HLS",
364
- HLS_LIVE = "HLS_LIVE"
365
+ HLS_LIVE = "HLS_LIVE",
366
+ WEB_RTC_LIVE = "WEB_RTC_LIVE"
365
367
  }
366
368
  export interface IVideoTrack {
367
369
  id: string;
@@ -0,0 +1,135 @@
1
+ import { Milliseconds } from '@vkontakte/videoplayer-shared';
2
+ import { IRepresentation } from '../types';
3
+ interface IParams {
4
+ videoElement: HTMLVideoElement;
5
+ playerCallback: (...args: any) => void;
6
+ config: {
7
+ minBuffer: Milliseconds;
8
+ lowLatencyMinBuffer: Milliseconds;
9
+ minBufferSegments: number;
10
+ lowLatencyMinBufferSegments: number;
11
+ maxParallelRequests: number;
12
+ };
13
+ logger: (...args: any[]) => void;
14
+ }
15
+ export default class LiveDashPlayer {
16
+ private paused;
17
+ private autoQuality;
18
+ private maxAutoQuality;
19
+ private buffering;
20
+ private destroyed;
21
+ private videoPlayStarted;
22
+ private lowLatency;
23
+ private rep?;
24
+ private bitrate;
25
+ private manifest;
26
+ private bitrateSwitcher?;
27
+ private filesFetcher?;
28
+ private sourceBuffer?;
29
+ private mediaSource?;
30
+ private currentManifestEntry?;
31
+ private manifestRequest?;
32
+ private manifestRefetchTimer?;
33
+ private bufferStates;
34
+ private downloadRate?;
35
+ private sourceJitter;
36
+ private chunkRateEstimator;
37
+ private manifestUrl;
38
+ private urlResolver;
39
+ private params;
40
+ constructor(params: IParams);
41
+ attachSource(manifestUrl: string): void;
42
+ /**
43
+ * switch to auto quality
44
+ */
45
+ setAutoQualityEnabled(enabled: boolean): void;
46
+ setMaxAutoQuality(height: number | undefined): void;
47
+ /**
48
+ * switch quality by name
49
+ */
50
+ switchByName(name: string): void;
51
+ /**
52
+ * seek to actual video position
53
+ */
54
+ catchUp(): void;
55
+ stop(): void;
56
+ pause(): void;
57
+ play(onPlayNotAllowed?: () => void): void;
58
+ startPlay(targetQ: IRepresentation, autoQuality: boolean): void;
59
+ /**
60
+ * destroy player
61
+ */
62
+ destroy(): void;
63
+ reinit(newManifestUrl: string): void;
64
+ /**
65
+ * if all retries fail...
66
+ */
67
+ private _handleNetworkError;
68
+ /**
69
+ * Retry request
70
+ */
71
+ private _retryCallback;
72
+ /**
73
+ * how many seconds are there in the buffer
74
+ */
75
+ private _getBufferSizeSec;
76
+ /**
77
+ * send buffering notification to player
78
+ */
79
+ private _notifyBuffering;
80
+ /**
81
+ * initialize video tag, add necessary event listeners
82
+ * @private
83
+ */
84
+ private _initVideo;
85
+ /**
86
+ * there may be small gaps of several milliseconds when switching quality
87
+ * we jump over these gaps here
88
+ */
89
+ private _fixupStall;
90
+ /**
91
+ * return best quality for rate
92
+ */
93
+ private _selectQuality;
94
+ private shouldPlay;
95
+ /**
96
+ * set video source
97
+ */
98
+ private _setVideoSrc;
99
+ /**
100
+ * initialize player with target quality
101
+ */
102
+ private _initPlayerWith;
103
+ /**
104
+ * represents specific quality stream
105
+ */
106
+ private _representation;
107
+ /**
108
+ * switch to quality
109
+ * TODO: Если новое качество выше старого – переключиться сразу. Если хуже, доиграть буфер
110
+ */
111
+ private _switchToQuality;
112
+ /**
113
+ * check if quality is available
114
+ */
115
+ private _qualityAvailable;
116
+ /**
117
+ * analyze bitrate data and switch qualities accordingly
118
+ */
119
+ private _initBitrateSwitcher;
120
+ /**
121
+ * load and parse manifest file
122
+ */
123
+ private _fetchManifest;
124
+ private _playVideoElement;
125
+ /**
126
+ * update internal state when manifest was received from remote
127
+ */
128
+ private _handleManifestUpdate;
129
+ /**
130
+ * schedule manifest update after delay
131
+ */
132
+ private _refetchManifest;
133
+ private _initManifest;
134
+ }
135
+ export {};
@@ -0,0 +1,188 @@
1
+ import { WebRTCLiveClientOptions } from "./interface/WebRTCLiveClientOptions";
2
+ /**
3
+ *
4
+ */
5
+ export declare class WebRTCLiveClient {
6
+ private options;
7
+ private ws;
8
+ private peerConnection;
9
+ serverUrl: string;
10
+ streamKey: string;
11
+ stream: MediaStream | null;
12
+ signalingType: string;
13
+ private retryTimeout;
14
+ private retryCount;
15
+ private externalStartCallback;
16
+ private externalStopCallback;
17
+ private externalErrorCallback;
18
+ /**
19
+ * @param url
20
+ * @param options
21
+ */
22
+ constructor(url: string, options?: Partial<WebRTCLiveClientOptions>);
23
+ /**
24
+ * Sets start streaming callback
25
+ *
26
+ * @param cb
27
+ */
28
+ onStart(cb: (stream: MediaStream) => void): void;
29
+ /**
30
+ * Sets stop streaming callback
31
+ *
32
+ * @param cb
33
+ */
34
+ onStop(cb: () => void): void;
35
+ /**
36
+ * Sets streaming or connection error callback
37
+ *
38
+ * @param cb
39
+ */
40
+ onError(cb: (e: Error) => void): void;
41
+ /**
42
+ * Start connection dialog
43
+ */
44
+ connect(): void;
45
+ /**
46
+ * Kill connection
47
+ */
48
+ disconnect(): void;
49
+ /**
50
+ * Begins socket opening
51
+ * @private
52
+ */
53
+ private connectWS;
54
+ /**
55
+ * Socket opened event handler
56
+ * Begins login process
57
+ * @private
58
+ */
59
+ private onSocketOpen;
60
+ /**
61
+ * Socket close event handler
62
+ * @param e
63
+ * @private
64
+ */
65
+ private onSocketClose;
66
+ /**
67
+ * Socket connection error handler
68
+ * @param e
69
+ * @private
70
+ */
71
+ private onSocketError;
72
+ /**
73
+ * Socket message handler
74
+ * @param message
75
+ * @private
76
+ */
77
+ private onSocketMessage;
78
+ /**
79
+ * Socket JOIN message handler
80
+ * @param message
81
+ * @private
82
+ */
83
+ private handleJoinMessage;
84
+ /**
85
+ * Socket STATUS message handler
86
+ * @param message
87
+ * @private
88
+ */
89
+ private handleStatusMessage;
90
+ /**
91
+ * Socket UPDATE message handler
92
+ * @param message
93
+ * @private
94
+ */
95
+ private handleUpdateMessage;
96
+ /**
97
+ * Handles peer connection login process
98
+ * @private
99
+ */
100
+ private handleLogin;
101
+ /**
102
+ * Adds received remote offer to peer connection
103
+ * @private
104
+ */
105
+ private handleAnswer;
106
+ /**
107
+ * Adds ICE candidate to peer connection
108
+ * @param candidate
109
+ * @private
110
+ */
111
+ private handleCandidate;
112
+ /**
113
+ * Live stream finish handler
114
+ * @private
115
+ */
116
+ private handleUnpublished;
117
+ /**
118
+ * Handles system failures
119
+ */
120
+ private handleSystemError;
121
+ /**
122
+ * Peer connection stream received handler
123
+ * @param e
124
+ * @private
125
+ */
126
+ private onPeerConnectionStream;
127
+ /**
128
+ * ICE candidate received handler
129
+ * @param e
130
+ * @private
131
+ */
132
+ private onPeerConnectionIceCandidate;
133
+ /**
134
+ * Peer connection ICE connection state change handler
135
+ * @private
136
+ */
137
+ private onPeerConnectionIceConnectionStateChange;
138
+ /**
139
+ * Returns newly created offer
140
+ * @private
141
+ */
142
+ private createOffer;
143
+ /**
144
+ * Handles RTC connection error
145
+ * @param e
146
+ * @private
147
+ */
148
+ private handleRTCError;
149
+ /**
150
+ * Handles network error
151
+ * @private
152
+ */
153
+ private handleNetworkError;
154
+ /**
155
+ * Sends message to websocket
156
+ * @param message
157
+ * @private
158
+ */
159
+ private send;
160
+ /**
161
+ * Parses JSON message to object
162
+ * @param message
163
+ */
164
+ private parseMessage;
165
+ /**
166
+ * Closes all connections (ws and peer connection)
167
+ * @private
168
+ */
169
+ private closeConnections;
170
+ /**
171
+ * Kills peer connection
172
+ * @private
173
+ */
174
+ private removePeerConnection;
175
+ /**
176
+ * Schedules connection retry
177
+ *
178
+ * @private
179
+ */
180
+ private scheduleRetry;
181
+ /**
182
+ * Returns normalized options with all defaults set
183
+ *
184
+ * @param userOptions
185
+ * @private
186
+ */
187
+ private normalizeOptions;
188
+ }
@@ -0,0 +1,60 @@
1
+ import { IProvider, IProviderParams } from "../types";
2
+ import { URLSource } from "../../player/types";
3
+ /**
4
+ * @class WebRTCLiveProvider
5
+ *
6
+ * Provides implementation of WEBRTC live streaming support
7
+ */
8
+ export default class WebRTCLiveProvider implements IProvider {
9
+ private readonly subscription;
10
+ private readonly params;
11
+ private log;
12
+ private video;
13
+ private videoState;
14
+ private liveStreamClient;
15
+ private maxSeekBackTime$;
16
+ /**
17
+ * @param params
18
+ */
19
+ constructor(params: IProviderParams<URLSource>);
20
+ /**
21
+ * Destroys the provider
22
+ */
23
+ destroy(): void;
24
+ /**
25
+ * Creates all needed provider subscriptions
26
+ * @private
27
+ */
28
+ private subscribe;
29
+ /**
30
+ * Live stream start handler
31
+ * @private
32
+ */
33
+ private onLiveStreamStart;
34
+ /**
35
+ * Live stream stop handler
36
+ * @private
37
+ */
38
+ private onLiveStreamStop;
39
+ /**
40
+ * Live stream error handler
41
+ * @private
42
+ */
43
+ private onLiveStreamError;
44
+ /**
45
+ * Tries to start playing
46
+ * @private
47
+ */
48
+ private playIfAllowed;
49
+ /**
50
+ * Runs preparation phase
51
+ * Starts live client connection
52
+ * @private
53
+ */
54
+ private prepare;
55
+ /**
56
+ * Performs synchronization between desired state and video state
57
+ * @private
58
+ */
59
+ private syncPlayback;
60
+ }
@@ -0,0 +1,3 @@
1
+ import { Milliseconds } from '@vkontakte/videoplayer-shared';
2
+ declare const _default: (timeRanges: TimeRanges, position: Milliseconds) => boolean;
3
+ export default _default;
@@ -65,6 +65,9 @@ export declare type ITuningConfig = {
65
65
  requestQuick: boolean;
66
66
  useDashJs: boolean;
67
67
  useHlsJs: boolean;
68
+ webrtc: {
69
+ connectionRetryMaxNumber: number;
70
+ };
68
71
  };
69
72
  export declare type IOptionalTuningConfig = {
70
73
  [key in keyof ITuningConfig]?: Partial<ITuningConfig[key]>;