1 import { Injectable } from '@angular/core'
4 export class ScreenService {
5 private windowInnerWidth: number
6 private lastFunctionCallTime: number
7 private cacheForMs = 500
10 this.refreshWindowInnerWidth()
14 return this.getWindowInnerWidth() < 800
18 return this.getWindowInnerWidth() < 1100
22 return this.getWindowInnerWidth() < 500
26 return 'ontouchstart' in window || navigator.msMaxTouchPoints
29 getNumberOfAvailableMiniatures () {
30 const screenWidth = this.getWindowInnerWidth()
32 let numberOfVideos = 1
34 if (screenWidth > 1850) numberOfVideos = 6
35 else if (screenWidth > 1600) numberOfVideos = 5
36 else if (screenWidth > 1370) numberOfVideos = 4
37 else if (screenWidth > 1100) numberOfVideos = 3
38 else if (screenWidth > 850) numberOfVideos = 2
43 // Cache window inner width, because it's an expensive call
44 getWindowInnerWidth () {
45 if (this.cacheWindowInnerWidthExpired()) this.refreshWindowInnerWidth()
47 return this.windowInnerWidth
50 private refreshWindowInnerWidth () {
51 this.lastFunctionCallTime = new Date().getTime()
53 this.windowInnerWidth = window.innerWidth
56 private cacheWindowInnerWidthExpired () {
57 if (!this.lastFunctionCallTime) return true
59 return new Date().getTime() > (this.lastFunctionCallTime + this.cacheForMs)