X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=skyquake%2Fframework%2Fcore%2Fapi_utils%2Fsockets.js;h=a86f5ed35adad74ba71860db565a8071b9605330;hb=3ae3b0785159fdfd2d674d3faab3a7b1eeaed663;hp=607659476d6339fc4a675a950b8cf1bebdfc1c0f;hpb=e29efc315df33d546237e270470916e26df391d6;p=osm%2FUI.git diff --git a/skyquake/framework/core/api_utils/sockets.js b/skyquake/framework/core/api_utils/sockets.js index 607659476..a86f5ed35 100644 --- a/skyquake/framework/core/api_utils/sockets.js +++ b/skyquake/framework/core/api_utils/sockets.js @@ -1,5 +1,5 @@ /* - * + * * Copyright 2016 RIFT.IO Inc * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -32,17 +32,10 @@ var Promise = require('promise'); var url = require('url'); var sockjs = require('sockjs'); var websocket_multiplex = require('websocket-multiplex'); +var utils = require('./utils.js'); +var configurationAPI = require('../modules/api/configuration.js'); -function getPortForProtocol (protocol) { - switch (protocol) { - case 'http': - return 8000; - case 'https': - return 8443; - } -} - var Subscriptions = function() { this.ID = 0; this.socketServers = {}; @@ -85,7 +78,7 @@ Subscriptions.prototype.subscribe = function(req, callback) { var origin = ''; if (req.query['api_server']) { var api_server_protocol = req.query['api_server'].match(protocolTest)[1]; - var api_server_origin = req.query['api_server'] + ':' + getPortForProtocol(api_server_protocol); + var api_server_origin = req.query['api_server'] + ':' + utils.getPortForProtocol(api_server_protocol); origin = api_server_origin; protocol = api_server_protocol; } else { @@ -190,7 +183,7 @@ Subscriptions.prototype.socketInstance = function(url, req, wss, Type, channelId if (Type == PollingSocket) { Socket = new Type(url, req, 1000, req.body); } else { - Socket = new Type(url); + Socket = new Type(url, ['Bearer', req.session.passport.user.user['access_token']]); } console.log('Socket assigned for url', url); } @@ -286,12 +279,12 @@ function PollingSocket(url, req, interval, config) { self.isClosed = false; var requestHeaders = {}; _.extend(requestHeaders, { - 'Authorization': req.get('Authorization') + Cookie: req.get('Cookie') }); var pollServer = function() { Request({ - url: url, + url: utils.projectContextUrl(req, url), method: config.method || 'GET', headers: requestHeaders, json: config.payload, @@ -302,7 +295,11 @@ function PollingSocket(url, req, interval, config) { console.log('Error polling: ' + url); } else { if (!self.isClosed) { - self.poll = setTimeout(pollServer, 1000 || interval); + if(process.env.DISABLE_POLLING != "TRUE") { + self.poll = setTimeout(pollServer, 1000 || interval); + } else { + console.log('Polling is disabled. Finishing request.') + } var data = response.body; if (self.onmessage) { self.onmessage(data);