jam-cloud/app/assets/javascripts/refreshSession.js

65 lines
1.9 KiB
JavaScript

(function(context,$) {
"use strict";
context.JK = context.JK || {};
context.JK.refreshMusicSession = function(session_id) {
var logger = context.JK.logger;
var server = context.JK.JamServer;
var client = context.jamClient;
if (!server.signedIn)
{
logger.log("Can't refresh a session because the client is not connected.");
return;
}
function _toJamClientParticipant(participant) {
return {
userID : "",
clientID : participant.client_id,
tcpPort : 0,
udpPort : 0,
localIPAddress : "",
globalIPAddress : "",
latency : 0,
natType : ""
};
}
logger.log("Refreshing session: " + session_id);
var url = "/api/sessions/" + session_id;
$.ajax({
type: "GET",
url: url
}).done(function (response) {
logger.log("Session:");
logger.log(response);
var changes = context.JK.Sessions.UpdateSessionParticipants(session_id, response.participants);
logger.log("Changes:");
logger.log(changes);
if (client !== undefined)
{
var session = { sessionID: session_id };
$.each(changes.removed, function(index, participant) {
if (participant.client_id != server.clientID) {
client.ParticipantLeft(session, _toJamClientParticipant(participant));
}
});
$.each(changes.added, function(index, participant) {
if (participant.client_id != server.clientID) {
client.ParticipantJoined(session, _toJamClientParticipant(participant));
}
});
}
});
};
})(window,jQuery);