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() < 500
22 return 'ontouchstart' in window || navigator.msMaxTouchPoints
25 getNumberOfAvailableMiniatures () {
26 const screenWidth = this.getWindowInnerWidth()
28 let numberOfVideos = 1
30 if (screenWidth > 1850) numberOfVideos = 6
31 else if (screenWidth > 1600) numberOfVideos = 5
32 else if (screenWidth > 1370) numberOfVideos = 4
33 else if (screenWidth > 1100) numberOfVideos = 3
34 else if (screenWidth > 850) numberOfVideos = 2
39 // Cache window inner width, because it's an expensive call
40 getWindowInnerWidth () {
41 if (this.cacheWindowInnerWidthExpired()) this.refreshWindowInnerWidth()
43 return this.windowInnerWidth
46 private refreshWindowInnerWidth () {
47 this.lastFunctionCallTime = new Date().getTime()
49 this.windowInnerWidth = window.innerWidth
52 private cacheWindowInnerWidthExpired () {
53 if (!this.lastFunctionCallTime) return true
55 return new Date().getTime() > (this.lastFunctionCallTime + this.cacheForMs)