2018-12-31 01:03:07 +01:00
|
|
|
import Debug from '../../conf/Debug';
|
|
|
|
import PlayerData from './PlayerData';
|
|
|
|
import Resizer from '../video-transform/Resizer';
|
|
|
|
import ArDetector from '../ar-detect/ArDetector';
|
|
|
|
|
2018-05-09 00:03:22 +02:00
|
|
|
class VideoData {
|
|
|
|
|
2018-09-21 00:26:08 +02:00
|
|
|
constructor(video, settings, pageInfo){
|
2018-05-16 23:26:47 +02:00
|
|
|
this.arSetupComplete = false;
|
2018-05-09 00:03:22 +02:00
|
|
|
this.video = video;
|
2018-05-21 22:43:56 +02:00
|
|
|
this.destroyed = false;
|
2018-08-05 23:48:56 +02:00
|
|
|
this.settings = settings;
|
2018-11-02 02:52:01 +01:00
|
|
|
this.pageInfo = pageInfo;
|
|
|
|
this.extensionMode = pageInfo.extensionMode;
|
|
|
|
|
2019-08-23 02:25:48 +02:00
|
|
|
this.vdid = (Math.random()*100).toFixed();
|
|
|
|
this.userCssClassName = `uw-fuck-you-and-do-what-i-tell-you_${this.vdid}`;
|
2018-11-02 21:19:34 +01:00
|
|
|
|
2019-08-24 17:05:04 +02:00
|
|
|
|
|
|
|
// We'll replace cssWatcher (in resizer) with mutationObserver
|
|
|
|
const observerConf = {
|
|
|
|
attributes: true,
|
|
|
|
// attributeFilter: ['style', 'class'],
|
|
|
|
attributeOldValue: true,
|
|
|
|
};
|
|
|
|
this.observer = new MutationObserver(this.onVideoDimensionsChanged);
|
|
|
|
this.observer.observe(video, observerConf);
|
|
|
|
|
2018-05-14 20:39:15 +02:00
|
|
|
// POZOR: VRSTNI RED JE POMEMBEN (arDetect mora bit zadnji)
|
|
|
|
// NOTE: ORDERING OF OBJ INITIALIZATIONS IS IMPORTANT (arDetect needs to go last)
|
2018-11-02 21:19:34 +01:00
|
|
|
this.player = new PlayerData(this);
|
2018-05-14 20:39:15 +02:00
|
|
|
this.resizer = new Resizer(this);
|
|
|
|
|
|
|
|
this.arDetector = new ArDetector(this); // this starts Ar detection. needs optional parameter that prevets ardetdctor from starting
|
2018-05-12 02:51:58 +02:00
|
|
|
// player dimensions need to be in:
|
|
|
|
// this.player.dimensions
|
2019-02-16 01:54:41 +01:00
|
|
|
|
|
|
|
// apply default align and stretch
|
|
|
|
if (Debug.init) {
|
|
|
|
console.log("%c[VideoData::ctor] Initial resizer reset!", {background: '#afd', color: '#132'});
|
|
|
|
}
|
|
|
|
this.resizer.reset();
|
|
|
|
|
2018-11-02 02:52:01 +01:00
|
|
|
|
2018-09-23 19:46:40 +02:00
|
|
|
if (Debug.init) {
|
2018-11-02 21:19:34 +01:00
|
|
|
console.log("[VideoData::ctor] Created videoData with vdid", this.vdid,"\nextension mode:", this.extensionMode);
|
2018-09-23 19:46:40 +02:00
|
|
|
}
|
2018-12-02 23:51:34 +01:00
|
|
|
|
|
|
|
this.pageInfo.initMouseActionHandler(this);
|
2019-08-23 02:25:48 +02:00
|
|
|
|
2019-08-24 17:05:04 +02:00
|
|
|
this.video.classList.add(this.userCssClassName); // this also needs to be applied BEFORE we initialize resizer!
|
2019-08-31 18:21:49 +02:00
|
|
|
|
2019-08-24 17:05:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
onVideoDimensionsChanged(mutationList, observer) {
|
2019-08-25 01:52:04 +02:00
|
|
|
if (!mutationList || this.video === undefined) { // something's wrong
|
|
|
|
if (observer && this.video) {
|
|
|
|
observer.disconnect();
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2019-08-24 17:05:04 +02:00
|
|
|
for (let mutation of mutationList) {
|
|
|
|
if (mutation.type === 'attributes') {
|
|
|
|
if (mutation.attributeName === 'class') {
|
|
|
|
if (!this.video.classList.contains(this.userCssClassName)) {
|
|
|
|
// force the page to include our class in classlist, if the classlist has been removed
|
|
|
|
this.video.classList.add(this.userCssClassName);
|
|
|
|
|
|
|
|
// } else if () {
|
|
|
|
// this bug should really get
|
|
|
|
} else {
|
|
|
|
this.restoreAr();
|
|
|
|
}
|
|
|
|
} else if (mutation.attributeName === 'style' && mutation.attributeOldValue !== this.video.getAttribute('style')) {
|
|
|
|
console.log("style changed")
|
|
|
|
// if size of the video has changed, this may mean we need to recalculate/reapply
|
|
|
|
// last calculated aspect ratio
|
|
|
|
this.restoreAr();
|
2019-08-25 01:52:04 +02:00
|
|
|
} else if (mutation.attribute = 'src' && mutation.attributeOldValue !== this.video.getAttribute('src')) {
|
|
|
|
// try fixing alignment issue on video change
|
|
|
|
try {
|
|
|
|
this.restoreAr();
|
|
|
|
} catch (e) {
|
|
|
|
console.error("[VideoData::onVideoDimensionsChanged] There was an error when handling src change.", e);
|
|
|
|
}
|
2019-08-24 17:05:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-05-12 02:51:58 +02:00
|
|
|
}
|
|
|
|
|
2018-05-16 23:26:47 +02:00
|
|
|
firstTimeArdInit(){
|
2018-09-23 19:46:40 +02:00
|
|
|
if(this.destroyed) {
|
2019-08-25 01:52:04 +02:00
|
|
|
// throw {error: 'VIDEO_DATA_DESTROYED', data: {videoData: this}};
|
|
|
|
return;
|
2018-09-23 19:46:40 +02:00
|
|
|
}
|
2018-05-16 23:26:47 +02:00
|
|
|
if(! this.arSetupComplete){
|
|
|
|
this.arDetector = new ArDetector(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-14 20:39:15 +02:00
|
|
|
initArDetection() {
|
2018-09-23 19:46:40 +02:00
|
|
|
if(this.destroyed) {
|
2019-08-25 01:52:04 +02:00
|
|
|
// throw {error: 'VIDEO_DATA_DESTROYED', data: {videoData: this}};
|
|
|
|
return;
|
2018-09-23 19:46:40 +02:00
|
|
|
}
|
2018-05-20 23:17:09 +02:00
|
|
|
if(this.arDetector){
|
2018-05-16 23:26:47 +02:00
|
|
|
this.arDetector.init();
|
2018-05-20 23:17:09 +02:00
|
|
|
}
|
|
|
|
else{
|
2018-05-16 23:26:47 +02:00
|
|
|
this.arDetector = new ArDetector(this);
|
2018-05-20 23:17:09 +02:00
|
|
|
this.arDetector.init();
|
|
|
|
}
|
2018-05-12 02:51:58 +02:00
|
|
|
}
|
2018-05-24 20:50:37 +02:00
|
|
|
|
2018-05-14 20:39:15 +02:00
|
|
|
startArDetection() {
|
2018-11-18 18:44:44 +01:00
|
|
|
if (Debug.debug) {
|
|
|
|
console.log("[VideoData::startArDetection] starting AR detection")
|
|
|
|
}
|
2018-09-23 19:46:40 +02:00
|
|
|
if(this.destroyed) {
|
2019-08-25 01:52:04 +02:00
|
|
|
// throw {error: 'VIDEO_DATA_DESTROYED', data: {videoData: this}};
|
|
|
|
return;
|
2018-09-23 19:46:40 +02:00
|
|
|
}
|
2018-08-31 00:35:52 +02:00
|
|
|
if(!this.arDetector) {
|
|
|
|
this.arDetector.init();
|
|
|
|
}
|
2018-05-12 02:51:58 +02:00
|
|
|
this.arDetector.start();
|
2018-05-09 00:03:22 +02:00
|
|
|
}
|
|
|
|
|
2018-11-02 21:41:26 +01:00
|
|
|
rebootArDetection() {
|
|
|
|
if(this.destroyed) {
|
2019-08-25 01:52:04 +02:00
|
|
|
// throw {error: 'VIDEO_DATA_DESTROYED', data: {videoData: this}};
|
|
|
|
return;
|
2018-11-02 21:41:26 +01:00
|
|
|
}
|
|
|
|
this.arDetector.init();
|
|
|
|
}
|
|
|
|
|
2018-05-24 20:50:37 +02:00
|
|
|
stopArDetection() {
|
2018-08-31 00:35:52 +02:00
|
|
|
if (this.arDetector) {
|
|
|
|
this.arDetector.stop();
|
|
|
|
}
|
2018-05-24 20:50:37 +02:00
|
|
|
}
|
|
|
|
|
2018-05-09 00:03:22 +02:00
|
|
|
destroy() {
|
2018-09-23 19:46:40 +02:00
|
|
|
if(Debug.debug || Debug.init){
|
|
|
|
console.log(`[VideoData::destroy] <vdid:${this.vdid}> received destroy command`);
|
2018-08-30 00:56:15 +02:00
|
|
|
}
|
|
|
|
|
2019-08-31 18:21:49 +02:00
|
|
|
this.video.classList.remove(this.userCssClassName);
|
|
|
|
|
2018-09-23 19:46:40 +02:00
|
|
|
this.pause();
|
2018-05-21 22:43:56 +02:00
|
|
|
this.destroyed = true;
|
2019-08-25 01:52:04 +02:00
|
|
|
if (this.arDetector){
|
|
|
|
try {
|
|
|
|
this.arDetector.stop();
|
|
|
|
this.arDetector.destroy();
|
|
|
|
} catch (e) {}
|
2018-05-16 23:26:47 +02:00
|
|
|
}
|
2019-08-25 01:52:04 +02:00
|
|
|
this.arDetector = undefined;
|
|
|
|
if (this.resizer){
|
|
|
|
try {
|
|
|
|
this.resizer.destroy();
|
|
|
|
} catch (e) {}
|
2018-05-16 23:26:47 +02:00
|
|
|
}
|
2019-08-25 01:52:04 +02:00
|
|
|
this.resizer = undefined;
|
|
|
|
if (this.player){
|
|
|
|
try {
|
|
|
|
this.player.destroy();
|
|
|
|
} catch (e) {}
|
|
|
|
}
|
|
|
|
if (this.observer) {
|
|
|
|
try {
|
|
|
|
this.observer.disconnect();
|
|
|
|
} catch (e) {}
|
2018-05-22 00:19:50 +02:00
|
|
|
}
|
2019-08-25 01:52:04 +02:00
|
|
|
this.player = undefined;
|
|
|
|
this.video = undefined;
|
2018-05-09 00:03:22 +02:00
|
|
|
}
|
2018-05-09 00:34:22 +02:00
|
|
|
|
2018-05-23 23:58:34 +02:00
|
|
|
pause(){
|
|
|
|
this.paused = true;
|
|
|
|
if(this.arDetector){
|
|
|
|
this.arDetector.stop();
|
|
|
|
}
|
|
|
|
if(this.player){
|
|
|
|
this.player.stop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resume(){
|
2018-09-23 19:46:40 +02:00
|
|
|
if(this.destroyed) {
|
2019-08-25 01:52:04 +02:00
|
|
|
// throw {error: 'VIDEO_DATA_DESTROYED', data: {videoData: this}};
|
|
|
|
return;
|
2018-09-23 19:46:40 +02:00
|
|
|
}
|
2018-05-23 23:58:34 +02:00
|
|
|
this.paused = false;
|
|
|
|
try {
|
|
|
|
this.resizer.start();
|
2018-11-02 02:52:01 +01:00
|
|
|
if (this.player) {
|
|
|
|
this.player.start();
|
|
|
|
}
|
2018-05-23 23:58:34 +02:00
|
|
|
} catch (e) {
|
|
|
|
if(Debug.debug){
|
|
|
|
console.log("[VideoData.js::resume] cannot resume for reasons. Will destroy videoData. Error here:", e);
|
|
|
|
}
|
|
|
|
this.destroy();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resumeAutoAr(){
|
|
|
|
if(this.arDetector){
|
|
|
|
this.startArDetection();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-16 01:19:29 +01:00
|
|
|
setManualTick(manualTick) {
|
|
|
|
if(this.arDetector){
|
|
|
|
this.arDetector.setManualTick(manualTick);
|
|
|
|
}
|
|
|
|
}
|
2019-02-16 01:54:41 +01:00
|
|
|
|
2019-02-16 01:19:29 +01:00
|
|
|
tick() {
|
|
|
|
if(this.arDetector){
|
|
|
|
this.arDetector.tick();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-09 00:34:22 +02:00
|
|
|
setLastAr(lastAr){
|
|
|
|
this.resizer.setLastAr(lastAr);
|
|
|
|
}
|
|
|
|
|
2018-05-13 21:05:11 +02:00
|
|
|
setAr(ar, lastAr){
|
|
|
|
this.resizer.setAr(ar, lastAr);
|
|
|
|
}
|
|
|
|
|
2018-09-14 00:10:57 +02:00
|
|
|
resetAr() {
|
|
|
|
this.resizer.reset();
|
|
|
|
}
|
|
|
|
|
2018-11-18 18:44:44 +01:00
|
|
|
resetLastAr() {
|
|
|
|
this.resizer.setLastAr('original');
|
|
|
|
}
|
|
|
|
|
2018-12-02 23:51:34 +01:00
|
|
|
panHandler(event, forcePan) {
|
2018-09-23 19:46:40 +02:00
|
|
|
if(this.destroyed) {
|
2019-08-25 01:52:04 +02:00
|
|
|
// throw {error: 'VIDEO_DATA_DESTROYED', data: {videoData: this}};
|
|
|
|
return;
|
2018-09-23 19:46:40 +02:00
|
|
|
}
|
2018-09-18 00:42:30 +02:00
|
|
|
if(!this.resizer) {
|
|
|
|
this.destroy();
|
|
|
|
return;
|
|
|
|
}
|
2018-12-02 23:51:34 +01:00
|
|
|
this.resizer.panHandler(event, forcePan);
|
2018-09-13 23:47:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
setPanMode(mode) {
|
|
|
|
this.resizer.setPanMode(mode);
|
|
|
|
}
|
|
|
|
|
2018-12-31 03:34:26 +01:00
|
|
|
setvideoAlignment(videoAlignment) {
|
|
|
|
this.resizer.setvideoAlignment(videoAlignment);
|
2018-09-23 02:39:27 +02:00
|
|
|
}
|
|
|
|
|
2018-07-15 16:22:32 +02:00
|
|
|
restoreAr(){
|
|
|
|
this.resizer.restore();
|
|
|
|
}
|
|
|
|
|
2018-05-13 21:05:11 +02:00
|
|
|
setStretchMode(stretchMode){
|
|
|
|
this.resizer.setStretchMode(stretchMode);
|
|
|
|
}
|
2018-05-13 13:49:25 +02:00
|
|
|
|
2018-09-21 00:26:08 +02:00
|
|
|
setZoom(zoomLevel, no_announce){
|
|
|
|
this.resizer.setZoom(zoomLevel, no_announce);
|
2018-09-18 23:37:33 +02:00
|
|
|
}
|
|
|
|
|
2018-05-24 20:50:37 +02:00
|
|
|
zoomStep(step){
|
2018-09-13 23:47:20 +02:00
|
|
|
this.resizer.zoomStep(step);
|
2018-05-24 20:50:37 +02:00
|
|
|
}
|
|
|
|
|
2018-09-21 00:26:08 +02:00
|
|
|
announceZoom(scale){
|
|
|
|
this.pageInfo.announceZoom(scale);
|
|
|
|
}
|
2018-11-21 21:58:13 +01:00
|
|
|
|
2018-12-06 23:55:54 +01:00
|
|
|
markPlayer(name, color) {
|
|
|
|
if (this.player) {
|
|
|
|
this.player.markPlayer(name, color)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
unmarkPlayer() {
|
|
|
|
this.player.unmarkPlayer();
|
|
|
|
}
|
|
|
|
|
2018-11-21 21:58:13 +01:00
|
|
|
isPlaying() {
|
2019-06-10 23:45:15 +02:00
|
|
|
// console.log("is playing? video:", this.video, "ctime:", this.video.currentTime,
|
|
|
|
// "paused/ended:", this.video.paused, this.video.ended,
|
|
|
|
// "is playing?", this.video && this.video.currentTime > 0 && !this.video.paused && !this.video.ended);
|
2018-11-21 21:58:13 +01:00
|
|
|
|
|
|
|
return this.video && this.video.currentTime > 0 && !this.video.paused && !this.video.ended;
|
|
|
|
}
|
2018-12-31 01:03:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export default VideoData;
|