76 lines
2.5 KiB
JavaScript
76 lines
2.5 KiB
JavaScript
(function(context,$) {
|
|
|
|
context.JK = context.JK || {};
|
|
context.JK.CreateSessionScreen = function(app) {
|
|
var logger = context.JK.logger;
|
|
var realtimeMessaging = context.JK.JamServer;
|
|
|
|
/*
|
|
Message from Seth on sequence for creating/joining sessions:
|
|
02:31:46 PM) Seth Call: sequence:
|
|
(02:31:53 PM) Seth Call: LOGIN websocket (get your client_id)
|
|
(02:32:02 PM) Seth Call: CRETAE SESSION
|
|
(02:32:09 PM) Seth Call: CREATE PARTICIPANT (pass in client_id)
|
|
(02:32:12 PM) Seth Call: that's it for client 1
|
|
(02:32:13 PM) Seth Call: client 2
|
|
(02:32:20 PM) Seth Call: LOGIN WEBSOCKET (get your client_id)
|
|
(02:32:29 PM) Seth Call: CREATE PARTICIPANT(pass in client_id for client2)
|
|
(02:32:31 PM) Seth Call: that's it
|
|
(02:32:43 PM) Seth Call: USER_JOINED_MUSIC_SESSION is an event from the server
|
|
(02:32:52 PM) Seth Call: and LOGIN_MUSIC_SESSION is deprecated/junk
|
|
*/
|
|
|
|
function afterShow(data) {}
|
|
|
|
function submitForm(evt) {
|
|
var $this = $(this);
|
|
var data = $this.formToObject();
|
|
data.client_id = app.clientId;
|
|
var url = "/api/sessions";
|
|
$.ajax({
|
|
type: "POST",
|
|
dataType: "json",
|
|
url: url,
|
|
data: data
|
|
}).done(
|
|
function(response) {
|
|
var newSessionId = response.id;
|
|
self.location = '#/session/' + newSessionId;
|
|
context.JK.joinMusicSession(newSessionId);
|
|
}
|
|
);
|
|
evt.preventDefault();
|
|
return false;
|
|
}
|
|
|
|
function events() {
|
|
$('#create-session-form').submit(submitForm);
|
|
}
|
|
|
|
function loadGenres() {
|
|
var url = "/api/genres";
|
|
$.ajax({
|
|
type: "GET",
|
|
url: url
|
|
}).done(function(response) {
|
|
var options = [];
|
|
var optionTemplate = $('#template-genre-option').html();
|
|
$.each(response, function() {
|
|
var d = {value: this.description, label: this.description};
|
|
var opt = context.JK.fillTemplate(optionTemplate, d);
|
|
options.push(opt);
|
|
});
|
|
$('#create-session-form select[name="genre"]').html(options.join(''));
|
|
});
|
|
}
|
|
|
|
this.initialize = function() {
|
|
events();
|
|
loadGenres();
|
|
screenBindings = { 'afterShow': afterShow };
|
|
app.bindScreen('session', screenBindings);
|
|
};
|
|
|
|
};
|
|
|
|
})(window,jQuery); |