@rsdoctor/components 0.4.7 → 0.4.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -41,10 +41,10 @@ class LocalServerDataLoader extends BaseDataLoader {
41
41
  async loadAPI(...args) {
42
42
  const [api, body] = args;
43
43
  const key = body ? `${api}_${JSON.stringify(body)}` : `${api}`;
44
- const socketUrl = this.get("__SOCKET__URL__") ?? "";
44
+ const socketPort = this.get("__SOCKET__PORT__") ?? "";
45
45
  return this.limit(key, async () => {
46
46
  return new Promise((resolve) => {
47
- getSocket(socketUrl).emit(
47
+ getSocket(socketPort).emit(
48
48
  api,
49
49
  body,
50
50
  (res) => {
@@ -4,6 +4,7 @@ export declare function loadManifestByUrl(url: string): Promise<{
4
4
  data: Manifest.RsdoctorManifestData;
5
5
  cloudData?: Record<keyof Manifest.RsdoctorManifestData, string[] | string>;
6
6
  __LOCAL__SERVER__?: boolean;
7
+ __SOCKET__PORT__?: string;
7
8
  __SOCKET__URL__?: string;
8
9
  client: Manifest.RsdoctorManifestClient;
9
10
  cloudManifestUrl?: string | undefined;
@@ -16,6 +17,7 @@ export declare function parseManifest(json: Manifest.RsdoctorManifestWithShardin
16
17
  data: Manifest.RsdoctorManifestData;
17
18
  cloudData?: Record<keyof Manifest.RsdoctorManifestData, string[] | string>;
18
19
  __LOCAL__SERVER__?: boolean;
20
+ __SOCKET__PORT__?: string;
19
21
  __SOCKET__URL__?: string;
20
22
  client: Manifest.RsdoctorManifestClient;
21
23
  cloudManifestUrl?: string | undefined;
@@ -1,2 +1,7 @@
1
1
  import { Socket } from 'socket.io-client';
2
- export declare function getSocket(socketUrl?: string): Socket;
2
+ export declare function getSocket(socketPort?: string): Socket;
3
+ export declare function formatURL({ port, protocol, hostname, }: {
4
+ port?: string;
5
+ protocol: string;
6
+ hostname: string;
7
+ }): string;
@@ -12,10 +12,31 @@ function ensureSocket(socketUrl = defaultSocketUrl) {
12
12
  }
13
13
  return map.get(socketUrl);
14
14
  }
15
- function getSocket(socketUrl) {
16
- const socket = ensureSocket(socketUrl || defaultSocketUrl);
15
+ function getSocket(socketPort) {
16
+ const socketUrl = formatURL({
17
+ port: socketPort,
18
+ hostname: location.hostname,
19
+ protocol: location.protocol
20
+ });
21
+ const socket = ensureSocket(socketPort ? socketUrl : defaultSocketUrl);
17
22
  return socket;
18
23
  }
24
+ function formatURL({
25
+ port,
26
+ protocol,
27
+ hostname
28
+ }) {
29
+ if (typeof URL !== "undefined") {
30
+ const url = new URL("http://localhost");
31
+ url.port = String(port);
32
+ url.hostname = hostname;
33
+ url.protocol = location.protocol.includes("https") ? "wss" : "ws";
34
+ return url.toString();
35
+ }
36
+ const colon = protocol.indexOf(":") === -1 ? ":" : "";
37
+ return `${protocol}${colon}//${hostname}:${port}`;
38
+ }
19
39
  export {
40
+ formatURL,
20
41
  getSocket
21
42
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsdoctor/components",
3
- "version": "0.4.7",
3
+ "version": "0.4.8",
4
4
  "main": "./dist/index.js",
5
5
  "license": "MIT",
6
6
  "module": "dist/index.js",
@@ -75,9 +75,9 @@
75
75
  "terser": "^5.34.1",
76
76
  "typescript": "^5.2.2",
77
77
  "url-parse": "1.5.10",
78
- "@rsdoctor/graph": "0.4.7",
79
- "@rsdoctor/types": "0.4.7",
80
- "@rsdoctor/utils": "0.4.7"
78
+ "@rsdoctor/graph": "0.4.8",
79
+ "@rsdoctor/types": "0.4.8",
80
+ "@rsdoctor/utils": "0.4.8"
81
81
  },
82
82
  "publishConfig": {
83
83
  "access": "public",