Skip to content

Commit bf84d59

Browse files
committed
Added option to connect to Europe server
1 parent 6a769c9 commit bf84d59

5 files changed

Lines changed: 39 additions & 10 deletions

File tree

package-lock.json

Lines changed: 28 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"url": "git+https://github.com/tago-io/tcore.git"
2121
},
2222
"dependencies": {
23-
"@tago-io/sdk": "11.3.6",
23+
"@tago-io/sdk": "11.3.10",
2424
"async": "3.2.6",
2525
"axios": "0.26.0",
2626
"body-parser": "2.0.1",

plugins/tagoio-integration/src/back/RealtimeConnection.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@ const pingInterval = 240000;
1616

1717
/**
1818
*/
19-
function startRealtimeCommunication(token: string) {
19+
async function startRealtimeCommunication(token: string) {
2020
if (!token || events) {
2121
return;
2222
}
2323

2424
const channel = "commands";
2525
const params = new URLSearchParams({ token, channel });
26-
const url = `${getConnectionURI.default.default("usa-1").sse}?${params.toString()}`;
26+
const region = await pluginStorage.get("region") || "us-e1";
27+
const url = `${getConnectionURI.default.default(region).sse}?${params.toString()}`;
2728

2829
const connect = () => {
2930
events = new EventSource(url);

plugins/tagoio-integration/src/back/Request.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import * as getConnectionURI from "@tago-io/sdk/lib/regions.js";
2+
import { pluginStorage } from "@tago-io/tcore-sdk";
23
import axios from "axios";
34

45
/**
56
* Creates a new instance with the given data.
67
*/
78
async function createTCore(token: string, data: any) {
89
try {
10+
const region = await pluginStorage.get("region") || "us-e1";
911
const response = await axios({
10-
url: `${getConnectionURI.default.default("usa-1").api}/tcore/instance`,
12+
url: `${getConnectionURI.default.default(region).api}/tcore/instance`,
1113
method: "POST",
1214
headers: { token },
1315
data,
@@ -28,8 +30,9 @@ async function sendDataToTagoio(
2830
operation: string,
2931
) {
3032
try {
33+
const region = await pluginStorage.get("region") || "us-e1";
3134
const response = await axios({
32-
url: `${getConnectionURI.default.default("usa-1").api}/tcore/sse/${connId}`,
35+
url: `${getConnectionURI.default.default(region).api}/tcore/sse/${connId}`,
3336
method: "POST",
3437
headers: { token },
3538
data: {

plugins/tagoio-integration/src/back/Server.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ async function routeStartTCore(req: Request, res: Response) {
8383
const tcoreStartTime = new Date(Date.now() - process.uptime() * 1000);
8484
const osInfo = await helpers.getOSInfo();
8585
const profileToken = "p-".concat(req.headers.token as string);
86+
const region = req.headers.region as string;
87+
await pluginStorage.set("region", region);
8688
const item = await pluginStorage.get("tcore").catch(() => null);
8789

8890
if (item?.token) {

0 commit comments

Comments
 (0)