@gcorevideo/player 2.22.17 → 2.22.18

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.
Files changed (52) hide show
  1. package/assets/clappr-nerd-stats/clappr-nerd-stats.ejs +76 -78
  2. package/assets/clappr-nerd-stats/clappr-nerd-stats.scss +10 -7
  3. package/dist/core.js +5 -7
  4. package/dist/index.css +1350 -1349
  5. package/dist/index.js +234 -89
  6. package/dist/plugins/index.css +666 -665
  7. package/dist/plugins/index.js +231 -83
  8. package/lib/playback/dash-playback/DashPlayback.d.ts +0 -1
  9. package/lib/playback/dash-playback/DashPlayback.d.ts.map +1 -1
  10. package/lib/playback/dash-playback/DashPlayback.js +4 -5
  11. package/lib/playback/hls-playback/HlsPlayback.d.ts +1 -1
  12. package/lib/playback/hls-playback/HlsPlayback.d.ts.map +1 -1
  13. package/lib/playback/hls-playback/HlsPlayback.js +0 -1
  14. package/lib/playback.types.d.ts +2 -3
  15. package/lib/playback.types.d.ts.map +1 -1
  16. package/lib/plugins/clappr-nerd-stats/NerdStats.d.ts +13 -10
  17. package/lib/plugins/clappr-nerd-stats/NerdStats.d.ts.map +1 -1
  18. package/lib/plugins/clappr-nerd-stats/NerdStats.js +171 -120
  19. package/lib/plugins/clappr-nerd-stats/formatter.d.ts +5 -0
  20. package/lib/plugins/clappr-nerd-stats/formatter.d.ts.map +1 -1
  21. package/lib/plugins/clappr-nerd-stats/formatter.js +56 -24
  22. package/lib/plugins/clappr-nerd-stats/speedtest/index.d.ts +2 -2
  23. package/lib/plugins/clappr-nerd-stats/speedtest/index.d.ts.map +1 -1
  24. package/lib/plugins/clappr-nerd-stats/speedtest/types.d.ts +1 -1
  25. package/lib/plugins/clappr-nerd-stats/speedtest/types.d.ts.map +1 -1
  26. package/lib/plugins/clappr-nerd-stats/types.d.ts +3 -0
  27. package/lib/plugins/clappr-nerd-stats/types.d.ts.map +1 -1
  28. package/lib/plugins/clappr-nerd-stats/utils.d.ts +7 -0
  29. package/lib/plugins/clappr-nerd-stats/utils.d.ts.map +1 -0
  30. package/lib/plugins/clappr-nerd-stats/utils.js +67 -0
  31. package/lib/plugins/clappr-stats/types.d.ts +0 -1
  32. package/lib/plugins/clappr-stats/types.d.ts.map +1 -1
  33. package/lib/plugins/clappr-stats/utils.d.ts +1 -1
  34. package/lib/plugins/clappr-stats/utils.d.ts.map +1 -1
  35. package/lib/plugins/clappr-stats/utils.js +0 -1
  36. package/lib/plugins/seek-time/SeekTime.d.ts +1 -1
  37. package/lib/plugins/seek-time/SeekTime.d.ts.map +1 -1
  38. package/lib/plugins/seek-time/SeekTime.js +3 -4
  39. package/package.json +1 -1
  40. package/src/playback/dash-playback/DashPlayback.ts +5 -7
  41. package/src/playback/hls-playback/HlsPlayback.ts +2 -4
  42. package/src/playback.types.ts +2 -3
  43. package/src/plugins/clappr-nerd-stats/NerdStats.ts +212 -139
  44. package/src/plugins/clappr-nerd-stats/formatter.ts +91 -47
  45. package/src/plugins/clappr-nerd-stats/speedtest/index.ts +2 -2
  46. package/src/plugins/clappr-nerd-stats/speedtest/types.ts +1 -1
  47. package/src/plugins/clappr-nerd-stats/types.ts +43 -3
  48. package/src/plugins/clappr-nerd-stats/utils.ts +75 -0
  49. package/src/plugins/clappr-stats/types.ts +39 -40
  50. package/src/plugins/clappr-stats/utils.ts +3 -4
  51. package/src/plugins/seek-time/SeekTime.ts +4 -5
  52. package/tsconfig.tsbuildinfo +1 -1
@@ -1,109 +1,153 @@
1
- import humanFormat, { ScaleLike } from 'human-format';
2
- import type { MetricsKind, MetricsType } from './types';
1
+ import humanFormat, { ScaleLike } from 'human-format'
2
+ import type { MetricName, MetricsKind, MetricsType } from './types'
3
3
 
4
4
  const timeScale = new humanFormat.Scale({
5
5
  ms: 1,
6
6
  sec: 1000,
7
7
  min: 60000,
8
- hours: 3600000
9
- });
8
+ hours: 3600000,
9
+ })
10
10
 
11
11
  const percentScale = new humanFormat.Scale({
12
- '%': 1
13
- });
12
+ '%': 1,
13
+ })
14
14
 
15
15
  type FormatParams = {
16
- scale?: ScaleLike;
17
- unit?: 'bps';
18
- decimals?: number;
16
+ scale?: ScaleLike
17
+ unit?: 'bps'
18
+ decimals?: number
19
19
  }
20
20
 
21
- const formattingTemplate: Record<MetricsKind, Partial<Record<MetricsType, FormatParams>>> = {
21
+ const metricTemplates: Partial<Record<MetricName, FormatParams>> = {
22
+ fps: {
23
+ scale: 'SI',
24
+ decimals: 0,
25
+ },
26
+ volume: {
27
+ scale: percentScale,
28
+ },
29
+ }
30
+
31
+ const formattingTemplate: Record<
32
+ MetricsKind,
33
+ Partial<Record<MetricsType, FormatParams>>
34
+ > = {
22
35
  general: {
23
36
  volume: {
24
- scale: percentScale
25
- }
37
+ scale: percentScale,
38
+ },
26
39
  },
27
40
  timers: {
28
41
  startup: {
29
- scale: timeScale
42
+ scale: timeScale,
30
43
  },
31
44
  watch: {
32
- scale: timeScale
45
+ scale: timeScale,
33
46
  },
34
47
  pause: {
35
- scale: timeScale
48
+ scale: timeScale,
36
49
  },
37
50
  buffering: {
38
- scale: timeScale
51
+ scale: timeScale,
39
52
  },
40
53
  session: {
41
- scale: timeScale
54
+ scale: timeScale,
42
55
  },
43
56
  latency: {
44
- scale: timeScale
45
- }
57
+ scale: timeScale,
58
+ },
46
59
  },
47
60
  extra: {
48
61
  buffersize: {
49
- scale: timeScale
62
+ scale: timeScale,
50
63
  },
51
64
  duration: {
52
- scale: timeScale
65
+ scale: timeScale,
53
66
  },
54
67
  currentTime: {
55
- scale: timeScale
68
+ scale: timeScale,
56
69
  },
57
70
  bitrateWeightedMean: {
58
- unit: 'bps'
71
+ unit: 'bps',
59
72
  },
60
73
  bitrateMostUsed: {
61
- unit: 'bps'
74
+ unit: 'bps',
62
75
  },
63
76
  bandwidth: {
64
- unit: 'bps'
77
+ unit: 'bps',
65
78
  },
66
79
  watchedPercentage: {
67
- scale: percentScale
80
+ scale: percentScale,
68
81
  },
69
82
  bufferingPercentage: {
70
- scale: percentScale
71
- }
72
- }
73
- };
83
+ scale: percentScale,
84
+ },
85
+ },
86
+ }
74
87
 
75
- type MetricsValue = number | string;
76
- type Metrics = Partial<Record<MetricsKind, Partial<Record<MetricsType, MetricsValue>>>>;
88
+ type MetricsValue = number | string
89
+ type Metrics = Partial<
90
+ Record<MetricsKind, Partial<Record<MetricsType, MetricsValue>>>
91
+ >
77
92
 
78
93
  export default class Formatter {
79
94
  static format(metrics: Metrics): Metrics {
80
- const formattedMetrics: Metrics = {};
95
+ const formattedMetrics: Metrics = {}
81
96
 
82
97
  Object.entries(metrics).forEach(([type, mm]) => {
83
- const fmt: Partial<Record<MetricsType, MetricsValue>> = {};
84
- formattedMetrics[type as MetricsKind] = fmt;
85
- const typeTemplate = formattingTemplate[type as MetricsKind];
98
+ const fmt: Partial<Record<MetricsType, MetricsValue>> = {}
99
+ formattedMetrics[type as MetricsKind] = fmt
100
+ const typeTemplate = formattingTemplate[type as MetricsKind]
86
101
 
87
102
  Object.entries(mm).forEach(([name, value]) => {
88
- // const value = mm[name];
89
-
90
- if (typeTemplate && typeTemplate[name as MetricsType] && (typeof value === 'number') && !isNaN(value)) {
103
+ if (
104
+ typeTemplate &&
105
+ typeTemplate[name as MetricsType] &&
106
+ typeof value === 'number' &&
107
+ !isNaN(value)
108
+ ) {
91
109
  // @ts-ignore
92
- const templateScale = typeTemplate[name as MetricsType].scale || 'SI';
110
+ const templateScale = typeTemplate[name as MetricsType].scale || 'SI'
93
111
  // @ts-ignore
94
- const templateUnit = typeTemplate[name as MetricsType].unit || '';
112
+ const templateUnit = typeTemplate[name as MetricsType].unit || ''
95
113
 
96
114
  fmt[name as MetricsType] = humanFormat(value, {
97
115
  scale: templateScale,
98
116
  unit: templateUnit,
99
- decimals: 2
100
- });
117
+ decimals: 2,
118
+ })
101
119
  } else {
102
- fmt[name as MetricsType] = value;
120
+ fmt[name as MetricsType] = value
103
121
  }
104
- });
105
- });
122
+ })
123
+ })
124
+
125
+ return formattedMetrics
126
+ }
127
+
128
+ static formatVolume(volume: number): string {
129
+ return humanFormat(volume, metricTemplates.volume)
130
+ }
131
+
132
+ static formatTime(time: number): string {
133
+ return humanFormat(time, {
134
+ scale: timeScale,
135
+ })
136
+ }
137
+
138
+ static formatFps(fps: number): string {
139
+ return humanFormat(fps, metricTemplates.fps)
140
+ }
141
+
142
+ static formatPercentage(percentage: number): string {
143
+ return humanFormat(percentage, {
144
+ scale: percentScale,
145
+ })
146
+ }
106
147
 
107
- return formattedMetrics;
148
+ static formatBitrate(bitrate: number): string {
149
+ return humanFormat(bitrate, {
150
+ unit: 'bps',
151
+ })
108
152
  }
109
153
  }
@@ -1,5 +1,5 @@
1
1
  import { type Server, type TestStatusInfo, Speedtest } from './Speedtest.js';
2
- import { CustomMetrics } from './types.js';
2
+ import { SpeedtestMetrics } from './types.js';
3
3
 
4
4
  const DIGITS_THRESHOLD = 99999;
5
5
  const DEFAULT_DOWNLOAD_SPEED = '0.00';
@@ -59,7 +59,7 @@ export function drawSpeedTestResults() {
59
59
 
60
60
  let inited: Promise<void> | null = null;
61
61
 
62
- export const initSpeedTest = (customMetrics: CustomMetrics): Promise<void> => {
62
+ export const initSpeedTest = (customMetrics: SpeedtestMetrics): Promise<void> => {
63
63
  if (inited !== null) {
64
64
  return inited;
65
65
  }
@@ -1,4 +1,4 @@
1
- export type CustomMetrics = {
1
+ export type SpeedtestMetrics = {
2
2
  ping: number;
3
3
  jitter: number;
4
4
  connectionSpeed: number;
@@ -1,3 +1,43 @@
1
- export type MetricsKind = 'general' | 'timers' | 'extra';
2
- export type MetricsType = 'volume' | 'startup' | 'watch' | 'pause' | 'buffering' | 'session' | 'latency' | 'buffersize' | 'duration' | 'currentTime' | 'bitrateWeightedMean' | 'bitrateMostUsed' | 'bandwidth' | 'watchedPercentage' | 'bufferingPercentage';
3
- export type MetricsValue = number;
1
+ export type MetricsKind = 'general' | 'timers' | 'extra'
2
+ export type MetricType = 'general' | 'timers' | 'extra'
3
+ export type MetricsType =
4
+ | 'volume'
5
+ | 'startup'
6
+ | 'watch'
7
+ | 'pause'
8
+ | 'buffering'
9
+ | 'session'
10
+ | 'latency'
11
+ | 'buffersize'
12
+ | 'duration'
13
+ | 'currentTime'
14
+ | 'bitrateWeightedMean'
15
+ | 'bitrateMostUsed'
16
+ | 'bandwidth'
17
+ | 'watchedPercentage'
18
+ | 'bufferingPercentage'
19
+ export type MetricName =
20
+ | 'volume'
21
+ | 'startup'
22
+ | 'watch'
23
+ | 'pause'
24
+ | 'buffering'
25
+ | 'session'
26
+ | 'latency'
27
+ | 'buffersize'
28
+ | 'duration'
29
+ | 'currentTime'
30
+ | 'bitrateWeightedMean'
31
+ | 'bitrateMostUsed'
32
+ | 'bandwidth'
33
+ | 'watchedPercentage'
34
+ | 'bufferingPercentage'
35
+ | 'fps'
36
+ export type MetricKind =
37
+ | 'volume'
38
+ | 'time'
39
+ | 'precisetime'
40
+ | 'percentage'
41
+ | 'bitrate'
42
+ | 'bandwidth'
43
+ export type MetricsValue = number
@@ -0,0 +1,75 @@
1
+ import { ZeptoResult } from "../../types"
2
+ import { SpeedtestMetrics } from "./speedtest/types"
3
+
4
+ const qualityClasses = [
5
+ 'speedtest-quality-value-1',
6
+ 'speedtest-quality-value-2',
7
+ 'speedtest-quality-value-3',
8
+ 'speedtest-quality-value-4',
9
+ 'speedtest-quality-value-5',
10
+ ]
11
+
12
+ export const getDownloadQuality = (speedValue: number): number => {
13
+ if (speedValue < 3) {
14
+ return 1
15
+ } else if (speedValue < 7) {
16
+ return 2
17
+ } else if (speedValue < 13) {
18
+ return 3
19
+ } else if (speedValue < 25) {
20
+ return 4
21
+ } else {
22
+ return 5
23
+ }
24
+ }
25
+
26
+ export const getPingQuality = (pingValue: number): number => {
27
+ if (pingValue < 20) {
28
+ return 5
29
+ } else if (pingValue < 50) {
30
+ return 4
31
+ } else if (pingValue < 100) {
32
+ return 3
33
+ } else if (pingValue < 150) {
34
+ return 2
35
+ } else {
36
+ return 1
37
+ }
38
+ }
39
+
40
+ export const generateQualityHtml = (quality: number): string => {
41
+ const html = []
42
+ const qualityClassName = qualityClasses[quality - 1]
43
+
44
+ for (let i = 0; i < qualityClasses.length; i++) {
45
+ if (i < quality) {
46
+ html.push(
47
+ `<div class="speedtest-quality-content-item ${qualityClassName}"></div>`,
48
+ )
49
+ } else {
50
+ html.push('<div class="speedtest-quality-content-item"></div>')
51
+ }
52
+ }
53
+
54
+ return html.join('')
55
+ }
56
+
57
+ export const drawSummary = (
58
+ customMetrics: SpeedtestMetrics,
59
+ vodContainer: ZeptoResult,
60
+ liveContainer: ZeptoResult,
61
+ ) => {
62
+ const { connectionSpeed, ping } = customMetrics
63
+
64
+ if (!connectionSpeed || !ping) {
65
+ return
66
+ }
67
+ const downloadQuality = getDownloadQuality(connectionSpeed)
68
+ const pingQuality = getPingQuality(ping)
69
+ const liveQuality = Math.min(downloadQuality, pingQuality)
70
+ const vodHtml = generateQualityHtml(downloadQuality)
71
+ const liveHtml = generateQualityHtml(liveQuality)
72
+
73
+ vodContainer.html(vodHtml)
74
+ liveContainer.html(liveHtml)
75
+ }
@@ -36,20 +36,20 @@ export type Metrics = {
36
36
  */
37
37
  counters: {
38
38
  /**
39
- *
39
+ *
40
40
  */
41
- [Counter.Play]: number;
42
- [Counter.Pause]: number;
43
- [Counter.Error]: number;
44
- [Counter.Buffering]: number;
45
- [Counter.DecodedFrames]: number;
46
- [Counter.DroppedFrames]: number;
47
- [Counter.Fps]: number;
48
- [Counter.ChangeLevel]: number;
49
- [Counter.Seek]: number;
50
- [Counter.Fullscreen]: number;
51
- [Counter.DvrUsage]: number;
52
- };
41
+ [Counter.Play]: number
42
+ [Counter.Pause]: number
43
+ [Counter.Error]: number
44
+ [Counter.Buffering]: number
45
+ [Counter.DecodedFrames]: number
46
+ [Counter.DroppedFrames]: number
47
+ [Counter.Fps]: number
48
+ [Counter.ChangeLevel]: number
49
+ [Counter.Seek]: number
50
+ [Counter.Fullscreen]: number
51
+ [Counter.DvrUsage]: number
52
+ }
53
53
  /**
54
54
  * Time measurements - accumulated duration of time-based activities
55
55
  */
@@ -57,44 +57,43 @@ export type Metrics = {
57
57
  /**
58
58
  * Time spent in the startup phase
59
59
  */
60
- [Chronograph.Startup]: number;
60
+ [Chronograph.Startup]: number
61
61
  /**
62
62
  * Total time spent in the watch phase
63
63
  */
64
- [Chronograph.Watch]: number;
64
+ [Chronograph.Watch]: number
65
65
  /**
66
- *
66
+ *
67
67
  */
68
- [Chronograph.Pause]: number;
69
- [Chronograph.Buffering]: number;
70
- [Chronograph.Session]: number;
68
+ [Chronograph.Pause]: number
69
+ [Chronograph.Buffering]: number
70
+ [Chronograph.Session]: number
71
71
  // [Chronograph.Latency]: number;
72
- };
72
+ }
73
73
  extra: {
74
- playbackName: string;
75
- playbackType: string;
76
- bitratesHistory: BitrateTrackRecord[];
77
- bitrateWeightedMean: number;
78
- bitrateMostUsed: number;
79
- buffersize: number;
80
- watchHistory: Array<[number, number]>;
81
- watchedPercentage: number;
82
- bufferingPercentage: number;
83
- bandwidth: number;
84
- duration: number;
85
- currentTime: number;
86
- };
87
- custom: Record<string, unknown>;
88
- };
74
+ playbackName: string
75
+ playbackType: string
76
+ bitratesHistory: BitrateTrackRecord[]
77
+ bitrateWeightedMean: number
78
+ bitrateMostUsed: number
79
+ buffersize: number
80
+ watchHistory: Array<[number, number]>
81
+ watchedPercentage: number
82
+ bufferingPercentage: number
83
+ bandwidth: number
84
+ duration: number
85
+ currentTime: number
86
+ }
87
+ }
89
88
 
90
89
  /**
91
90
  * @beta
92
91
  */
93
92
  export type BitrateTrackRecord = {
94
- start: number;
95
- end?: number;
96
- time?: number;
97
- bitrate: number;
93
+ start: number
94
+ end?: number
95
+ time?: number
96
+ bitrate: number
98
97
  }
99
98
 
100
99
  /**
@@ -109,4 +108,4 @@ export enum ClapprStatsEvents {
109
108
  * Emitted when the playback reaches a certain percentage of the total duration.
110
109
  */
111
110
  // PERCENTAGE = 'clappr:stats:percentage',
112
- }
111
+ }
@@ -1,4 +1,4 @@
1
- import type { Metrics } from "./types";
1
+ import type { Metrics } from './types'
2
2
 
3
3
  export function newMetrics(): Metrics {
4
4
  return {
@@ -36,6 +36,5 @@ export function newMetrics(): Metrics {
36
36
  duration: 0,
37
37
  currentTime: 0,
38
38
  },
39
- custom: {},
40
- };
41
- }
39
+ }
40
+ }
@@ -3,7 +3,7 @@
3
3
  // license that can be found at https://github.com/clappr/clappr-plugins/blob/master/LICENSE
4
4
 
5
5
  import { Events, Playback, UICorePlugin, Utils, template } from '@clappr/core';
6
- import { TimeUpdate } from '../../playback.types.js';
6
+ import { TimePosition } from '../../playback.types.js';
7
7
 
8
8
  import { CLAPPR_VERSION } from '../../build.js';
9
9
 
@@ -79,7 +79,7 @@ export class SeekTime extends UICorePlugin {
79
79
  this.listenTo(this.mediaControl, Events.MEDIACONTROL_CONTAINERCHANGED, this.onContainerChanged);
80
80
  if (this.mediaControlContainer) {
81
81
  this.listenTo(this.mediaControlContainer, Events.CONTAINER_PLAYBACKDVRSTATECHANGED, this.update);
82
- this.listenTo(this.mediaControlContainer, Events.CONTAINER_TIMEUPDATE, this.updateDuration);
82
+ this.listenTo(this.mediaControlContainer, Events.CONTAINER_TIMEUPDATE, this.onTimeUpdate);
83
83
  }
84
84
  }
85
85
 
@@ -89,9 +89,8 @@ export class SeekTime extends UICorePlugin {
89
89
  this.bindEvents();
90
90
  }
91
91
 
92
- private updateDuration(timeProgress: TimeUpdate) {
93
- this.duration = timeProgress.total;
94
- // this.firstFragDateTime = timeProgress.firstFragDateTime;
92
+ private onTimeUpdate({ total }: TimePosition) {
93
+ this.duration = total;
95
94
  this.update();
96
95
  }
97
96