Files
pgsql-jellyfin/Jellyfin.Server/wwwroot/syncPlay-core-PlaybackCore.cc8de35f6e45025ba142.chunk.js
T
2026-07-08 13:13:46 -04:00

2 lines
17 KiB
JavaScript

/*! For license information please see syncPlay-core-PlaybackCore.cc8de35f6e45025ba142.chunk.js.LICENSE.txt */
"use strict";(self.webpackChunk=self.webpackChunk||[]).push([[13151,14510,65849,80835],{629:function(e,t,n){n.r(t),n(29305),n(32733),n(84701),n(81678),n(2623),n(24776),n(44962),n(4754),n(10849),n(70389),n(94),n(9698),n(36947),n(26437),n(52697),n(78557),n(90076),n(83994),n(82367);var i=n(44797),a=n(44305),r=n(20919),o=n(4438);function s(e){return s="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},s(e)}function c(){var e,t,n="function"==typeof Symbol?Symbol:{},i=n.iterator||"@@iterator",a=n.toStringTag||"@@toStringTag";function r(n,i,a,r){var c=i&&i.prototype instanceof s?i:s,l=Object.create(c.prototype);return u(l,"_invoke",function(n,i,a){var r,s,c,u=0,l=a||[],y=!1,d={p:0,n:0,v:e,a:m,f:m.bind(e,4),d:function(t,n){return r=t,s=0,c=e,d.n=n,o}};function m(n,i){for(s=n,c=i,t=0;!y&&u&&!a&&t<l.length;t++){var a,r=l[t],m=d.p,f=r[2];n>3?(a=f===i)&&(c=r[(s=r[4])?5:(s=3,3)],r[4]=r[5]=e):r[0]<=m&&((a=n<2&&m<r[1])?(s=0,d.v=i,d.n=r[1]):m<f&&(a=n<3||r[0]>i||i>f)&&(r[4]=n,r[5]=i,d.n=f,s=0))}if(a||n>1)return o;throw y=!0,i}return function(a,l,f){if(u>1)throw TypeError("Generator is already running");for(y&&1===l&&m(l,f),s=l,c=f;(t=s<2?e:c)||!y;){r||(s?s<3?(s>1&&(d.n=-1),m(s,c)):d.n=c:d.v=c);try{if(u=2,r){if(s||(a="next"),t=r[a]){if(!(t=t.call(r,c)))throw TypeError("iterator result is not an object");if(!t.done)return t;c=t.value,s<2&&(s=0)}else 1===s&&(t=r.return)&&t.call(r),s<2&&(c=TypeError("The iterator does not provide a '"+a+"' method"),s=1);r=e}else if((t=(y=d.n<0)?c:n.call(i,d))!==o)break}catch(t){r=e,s=1,c=t}finally{u=1}}return{value:t,done:y}}}(n,a,r),!0),l}var o={};function s(){}function l(){}function y(){}t=Object.getPrototypeOf;var d=[][i]?t(t([][i]())):(u(t={},i,(function(){return this})),t),m=y.prototype=s.prototype=Object.create(d);function f(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,y):(e.__proto__=y,u(e,a,"GeneratorFunction")),e.prototype=Object.create(m),e}return l.prototype=y,u(m,"constructor",y),u(y,"constructor",l),l.displayName="GeneratorFunction",u(y,a,"GeneratorFunction"),u(m),u(m,a,"Generator"),u(m,i,(function(){return this})),u(m,"toString",(function(){return"[object Generator]"})),(c=function(){return{w:r,m:f}})()}function u(e,t,n,i){var a=Object.defineProperty;try{a({},"",{})}catch(e){a=0}u=function(e,t,n,i){if(t)a?a(e,t,{value:n,enumerable:!i,configurable:!i,writable:!i}):e[t]=n;else{var r=function(t,n){u(e,t,(function(e){return this._invoke(t,n,e)}))};r("next",0),r("throw",1),r("return",2)}},u(e,t,n,i)}function l(e,t,n,i,a,r,o){try{var s=e[r](o),c=s.value}catch(e){return void n(e)}s.done?t(c):Promise.resolve(c).then(i,a)}function y(e){return function(){var t=this,n=arguments;return new Promise((function(i,a){var r=e.apply(t,n);function o(e){l(r,i,a,o,s,"next",e)}function s(e){l(r,i,a,o,s,"throw",e)}o(void 0)}))}}function d(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,m(i.key),i)}}function m(e){var t=function(e){if("object"!=s(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=s(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==s(t)?t:t+""}var f=function(){return e=function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.manager=null,this.timeSyncCore=null,this.syncEnabled=!1,this.playbackDiffMillis=0,this.syncAttempts=0,this.lastSyncTime=new Date,this.playerIsBuffering=!1,this.lastCommand=null,this.scheduledCommandTimeout=null,this.syncTimeout=null,this.loadPreferences()},t=[{key:"init",value:function(e){var t=this;this.manager=e,this.timeSyncCore=e.getTimeSyncCore(),i.A.on(this.manager,"settings-update",(function(){t.loadPreferences()}))}},{key:"loadPreferences",value:function(){this.minDelaySpeedToSync=(0,a.SP)((0,o.getSetting)("minDelaySpeedToSync"),60),this.maxDelaySpeedToSync=(0,a.SP)((0,o.getSetting)("maxDelaySpeedToSync"),3e3),this.speedToSyncDuration=(0,a.SP)((0,o.getSetting)("speedToSyncDuration"),1e3),this.minDelaySkipToSync=(0,a.SP)((0,o.getSetting)("minDelaySkipToSync"),400),this.useSpeedToSync=(0,a.G4)((0,o.getSetting)("useSpeedToSync"),!0),this.useSkipToSync=(0,a.G4)((0,o.getSetting)("useSkipToSync"),!0),this.enableSyncCorrection=(0,a.G4)((0,o.getSetting)("enableSyncCorrection"),!1)}},{key:"onPlaybackStart",value:function(e,t){i.A.trigger(this.manager,"playbackstart",[e,t])}},{key:"onPlaybackStop",value:function(e){this.lastCommand=null,i.A.trigger(this.manager,"playbackstop",[e])}},{key:"onUnpause",value:function(){i.A.trigger(this.manager,"unpause")}},{key:"onPause",value:function(){i.A.trigger(this.manager,"pause")}},{key:"onTimeUpdate",value:function(e,t){this.syncPlaybackTime(t),i.A.trigger(this.manager,"timeupdate",[e,t])}},{key:"onReady",value:function(){this.playerIsBuffering=!1,this.sendBufferingRequest(!1),i.A.trigger(this.manager,"ready")}},{key:"onBuffering",value:function(){this.playerIsBuffering=!0,this.sendBufferingRequest(!0),i.A.trigger(this.manager,"buffering")}},{key:"sendBufferingRequest",value:(u=y(c().m((function e(){var t,n,i,a,o,s,u,l,y,d,m,f=arguments;return c().w((function(e){for(;;)switch(e.n){case 0:if(t=!(f.length>0&&void 0!==f[0])||f[0],!(n=this.manager.getPlayerWrapper()).currentTimeAsync){e.n=2;break}return e.n=1,n.currentTimeAsync();case 1:m=e.v,e.n=3;break;case 2:m=n.currentTime();case 3:i=m,a=Math.round(i*r.TicksPerMillisecond),o=n.isPlaying(),s=new Date,u=this.timeSyncCore.localDateToRemote(s),l=this.manager.getQueueCore().getCurrentPlaylistItemId(),y={When:u.toISOString(),PositionTicks:a,IsPlaying:o,PlaylistItemId:l},d=this.manager.getApiClient(),t?d.requestSyncPlayBuffering(y):d.requestSyncPlayReady(y);case 4:return e.a(2)}}),e,this)}))),function(){return u.apply(this,arguments)})},{key:"isBuffering",value:function(){return this.playerIsBuffering}},{key:"applyCommand",value:(s=y(c().m((function e(t){var n,i,a,o,s,u,l,y,d,m,f,h;return c().w((function(e){for(;;)switch(e.n){case 0:if(!this.lastCommand||this.lastCommand.When.getTime()!==t.When.getTime()||this.lastCommand.PositionTicks!==t.PositionTicks||this.lastCommand.Command!==t.Command||this.lastCommand.PlaylistItemId!==t.PlaylistItemId){e.n=11;break}if(console.debug("SyncPlay applyCommand: duplicate command received!",t),n=new Date,!(this.timeSyncCore.remoteDateToLocal(t.When)>n)){e.n=1;break}return console.debug("SyncPlay applyCommand: command already scheduled.",t),e.a(2);case 1:if(i=this.manager.getPlayerWrapper(),u=Math,!i.currentTimeAsync){e.n=3;break}return e.n=2,i.currentTimeAsync();case 2:l=e.v,e.n=4;break;case 3:l=i.currentTime();case 4:y=l,d=r.TicksPerMillisecond,m=y*d,a=u.round.call(u,m),o=i.isPlaying(),f=t.Command,e.n="Unpause"===f?5:"Pause"===f?6:"Stop"===f?7:"Seek"===f?8:9;break;case 5:return o||this.scheduleUnpause(t.When,t.PositionTicks),e.a(3,10);case 6:return(o||a!==t.PositionTicks)&&this.schedulePause(t.When,t.PositionTicks),e.a(3,10);case 7:return o&&this.scheduleStop(t.When),e.a(3,10);case 8:return o||a!==t.PositionTicks?(s=Math.round(100*(Math.random()-.5))*r.TicksPerMillisecond,this.scheduleSeek(t.When,t.PositionTicks+s),console.debug("SyncPlay applyCommand: adding random offset to force seek:",s,t)):this.sendBufferingRequest(!1),e.a(3,10);case 9:return console.error("SyncPlay applyCommand: command is not recognised:",t),e.a(3,10);case 10:return e.a(2);case 11:if(this.lastCommand=t,!this.manager.isRemote()){e.n=12;break}return e.a(2);case 12:h=t.Command,e.n="Unpause"===h?13:"Pause"===h?14:"Stop"===h?15:"Seek"===h?16:17;break;case 13:return this.scheduleUnpause(t.When,t.PositionTicks),e.a(3,18);case 14:return this.schedulePause(t.When,t.PositionTicks),e.a(3,18);case 15:return this.scheduleStop(t.When),e.a(3,18);case 16:return this.scheduleSeek(t.When,t.PositionTicks),e.a(3,18);case 17:return console.error("SyncPlay applyCommand: command is not recognised:",t),e.a(3,18);case 18:return e.a(2)}}),e,this)}))),function(e){return s.apply(this,arguments)})},{key:"scheduleUnpause",value:(n=y(c().m((function e(t,n){var a,o,s,u,l,y,d,m,f,h,p=this;return c().w((function(e){for(;;)switch(e.n){case 0:if(this.clearScheduledCommand(),a=this.maxDelaySpeedToSync/2,o=new Date,s=this.timeSyncCore.remoteDateToLocal(t),!(u=this.manager.getPlayerWrapper()).currentTimeAsync){e.n=2;break}return e.n=1,u.currentTimeAsync();case 1:m=e.v,e.n=3;break;case 2:m=u.currentTime();case 3:f=m,h=r.TicksPerMillisecond,l=f*h,s>o?(y=s-o,l-n>this.minDelaySkipToSync*r.TicksPerMillisecond&&this.localSeek(n),this.scheduledCommandTimeout=setTimeout((function(){p.localUnpause(),i.A.trigger(p.manager,"notify-osd",["unpause"]),p.syncTimeout=setTimeout((function(){p.syncEnabled=!0}),a)}),y),console.debug("Scheduled unpause in",y/1e3,"seconds.")):(d=this.estimateCurrentTicks(n,t),r.waitForEventOnce(this.manager,"unpause").then((function(){p.localSeek(d)})),this.localUnpause(),setTimeout((function(){i.A.trigger(p.manager,"notify-osd",["unpause"])}),100),this.syncTimeout=setTimeout((function(){p.syncEnabled=!0}),a),console.debug("SyncPlay scheduleUnpause: unpause now from ".concat(d," (was at ").concat(l,").")));case 4:return e.a(2)}}),e,this)}))),function(e,t){return n.apply(this,arguments)})},{key:"schedulePause",value:function(e,t){var n=this;this.clearScheduledCommand();var i=new Date,a=this.timeSyncCore.remoteDateToLocal(e),o=function(){r.waitForEventOnce(n.manager,"pause",r.WaitForPlayerEventTimeout).then((function(){n.localSeek(t)})).catch((function(){n.localSeek(t)})),n.localPause()};if(a>i){var s=a-i;this.scheduledCommandTimeout=setTimeout(o,s),console.debug("Scheduled pause in",s/1e3,"seconds.")}else o(),console.debug("SyncPlay schedulePause: now.")}},{key:"scheduleStop",value:function(e){var t=this;this.clearScheduledCommand();var n=new Date,i=this.timeSyncCore.remoteDateToLocal(e),a=function(){t.localStop()};if(i>n){var r=i-n;this.scheduledCommandTimeout=setTimeout(a,r),console.debug("Scheduled stop in",r/1e3,"seconds.")}else a(),console.debug("SyncPlay scheduleStop: now.")}},{key:"scheduleSeek",value:function(e,t){var n=this;this.clearScheduledCommand();var i=new Date,a=this.timeSyncCore.remoteDateToLocal(e),o=function(){n.localUnpause(),n.localSeek(t),r.waitForEventOnce(n.manager,"ready",r.WaitForEventDefaultTimeout).then((function(){n.localPause(),n.sendBufferingRequest(!1)})).catch((function(e){console.error("Timed out while waiting for 'ready' event! Seeking to ".concat(t,"."),e),n.localSeek(t)}))};if(a>i){var s=a-i;this.scheduledCommandTimeout=setTimeout(o,s),console.debug("Scheduled seek in",s/1e3,"seconds.")}else o(),console.debug("SyncPlay scheduleSeek: now.")}},{key:"clearScheduledCommand",value:function(){clearTimeout(this.scheduledCommandTimeout),clearTimeout(this.syncTimeout),this.syncEnabled=!1;var e=this.manager.getPlayerWrapper();e.hasPlaybackRate()&&e.setPlaybackRate(1),this.manager.clearSyncIcon()}},{key:"localUnpause",value:function(){if(this.manager.isPlaybackActive())return this.manager.getPlayerWrapper().localUnpause();console.debug("SyncPlay localUnpause: no active player!")}},{key:"localPause",value:function(){if(this.manager.isPlaybackActive())return this.manager.getPlayerWrapper().localPause();console.debug("SyncPlay localPause: no active player!")}},{key:"localSeek",value:function(e){if(this.manager.isPlaybackActive())return this.manager.getPlayerWrapper().localSeek(e);console.debug("SyncPlay localSeek: no active player!")}},{key:"localStop",value:function(){if(this.manager.isPlaybackActive())return this.manager.getPlayerWrapper().localStop();console.debug("SyncPlay localStop: no active player!")}},{key:"estimateCurrentTicks",value:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:new Date;return e+(this.timeSyncCore.localDateToRemote(n).getTime()-t.getTime())*r.TicksPerMillisecond}},{key:"syncPlaybackTime",value:function(e){var t=this,n=this.maxDelaySpeedToSync,a=this.speedToSyncDuration;if(this.manager.isPlaybackActive()){var o=this.lastCommand;if(o&&"Unpause"===o.Command&&!this.isBuffering()){var s=this.manager.getQueueCore().getCurrentPlaylistItemId();if(o.PlaylistItemId===s){var c=e.currentTime,u=e.currentPosition*r.TicksPerMillisecond,l=this.estimateCurrentTicks(o.PositionTicks,o.When,c),y=(l-u)/r.TicksPerMillisecond;if(this.playbackDiffMillis=y,i.A.trigger(this.manager,"playback-diff",[this.playbackDiffMillis]),!(c-this.lastSyncTime<n/2)){this.lastSyncTime=c;var d=this.manager.getPlayerWrapper();if(this.syncEnabled&&this.enableSyncCorrection){var m=Math.abs(y);if(d.hasPlaybackRate()&&this.useSpeedToSync&&m>=this.minDelaySpeedToSync&&m<this.maxDelaySpeedToSync){y<=.2*-a&&(a=Math.abs(y)/.8);var f=1+y/a;f<=0&&console.error("SyncPlay error: speed should not be negative!",f,y,a),d.setPlaybackRate(f),this.syncEnabled=!1,this.syncAttempts++,this.manager.showSyncIcon("SpeedToSync (x".concat(f.toFixed(2),")")),this.syncTimeout=setTimeout((function(){d.setPlaybackRate(1),t.syncEnabled=!0,t.manager.clearSyncIcon()}),a),console.log("SyncPlay SpeedToSync",f)}else this.useSkipToSync&&m>=this.minDelaySkipToSync?(this.localSeek(l),this.syncEnabled=!1,this.syncAttempts++,this.manager.showSyncIcon("SkipToSync (".concat(this.syncAttempts,")")),this.syncTimeout=setTimeout((function(){t.syncEnabled=!0,t.manager.clearSyncIcon()}),n/2),console.log("SyncPlay SkipToSync",l)):(this.syncAttempts>0&&console.debug("Playback has been synced after",this.syncAttempts,"attempts."),this.syncAttempts=0)}}}}}else console.debug("SyncPlay syncPlaybackTime: no active player!")}}],t&&d(e.prototype,t),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,n,s,u}();t.default=f},4438:function(e,t,n){n.r(t),n.d(t,{getSetting:function(){return r},setSetting:function(){return o}});var i=n(90381),a="syncPlay";function r(e){return i.A.get(e,a)}function o(e,t){return i.A.set(e,t,a)}},20919:function(e,t,n){n.r(t),n.d(t,{TicksPerMillisecond:function(){return s},WaitForEventDefaultTimeout:function(){return r},WaitForPlayerEventTimeout:function(){return o},getItemsForPlayback:function(){return l},stringToGuid:function(){return u},translateItemsForPlayback:function(){return y},waitForEventOnce:function(){return c}}),n(14382),n(84734),n(86584),n(26448),n(77575),n(78557),n(90076),n(95021),n(93062),n(23630);var i=n(44797),a=n(2290),r=3e4,o=500,s=1e4;function c(e,t,n,a){var r=arguments;return new Promise((function(o,s){var c;n&&(c=setTimeout((function(){s(new Error("Timed out."))}),n));var u=function(){i.A.off(e,t,l),c&&clearTimeout(c),Array.isArray(a)&&a.forEach((function(t){i.A.off(e,t,y)}))},l=function(){u(),o(r)},y=function(e){u(),s(e.type)};i.A.on(e,t,l),Array.isArray(a)&&a.forEach((function(t){i.A.on(e,t,y)}))}))}function u(e){return e.replace(/([0-z]{8})([0-z]{4})([0-z]{4})([0-z]{4})([0-z]{12})/,"$1-$2-$3-$4-$5")}function l(e,t){if(t.Ids&&1===t.Ids.split(",").length){var n=t.Ids.split(",");return e.getItem(e.getCurrentUserId(),n).then((function(e){return{Items:[e]}}))}return t.Limit=t.Limit||300,t.Fields=["Chapters","Trickplay"],t.ExcludeLocationTypes="Virtual",t.EnableTotalRecordCount=!1,t.CollapseBoxSetItems=!1,(0,a.J)(e,e.getCurrentUserId(),t)}function y(e,t,n){t.length>1&&null!=n&&n.ids&&t.sort((function(e,t){return n.ids.indexOf(e.Id)-n.ids.indexOf(t.Id)}));var i,a,r,o,s,c=t[0],u=n.queryOptions||{};if("Program"===c.Type)i=l(e,{Ids:c.ChannelId});else if("Playlist"===c.Type)i=l(e,{ParentId:c.Id,SortBy:n.shuffle?"Random":null});else if("MusicArtist"===c.Type)i=l(e,{ArtistIds:c.Id,Filters:"IsNotFolder",Recursive:!0,SortBy:n.shuffle?"Random":"SortName",MediaTypes:"Audio"});else if("Photo"===c.MediaType)i=l(e,{ParentId:c.ParentId,Filters:"IsNotFolder",Recursive:!1,SortBy:n.shuffle?"Random":"SortName",MediaTypes:"Photo,Video"}).then((function(e){var t=e.Items.map((function(e){return e.Id})).indexOf(c.Id);return-1===t&&(t=0),n.startIndex=t,Promise.resolve(e)}));else if("PhotoAlbum"===c.Type)i=l(e,{ParentId:c.Id,Filters:"IsNotFolder",Recursive:!1,SortBy:n.shuffle?"Random":"SortName",MediaTypes:"Photo,Video",Limit:1e3});else if("MusicGenre"===c.Type)i=l(e,{GenreIds:c.Id,Filters:"IsNotFolder",Recursive:!0,SortBy:n.shuffle?"Random":"SortName",MediaTypes:"Audio"});else if(c.IsFolder){var y=null;n.shuffle?y="Random":"BoxSet"===c.Type&&(y="SortName"),i=l(e,(a={ParentId:c.Id,Filters:"IsNotFolder",Recursive:!0,SortBy:y,MediaTypes:"Audio,Video"},r=u,-1===(s=(o=Object.assign(a,r)).Filters?o.Filters.split(","):[]).indexOf("IsNotFolder")&&s.push("IsNotFolder"),o.Filters=s.join(","),o))}else"Episode"===c.Type&&1===t.length&&(i=new Promise((function(t,n){e.getCurrentUser().then((function(i){i.Configuration.EnableNextEpisodeAutoPlay&&c.SeriesId?e.getEpisodes(c.SeriesId,{IsVirtualUnaired:!1,IsMissing:!1,UserId:e.getCurrentUserId(),Fields:["Chapters","Trickplay"]}).then((function(e){var n=!1;e.Items=e.Items.filter((function(e){return!!n||e.Id===c.Id&&(n=!0,!0)})),e.TotalRecordCount=e.Items.length,t(e)}),n):t(null)}))})));return i?i.then((function(e){return e?e.Items:t})):Promise.resolve(t)}}}]);