mirror of https://github.com/calzoneman/sync.git
Initial sioconfig migration work
This commit is contained in:
parent
dacda65961
commit
40e2a608f6
22
NEWS.md
22
NEWS.md
|
@ -1,3 +1,25 @@
|
||||||
|
2015-10-19
|
||||||
|
==========
|
||||||
|
|
||||||
|
In order to support future clustering support, the legacy `/sioconfig`
|
||||||
|
endpoint is being deprecated. Instead, you should make a request to
|
||||||
|
`/socketconfig/<channel name>.json`. The response will look similar to
|
||||||
|
these:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{"url":"https://some-website.com:8443","secure":true}
|
||||||
|
{"error":"Channel \"!@#$\" does not exist."}
|
||||||
|
```
|
||||||
|
|
||||||
|
The `url` key specifies the socket.io URL to connect to, and the `secure`
|
||||||
|
key indicates whether the connection is secured with TLS. If an `error` key
|
||||||
|
is present, something went wrong and the value will contain an error
|
||||||
|
message.
|
||||||
|
|
||||||
|
For now, only one URL is returned, however in the future this may be
|
||||||
|
extended by adding an `alt` key specifying an array of acceptable URLs to
|
||||||
|
connect to.
|
||||||
|
|
||||||
2015-10-04
|
2015-10-04
|
||||||
==========
|
==========
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
"author": "Calvin Montgomery",
|
"author": "Calvin Montgomery",
|
||||||
"name": "CyTube",
|
"name": "CyTube",
|
||||||
"description": "Online media synchronizer and chat",
|
"description": "Online media synchronizer and chat",
|
||||||
"version": "3.11.2",
|
"version": "3.12.0",
|
||||||
"repository": {
|
"repository": {
|
||||||
"url": "http://github.com/calzoneman/sync"
|
"url": "http://github.com/calzoneman/sync"
|
||||||
},
|
},
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
export default class IOConfiguration {
|
||||||
|
constructor(config) {
|
||||||
|
this.config = config;
|
||||||
|
}
|
||||||
|
|
||||||
|
getSocketURL() {
|
||||||
|
return this.config.urls[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
IOConfiguration.fromOldConfig = function (oldConfig) {
|
||||||
|
const config = {
|
||||||
|
urls: []
|
||||||
|
};
|
||||||
|
|
||||||
|
['ipv4-ssl', 'ipv4-nossl', 'ipv6-ssl', 'ipv6-nossl'].forEach(key => {
|
||||||
|
if (oldConfig.get('io.' + key)) {
|
||||||
|
config.urls.push(oldConfig.get('io.' + key));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return new IOConfiguration(config);
|
||||||
|
};
|
|
@ -0,0 +1,11 @@
|
||||||
|
import Promise from 'bluebird';
|
||||||
|
|
||||||
|
export default class NullClusterClient {
|
||||||
|
constructor(ioConfig) {
|
||||||
|
this.ioConfig = ioConfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
getSocketURL(channel) {
|
||||||
|
return Promise.resolve(this.ioConfig.getSocketURL());
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,24 @@
|
||||||
|
import IOConfiguration from '../../configuration/ioconfig';
|
||||||
|
import NullClusterClient from '../../io/cluster/nullclusterclient';
|
||||||
|
import Config from '../../config';
|
||||||
|
import CyTubeUtil from '../../utilities';
|
||||||
|
|
||||||
|
export default function initialize(app) {
|
||||||
|
const ioConfig = IOConfiguration.fromOldConfig(Config);
|
||||||
|
const clusterClient = new NullClusterClient(ioConfig);
|
||||||
|
|
||||||
|
app.get('/socketconfig/:channel.json', (req, res) => {
|
||||||
|
if (!req.params.channel || !CyTubeUtil.isValidChannelName(req.params.channel)) {
|
||||||
|
return res.status(400).json({
|
||||||
|
error: `Channel "${req.params.channel}" does not exist.`
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
clusterClient.getSocketURL(req.params.channel).then(url => {
|
||||||
|
res.json({
|
||||||
|
url,
|
||||||
|
secure: /^(https|wss)/.test(url)
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
|
@ -117,7 +117,8 @@ function handleIndex(req, res) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles a request for the socket.io information
|
* Legacy socket.io configuration endpoint. This is being migrated to
|
||||||
|
* /socketconfig/<channel name>.json (see ./routes/socketconfig.js)
|
||||||
*/
|
*/
|
||||||
function handleSocketConfig(req, res) {
|
function handleSocketConfig(req, res) {
|
||||||
if (/\.json$/.test(req.path)) {
|
if (/\.json$/.test(req.path)) {
|
||||||
|
@ -243,6 +244,7 @@ module.exports = {
|
||||||
app.get("/r/:channel", handleChannel);
|
app.get("/r/:channel", handleChannel);
|
||||||
app.get("/", handleIndex);
|
app.get("/", handleIndex);
|
||||||
app.get("/sioconfig(.json)?", handleSocketConfig);
|
app.get("/sioconfig(.json)?", handleSocketConfig);
|
||||||
|
require("./routes/socketconfig")(app);
|
||||||
app.get("/useragreement", handleUserAgreement);
|
app.get("/useragreement", handleUserAgreement);
|
||||||
app.get("/contact", handleContactPage);
|
app.get("/contact", handleContactPage);
|
||||||
require("./auth").init(app);
|
require("./auth").init(app);
|
||||||
|
|
|
@ -239,7 +239,6 @@ html(lang="en")
|
||||||
mixin footer()
|
mixin footer()
|
||||||
script(src=sioSource)
|
script(src=sioSource)
|
||||||
script(src="/js/data.js")
|
script(src="/js/data.js")
|
||||||
script(src="/sioconfig")
|
|
||||||
script(src="/js/util.js")
|
script(src="/js/util.js")
|
||||||
script(src="/js/player.js")
|
script(src="/js/player.js")
|
||||||
script(src="/js/paginator.js")
|
script(src="/js/paginator.js")
|
||||||
|
|
|
@ -1096,27 +1096,39 @@ setupCallbacks = function() {
|
||||||
});
|
});
|
||||||
})(key);
|
})(key);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
try {
|
(function () {
|
||||||
if (typeof io === "undefined") {
|
if (typeof io === "undefined") {
|
||||||
makeAlert("Uh oh!", "It appears the connection to <code>" + IO_URL + "</code> " +
|
makeAlert("Uh oh!", "It appears the connection to <code>" + IO_URL + "</code> " +
|
||||||
"has failed. If this error persists, a firewall or " +
|
"has failed. If this error persists, a firewall or " +
|
||||||
"antivirus is likely blocking the connection, or the " +
|
"antivirus is likely blocking the connection, or the " +
|
||||||
"server is down.", "alert-danger")
|
"server is down.", "alert-danger")
|
||||||
.appendTo($("#announcements"));
|
.appendTo($("#announcements"));
|
||||||
throw false;
|
Callbacks.disconnect();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var opts = { transports: ["websocket", "polling"] };
|
$.getJSON("/socketconfig/" + CHANNEL.name + ".json")
|
||||||
if (IO_URL === IO_URLS["ipv4-ssl"] || IO_URL === IO_URLS["ipv6-ssl"]) {
|
.done(function (socketConfig) {
|
||||||
opts.secure = true;
|
console.log(socketConfig);
|
||||||
socket = io(IO_URL, { secure: true });
|
if (socketConfig.error) {
|
||||||
|
makeAlert("Socket.io configuration returned error: " +
|
||||||
|
socketConfig.error, "alert-danger")
|
||||||
|
.appendTo($("#announcements"));
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
socket = io(IO_URL, opts);
|
|
||||||
|
var opts = {
|
||||||
|
transports: ["websocket", "polling"],
|
||||||
|
secure: socketConfig.secure
|
||||||
|
};
|
||||||
|
|
||||||
|
socket = io(socketConfig.url, opts);
|
||||||
setupCallbacks();
|
setupCallbacks();
|
||||||
} catch (e) {
|
}).fail(function () {
|
||||||
if (e) {
|
makeAlert("Failed to retrieve socket.io configuration", "alert-danger")
|
||||||
|
.appendTo($("#announcements"));
|
||||||
Callbacks.disconnect();
|
Callbacks.disconnect();
|
||||||
}
|
});
|
||||||
}
|
})();
|
||||||
|
|
Loading…
Reference in New Issue