jam-cloud/web/app/assets/javascripts/client_init.js.coffee

45 lines
1.1 KiB
CoffeeScript

# one time init stuff for the /client view
$ = jQuery
context = window
context.JK ||= {};
broadcastActions = @BroadcastActions
logger = context.JK.logger
context.JK.ClientInit = class ClientInit
constructor: () ->
@gearUtils = context.JK.GearUtils
@ALERT_NAMES = context.JK.ALERT_NAMES;
@lastCheckedBroadcast = null
init: () =>
if context.gon.isNativeClient
this.nativeClientInit()
context.JK.onBackendEvent(@ALERT_NAMES.WINDOW_OPEN_FOREGROUND_MODE, 'client_init', @watchBroadcast);
this.watchBroadcast()
checkBroadcast: () =>
promise = broadcastActions.load.trigger()
if promise
promise.catch(() ->
false
)
watchBroadcast: () =>
if context.JK.currentUserId
# create a 15 second buffer to not check too fast for some reason (like the client firing multiple foreground events)
if !@lastCheckedBroadcast? || @lastCheckedBroadcast.getTime() < new Date().getTime() - 15000
@lastCheckedBroadcast = new Date()
setTimeout(@checkBroadcast, 3000)
nativeClientInit: () =>
@gearUtils.bootstrapDefaultPlaybackProfile();
window.VideoActions.checkPromptConfigureVideo()