Save watch progress when closing window (#1217)
This commit is contained in:
		
							parent
							
								
									5f4ea74c16
								
							
						
					
					
						commit
						c8d96d38b6
					
				|  | @ -32,6 +32,7 @@ export default Vue.extend({ | ||||||
|   }, |   }, | ||||||
|   beforeRouteLeave: function (to, from, next) { |   beforeRouteLeave: function (to, from, next) { | ||||||
|     this.handleRouteChange() |     this.handleRouteChange() | ||||||
|  |     window.removeEventListener('beforeunload', this.handleWatchProgress) | ||||||
|     next() |     next() | ||||||
|   }, |   }, | ||||||
|   data: function() { |   data: function() { | ||||||
|  | @ -195,6 +196,8 @@ export default Vue.extend({ | ||||||
|           break |           break | ||||||
|       } |       } | ||||||
|     } |     } | ||||||
|  | 
 | ||||||
|  |     window.addEventListener('beforeunload', this.handleWatchProgress) | ||||||
|   }, |   }, | ||||||
|   methods: { |   methods: { | ||||||
|     changeTimestamp: function(timestamp) { |     changeTimestamp: function(timestamp) { | ||||||
|  | @ -688,6 +691,21 @@ export default Vue.extend({ | ||||||
|       this.updateHistory(videoData) |       this.updateHistory(videoData) | ||||||
|     }, |     }, | ||||||
| 
 | 
 | ||||||
|  |     handleWatchProgress: function () { | ||||||
|  |       if (this.rememberHistory && !this.isUpcoming && !this.isLoading && !this.isLive) { | ||||||
|  |         const player = this.$refs.videoPlayer.player | ||||||
|  | 
 | ||||||
|  |         if (player !== null && this.saveWatchedProgress) { | ||||||
|  |           const currentTime = this.getWatchedProgress() | ||||||
|  |           const payload = { | ||||||
|  |             videoId: this.videoId, | ||||||
|  |             watchProgress: currentTime | ||||||
|  |           } | ||||||
|  |           this.updateWatchProgress(payload) | ||||||
|  |         } | ||||||
|  |       } | ||||||
|  |     }, | ||||||
|  | 
 | ||||||
|     checkIfWatched: function () { |     checkIfWatched: function () { | ||||||
|       const historyIndex = this.historyCache.findIndex((video) => { |       const historyIndex = this.historyCache.findIndex((video) => { | ||||||
|         return video.videoId === this.videoId |         return video.videoId === this.videoId | ||||||
|  | @ -900,18 +918,7 @@ export default Vue.extend({ | ||||||
|     handleRouteChange: function () { |     handleRouteChange: function () { | ||||||
|       clearTimeout(this.playNextTimeout) |       clearTimeout(this.playNextTimeout) | ||||||
| 
 | 
 | ||||||
|       if (this.rememberHistory && !this.isUpcoming && !this.isLoading && !this.isLive) { |       this.handleWatchProgress() | ||||||
|         const player = this.$refs.videoPlayer.player |  | ||||||
| 
 |  | ||||||
|         if (player !== null && this.saveWatchedProgress) { |  | ||||||
|           const currentTime = this.getWatchedProgress() |  | ||||||
|           const payload = { |  | ||||||
|             videoId: this.videoId, |  | ||||||
|             watchProgress: currentTime |  | ||||||
|           } |  | ||||||
|           this.updateWatchProgress(payload) |  | ||||||
|         } |  | ||||||
|       } |  | ||||||
| 
 | 
 | ||||||
|       if (!this.isUpcoming && !this.isLoading) { |       if (!this.isUpcoming && !this.isLoading) { | ||||||
|         const player = this.$refs.videoPlayer.player |         const player = this.$refs.videoPlayer.player | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue