Default to using both clouddata.turbowarp.org and clouddata.turbowarp.xyz
This commit is contained in:
1 parent
0126cb36bb
commit
860f715201
3 files changed
+32
-15
No files matched your search
@@ -525,10 +525,13 @@
|
||||
{$_('options.cloudVariablesHost')}
|
||||
<input type="text" bind:value={$options.cloudVariables.cloudHost}>
|
||||
</label>
|
||||
<!-- TODO: Remove 12/20 -->
|
||||
<p class="small">
|
||||
Update: The default cloud variable server has changed from clouddata.turbowarp.org to clouddata.turbowarp.xyz. It's the same server with the same variables, just a different name.
|
||||
</p>
|
||||
<!-- TODO: Remove mid January 2021 -->
|
||||
{#if $options.cloudVariables.cloudHost === 'wss://clouddata.turbowarp.org'}
|
||||
<p class="small">
|
||||
Another update: The packager will try to connect to clouddata.turbowarp.org first, and if that fails, it will try clouddata.turbowarp.xyz instead.
|
||||
This should make connections more reliable on filtered internet connections.
|
||||
</p>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
|
||||
@@ -600,7 +600,14 @@ cd "$(dirname "$0")"
|
||||
}
|
||||
|
||||
makeWebSocketProvider () {
|
||||
return `new Scaffolding.Cloud.WebSocketProvider(${JSON.stringify(this.options.cloudVariables.cloudHost)}, ${JSON.stringify(this.options.projectId)})`;
|
||||
// If using the default turbowarp.org server, we'll add a fallback for the turbowarp.xyz alias.
|
||||
// This helps work around web filters as turbowarp.org can be blocked for games and turbowarp.xyz uses
|
||||
// a problematic TLD. These are the same server and same variables, just different domain.
|
||||
const cloudHost = this.options.cloudVariables.cloudHost === 'wss://clouddata.turbowarp.org' ? [
|
||||
'wss://clouddata.turbowarp.org',
|
||||
'wss://clouddata.turbowarp.xyz'
|
||||
] : this.options.cloudVariables.cloudHost;
|
||||
return `new Scaffolding.Cloud.WebSocketProvider(${JSON.stringify(cloudHost)}, ${JSON.stringify(this.options.projectId)})`;
|
||||
}
|
||||
|
||||
makeLocalStorageProvider () {
|
||||
@@ -1285,7 +1292,7 @@ Packager.DEFAULT_OPTIONS = () => ({
|
||||
},
|
||||
cloudVariables: {
|
||||
mode: 'ws',
|
||||
cloudHost: 'wss://clouddata.turbowarp.xyz',
|
||||
cloudHost: 'wss://clouddata.turbowarp.org',
|
||||
custom: {},
|
||||
specialCloudBehaviors: false,
|
||||
},
|
||||
|
||||
@@ -79,14 +79,19 @@ class CloudManager {
|
||||
}
|
||||
|
||||
class WebSocketProvider {
|
||||
/**
|
||||
* @param {string[]|string} cloudHost URLs of servers to connect to, including ws:// or wss://
|
||||
* If cloudHost is an array, the server will consecutively try each server until one connects.
|
||||
* @param {string} projectId The ID of the project
|
||||
*/
|
||||
constructor(cloudHost, projectId) {
|
||||
this.cloudHost = cloudHost;
|
||||
this.cloudHosts = Array.isArray(cloudHost) ? cloudHost : [cloudHost];
|
||||
this.projectId = projectId;
|
||||
this.connectionAttempts = 0;
|
||||
this.openConnection = this.openConnection.bind(this);
|
||||
this._throttleTimeoutFinished = this._throttleTimeoutFinished.bind(this);
|
||||
this.attemptedConnections = 0;
|
||||
this.messageQueue = [];
|
||||
this.throttleTimeout = null;
|
||||
this.openConnection = this.openConnection.bind(this);
|
||||
this._throttleTimeoutFinished = this._throttleTimeoutFinished.bind(this);
|
||||
}
|
||||
|
||||
enable () {
|
||||
@@ -94,8 +99,10 @@ class WebSocketProvider {
|
||||
}
|
||||
|
||||
openConnection () {
|
||||
this.connectionAttempts += 1;
|
||||
this.ws = new WebSocket(this.cloudHost);
|
||||
this.currentCloudHost = this.cloudHosts[this.attemptedConnections % this.cloudHosts.length];
|
||||
this.attemptedConnections++;
|
||||
console.log(`Connecting to ${this.currentCloudHost}`);
|
||||
this.ws = new WebSocket(this.currentCloudHost);
|
||||
this.ws.onerror = this.onerror.bind(this);
|
||||
this.ws.onmessage = this.onmessage.bind(this);
|
||||
this.ws.onopen = this.onopen.bind(this);
|
||||
@@ -118,7 +125,7 @@ class WebSocketProvider {
|
||||
}
|
||||
|
||||
onopen () {
|
||||
this.connectionAttempts = 1;
|
||||
this.attemptedConnections = 0;
|
||||
this.writeToServer({
|
||||
method: 'handshake'
|
||||
});
|
||||
@@ -131,8 +138,8 @@ class WebSocketProvider {
|
||||
console.log('WebSocket username is invalid, not reconnecting.');
|
||||
return;
|
||||
}
|
||||
const timeout = Math.random() * (Math.pow(2, Math.min(this.connectionAttempts, 5)) - 1) * 1000;
|
||||
console.log(`Reconnecting in ${(timeout / 1000).toFixed(1)}s, attempt ${this.connectionAttempts}`);
|
||||
const timeout = Math.random() * (Math.pow(2, Math.min(this.attemptedConnections + 1, 5)) - 1) * 1000;
|
||||
console.log(`Reconnecting in ${Math.round(timeout)}ms`);
|
||||
setTimeout(this.openConnection, timeout);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user