Skip to content

Commit

Permalink
Merge pull request #397 from andig/wamp-proxy
Browse files Browse the repository at this point in the history
Add support for websocket proxying via http port
  • Loading branch information
andig committed Feb 13, 2016
2 parents 8b7880c + d32363e commit c7e97f0
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 23 deletions.
50 changes: 31 additions & 19 deletions htdocs/frontend/javascripts/init.js
Expand Up @@ -130,26 +130,38 @@ $(document).ready(function() {

// create WAMP sessions for each middleware
vz.middleware.each(function(idx, middleware) {
// update port configured?
if (middleware.live) {
var parser = document.createElement('a');
parser.href = middleware.url;
var host = parser.hostname || location.host; // location object for IE
var protocol = (parser.protocol || location.protocol).toLowerCase().indexOf("https") === 0 ? "wss" : "ws";
var uri = protocol + "://" + host + ":" + middleware.live;

// connect and store session
new ab.connect(uri, function(session) {
middleware.session = session;

// subscribe entities
vz.entities.each(function(entity) {
if (entity.active && entity.middleware == middleware.url) {
entity.subscribe(session);
}
}, true);
});
var parser = document.createElement('a');
parser.href = middleware.url;
var host = parser.hostname || location.host; // location object for IE
var protocol = (parser.protocol || location.protocol).toLowerCase().indexOf("https") === 0 ? "wss" : "ws";
var uri = protocol + "://" + host;

// try uri if nothing configured - requires Apache ProxyPass, see
// https://github.com/volkszaehler/volkszaehler.org/issues/382
if (isNaN(parseFloat(middleware.live))) {
if (parser.port) {
uri += ":" + parser.port;
}
// if Apache ProxyPass is used, connect with http(s) but always forward to unencrypted port
uri += parser.pathname.replace(/middleware.php$/, "ws");
console.info("Live updates not configured. Trying default path at " + uri);
}
else {
// use dedicated port
uri += ":" + middleware.live;
}

// connect and store session
new ab.connect(uri, function(session) {
middleware.session = session;

// subscribe entities
vz.entities.each(function(entity) {
if (entity.active && entity.middleware == middleware.url) {
entity.subscribe(session);
}
}, true);
});
});
});
});
Expand Down
11 changes: 7 additions & 4 deletions htdocs/frontend/javascripts/options.js
Expand Up @@ -37,12 +37,15 @@ vz.options = {
middleware: [
{
title: 'Local (default)',
url: '../middleware.php',
live: 8082
url: '../middleware.php'
// live: 8082 // NOTE: live updates require
// - push-server running and
// - either apache proxy forwarding configured according to
// https://github.com/volkszaehler/volkszaehler.org/issues/382
// - or push-server live update port configured and accessible
}, {
title: 'Volkszaehler Demo',
url: '//demo.volkszaehler.org/middleware.php',
live: 8082
url: '//demo.volkszaehler.org/middleware.php'
}
],
monthNames: ['Jan', 'Feb', unescape('M%E4r'), 'Apr', 'Mai', 'Jun', 'Jul', 'Aug', 'Sep', 'Okt', 'Nov', 'Dez'],
Expand Down

0 comments on commit c7e97f0

Please sign in to comment.