2014-07-09 19:10:42 +00:00
|
|
|
// Includes code that should be run on every single page of the site
|
2014-07-09 22:20:20 +00:00
|
|
|
// !!!! Keep white space after last require !!!!
|
|
|
|
|
//
|
|
|
|
|
//= require fakeJamClient
|
|
|
|
|
//= require fakeJamClientMessages
|
|
|
|
|
//= require fakeJamClientRecordings
|
|
|
|
|
//= require backend_alerts
|
2014-09-13 03:30:51 +00:00
|
|
|
//= require stun
|
2014-12-31 03:06:56 +00:00
|
|
|
//= require influxdb-latest
|
2015-02-23 23:30:06 +00:00
|
|
|
//= require jam_track_utils
|
2016-07-17 15:16:27 +00:00
|
|
|
//= require bridge
|
|
|
|
|
//= require bridge_api
|
|
|
|
|
|
2014-07-09 19:10:42 +00:00
|
|
|
|
|
|
|
|
(function (context, $) {
|
|
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
|
|
context.JK = context.JK || {};
|
|
|
|
|
|
2014-08-29 02:11:25 +00:00
|
|
|
var ALERT_NAMES = context.JK.ALERT_NAMES;
|
2014-09-13 03:30:51 +00:00
|
|
|
var logger = context.JK.logger;
|
|
|
|
|
var stun = null;
|
2015-02-23 21:55:02 +00:00
|
|
|
var rest = context.JK.Rest();
|
2014-08-29 02:11:25 +00:00
|
|
|
|
2015-05-28 16:10:50 +00:00
|
|
|
if(gon.global.web_performance_timing_enabled) {
|
|
|
|
|
$(window).on('load', sendTimingResults)
|
|
|
|
|
$(window).on('pagehide', setNavigationStart)
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-14 19:12:24 +00:00
|
|
|
|
2014-08-29 02:11:25 +00:00
|
|
|
$(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);
|
2014-09-13 03:30:51 +00:00
|
|
|
|
|
|
|
|
updateScoringIntervals();
|
2014-12-30 23:10:16 +00:00
|
|
|
|
|
|
|
|
initializeInfluxDB();
|
2015-04-14 19:12:24 +00:00
|
|
|
|
|
|
|
|
trackNewUser();
|
2016-01-14 10:49:02 +00:00
|
|
|
|
|
|
|
|
trackScreenChanges();
|
2016-01-19 00:41:53 +00:00
|
|
|
|
2018-02-15 04:16:32 +00:00
|
|
|
setTimezone()
|
2014-08-29 02:11:25 +00:00
|
|
|
})
|
|
|
|
|
|
2018-02-15 04:16:32 +00:00
|
|
|
function setTimezone() {
|
|
|
|
|
$.cookie("browser.timezone", window.jstz.determine().name(), { expires: 365, path: '/' });
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-29 02:11:25 +00:00
|
|
|
$(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();
|
|
|
|
|
|
2014-09-13 03:30:51 +00:00
|
|
|
checkMacOSXInstalledCorrectly();
|
|
|
|
|
|
2014-09-15 12:45:17 +00:00
|
|
|
watchPreferencesEvent(app);
|
2014-09-13 03:30:51 +00:00
|
|
|
|
2017-06-26 17:10:58 +00:00
|
|
|
watchNetworkTestEvent(app);
|
|
|
|
|
|
2014-09-13 03:30:51 +00:00
|
|
|
initializeStun(app);
|
2014-08-31 15:30:59 +00:00
|
|
|
|
2014-09-13 03:30:51 +00:00
|
|
|
operationalEvents(app);
|
2014-09-22 19:20:58 +00:00
|
|
|
|
|
|
|
|
handleGettingStarted(app);
|
2015-02-23 22:00:30 +00:00
|
|
|
|
|
|
|
|
initShoppingCart(app);
|
2014-09-13 03:30:51 +00:00
|
|
|
});
|
|
|
|
|
|
2014-09-15 12:45:17 +00:00
|
|
|
function watchPreferencesEvent(app) {
|
2014-08-29 02:11:25 +00:00
|
|
|
context.JK.onBackendEvent(ALERT_NAMES.SHOW_PREFERENCES, 'everywhere', function() {
|
|
|
|
|
app.layout.showDialog('client-preferences-dialog')
|
|
|
|
|
});
|
2014-09-13 03:30:51 +00:00
|
|
|
}
|
2014-07-09 19:10:42 +00:00
|
|
|
|
2017-06-26 17:10:58 +00:00
|
|
|
function watchNetworkTestEvent(app) {
|
|
|
|
|
context.JK.onBackendEvent(ALERT_NAMES.SHOW_NETWORK_TEST, 'everywhere', function() {
|
|
|
|
|
app.layout.showDialog('network-test')
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-31 15:30:59 +00:00
|
|
|
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(
|
2014-08-31 16:57:59 +00:00
|
|
|
{ title: "Drag JamKazam to the Applications Folder!",
|
2014-08-31 15:30:59 +00:00
|
|
|
buttons: [{name: 'SHUTDOWN APPLICATION', click: function() {context.jamClient.ShutdownApplication()}} ],
|
|
|
|
|
html: $('#template-app-in-read-only-volume').html()});
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-09 22:20:20 +00:00
|
|
|
function initializeDialogs(app) {
|
|
|
|
|
|
2018-02-15 04:16:32 +00:00
|
|
|
if(!JK.Banner) {
|
|
|
|
|
// we don't use dialogs everywhere (yes, ugly)
|
|
|
|
|
return
|
|
|
|
|
}
|
2014-07-09 22:20:20 +00:00
|
|
|
var backendAlerts = new JK.BackendAlerts(app);
|
|
|
|
|
backendAlerts.initialize();
|
2014-07-09 19:10:42 +00:00
|
|
|
|
2014-07-09 22:20:20 +00:00
|
|
|
JK.Banner.initialize();
|
2014-07-09 19:10:42 +00:00
|
|
|
|
|
|
|
|
var shutdownDialog = new JK.ShutdownDialog(app);
|
|
|
|
|
shutdownDialog.initialize();
|
2014-07-09 22:20:20 +00:00
|
|
|
|
2014-08-14 15:09:33 +00:00
|
|
|
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);
|
|
|
|
|
|
2014-07-09 22:20:20 +00:00
|
|
|
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);
|
|
|
|
|
|
2014-09-22 19:20:58 +00:00
|
|
|
var gettingStartedDialog = new JK.GettingStartedDialog(app);
|
|
|
|
|
gettingStartedDialog.initialize(invitationDialog);
|
|
|
|
|
|
|
|
|
|
var joinTestSessionDialog = new JK.JoinTestSessionDialog(app);
|
|
|
|
|
joinTestSessionDialog.initialize();
|
2014-07-09 22:20:20 +00:00
|
|
|
|
|
|
|
|
var videoDialog = new JK.VideoDialog(app);
|
|
|
|
|
videoDialog.initialize();
|
|
|
|
|
|
2014-08-29 02:11:25 +00:00
|
|
|
var clientPreferencesDialog = new JK.ClientPreferencesDialog(app);
|
|
|
|
|
clientPreferencesDialog.initialize();
|
2015-03-11 21:44:22 +00:00
|
|
|
|
|
|
|
|
var loginRequiredDialog = new JK.LoginRequiredDialog(app);
|
|
|
|
|
loginRequiredDialog.initialize();
|
2014-08-29 02:11:25 +00:00
|
|
|
}
|
2014-07-09 22:20:20 +00:00
|
|
|
|
2014-08-29 02:11:25 +00:00
|
|
|
// wait 10 seconds
|
|
|
|
|
function checkAudioStopped() {
|
2014-07-09 22:20:20 +00:00
|
|
|
|
2014-08-29 14:59:12 +00:00
|
|
|
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);
|
|
|
|
|
}
|
2014-08-29 02:11:25 +00:00
|
|
|
}
|
2014-07-09 22:20:20 +00:00
|
|
|
|
2014-09-13 03:30:51 +00:00
|
|
|
function updateScoringIntervals() {
|
2014-10-09 21:45:48 +00:00
|
|
|
if(context.jamClient.SetLatencyTestBlocked) {
|
|
|
|
|
// make sure latency testing is still going on, in case a refresh occurred during network test
|
|
|
|
|
context.jamClient.SetLatencyTestBlocked(false)
|
|
|
|
|
}
|
2014-10-06 21:44:30 +00:00
|
|
|
|
2014-09-13 03:30:51 +00:00
|
|
|
// 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")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-30 23:10:16 +00:00
|
|
|
function initializeInfluxDB() {
|
2016-09-13 03:25:13 +00:00
|
|
|
/**
|
2014-12-30 23:10:16 +00:00
|
|
|
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
|
|
|
|
|
});
|
|
|
|
|
|
2014-12-30 23:15:28 +00:00
|
|
|
context.stats.write = context.stats.writePoint;
|
2016-09-13 03:25:13 +00:00
|
|
|
*/
|
|
|
|
|
context.stats = {write:function() {}}
|
2014-12-30 23:10:16 +00:00
|
|
|
}
|
2015-10-19 18:42:39 +00:00
|
|
|
|
2014-09-13 03:30:51 +00:00
|
|
|
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();
|
|
|
|
|
});
|
2016-06-24 14:15:04 +00:00
|
|
|
|
2014-09-22 19:20:58 +00:00
|
|
|
}
|
2014-09-13 03:30:51 +00:00
|
|
|
|
2014-09-22 19:20:58 +00:00
|
|
|
function handleGettingStarted(app) {
|
2016-06-02 14:04:56 +00:00
|
|
|
/**
|
2015-01-06 23:14:33 +00:00
|
|
|
var user = app.user()
|
|
|
|
|
if(user) {
|
|
|
|
|
user.done(function(userProfile) {
|
2015-04-17 19:01:07 +00:00
|
|
|
if (!userProfile.show_jamtrack_guide && userProfile.show_whats_next && userProfile.show_whats_next_count < 10 &&
|
2015-01-06 23:14:33 +00:00
|
|
|
window.location.pathname.indexOf(gon.client_path) == 0 &&
|
2015-04-14 19:12:24 +00:00
|
|
|
window.location.hash.indexOf('/checkout') == -1 &&
|
2015-05-15 17:34:35 +00:00
|
|
|
window.location.hash.indexOf('/redeem') == -1 &&
|
2016-02-08 22:48:12 +00:00
|
|
|
window.location.hash.indexOf('/teachers/setup') == -1 &&
|
2015-01-06 23:14:33 +00:00
|
|
|
!app.layout.isDialogShowing('getting-started'))
|
|
|
|
|
{
|
|
|
|
|
app.layout.showDialog('getting-started');
|
|
|
|
|
}
|
|
|
|
|
})
|
2016-06-02 14:04:56 +00:00
|
|
|
}*/
|
2014-09-13 03:30:51 +00:00
|
|
|
}
|
|
|
|
|
|
2015-02-23 21:55:02 +00:00
|
|
|
function initShoppingCart(app) {
|
2015-03-20 13:48:00 +00:00
|
|
|
context.JK.JamTrackUtils.checkShoppingCart();
|
2015-02-23 21:55:02 +00:00
|
|
|
}
|
|
|
|
|
|
2015-04-14 19:12:24 +00:00
|
|
|
function trackNewUser() {
|
|
|
|
|
var cookie = $.cookie('new_user')
|
|
|
|
|
|
|
|
|
|
if(cookie) {
|
|
|
|
|
try {
|
|
|
|
|
cookie = JSON.parse(cookie)
|
|
|
|
|
|
2015-05-15 21:01:39 +00:00
|
|
|
context.JK.signupData = {}
|
|
|
|
|
context.JK.signupData = cookie
|
2015-04-16 02:37:22 +00:00
|
|
|
|
2015-04-14 19:12:24 +00:00
|
|
|
$(function() {
|
|
|
|
|
// ga() object isn't ready until the page is loaded
|
|
|
|
|
$.removeCookie('new_user')
|
|
|
|
|
context.JK.GA.trackRegister(cookie.musician, cookie.registrationType);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
catch(e) {
|
|
|
|
|
logger.error("unable to deserialize new_user cookie")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-14 10:49:02 +00:00
|
|
|
function trackScreenChanges() {
|
|
|
|
|
|
|
|
|
|
if (!window.olark) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-18 01:29:56 +00:00
|
|
|
var activate = ["jamtrack/search", "jamtrack/filter",
|
|
|
|
|
"shoppingCart", "checkoutPayment", "checkoutOrder", "redeemComplete", "checkoutComplete",
|
|
|
|
|
"teachers/setup/introduction", "teachers/setup/basics", "teachers/setup/experience", "teachers/setup/pricing",
|
|
|
|
|
"account/profile", "account/profile/experience", "account/profile/interests", "account/profile/samples",
|
2016-05-19 04:03:22 +00:00
|
|
|
"jamclass", "jamclass/searchOptions", "teachers/search", "profile/teacher", "jamclass/test-drive-selection", "jamclass/book-lesson"]
|
2016-01-14 10:49:02 +00:00
|
|
|
$(document).on(context.JK.EVENTS.SCREEN_CHANGED, function(e, data) {
|
|
|
|
|
|
|
|
|
|
var show = false;
|
|
|
|
|
|
|
|
|
|
if (data.newScreen && activate.indexOf(data.newScreen) > -1) {
|
|
|
|
|
show = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (show) {
|
2018-04-21 16:33:18 +00:00
|
|
|
if(window.olark) olark('api.box.show');
|
2016-01-14 10:49:02 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2018-04-21 16:33:18 +00:00
|
|
|
if(window.olark) olark('api.box.hide');
|
2016-01-14 10:49:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-28 15:34:07 +00:00
|
|
|
function setNavigationStart() {
|
|
|
|
|
if(!window.performance || !window.performance.timing) {
|
|
|
|
|
try {
|
|
|
|
|
window.sessionStorage.setItem('navigationStart', Date.now())
|
|
|
|
|
}
|
|
|
|
|
catch(e) {
|
|
|
|
|
logger.debug("unable to accesss sessionStorage")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// http://githubengineering.com/browser-monitoring-for-github-com/
|
|
|
|
|
function sendTimingResults() {
|
2015-05-28 16:10:50 +00:00
|
|
|
|
2015-05-28 15:34:07 +00:00
|
|
|
setTimeout(function() {
|
|
|
|
|
var timing;
|
|
|
|
|
var hasTimingApi;
|
|
|
|
|
|
|
|
|
|
if(window.performance && window.performance.timing) {
|
|
|
|
|
timing = window.performance.timing
|
|
|
|
|
hasTimingApi = true;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
timing = {}
|
|
|
|
|
hasTimingApi = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Merge in simulated cross-browser load event
|
|
|
|
|
timing['crossBrowserLoadEvent'] = Date.now()
|
|
|
|
|
|
|
|
|
|
var chromeFirstPaintTime;
|
|
|
|
|
if(window.chrome && window.chrome.loadTimes) {
|
|
|
|
|
var loadTimes = window.chrome.loadTimes()
|
|
|
|
|
if(loadTimes) {
|
|
|
|
|
chromeFirstPaintTime = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// firstPaintTime is in seconds; convert to milliseconds to match performance.timing.
|
|
|
|
|
timing['chromeFirstPaintTime'] = Math.round(chromeFirstPaintTime * 1000);
|
|
|
|
|
|
|
|
|
|
// Merge in simulated navigation start, if no navigation timing
|
|
|
|
|
if (!hasTimingApi) {
|
|
|
|
|
try {
|
|
|
|
|
var navStart = window.sessionStorage.getItem('navigationStart')
|
|
|
|
|
if(navStart) {
|
2015-05-28 16:10:50 +00:00
|
|
|
timing['navigationStart'] = parseInt(navStart, 10)
|
2015-05-28 15:34:07 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch(e) { }
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-28 16:10:50 +00:00
|
|
|
context.JK.GA.trackTiming(timing);
|
2015-05-28 15:34:07 +00:00
|
|
|
}, 0)
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-30 23:15:28 +00:00
|
|
|
})(window, jQuery);
|