Skip to content

Commit 5e41fbe

Browse files
committed
xapiPlugin
1 parent d301bb4 commit 5e41fbe

File tree

9 files changed

+43
-246
lines changed

9 files changed

+43
-246
lines changed

src/frontend/packages/lib_video/src/components/common/Player/createPlayer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export const createPlayer: VideoPlayerCreator = (
2323
);
2424

2525
const trackTextKind: {
26-
[key in timedTextMode]?: videojs.default.TextTrack.Kind;
26+
[key in timedTextMode]?: string;
2727
} = {
2828
[timedTextMode.CLOSED_CAPTIONING]: 'captions',
2929
[timedTextMode.SUBTITLE]: 'subtitles',

src/frontend/packages/lib_video/src/components/common/Player/createVideojsPlayer.ts

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import 'video.js/dist/video-js.css';
22

3-
//import 'videojs-contrib-quality-levels';
43
import 'videojs-http-source-selector';
54
import './videojs/qualitySelectorPlugin';
65
import './videojs/p2pHlsPlugin';
@@ -13,14 +12,7 @@ import './videojs/transcriptPlugin';
1312
import { Maybe } from 'lib-common';
1413
import { Video, useP2PConfig, videoSize } from 'lib-components';
1514
import videojs, { Player, Plugins, Source } from 'video.js';
16-
// import from 'video.js/dist/types/plugin';
17-
// import videojs, {
18-
// VideoJsPlayer,
19-
// VideoJsPlayerOptions,
20-
// VideoJsPlayerPluginOptions,
21-
// } from 'video.js';
2215

23-
//import { VideoJsExtendedSourceObject } from '@lib-video/types/libs/video.js/extend';
2416
import { isMSESupported } from '@lib-video/utils/isMSESupported';
2517

2618
export const createVideojsPlayer = (
@@ -48,9 +40,7 @@ export const createVideojsPlayer = (
4840
const sources: Source[] = [];
4941
const plugins: Partial<Plugins> = {};
5042

51-
console.log('urls.mp4', urls.mp4);
52-
53-
if (isMSESupported()) {
43+
if (!isMSESupported()) {
5444
plugins.qualitySelector = {
5545
default: '480',
5646
};
@@ -103,8 +93,6 @@ export const createVideojsPlayer = (
10393
sources,
10494
};
10595

106-
console.log('options', { options, isMSESupported: isMSESupported() });
107-
10896
const player = videojs(videoNode, options) as Player;
10997

11098
if (video.is_live) {
@@ -113,8 +101,6 @@ export const createVideojsPlayer = (
113101

114102
onReady?.(player);
115103

116-
console.log('player', { player });
117-
118104
// plugins initialization
119105
if (isMSESupported()) {
120106
if (isP2pQueryEnabled && isP2PEnabled) {
@@ -132,7 +118,7 @@ export const createVideojsPlayer = (
132118
//player.httpSourceSelector();
133119
}
134120
player.id3Plugin();
135-
// player.xapiPlugin({ video, locale, dispatchPlayerTimeUpdate });
121+
player.xapiPlugin({ video, locale, dispatchPlayerTimeUpdate });
136122

137123
return player;
138124
};

src/frontend/packages/lib_video/src/components/common/Player/videojs/id3Plugin/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ export class id3Plugin extends PluginClass {
3030
}
3131

3232
handleLoadedMetadata() {
33-
console.log('handleLoadedMetadata', this.player);
34-
3533
const tracks = this.player.textTracks();
3634
for (let index = 0; index < tracks.length; index++) {
3735
const track = tracks[index];

src/frontend/packages/lib_video/src/components/common/Player/videojs/p2pHlsPlugin/types.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import videojs, { Player } from 'video.js';
22
import PluginType from 'video.js/dist/types/plugin';
33

4-
const Plugin = videojs.getPlugin('plugin') as typeof PluginType;
5-
64
export interface HlsData {
75
frag: {
86
url: string;
@@ -21,6 +19,7 @@ export interface ExtendedVideoJs {
2119
};
2220
}
2321

22+
const Plugin = videojs.getPlugin('plugin') as typeof PluginType;
2423
export class P2pHlsPlugin extends Plugin {
2524
declare player: Player;
2625

src/frontend/packages/lib_video/src/components/common/Player/videojs/xapiPlugin/index.ts

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
useCurrentSession,
1010
useJwt,
1111
} from 'lib-components';
12-
import videojs from 'video.js';
12+
import videojs, { Player } from 'video.js';
1313

1414
import { pushAttendance } from '@lib-video/api/pushAttendance';
1515
import { useAttendance } from '@lib-video/hooks/useAttendance';
@@ -19,11 +19,11 @@ import { isMSESupported } from '@lib-video/utils/isMSESupported';
1919

2020
import { Events } from '../qualitySelectorPlugin/types';
2121

22-
import { XapiPluginOptions } from './types';
22+
import { XapiPluginOptions, XapiPluginType } from './types';
2323

24-
const Plugin = videojs.getPlugin('plugin');
24+
const PluginClass = videojs.getPlugin('plugin') as XapiPluginType;
2525

26-
export class xapiPlugin extends Plugin {
26+
export class xapiPlugin extends PluginClass {
2727
private xapiStatement: VideoXAPIStatementInterface;
2828
video: Video;
2929
currentTime: number;
@@ -34,8 +34,9 @@ export class xapiPlugin extends Plugin {
3434
hasAttendance: boolean;
3535
currentTrack: Nullable<TextTrack>;
3636
locale: Maybe<string>;
37+
declare player: Player;
3738

38-
constructor(player: videojs.Player, options: XapiPluginOptions) {
39+
constructor(player: Player, options: XapiPluginOptions) {
3940
super(player, options);
4041

4142
this.video = options.video;
@@ -74,20 +75,20 @@ export class xapiPlugin extends Plugin {
7475
player.on('canplaythrough', this.initialize.bind(this));
7576
player.on('play', () => {
7677
this.xapiStatement.played({
77-
time: player.currentTime(),
78+
time: player.currentTime() || 0,
7879
});
7980
});
8081
player.on('pause', () => {
8182
this.xapiStatement.paused({
82-
time: player.currentTime(),
83+
time: player.currentTime() || 0,
8384
});
8485
});
8586

8687
player.on('timeupdate', () => {
8788
if (this.isInitialized && !player.seeking()) {
88-
this.currentTime = player.currentTime();
89+
this.currentTime = player.currentTime() || 0;
8990
}
90-
options.dispatchPlayerTimeUpdate(player.currentTime());
91+
options.dispatchPlayerTimeUpdate(player.currentTime() || 0);
9192
});
9293

9394
player.on('seeking', () => {
@@ -102,7 +103,7 @@ export class xapiPlugin extends Plugin {
102103
this.hasSeeked = false;
103104
this.xapiStatement.seeked({
104105
timeFrom: this.seekingAt,
105-
timeTo: player.currentTime(),
106+
timeTo: player.currentTime() || 0,
106107
});
107108
});
108109
player.on('fullscreenchange', this.interacted.bind(this));
@@ -122,7 +123,7 @@ export class xapiPlugin extends Plugin {
122123
return;
123124
}
124125

125-
this.xapiStatement.terminated({ time: player.currentTime() });
126+
this.xapiStatement.terminated({ time: player.currentTime() || 0 });
126127

127128
if (this.interval) {
128129
player.clearInterval(this.interval);
@@ -165,7 +166,7 @@ export class xapiPlugin extends Plugin {
165166
const contextExtensions = {
166167
ccSubtitleEnabled: this.currentTrack !== null,
167168
fullScreen: this.player.isFullscreen(),
168-
length: this.player.duration(),
169+
length: this.player.duration() || 0,
169170
speed: `${this.player.playbackRate()}x`,
170171
volume: this.player.volume(),
171172
};
@@ -215,7 +216,7 @@ export class xapiPlugin extends Plugin {
215216
}
216217

217218
this.xapiStatement.interacted(
218-
{ time: this.player.currentTime() },
219+
{ time: this.player.currentTime() || 0 },
219220
contextExtensions,
220221
);
221222
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,21 @@
11
import { Maybe } from 'lib-common';
22
import { Video } from 'lib-components';
3+
import videojs, { Player } from 'video.js';
4+
import PluginType from 'video.js/dist/types/plugin';
35

46
export interface XapiPluginOptions {
57
video: Video;
68
locale: Maybe<string>;
79
dispatchPlayerTimeUpdate: (time: number) => void;
810
}
11+
12+
const Plugin = videojs.getPlugin('plugin') as typeof PluginType;
13+
export class XapiPlugin extends Plugin {
14+
declare player: Player;
15+
16+
constructor(player: Player, _options?: XapiPluginOptions) {
17+
super(player);
18+
}
19+
}
20+
21+
export type XapiPluginType = typeof XapiPlugin;

src/frontend/packages/lib_video/src/types/VideoPlayer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Maybe } from 'lib-common';
22
import { TimedText, Video } from 'lib-components';
3-
import { VideoJsPlayer } from 'video.js';
3+
import { Player } from 'video.js';
44

55
export interface VideoPlayerInterface {
66
addTrack(track: TimedText, languages: { [key: string]: string }): void;
@@ -17,5 +17,5 @@ export type VideoPlayerCreator = (
1717
dispatchPlayerTimeUpdate: (time: number) => void,
1818
video: Video,
1919
locale?: string,
20-
onReady?: (player: VideoJsPlayer) => void,
20+
onReady?: (player: Player) => void,
2121
) => Maybe<VideoPlayerInterface>;

0 commit comments

Comments
 (0)