Skip to content

Commit 3026f24

Browse files
committed
fix: remove mixin
1 parent 49f1ad1 commit 3026f24

3 files changed

Lines changed: 63 additions & 58 deletions

File tree

src/mixins/eventable.js

Lines changed: 0 additions & 54 deletions
This file was deleted.

src/utils/setup-event-methods.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/**
2+
* Sets up event methods (on, one, off, trigger) on the VideoPlayer instance.
3+
* These methods wrap Video.js event methods and add the Player context to events.
4+
*
5+
* @param {Object} player - The VideoPlayer instance
6+
* @param {Object} videojsInstance - The underlying Video.js player instance
7+
*/
8+
const setupEventMethods = (player, videojsInstance) => {
9+
const handlers = {};
10+
11+
player.on = (...args) => {
12+
const lastIndex = args.length - 1;
13+
const func = args[lastIndex];
14+
15+
handlers[func] = (event, ..._args) => {
16+
event.Player = player;
17+
func(event, ..._args);
18+
};
19+
20+
args[lastIndex] = handlers[func];
21+
22+
return videojsInstance.on(...args);
23+
};
24+
25+
player.one = (...args) => {
26+
const lastIndex = args.length - 1;
27+
const func = args[lastIndex];
28+
29+
handlers[func] = (event, ..._args) => {
30+
event.Player = player;
31+
func(event, ..._args);
32+
delete handlers[func];
33+
};
34+
35+
args[lastIndex] = handlers[func];
36+
37+
return videojsInstance.one(...args);
38+
};
39+
40+
player.off = (...args) => {
41+
const lastIndex = args.length - 1;
42+
const func = args[lastIndex];
43+
44+
args[lastIndex] = handlers[func];
45+
46+
const res = videojsInstance.off(...args);
47+
delete handlers[func];
48+
49+
return res;
50+
};
51+
52+
player.trigger = (...args) => {
53+
videojsInstance.trigger(...args);
54+
};
55+
};
56+
57+
export default setupEventMethods;
58+

src/video-player.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import './components';
1010
import plugins from './plugins';
1111
import Utils from './utils';
1212
import defaults from './config/defaults';
13-
import Eventable from './mixins/eventable';
13+
import setupEventMethods from './utils/setup-event-methods';
1414
import ExtendedEvents from './extended-events';
1515
import VideoSource from './plugins/cloudinary/models/video-source/video-source';
1616
import {
@@ -35,7 +35,7 @@ Object.keys(plugins).forEach((key) => {
3535

3636
overrideDefaultVideojsComponents();
3737

38-
class VideoPlayer extends Utils.mixin(Eventable) {
38+
class VideoPlayer {
3939

4040
static all(selector, ...args) {
4141
const nodeList = document.querySelectorAll(selector);
@@ -47,8 +47,6 @@ class VideoPlayer extends Utils.mixin(Eventable) {
4747
}
4848

4949
constructor(elem, options, ready) {
50-
super();
51-
5250
this.videoElement = elem;
5351
this.options = splitOptions(options);
5452
this._videojsOptions = this.options.videojsOptions;
@@ -67,6 +65,9 @@ class VideoPlayer extends Utils.mixin(Eventable) {
6765

6866
this.videojs = videojs(this.videoElement, this._videojsOptions);
6967

68+
// Setup event methods (on, one, off, trigger)
69+
setupEventMethods(this, this.videojs);
70+
7071
this._isPlayerConfigValid = true;
7172
if (this.playerOptions.debug) {
7273
isValidPlayerConfig(this.options).then((valid) => {

0 commit comments

Comments
 (0)