(function(context,$) {

    "use strict";

    context.JK = context.JK || {};

    context.JK.leaveMusicSession = function(session_id) {
        var logger = context.JK.logger;
        var server = context.JK.JamServer;
        var client = context.jamClient;

        if (!server.signedIn)
        {
            logger.log("Can't leave a session because the client is not connected.");
            return;
        }

        logger.log("Leaving session: " + session_id);

        var url = "/api/participants/" + server.clientID;
        $.ajax({
            type: "DELETE",
            url: url
        }).done(function (response) {
            context.JK.Sessions.LeaveSession(session_id);
            if (client !== undefined) {
                client.LeaveSession({ sessionID: session_id });
            }
        });
    };

 })(window,jQuery);