GT.websocketHandler = (function () {
    var pub = {};

    pub.init = function () {
        GT.webSocket.addOnMessageHandler(function (payload) {
            GT.websocketHandler.processMessage(payload);
        });

        GT.webSocket.connect();
    };

    pub.processMessage = function (payload) {
        $(GT.app).trigger(payload.type, payload);
    };

    return pub;
})();

$(function () {
    if (!g_isSPA) {
        // Do not load GT websocket handler on page load in SPA as script is loaded on page load
        // regardless if the user is logged in or not. This will be called through the action "authorization/initPageLoad"
        GT.websocketHandler.init();
    }
});
