// Includes code that should be run on every single page of the site // !!!! Keep white space after last require !!!! // //= require fakeJamClient //= require fakeJamClientMessages //= require fakeJamClientRecordings //= require backend_alerts //= require stun //= requre influxdb-latest (function (context, $) { "use strict"; context.JK = context.JK || {}; var ALERT_NAMES = context.JK.ALERT_NAMES; var logger = context.JK.logger; var stun = null; $(document).on('JAMKAZAM_CONSTRUCTED', function(e, data) { var app = data.app; if(!app) throw "app not found"; // makes window.jamClient / context.jamClient set to something non-null very early on context.JK.initJamClient(app); updateScoringIntervals(); initializeInfluxDB(); }) $(document).on('JAMKAZAM_READY', function() { // this event is fired when context.app is initialized var app = context.JK.app; if(!app) throw "app not found" initializeDialogs(app); checkAudioStopped(); checkMacOSXInstalledCorrectly(); watchPreferencesEvent(app); initializeStun(app); operationalEvents(app); handleGettingStarted(app); }); function watchPreferencesEvent(app) { context.JK.onBackendEvent(ALERT_NAMES.SHOW_PREFERENCES, 'everywhere', function() { app.layout.showDialog('client-preferences-dialog') }); } function checkMacOSXInstalledCorrectly() { var os = context.jamClient.GetOSAsString(); // check if method exists at all for migration purposes if(context.jamClient.IsAppInWritableVolume && os == "MacOSX" && !context.jamClient.IsAppInWritableVolume()) { context.JK.Banner.showAlert( { title: "Drag JamKazam to the Applications Folder!", buttons: [{name: 'SHUTDOWN APPLICATION', click: function() {context.jamClient.ShutdownApplication()}} ], html: $('#template-app-in-read-only-volume').html()}); return; } } function initializeDialogs(app) { var backendAlerts = new JK.BackendAlerts(app); backendAlerts.initialize(); JK.Banner.initialize(); var shutdownDialog = new JK.ShutdownDialog(app); shutdownDialog.initialize(); var googleHelper = new JK.GoogleHelper(app); JK.GoogleHelperInstance = googleHelper; googleHelper.initialize(); var twitterHelper = new JK.TwitterHelper(app); JK.TwitterHelperInstance = twitterHelper; twitterHelper.initialize(gon.global.twitter_public_account); var facebookHelper = new JK.FacebookHelper(app); JK.FacebookHelperInstance = facebookHelper; facebookHelper.initialize(gon.global.facebook_app_id); var invitationDialog = new JK.InvitationDialog(app); JK.InvitationDialogInstance = invitationDialog; invitationDialog.initialize(facebookHelper); var textMessageDialog = new JK.TextMessageDialog(app); JK.TextMessageDialogInstance = textMessageDialog; textMessageDialog.initialize(); var friendSelectorDialog = new JK.FriendSelectorDialog(app); JK.FriendSelectorDialogInstance = friendSelectorDialog; friendSelectorDialog.initialize(); var launchAppDialog = new JK.LaunchAppDialog(app); launchAppDialog.initialize(); var userDropdown = new JK.UserDropdown(app); JK.UserDropdown = userDropdown; userDropdown.initialize(invitationDialog); var gettingStartedDialog = new JK.GettingStartedDialog(app); gettingStartedDialog.initialize(invitationDialog); var joinTestSessionDialog = new JK.JoinTestSessionDialog(app); joinTestSessionDialog.initialize(); var videoDialog = new JK.VideoDialog(app); videoDialog.initialize(); var clientPreferencesDialog = new JK.ClientPreferencesDialog(app); clientPreferencesDialog.initialize(); } // wait 10 seconds function checkAudioStopped() { if(context.jamClient.ResetPageCounters) { // upgrade concern context.jamClient.ResetPageCounters(); context.JK.AudioStopTimeout = setTimeout(function() { if(context.jamClient.IsAudioStarted()) { logger.debug("checkAudioStopped: stopping audio ...") context.jamClient.StopAudio(); } }, 10000); } } function updateScoringIntervals() { if(context.jamClient.SetLatencyTestBlocked) { // make sure latency testing is still going on, in case a refresh occurred during network test context.jamClient.SetLatencyTestBlocked(false) } // set scoring intervals if(context.jamClient.SetScoreWorkTimingInterval){ var success = context.jamClient.SetScoreWorkTimingInterval( { interval: gon.global.scoring_get_work_interval, backoff: gon.global.scoring_get_work_backoff_interval }) if(!success) logger.warning("unable to set scoring intervals") } } function initializeInfluxDB() { context.stats = new InfluxDB({ "host" : gon.global.influxdb_host, "port" : gon.global.influxdb_port, "username" : gon.global.influxdb_username, "password" : gon.global.influxdb_password, "database" : gon.global.influxdb_database }); context.stats.write = context.stats.write_point; } function initializeStun(app) { stun = new context.JK.Stun(app); context.JK.StunInstance = stun; stun.initialize(); } function operationalEvents(app) { if(!JK.JamServer || !JK.JamServer.registerMessageCallback) {return;} //no websocket means no events JK.JamServer.registerMessageCallback(JK.MessageType.RELOAD, function(header, payload) { window.location.reload(); }); JK.JamServer.registerMessageCallback(JK.MessageType.RESTART_APPLICATION, function(header, payload) { context.jamClient.RestartApplication(); }); JK.JamServer.registerMessageCallback(JK.MessageType.STOP_APPLICATION, function(header, payload) { context.jamClient.ShutdownApplication(); }); } function handleGettingStarted(app) { app.user() .done(function(userProfile) { if (userProfile.show_whats_next && window.location.pathname.indexOf(gon.client_path) == 0 && !app.layout.isDialogShowing('getting-started')) { app.layout.showDialog('getting-started'); } }) } })(window, jQuery);