1136 lines
44 KiB
JavaScript
1136 lines
44 KiB
JavaScript
(function(context,$) {
|
|
|
|
"use strict";
|
|
|
|
context.JK = context.JK || {};
|
|
context.JK.Sidebar = function(app) {
|
|
var logger = context.JK.logger;
|
|
var friends = [];
|
|
var rest = context.JK.Rest();
|
|
var invitationDialog = null;
|
|
|
|
function initializeSearchPanel() {
|
|
$('#search_text_type').change(function() {
|
|
searchForInput();
|
|
context.JK.SearchResultScreen.searchTypeSelection($('#search_text_type').val());
|
|
});
|
|
}
|
|
|
|
context.JK.Sidebar.searchTypeSelection = function(typeSelection) {
|
|
$('#search_text_type').val(typeSelection);
|
|
emptySearchResults();
|
|
}
|
|
|
|
function initializeFriendsPanel() {
|
|
|
|
/////////////////////////////////////////////////////////////
|
|
// THIS IS TEST CODE TO GENERATE BACK TO BACK NOTIFICATIONS
|
|
// app.notify({
|
|
// "title": "TEST 1",
|
|
// "text": "Test 1",
|
|
// "icon_url": context.JK.resolveAvatarUrl("")
|
|
// });
|
|
|
|
// app.notify({
|
|
// "title": "TEST 2",
|
|
// "text": "Test 2",
|
|
// "icon_url": context.JK.resolveAvatarUrl("")
|
|
// });
|
|
|
|
// app.notify({
|
|
// "title": "TEST 3",
|
|
// "text": "Test 3",
|
|
// "icon_url": context.JK.resolveAvatarUrl("")
|
|
// });
|
|
/////////////////////////////////////////////////////////////
|
|
|
|
$('#sidebar-search-header').hide();
|
|
|
|
var url = "/api/users/" + context.JK.currentUserId + "/friends"
|
|
$.ajax({
|
|
type: "GET",
|
|
dataType: "json",
|
|
contentType: 'application/json',
|
|
url: url,
|
|
processData: false,
|
|
success: function(response) {
|
|
friends = response;
|
|
updateFriendList(response);
|
|
|
|
// set friend count
|
|
$('#sidebar-friend-count').html(response.length);
|
|
},
|
|
error: app.ajaxError
|
|
});
|
|
|
|
return false;
|
|
}
|
|
|
|
function updateFriendList(response) {
|
|
$('#sidebar-friend-list li:not(.invite-friend-row)').remove();
|
|
|
|
// show online friends first (sort by first name within online/offline groups)
|
|
response.sort(function(a, b) {
|
|
|
|
var a_online = a.online;
|
|
var b_online = b.online;
|
|
|
|
var a_firstname = a.first_name.toLowerCase();
|
|
var b_firstname = b.first_name.toLowerCase();
|
|
|
|
if (b_online != a_online) {
|
|
if (b_online < a_online) return -1;
|
|
if (b_online > a_online) return 1;
|
|
return 0;
|
|
}
|
|
|
|
if (a_firstname < b_firstname) return -1;
|
|
if (a_firstname > b_firstname) return 1;
|
|
return 0;
|
|
});
|
|
|
|
$.each(response, function(index, val) {
|
|
|
|
var css = val.online ? '' : 'offline';
|
|
|
|
friends[val.id] = val;
|
|
|
|
// fill in template for Connect pre-click
|
|
var template = $('#template-friend-panel').html();
|
|
var searchResultHtml = context.JK.fillTemplate(template, {
|
|
userId: val.id,
|
|
cssClass: css,
|
|
avatar_url: context.JK.resolveAvatarUrl(val.photo_url),
|
|
userName: val.name.length > 20 ? val.name.substring(0,20) + "..." : val.name,
|
|
status: val.online ? 'Available' : 'Offline',
|
|
extra_info: '',
|
|
hoverAction: val.musician ? "musician" : "fan",
|
|
info_image_url: ''
|
|
});
|
|
|
|
$('#sidebar-friend-list li.invite-friend-row').before(searchResultHtml);
|
|
});
|
|
|
|
context.JK.bindHoverEvents();
|
|
}
|
|
|
|
function initializeNotificationsPanel() {
|
|
// retrieve pending notifications for this user
|
|
var url = "/api/users/" + context.JK.currentUserId + "/notifications"
|
|
$.ajax({
|
|
type: "GET",
|
|
dataType: "json",
|
|
contentType: 'application/json',
|
|
url: url,
|
|
processData: false,
|
|
success: function(response) {
|
|
|
|
updateNotificationList(response);
|
|
|
|
// set notification count
|
|
$('#sidebar-notification-count').html(response.length);
|
|
},
|
|
error: app.ajaxError
|
|
});
|
|
}
|
|
|
|
function updateNotificationList(response) {
|
|
$('#sidebar-notification-list').empty();
|
|
|
|
$.each(response, function(index, val) {
|
|
|
|
// fill in template for Connect pre-click
|
|
var template = $('#template-notification-panel').html();
|
|
var notificationHtml = context.JK.fillTemplate(template, {
|
|
notificationId: val.notification_id,
|
|
sessionId: val.session_id,
|
|
avatar_url: context.JK.resolveAvatarUrl(val.photo_url),
|
|
text: val.formatted_msg,
|
|
date: $.timeago(val.created_at)
|
|
});
|
|
|
|
$('#sidebar-notification-list').append(notificationHtml);
|
|
|
|
// val.description contains the notification record's description value from the DB (i.e., type)
|
|
initializeActions(val, val.description);
|
|
});
|
|
}
|
|
|
|
function initializeActions(payload, type) {
|
|
|
|
var $notification = $('li[notification-id=' + payload.notification_id + ']');
|
|
var $btnNotificationAction = '#btn-notification-action';
|
|
|
|
// wire up "x" button to delete notification
|
|
$notification.find('#img-delete-notification').click(deleteNotificationHandler);
|
|
|
|
// customize action buttons based on notification type
|
|
if (type === context.JK.MessageType.FRIEND_REQUEST) {
|
|
var $action_btn = $notification.find($btnNotificationAction);
|
|
$action_btn.text('ACCEPT');
|
|
$action_btn.click(function() {
|
|
acceptFriendRequest(payload);
|
|
});
|
|
}
|
|
|
|
else if (type === context.JK.MessageType.FRIEND_REQUEST_ACCEPTED) {
|
|
$notification.find('#div-actions').hide();
|
|
}
|
|
|
|
else if (type === context.JK.MessageType.NEW_USER_FOLLOWER || type === context.JK.MessageType.NEW_BAND_FOLLOWER) {
|
|
$notification.find('#div-actions').hide();
|
|
}
|
|
|
|
else if (type === context.JK.MessageType.SESSION_INVITATION) {
|
|
var $action_btn = $notification.find($btnNotificationAction);
|
|
$action_btn.text('JOIN');
|
|
$action_btn.click(function() {
|
|
openTerms(payload);
|
|
});
|
|
}
|
|
|
|
else if (type === context.JK.MessageType.JOIN_REQUEST) {
|
|
var $action_btn = $notification.find($btnNotificationAction);
|
|
$action_btn.text('APPROVE');
|
|
$action_btn.click(function() {
|
|
approveJoinRequest(payload);
|
|
});
|
|
}
|
|
|
|
else if (type === context.JK.MessageType.JOIN_REQUEST_APPROVED) {
|
|
var $action_btn = $notification.find($btnNotificationAction);
|
|
$action_btn.text('JOIN');
|
|
$action_btn.click(function() {
|
|
openTerms(payload);
|
|
});
|
|
}
|
|
|
|
else if (type === context.JK.MessageType.JOIN_REQUEST_REJECTED) {
|
|
$notification.find('#div-actions').hide();
|
|
}
|
|
|
|
else if (type === context.JK.MessageType.MUSICIAN_SESSION_JOIN || type === context.JK.MessageType.BAND_SESSION_JOIN) {
|
|
|
|
var actionText = '';
|
|
var callback;
|
|
if (context.JK.currentUserMusician) {
|
|
// user is MUSICIAN; musician_access = TRUE
|
|
if (payload.musician_access) {
|
|
actionText = "JOIN";
|
|
callback = joinSession;
|
|
}
|
|
// user is MUSICIAN; fan_access = TRUE
|
|
else if (payload.fan_access) {
|
|
actionText = "LISTEN";
|
|
callback = listenToSession;
|
|
}
|
|
}
|
|
else {
|
|
// user is FAN; fan_access = TRUE
|
|
if (payload.fan_access) {
|
|
actionText = "LISTEN";
|
|
callback = listenToSession;
|
|
}
|
|
}
|
|
|
|
var $action_btn = $notification.find($btnNotificationAction);
|
|
$action_btn.text(actionText);
|
|
$action_btn.click(function() {
|
|
callback(payload);
|
|
});
|
|
}
|
|
|
|
else if (type === context.JK.MessageType.MUSICIAN_RECORDING_SAVED || type === context.JK.MessageType.BAND_RECORDING_SAVED) {
|
|
var $action_btn = $notification.find($btnNotificationAction);
|
|
$action_btn.text('LISTEN');
|
|
$action_btn.click(function() {
|
|
listenToRecording(payload);
|
|
});
|
|
}
|
|
|
|
else if (type === context.JK.MessageType.RECORDING_MASTER_MIX_COMPLETE) {
|
|
$notification.find('#div-actions').hide();
|
|
context.jamClient.OnDownloadAvailable(); // poke backend, letting it know a download is available
|
|
}
|
|
|
|
else if (type === context.JK.MessageType.BAND_INVITATION) {
|
|
var $action_btn = $notification.find($btnNotificationAction);
|
|
$action_btn.text('ACCEPT');
|
|
$action_btn.click(function() {
|
|
acceptBandInvitation(payload);
|
|
});
|
|
}
|
|
else if (type === context.JK.MessageType.BAND_INVITATION_ACCEPTED) {
|
|
$notification.find('#div-actions').hide();
|
|
}
|
|
}
|
|
|
|
function deleteNotificationHandler(evt) {
|
|
evt.stopPropagation();
|
|
var notificationId = $(this).attr('notification-id');
|
|
deleteNotification(notificationId);
|
|
}
|
|
|
|
function deleteNotification(notificationId) {
|
|
var url = "/api/users/" + context.JK.currentUserId + "/notifications/" + notificationId;
|
|
$.ajax({
|
|
type: "DELETE",
|
|
dataType: "json",
|
|
contentType: 'application/json',
|
|
url: url,
|
|
processData: false,
|
|
success: function(response) {
|
|
$('li[notification-id=' + notificationId + ']').hide();
|
|
decrementNotificationCount();
|
|
},
|
|
error: app.ajaxError
|
|
});
|
|
}
|
|
|
|
function initializeChatPanel() {
|
|
}
|
|
|
|
function search(query) {
|
|
logger.debug('query=' + query);
|
|
if (query !== '') {
|
|
context.JK.search(query, app, context.JK.SearchResultScreen.onSearchSuccess);
|
|
}
|
|
}
|
|
|
|
context.JK.Sidebar.getHeight = function() {
|
|
// TODO: refactor this - copied from layout.js
|
|
var sidebarHeight = $(context).height() - 75 - 2 * 60 + $('[layout-sidebar-expander]').height();
|
|
var combinedHeaderHeight = $('[layout-panel="contents"]').length * 36;
|
|
var searchHeight = $('.sidebar .search').first().height();
|
|
var expanderHeight = $('[layout-sidebar-expander]').height();
|
|
var expandedPanelHeight = sidebarHeight - (combinedHeaderHeight + expanderHeight + searchHeight);
|
|
return expandedPanelHeight;
|
|
}
|
|
|
|
function showFriendsPanel() {
|
|
|
|
var $expandedPanelContents = $('[layout-id="panelFriends"] [layout-panel="contents"]');
|
|
var expandedPanelHeight = context.JK.Sidebar.getHeight();
|
|
|
|
// hide all other contents
|
|
$('[layout-panel="contents"]').hide();
|
|
$('[layout-panel="contents"]').css({"height": "1px"});
|
|
|
|
// show the appropriate contens
|
|
$expandedPanelContents.show();
|
|
$expandedPanelContents.animate({"height": expandedPanelHeight + "px"}, 400);
|
|
}
|
|
|
|
function hideSearchResults() {
|
|
emptySearchResults();
|
|
$('#search-input').val('');
|
|
$('#sidebar-search-header').hide();
|
|
showFriendsPanel();
|
|
}
|
|
|
|
function emptySearchResults() {
|
|
$('#sidebar-search-results').empty();
|
|
$('#sidebar-search-results').height('0px');
|
|
}
|
|
|
|
function incrementNotificationCount() {
|
|
var count = parseInt($('#sidebar-notification-count').html());
|
|
$('#sidebar-notification-count').html(count + 1);
|
|
}
|
|
|
|
function decrementNotificationCount() {
|
|
var count = parseInt($('#sidebar-notification-count').html());
|
|
if (count === 0) {
|
|
$('#sidebar-notification-count').html(0);
|
|
}
|
|
else {
|
|
$('#sidebar-notification-count').html(count - 1);
|
|
}
|
|
}
|
|
|
|
// default handler for incoming notification
|
|
function handleNotification(payload, type) {
|
|
var sidebarText;
|
|
sidebarText = payload.msg;
|
|
|
|
// increment displayed notification count
|
|
incrementNotificationCount();
|
|
|
|
// add notification to sidebar
|
|
var template = $("#template-notification-panel").html();
|
|
var notificationHtml = context.JK.fillTemplate(template, {
|
|
notificationId: payload.notification_id,
|
|
sessionId: payload.session_id,
|
|
avatar_url: context.JK.resolveAvatarUrl(payload.photo_url),
|
|
text: sidebarText,
|
|
date: $.timeago(payload.created_at)
|
|
});
|
|
|
|
$('#sidebar-notification-list').prepend(notificationHtml);
|
|
|
|
initializeActions(payload, type);
|
|
}
|
|
|
|
var delay = (function(){
|
|
var timer = 0;
|
|
return function(callback, ms) {
|
|
clearTimeout(timer);
|
|
timer = setTimeout(callback, ms);
|
|
};
|
|
})();
|
|
|
|
|
|
function inviteHoverIn() {
|
|
$('.invitation-button-holder').slideDown();
|
|
}
|
|
|
|
function inviteHoverOut() {
|
|
$('.invitation-button-holder').slideUp();
|
|
}
|
|
|
|
function searchForInput() {
|
|
var query = $('#search-input').val();
|
|
// logger.debug("query=" + query);
|
|
if (query === '') {
|
|
return hideSearchResults();
|
|
}
|
|
|
|
if (query.length > 2) {
|
|
// FIXME: this is in searchResults
|
|
$('#query').html(query);
|
|
query += '&search_text_type='+$('#search_text_type').val();
|
|
emptySearchResults();
|
|
search(query);
|
|
}
|
|
}
|
|
|
|
function events() {
|
|
$('#search-input').keyup(function(evt) {
|
|
delay(function() {
|
|
// ENTER KEY
|
|
if (evt.which === 13) {
|
|
return hideSearchResults();
|
|
}
|
|
// ESCAPE KEY
|
|
if (evt.which === 27) {
|
|
return hideSearchResults();
|
|
}
|
|
searchForInput();
|
|
}, 500);
|
|
});
|
|
|
|
$('#sidebar-search-expand').click(function(evt) {
|
|
$('#searchForm').submit();
|
|
hideSearchResults();
|
|
});
|
|
|
|
$('.sidebar .invite-friend-row').hoverIntent(inviteHoverIn, inviteHoverOut);
|
|
|
|
// friend notifications
|
|
registerFriendUpdate();
|
|
registerFriendRequest();
|
|
registerFriendRequestAccepted();
|
|
registerNewUserFollower();
|
|
registerNewBandFollower();
|
|
|
|
// session invitations
|
|
registerSessionInvitation();
|
|
registerSessionEnded();
|
|
registerJoinRequest();
|
|
registerJoinRequestApproved();
|
|
registerJoinRequestRejected();
|
|
registerSessionJoin();
|
|
registerSessionDepart();
|
|
registerMusicianSessionJoin();
|
|
registerBandSessionJoin();
|
|
|
|
// recording notifications
|
|
registerMusicianRecordingSaved();
|
|
registerBandRecordingSaved();
|
|
registerRecordingStarted();
|
|
registerRecordingEnded();
|
|
registerRecordingMasterMixComplete();
|
|
|
|
// band notifications
|
|
registerBandInvitation();
|
|
registerBandInvitationAccepted();
|
|
|
|
// broadcast notifications
|
|
registerSourceUpRequested();
|
|
registerSourceDownRequested();
|
|
registerSourceUp();
|
|
registerSourceDown();
|
|
|
|
// watch for Invite More Users events
|
|
$('#sidebar-div .btn-email-invitation').click(function() {
|
|
invitationDialog.showEmailDialog();
|
|
return false;
|
|
});
|
|
|
|
$('#sidebar-div .btn-gmail-invitation').click(function() {
|
|
invitationDialog.showGoogleDialog();
|
|
return false;
|
|
});
|
|
|
|
$('#sidebar-div .btn-facebook-invitation').click(function(evt) {
|
|
invitationDialog.showFacebookDialog(evt);
|
|
return false;
|
|
});
|
|
}
|
|
|
|
function registerFriendUpdate() {
|
|
context.JK.JamServer.registerMessageCallback(context.JK.MessageType.FRIEND_UPDATE, function(header, payload) {
|
|
logger.debug("Handling FRIEND_UPDATE msg " + JSON.stringify(payload));
|
|
|
|
friends[payload.user_id].online = payload.online;
|
|
updateFriendList(friends);
|
|
|
|
var online_text = payload.online ? "online" : "offline";
|
|
app.notify({
|
|
"title": "Friend is now " + online_text,
|
|
"text": payload.msg,
|
|
"icon_url": context.JK.resolveAvatarUrl(payload.photo_url)
|
|
});
|
|
});
|
|
}
|
|
|
|
function registerFriendRequest() {
|
|
context.JK.JamServer.registerMessageCallback(context.JK.MessageType.FRIEND_REQUEST, function(header, payload) {
|
|
logger.debug("Handling FRIEND_REQUEST msg " + JSON.stringify(payload));
|
|
|
|
handleNotification(payload, header.type);
|
|
|
|
app.notify({
|
|
"title": "New Friend Request",
|
|
"text": payload.msg,
|
|
"icon_url": context.JK.resolveAvatarUrl(payload.photo_url)
|
|
}, {
|
|
"ok_text": "ACCEPT",
|
|
"ok_callback": acceptFriendRequest,
|
|
"ok_callback_args": { "friend_request_id": payload.friend_request_id, "notification_id": payload.notification_id }
|
|
});
|
|
});
|
|
}
|
|
|
|
function acceptFriendRequest(args) {
|
|
|
|
rest.acceptFriendRequest({
|
|
status : 'accept',
|
|
friend_request_id : args.friend_request_id
|
|
}).done(function(response) {
|
|
deleteNotification(args.notification_id); // delete notification corresponding to this friend request
|
|
initializeFriendsPanel(); // refresh friends panel when request is accepted
|
|
}).error(app.ajaxError);
|
|
}
|
|
|
|
function registerFriendRequestAccepted() {
|
|
context.JK.JamServer.registerMessageCallback(context.JK.MessageType.FRIEND_REQUEST_ACCEPTED, function(header, payload) {
|
|
logger.debug("Handling FRIEND_REQUEST_ACCEPTED msg " + JSON.stringify(payload));
|
|
|
|
handleNotification(payload, header.type);
|
|
|
|
initializeFriendsPanel();
|
|
|
|
app.notify({
|
|
"title": "Friend Request Accepted",
|
|
"text": payload.msg,
|
|
"icon_url": context.JK.resolveAvatarUrl(payload.photo_url)
|
|
});
|
|
});
|
|
}
|
|
|
|
function registerNewUserFollower() {
|
|
|
|
context.JK.JamServer.registerMessageCallback(context.JK.MessageType.NEW_USER_FOLLOWER, function(header, payload) {
|
|
logger.debug("Handling NEW_USER_FOLLOWER msg " + JSON.stringify(payload));
|
|
|
|
handleNotification(payload, header.type);
|
|
|
|
app.notify({
|
|
"title": "New Follower",
|
|
"text": payload.msg,
|
|
"icon_url": context.JK.resolveAvatarUrl(payload.photo_url)
|
|
});
|
|
});
|
|
}
|
|
|
|
function registerNewBandFollower() {
|
|
|
|
context.JK.JamServer.registerMessageCallback(context.JK.MessageType.NEW_BAND_FOLLOWER, function(header, payload) {
|
|
logger.debug("Handling NEW_BAND_FOLLOWER msg " + JSON.stringify(payload));
|
|
|
|
handleNotification(payload, header.type);
|
|
|
|
app.notify({
|
|
"title": "New Band Follower",
|
|
"text": payload.msg,
|
|
"icon_url": context.JK.resolveAvatarUrl(payload.photo_url)
|
|
});
|
|
});
|
|
|
|
}
|
|
|
|
function registerSessionInvitation() {
|
|
context.JK.JamServer.registerMessageCallback(context.JK.MessageType.SESSION_INVITATION, function(header, payload) {
|
|
logger.debug("Handling SESSION_INVITATION msg " + JSON.stringify(payload));
|
|
|
|
handleNotification(payload, header.type);
|
|
|
|
var participants = [];
|
|
rest.getSession(payload.session_id).done(function(response) {
|
|
$.each(response.participants, function(index, val) {
|
|
participants.push({"photo_url": context.JK.resolveAvatarUrl(val.user.photo_url), "name": val.user.name});
|
|
});
|
|
|
|
var participantHtml = "You have been invited to join a session with: <br/><br/>";
|
|
participantHtml += "<table><tbody>";
|
|
|
|
$.each(participants, function(index, val) {
|
|
if (index < 4) {
|
|
participantHtml += "<tr><td><img class='avatar-small' src='" + context.JK.resolveAvatarUrl(val.photo_url) + "' /></td><td>" + val.name + "</td></tr>";
|
|
}
|
|
});
|
|
|
|
participantHtml += "</tbody></table>";
|
|
|
|
app.notify({
|
|
"title": "Session Invitation",
|
|
"text": participantHtml
|
|
}, {
|
|
"ok_text": "JOIN SESSION",
|
|
"ok_callback": openTerms,
|
|
"ok_callback_args": { "session_id": payload.session_id, "notification_id": payload.notification_id }
|
|
});
|
|
}).error(app.ajaxError);
|
|
|
|
});
|
|
}
|
|
|
|
function openTerms(args) {
|
|
var termsDialog = new context.JK.TermsDialog(app, args, onTermsAccepted);
|
|
termsDialog.initialize();
|
|
app.layout.showDialog('terms');
|
|
}
|
|
|
|
function onTermsAccepted(args) {
|
|
deleteNotification(args.notification_id);
|
|
context.location = '/client#/session/' + args.session_id;
|
|
}
|
|
|
|
function registerSessionEnded() {
|
|
// TODO: this should clean up all notifications related to this session
|
|
context.JK.JamServer.registerMessageCallback(context.JK.MessageType.SESSION_ENDED, function(header, payload) {
|
|
logger.debug("Handling SESSION_ENDED msg " + JSON.stringify(payload));
|
|
deleteSessionNotifications(payload.session_id);
|
|
});
|
|
}
|
|
|
|
// remove all notifications for this session
|
|
function deleteSessionNotifications(sessionId) {
|
|
$('li[session-id=' + sessionId + ']').hide();
|
|
decrementNotificationCount();
|
|
}
|
|
|
|
function registerJoinRequest() {
|
|
context.JK.JamServer.registerMessageCallback(context.JK.MessageType.JOIN_REQUEST, function(header, payload) {
|
|
logger.debug("Handling JOIN_REQUEST msg " + JSON.stringify(payload));
|
|
|
|
handleNotification(payload, header.type);
|
|
|
|
app.notify({
|
|
"title": "New Join Request",
|
|
"text": payload.msg,
|
|
"icon_url": context.JK.resolveAvatarUrl(payload.photo_url)
|
|
}, {
|
|
"ok_text": "APPROVE",
|
|
"ok_callback": approveJoinRequest,
|
|
"ok_callback_args": { "join_request_id": payload.join_request_id, "notification_id": payload.notification_id },
|
|
"cancel_text": "REJECT",
|
|
"cancel_callback": rejectJoinRequest,
|
|
"cancel_callback_args": { "join_request_id": payload.join_request_id, "notification_id": payload.notification_id }
|
|
});
|
|
});
|
|
}
|
|
|
|
function approveJoinRequest(args) {
|
|
rest.updateJoinRequest(args.join_request_id, true)
|
|
.done(function(response) {
|
|
deleteNotification(args.notification_id);
|
|
}).error(app.ajaxError);
|
|
}
|
|
|
|
function rejectJoinRequest(args) {
|
|
rest.updateJoinRequest(args.join_request_id, false)
|
|
.done(function(response) {
|
|
deleteNotification(args.notification_id);
|
|
}).error(app.ajaxError);
|
|
}
|
|
|
|
function registerJoinRequestApproved() {
|
|
context.JK.JamServer.registerMessageCallback(context.JK.MessageType.JOIN_REQUEST_APPROVED, function(header, payload) {
|
|
logger.debug("Handling JOIN_REQUEST_APPROVED msg " + JSON.stringify(payload));
|
|
|
|
handleNotification(payload, header.type);
|
|
|
|
app.notify({
|
|
"title": "Join Request Approved",
|
|
"text": payload.msg,
|
|
"icon_url": context.JK.resolveAvatarUrl(payload.photo_url)
|
|
}, {
|
|
"ok_text": "JOIN SESSION",
|
|
"ok_callback": openTerms,
|
|
"ok_callback_args": { "session_id": payload.session_id, "notification_id": payload.notification_id }
|
|
});
|
|
});
|
|
}
|
|
|
|
function registerJoinRequestRejected() {
|
|
context.JK.JamServer.registerMessageCallback(context.JK.MessageType.JOIN_REQUEST_REJECTED, function(header, payload) {
|
|
logger.debug("Handling JOIN_REQUEST_REJECTED msg " + JSON.stringify(payload));
|
|
|
|
handleNotification(payload, header.type);
|
|
|
|
app.notify({
|
|
"title": "Join Request Rejected",
|
|
"text": payload.msg,
|
|
"icon_url": context.JK.resolveAvatarUrl(payload.photo_url)
|
|
});
|
|
});
|
|
}
|
|
|
|
function registerSessionJoin() {
|
|
context.JK.JamServer.registerMessageCallback(context.JK.MessageType.SESSION_JOIN, function(header, payload) {
|
|
logger.debug("Handling SESSION_JOIN msg " + JSON.stringify(payload));
|
|
|
|
// display notification
|
|
app.notify({
|
|
"title": "New Session Participant",
|
|
"text": payload.msg,
|
|
"icon_url": context.JK.resolveAvatarUrl(payload.photo_url)
|
|
});
|
|
});
|
|
}
|
|
|
|
function registerSessionDepart() {
|
|
context.JK.JamServer.registerMessageCallback(context.JK.MessageType.SESSION_DEPART, function(header, payload) {
|
|
logger.debug("Handling SESSION_DEPART msg " + JSON.stringify(payload));
|
|
|
|
var recordingId = payload.recording_id;
|
|
|
|
if(recordingId && context.JK.CurrentSessionModel.recordingModel.isRecording(recordingId)) {
|
|
context.JK.CurrentSessionModel.recordingModel.onServerStopRecording(recordingId);
|
|
}
|
|
else {
|
|
app.notify({
|
|
"title": "Musician Left Session",
|
|
"text": payload.msg,
|
|
"icon_url": context.JK.resolveAvatarUrl(payload.photo_url)
|
|
});
|
|
}
|
|
});
|
|
}
|
|
|
|
function registerMusicianSessionJoin() {
|
|
context.JK.JamServer.registerMessageCallback(context.JK.MessageType.MUSICIAN_SESSION_JOIN, function(header, payload) {
|
|
logger.debug("Handling MUSICIAN_SESSION_JOIN msg " + JSON.stringify(payload));
|
|
|
|
var okText = '';
|
|
var showNotification = false;
|
|
var callback;
|
|
if (context.JK.currentUserMusician) {
|
|
// user is MUSICIAN; musician_access = TRUE
|
|
if (payload.musician_access) {
|
|
showNotification = true;
|
|
okText = "JOIN";
|
|
callback = joinSession;
|
|
}
|
|
// user is MUSICIAN; fan_access = TRUE
|
|
else if (payload.fan_access) {
|
|
showNotification = true;
|
|
okText = "LISTEN";
|
|
callback = listenToSession;
|
|
}
|
|
}
|
|
else {
|
|
// user is FAN; fan_access = TRUE
|
|
if (payload.fan_access) {
|
|
showNotification = true;
|
|
okText = "LISTEN";
|
|
callback = listenToSession;
|
|
}
|
|
}
|
|
|
|
if (showNotification) {
|
|
handleNotification(payload, header.type);
|
|
|
|
app.notify({
|
|
"title": "Musician Joined Session",
|
|
"text": payload.msg,
|
|
"icon_url": context.JK.resolveAvatarUrl(payload.photo_url)
|
|
}, {
|
|
"ok_text": okText,
|
|
"ok_callback": callback,
|
|
"ok_callback_args": {
|
|
"session_id": payload.session_id,
|
|
"fan_access": payload.fan_access,
|
|
"musician_access": payload.musician_access,
|
|
"approval_required": payload.approval_required,
|
|
"notification_id": payload.notification_id
|
|
}
|
|
}
|
|
);
|
|
}
|
|
});
|
|
}
|
|
|
|
function registerBandSessionJoin() {
|
|
context.JK.JamServer.registerMessageCallback(context.JK.MessageType.BAND_SESSION_JOIN, function(header, payload) {
|
|
logger.debug("Handling BAND_SESSION_JOIN msg " + JSON.stringify(payload));
|
|
|
|
var okText = '';
|
|
var showNotification = false;
|
|
var callback;
|
|
if (context.JK.currentUserMusician) {
|
|
// user is MUSICIAN; musician_access = TRUE
|
|
if (payload.musician_access) {
|
|
showNotification = true;
|
|
okText = "JOIN";
|
|
callback = joinSession;
|
|
}
|
|
// user is MUSICIAN; fan_access = TRUE
|
|
else if (payload.fan_access) {
|
|
showNotification = true;
|
|
okText = "LISTEN";
|
|
callback = listenToSession;
|
|
}
|
|
}
|
|
else {
|
|
// user is FAN; fan_access = TRUE
|
|
if (payload.fan_access) {
|
|
showNotification = true;
|
|
okText = "LISTEN";
|
|
callback = listenToSession;
|
|
}
|
|
}
|
|
|
|
if (showNotification) {
|
|
handleNotification(payload, header.type);
|
|
|
|
app.notify({
|
|
"title": "Band Joined Session",
|
|
"text": payload.msg,
|
|
"icon_url": context.JK.resolveAvatarUrl(payload.photo_url)
|
|
}, {
|
|
"ok_text": "LISTEN",
|
|
"ok_callback": callback,
|
|
"ok_callback_args": {
|
|
"session_id": payload.session_id,
|
|
"fan_access": payload.fan_access,
|
|
"musician_access": payload.musician_access,
|
|
"approval_required": payload.approval_required,
|
|
"notification_id": payload.notification_id
|
|
}
|
|
}
|
|
);
|
|
}
|
|
});
|
|
}
|
|
|
|
function listenToSession(args) {
|
|
deleteNotification(args.notification_id);
|
|
context.JK.popExternalLink('/sessions/' + args.session_id);
|
|
}
|
|
|
|
/*********** TODO: THE NEXT 3 FUNCTIONS ARE COPIED FROM sessionList.js. REFACTOR TO COMMON PLACE. *************/
|
|
function joinSession(args) {
|
|
// NOTE: invited musicians get their own notification, so no need to check if user has invitation here
|
|
// like other places because an invited user would never get this notification
|
|
if (args.musician_access) {
|
|
if (args.approval_required) {
|
|
openAlert(args.session_id);
|
|
}
|
|
else {
|
|
openTerms(args);
|
|
}
|
|
}
|
|
deleteNotification(args.notification_id);
|
|
}
|
|
|
|
function openAlert(sessionId) {
|
|
var alertDialog = new context.JK.AlertDialog(context.JK.app, "YES",
|
|
"You must be approved to join this session. Would you like to send a request to join?",
|
|
sessionId, onCreateJoinRequest);
|
|
|
|
alertDialog.initialize();
|
|
context.JK.app.layout.showDialog('alert');
|
|
}
|
|
|
|
function onCreateJoinRequest(sessionId) {
|
|
var joinRequest = {};
|
|
joinRequest.music_session = sessionId;
|
|
joinRequest.user = context.JK.currentUserId;
|
|
rest.createJoinRequest(joinRequest)
|
|
.done(function(response) {
|
|
|
|
}).error(context.JK.app.ajaxError);
|
|
|
|
context.JK.app.layout.closeDialog('alert');
|
|
}
|
|
//////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
function registerMusicianRecordingSaved() {
|
|
context.JK.JamServer.registerMessageCallback(context.JK.MessageType.MUSICIAN_RECORDING_SAVED, function(header, payload) {
|
|
logger.debug("Handling MUSICIAN_RECORDING_SAVED msg " + JSON.stringify(payload));
|
|
|
|
handleNotification(payload, header.type);
|
|
|
|
app.notify({
|
|
"title": "Musician Recording Saved",
|
|
"text": payload.msg,
|
|
"icon_url": context.JK.resolveAvatarUrl(payload.photo_url)
|
|
}, {
|
|
"ok_text": "LISTEN",
|
|
"ok_callback": listenToRecording,
|
|
"ok_callback_args": {
|
|
"recording_id": payload.recording_id,
|
|
"notification_id": payload.notification_id
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|
|
function registerBandRecordingSaved() {
|
|
context.JK.JamServer.registerMessageCallback(context.JK.MessageType.BAND_RECORDING_SAVED, function(header, payload) {
|
|
logger.debug("Handling BAND_RECORDING_SAVED msg " + JSON.stringify(payload));
|
|
|
|
handleNotification(payload, header.type);
|
|
|
|
app.notify({
|
|
"title": "Band Recording Saved",
|
|
"text": payload.msg,
|
|
"icon_url": context.JK.resolveAvatarUrl(payload.photo_url)
|
|
}, {
|
|
"ok_text": "LISTEN",
|
|
"ok_callback": listenToRecording,
|
|
"ok_callback_args": {
|
|
"recording_id": payload.recording_id,
|
|
"notification_id": payload.notification_id
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|
|
function listenToRecording(args) {
|
|
deleteNotification(args.notification_id);
|
|
context.JK.popExternalLink('/recordings/' + args.recording_id);
|
|
}
|
|
|
|
function registerRecordingStarted() {
|
|
context.JK.JamServer.registerMessageCallback(context.JK.MessageType.RECORDING_STARTED, function(header, payload) {
|
|
logger.debug("Handling RECORDING_STARTED msg " + JSON.stringify(payload));
|
|
|
|
app.notify({
|
|
"title": "Recording Started",
|
|
"text": payload.msg,
|
|
"icon_url": context.JK.resolveAvatarUrl(payload.photo_url)
|
|
});
|
|
});
|
|
}
|
|
|
|
function registerRecordingEnded() {
|
|
context.JK.JamServer.registerMessageCallback(context.JK.MessageType.RECORDING_ENDED, function(header, payload) {
|
|
logger.debug("Handling RECORDING_ENDED msg " + JSON.stringify(payload));
|
|
|
|
app.notify({
|
|
"title": "Recording Ended",
|
|
"text": payload.msg,
|
|
"icon_url": context.JK.resolveAvatarUrl(payload.photo_url)
|
|
});
|
|
});
|
|
}
|
|
|
|
function registerRecordingMasterMixComplete() {
|
|
context.JK.JamServer.registerMessageCallback(context.JK.MessageType.RECORDING_MASTER_MIX_COMPLETE, function(header, payload) {
|
|
logger.debug("Handling RECORDING_MASTER_MIX_COMPLETE msg " + JSON.stringify(payload));
|
|
|
|
handleNotification(payload, header.type);
|
|
|
|
app.notify({
|
|
"title": "Recording Master Mix Complete",
|
|
"text": payload.msg,
|
|
"icon_url": context.JK.resolveAvatarUrl(payload.photo_url)
|
|
}, {
|
|
"ok_text": "SHARE",
|
|
"ok_callback": shareRecording,
|
|
"ok_callback_args": {
|
|
"recording_id": payload.recording_id
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|
|
function shareRecording(args) {
|
|
var recordingId = args.recording_id;
|
|
}
|
|
|
|
function registerBandInvitation() {
|
|
context.JK.JamServer.registerMessageCallback(context.JK.MessageType.BAND_INVITATION, function(header, payload) {
|
|
logger.debug("Handling BAND_INVITATION msg " + JSON.stringify(payload));
|
|
|
|
handleNotification(payload, header.type);
|
|
|
|
app.notify({
|
|
"title": "Band Invitation",
|
|
"text": payload.msg,
|
|
"icon_url": context.JK.resolveAvatarUrl(payload.photo_url)
|
|
}, {
|
|
"ok_text": "ACCEPT",
|
|
"ok_callback": acceptBandInvitation,
|
|
"ok_callback_args": {
|
|
"band_invitation_id": payload.band_invitation_id,
|
|
"band_id": payload.band_id,
|
|
"notification_id": payload.notification_id
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|
|
function acceptBandInvitation(args) {
|
|
rest.updateBandInvitation(
|
|
args.band_id,
|
|
args.band_invitation_id,
|
|
true
|
|
).done(function(response) {
|
|
deleteNotification(args.notification_id); // delete notification corresponding to this friend request
|
|
}).error(app.ajaxError);
|
|
}
|
|
|
|
function registerBandInvitationAccepted() {
|
|
context.JK.JamServer.registerMessageCallback(context.JK.MessageType.BAND_INVITATION_ACCEPTED, function(header, payload) {
|
|
logger.debug("Handling BAND_INVITATION_ACCEPTED msg " + JSON.stringify(payload));
|
|
|
|
handleNotification(payload, header.type);
|
|
|
|
app.notify({
|
|
"title": "Band Invitation Accepted",
|
|
"text": payload.msg,
|
|
"icon_url": context.JK.resolveAvatarUrl(payload.photo_url)
|
|
});
|
|
});
|
|
}
|
|
|
|
function registerSourceUpRequested() {
|
|
context.JK.JamServer.registerMessageCallback(context.JK.MessageType.SOURCE_UP_REQUESTED, function(header, payload) {
|
|
|
|
logger.debug("Handling SOURCE_UP_REQUESTED msg " + JSON.stringify(payload));
|
|
|
|
var current_session_id = context.JK.CurrentSessionModel.id();
|
|
|
|
if (!current_session_id) {
|
|
// we are not in a session
|
|
var last_session = context.JK.CurrentSessionModel.getCurrentOrLastSession();
|
|
if(last_session && last_session.id == payload.music_session) {
|
|
// the last session we were in was responsible for this message. not that odd at all
|
|
logger.debug("SOURCE_UP_REQUESTED came in for session_id" + payload.music_session + ", but was dropped because we have left that session")
|
|
}
|
|
else {
|
|
// this means we aren't in a session, and, what's worse,
|
|
// the last session we were in does not match the specified music_session id
|
|
throw "SOURCE_UP_REQUESTED came in for session_id:" + payload.music_session + ", but we are not in a session and the last session ID did not match the one specified";
|
|
}
|
|
}
|
|
else {
|
|
// we are in a session
|
|
if(current_session_id == payload.music_session) {
|
|
context.jamClient.SessionLiveBroadcastStart(payload.host, payload.port, payload.mount,
|
|
payload.source_user, payload.source_pass,
|
|
'', payload.bitrate)
|
|
}
|
|
else {
|
|
var last_session = context.JK.CurrentSessionModel.getCurrentOrLastSession();
|
|
if(last_session && last_session.id == payload.music_session) {
|
|
// the last session we were in was responsible for this message. not that odd at all
|
|
logger.debug("SOURCE_UP_REQUESTED came in for session_id" + payload.music_session + ", but was dropped because we have left that session and are in a new one")
|
|
}
|
|
else {
|
|
// this means we aren't in a session, and, what's worse,
|
|
// the last session we were in does not match the specified music_session id
|
|
throw "SOURCE_UP_REQUESTED came in for session_id:" + payload.music_session + ", but we are in a session and the last session ID did not match the one specified";
|
|
}
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
function registerSourceDownRequested() {
|
|
context.JK.JamServer.registerMessageCallback(context.JK.MessageType.SOURCE_DOWN_REQUESTED, function(header, payload) {
|
|
logger.debug("Handling SOURCE_DOWN_REQUESTED msg " + JSON.stringify(payload));
|
|
var current_session_id = context.JK.CurrentSessionModel.id();
|
|
|
|
if (!current_session_id) {
|
|
// we are not in a session
|
|
var last_session = context.JK.CurrentSessionModel.getCurrentOrLastSession();
|
|
if(last_session && last_session.id == payload.music_session) {
|
|
// the last session we were in was responsible for this message. not that odd at all
|
|
logger.debug("SOURCE_DOWN_REQUESTED came in for session_id" + payload.music_session + ", but was dropped because we have left that session")
|
|
}
|
|
else {
|
|
// this means we aren't in a session, and, what's worse,
|
|
// the last session we were in does not match the specified music_session id
|
|
throw "SOURCE_DOWN_REQUESTED came in for session_id:" + payload.music_session + ", but we are not in a session and the last session ID did not match the one specified";
|
|
}
|
|
}
|
|
else {
|
|
// we are in a session
|
|
if(current_session_id == payload.music_session) {
|
|
context.jamClient.SessionLiveBroadcastStop();
|
|
}
|
|
else {
|
|
var last_session = context.JK.CurrentSessionModel.getCurrentOrLastSession();
|
|
if(last_session && last_session.id == payload.music_session) {
|
|
// the last session we were in was responsible for this message. not that odd at all
|
|
logger.debug("SOURCE_DOWN_REQUESTED came in for session_id" + payload.music_session + ", but was dropped because we have left that session and are in a new one")
|
|
}
|
|
else {
|
|
// this means we aren't in a session, and, what's worse,
|
|
// the last session we were in does not match the specified music_session id
|
|
throw "SOURCE_DOWN_REQUESTED came in for session_id:" + payload.music_session + ", but we are in a session and the last session ID did not match the one specified";
|
|
}
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
function registerSourceUp() {
|
|
context.JK.JamServer.registerMessageCallback(context.JK.MessageType.SOURCE_UP, function(header, payload) {
|
|
logger.debug("Handling SOURCE_UP msg " + JSON.stringify(payload));
|
|
|
|
logger.debug("session %o is now being broadcasted", payload.music_session);
|
|
app.notify({
|
|
"title": "Now Broadcasting",
|
|
"text": "This session is now being broadcasted."
|
|
});
|
|
});
|
|
}
|
|
|
|
function registerSourceDown() {
|
|
context.JK.JamServer.registerMessageCallback(context.JK.MessageType.SOURCE_DOWN, function(header, payload) {
|
|
logger.debug("Handling SOURCE_DOWN msg " + JSON.stringify(payload));
|
|
logger.debug("session %o is no longer being broadcasted", payload.music_session);
|
|
app.notify({
|
|
"title": "No Longer Broadcasting",
|
|
"text": "This session is no longer being broadcasted."
|
|
});
|
|
});
|
|
}
|
|
|
|
this.initialize = function(invitationDialogInstance) {
|
|
events();
|
|
initializeSearchPanel();
|
|
initializeFriendsPanel();
|
|
initializeChatPanel();
|
|
initializeNotificationsPanel();
|
|
invitationDialog = invitationDialogInstance;
|
|
};
|
|
}
|
|
})(window,jQuery); |