connectbase-client 5.12.2 → 5.12.3
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.
- package/CHANGELOG.md +18 -0
- package/dist/connect-base.umd.js +5 -5
- package/dist/index.d.mts +25 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.js +65 -10
- package/dist/index.mjs +65 -10
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -276,6 +276,19 @@ declare class HttpClient {
|
|
|
276
276
|
* 반복하지 않고 한 번에 포기하는 쪽이 안전하다.
|
|
277
277
|
*/
|
|
278
278
|
private directDisabled;
|
|
279
|
+
/**
|
|
280
|
+
* 서버가 `X-CB-Realtime-Direct-Base` 로 알려준 socket-server 저지연 원본(`wss://...`).
|
|
281
|
+
* HTTP direct(`directBaseUrl`)와 별도 값·별도 킬 스위치 — core-server 응답에서만 학습되고
|
|
282
|
+
* (WS 업그레이드 응답 헤더는 브라우저가 못 읽는다), `RealtimeAPI.doConnect()` 가 매 연결
|
|
283
|
+
* 시도마다 lazy 하게 조회한다. platform-issue 019fe448.
|
|
284
|
+
*/
|
|
285
|
+
private directRealtimeBaseUrl;
|
|
286
|
+
/**
|
|
287
|
+
* realtime WS 연결이 direct 원본에서 네트워크 레벨로 실패하면 세운다 — `directDisabled`
|
|
288
|
+
* 와 같은 철학("한 번 실패하면 이 세션에서는 포기하고 원래 호스트로")이지만, 실패 감지가
|
|
289
|
+
* WS 상태 머신(RealtimeAPI) 쪽에서 일어나므로 별도 플래그로 둔다.
|
|
290
|
+
*/
|
|
291
|
+
private directRealtimeDisabled;
|
|
279
292
|
/**
|
|
280
293
|
* 클라이언트 생성 시 명시된 요청 타임아웃(ms). 미지정이면 `undefined`.
|
|
281
294
|
*
|
|
@@ -377,6 +390,18 @@ declare class HttpClient {
|
|
|
377
390
|
* Base URL 반환
|
|
378
391
|
*/
|
|
379
392
|
getBaseUrl(): string;
|
|
393
|
+
/**
|
|
394
|
+
* socket-server 의 direct(저지연) WS 원본. 아직 학습 전이거나(REST 요청을 한 번도 안
|
|
395
|
+
* 보냈거나 서버가 광고를 안 함) 네트워크 레벨로 실패해 이 세션에서 포기했으면 `null` —
|
|
396
|
+
* 호출자(`RealtimeAPI`)는 이 경우 원래 소켓 URL로 폴백해야 한다.
|
|
397
|
+
*/
|
|
398
|
+
getDirectRealtimeBaseUrl(): string | null;
|
|
399
|
+
/**
|
|
400
|
+
* direct WS 원본이 네트워크 레벨로 실패했을 때 `RealtimeAPI` 가 호출한다. 이후 연결
|
|
401
|
+
* 시도는 이 세션 동안 전부 원래 소켓 URL로 간다 — direct 는 최적화일 뿐 필수가 아니므로
|
|
402
|
+
* 재시도를 반복하지 않는다(`directDisabled`/HTTP direct 와 같은 철학).
|
|
403
|
+
*/
|
|
404
|
+
disableDirectRealtime(): void;
|
|
380
405
|
/**
|
|
381
406
|
* 이 클라이언트에 설정된 앱 ID 반환 (미설정 시 undefined).
|
|
382
407
|
*
|
package/dist/index.d.ts
CHANGED
|
@@ -276,6 +276,19 @@ declare class HttpClient {
|
|
|
276
276
|
* 반복하지 않고 한 번에 포기하는 쪽이 안전하다.
|
|
277
277
|
*/
|
|
278
278
|
private directDisabled;
|
|
279
|
+
/**
|
|
280
|
+
* 서버가 `X-CB-Realtime-Direct-Base` 로 알려준 socket-server 저지연 원본(`wss://...`).
|
|
281
|
+
* HTTP direct(`directBaseUrl`)와 별도 값·별도 킬 스위치 — core-server 응답에서만 학습되고
|
|
282
|
+
* (WS 업그레이드 응답 헤더는 브라우저가 못 읽는다), `RealtimeAPI.doConnect()` 가 매 연결
|
|
283
|
+
* 시도마다 lazy 하게 조회한다. platform-issue 019fe448.
|
|
284
|
+
*/
|
|
285
|
+
private directRealtimeBaseUrl;
|
|
286
|
+
/**
|
|
287
|
+
* realtime WS 연결이 direct 원본에서 네트워크 레벨로 실패하면 세운다 — `directDisabled`
|
|
288
|
+
* 와 같은 철학("한 번 실패하면 이 세션에서는 포기하고 원래 호스트로")이지만, 실패 감지가
|
|
289
|
+
* WS 상태 머신(RealtimeAPI) 쪽에서 일어나므로 별도 플래그로 둔다.
|
|
290
|
+
*/
|
|
291
|
+
private directRealtimeDisabled;
|
|
279
292
|
/**
|
|
280
293
|
* 클라이언트 생성 시 명시된 요청 타임아웃(ms). 미지정이면 `undefined`.
|
|
281
294
|
*
|
|
@@ -377,6 +390,18 @@ declare class HttpClient {
|
|
|
377
390
|
* Base URL 반환
|
|
378
391
|
*/
|
|
379
392
|
getBaseUrl(): string;
|
|
393
|
+
/**
|
|
394
|
+
* socket-server 의 direct(저지연) WS 원본. 아직 학습 전이거나(REST 요청을 한 번도 안
|
|
395
|
+
* 보냈거나 서버가 광고를 안 함) 네트워크 레벨로 실패해 이 세션에서 포기했으면 `null` —
|
|
396
|
+
* 호출자(`RealtimeAPI`)는 이 경우 원래 소켓 URL로 폴백해야 한다.
|
|
397
|
+
*/
|
|
398
|
+
getDirectRealtimeBaseUrl(): string | null;
|
|
399
|
+
/**
|
|
400
|
+
* direct WS 원본이 네트워크 레벨로 실패했을 때 `RealtimeAPI` 가 호출한다. 이후 연결
|
|
401
|
+
* 시도는 이 세션 동안 전부 원래 소켓 URL로 간다 — direct 는 최적화일 뿐 필수가 아니므로
|
|
402
|
+
* 재시도를 반복하지 않는다(`directDisabled`/HTTP direct 와 같은 철학).
|
|
403
|
+
*/
|
|
404
|
+
disableDirectRealtime(): void;
|
|
380
405
|
/**
|
|
381
406
|
* 이 클라이언트에 설정된 앱 ID 반환 (미설정 시 undefined).
|
|
382
407
|
*
|
package/dist/index.js
CHANGED
|
@@ -8141,7 +8141,9 @@ var RealtimeAPI = class {
|
|
|
8141
8141
|
this.state = "connecting";
|
|
8142
8142
|
this.notifyStateChange();
|
|
8143
8143
|
this.log("Connecting...");
|
|
8144
|
-
const
|
|
8144
|
+
const directWsBase = this.http.getDirectRealtimeBaseUrl();
|
|
8145
|
+
const usingDirect = !!directWsBase;
|
|
8146
|
+
const wsUrl = (directWsBase ?? this.socketUrl).replace(/^http/, "ws");
|
|
8145
8147
|
let url;
|
|
8146
8148
|
if (this.options.accessToken) {
|
|
8147
8149
|
url = `${wsUrl}/v1/realtime/auth?access_token=${encodeURIComponent(this.options.accessToken)}&client_id=${this.clientId}`;
|
|
@@ -8171,6 +8173,7 @@ var RealtimeAPI = class {
|
|
|
8171
8173
|
this.ws.close();
|
|
8172
8174
|
this.ws = null;
|
|
8173
8175
|
}
|
|
8176
|
+
if (usingDirect) this.http.disableDirectRealtime();
|
|
8174
8177
|
this.state = "disconnected";
|
|
8175
8178
|
this.notifyStateChange();
|
|
8176
8179
|
reject(
|
|
@@ -8209,6 +8212,7 @@ var RealtimeAPI = class {
|
|
|
8209
8212
|
if (!settled && this.state === "connecting") {
|
|
8210
8213
|
settled = true;
|
|
8211
8214
|
clearTimeout(timeoutId);
|
|
8215
|
+
if (usingDirect) this.http.disableDirectRealtime();
|
|
8212
8216
|
reject(
|
|
8213
8217
|
new Error(
|
|
8214
8218
|
`Connection closed: ${event.reason || "unknown reason"}`
|
|
@@ -8226,12 +8230,14 @@ var RealtimeAPI = class {
|
|
|
8226
8230
|
if (!settled && this.state === "connecting") {
|
|
8227
8231
|
settled = true;
|
|
8228
8232
|
clearTimeout(timeoutId);
|
|
8233
|
+
if (usingDirect) this.http.disableDirectRealtime();
|
|
8229
8234
|
reject(new Error("Failed to connect"));
|
|
8230
8235
|
}
|
|
8231
8236
|
};
|
|
8232
8237
|
} catch (e) {
|
|
8233
8238
|
settled = true;
|
|
8234
8239
|
clearTimeout(timeoutId);
|
|
8240
|
+
if (usingDirect) this.http.disableDirectRealtime();
|
|
8235
8241
|
reject(e);
|
|
8236
8242
|
}
|
|
8237
8243
|
});
|
|
@@ -11550,6 +11556,19 @@ var HttpClient = class {
|
|
|
11550
11556
|
* 반복하지 않고 한 번에 포기하는 쪽이 안전하다.
|
|
11551
11557
|
*/
|
|
11552
11558
|
this.directDisabled = false;
|
|
11559
|
+
/**
|
|
11560
|
+
* 서버가 `X-CB-Realtime-Direct-Base` 로 알려준 socket-server 저지연 원본(`wss://...`).
|
|
11561
|
+
* HTTP direct(`directBaseUrl`)와 별도 값·별도 킬 스위치 — core-server 응답에서만 학습되고
|
|
11562
|
+
* (WS 업그레이드 응답 헤더는 브라우저가 못 읽는다), `RealtimeAPI.doConnect()` 가 매 연결
|
|
11563
|
+
* 시도마다 lazy 하게 조회한다. platform-issue 019fe448.
|
|
11564
|
+
*/
|
|
11565
|
+
this.directRealtimeBaseUrl = null;
|
|
11566
|
+
/**
|
|
11567
|
+
* realtime WS 연결이 direct 원본에서 네트워크 레벨로 실패하면 세운다 — `directDisabled`
|
|
11568
|
+
* 와 같은 철학("한 번 실패하면 이 세션에서는 포기하고 원래 호스트로")이지만, 실패 감지가
|
|
11569
|
+
* WS 상태 머신(RealtimeAPI) 쪽에서 일어나므로 별도 플래그로 둔다.
|
|
11570
|
+
*/
|
|
11571
|
+
this.directRealtimeDisabled = false;
|
|
11553
11572
|
this.config = { ...config };
|
|
11554
11573
|
this.storageKey = this.buildStorageKey();
|
|
11555
11574
|
this.warnIfUnsafePersistence();
|
|
@@ -11795,6 +11814,22 @@ var HttpClient = class {
|
|
|
11795
11814
|
getBaseUrl() {
|
|
11796
11815
|
return this.config.baseUrl;
|
|
11797
11816
|
}
|
|
11817
|
+
/**
|
|
11818
|
+
* socket-server 의 direct(저지연) WS 원본. 아직 학습 전이거나(REST 요청을 한 번도 안
|
|
11819
|
+
* 보냈거나 서버가 광고를 안 함) 네트워크 레벨로 실패해 이 세션에서 포기했으면 `null` —
|
|
11820
|
+
* 호출자(`RealtimeAPI`)는 이 경우 원래 소켓 URL로 폴백해야 한다.
|
|
11821
|
+
*/
|
|
11822
|
+
getDirectRealtimeBaseUrl() {
|
|
11823
|
+
return this.directRealtimeDisabled ? null : this.directRealtimeBaseUrl;
|
|
11824
|
+
}
|
|
11825
|
+
/**
|
|
11826
|
+
* direct WS 원본이 네트워크 레벨로 실패했을 때 `RealtimeAPI` 가 호출한다. 이후 연결
|
|
11827
|
+
* 시도는 이 세션 동안 전부 원래 소켓 URL로 간다 — direct 는 최적화일 뿐 필수가 아니므로
|
|
11828
|
+
* 재시도를 반복하지 않는다(`directDisabled`/HTTP direct 와 같은 철학).
|
|
11829
|
+
*/
|
|
11830
|
+
disableDirectRealtime() {
|
|
11831
|
+
this.directRealtimeDisabled = true;
|
|
11832
|
+
}
|
|
11798
11833
|
/**
|
|
11799
11834
|
* 이 클라이언트에 설정된 앱 ID 반환 (미설정 시 undefined).
|
|
11800
11835
|
*
|
|
@@ -12178,17 +12213,37 @@ var HttpClient = class {
|
|
|
12178
12213
|
* 일은 없어야 한다.
|
|
12179
12214
|
*/
|
|
12180
12215
|
learnDirectOrigin(response) {
|
|
12181
|
-
if (
|
|
12182
|
-
const
|
|
12183
|
-
|
|
12216
|
+
if (!response.headers) return;
|
|
12217
|
+
const tail = (h) => h.split(".").slice(-2).join(".");
|
|
12218
|
+
let base;
|
|
12184
12219
|
try {
|
|
12185
|
-
|
|
12186
|
-
const base = new URL(this.config.baseUrl);
|
|
12187
|
-
if (next.protocol !== "https:") return;
|
|
12188
|
-
const tail = (h) => h.split(".").slice(-2).join(".");
|
|
12189
|
-
if (tail(next.hostname) !== tail(base.hostname)) return;
|
|
12190
|
-
this.directBaseUrl = next.origin;
|
|
12220
|
+
base = new URL(this.config.baseUrl);
|
|
12191
12221
|
} catch {
|
|
12222
|
+
return;
|
|
12223
|
+
}
|
|
12224
|
+
if (!this.directDisabled && !this.directBaseUrl) {
|
|
12225
|
+
const advertised = response.headers.get("X-CB-Direct-Base");
|
|
12226
|
+
if (advertised) {
|
|
12227
|
+
try {
|
|
12228
|
+
const next = new URL(advertised);
|
|
12229
|
+
if (next.protocol === "https:" && tail(next.hostname) === tail(base.hostname)) {
|
|
12230
|
+
this.directBaseUrl = next.origin;
|
|
12231
|
+
}
|
|
12232
|
+
} catch {
|
|
12233
|
+
}
|
|
12234
|
+
}
|
|
12235
|
+
}
|
|
12236
|
+
if (!this.directRealtimeDisabled && !this.directRealtimeBaseUrl) {
|
|
12237
|
+
const advertisedRealtime = response.headers.get("X-CB-Realtime-Direct-Base");
|
|
12238
|
+
if (advertisedRealtime) {
|
|
12239
|
+
try {
|
|
12240
|
+
const next = new URL(advertisedRealtime);
|
|
12241
|
+
if (next.protocol === "wss:" && tail(next.hostname) === tail(base.hostname)) {
|
|
12242
|
+
this.directRealtimeBaseUrl = next.origin;
|
|
12243
|
+
}
|
|
12244
|
+
} catch {
|
|
12245
|
+
}
|
|
12246
|
+
}
|
|
12192
12247
|
}
|
|
12193
12248
|
}
|
|
12194
12249
|
/**
|
package/dist/index.mjs
CHANGED
|
@@ -8092,7 +8092,9 @@ var RealtimeAPI = class {
|
|
|
8092
8092
|
this.state = "connecting";
|
|
8093
8093
|
this.notifyStateChange();
|
|
8094
8094
|
this.log("Connecting...");
|
|
8095
|
-
const
|
|
8095
|
+
const directWsBase = this.http.getDirectRealtimeBaseUrl();
|
|
8096
|
+
const usingDirect = !!directWsBase;
|
|
8097
|
+
const wsUrl = (directWsBase ?? this.socketUrl).replace(/^http/, "ws");
|
|
8096
8098
|
let url;
|
|
8097
8099
|
if (this.options.accessToken) {
|
|
8098
8100
|
url = `${wsUrl}/v1/realtime/auth?access_token=${encodeURIComponent(this.options.accessToken)}&client_id=${this.clientId}`;
|
|
@@ -8122,6 +8124,7 @@ var RealtimeAPI = class {
|
|
|
8122
8124
|
this.ws.close();
|
|
8123
8125
|
this.ws = null;
|
|
8124
8126
|
}
|
|
8127
|
+
if (usingDirect) this.http.disableDirectRealtime();
|
|
8125
8128
|
this.state = "disconnected";
|
|
8126
8129
|
this.notifyStateChange();
|
|
8127
8130
|
reject(
|
|
@@ -8160,6 +8163,7 @@ var RealtimeAPI = class {
|
|
|
8160
8163
|
if (!settled && this.state === "connecting") {
|
|
8161
8164
|
settled = true;
|
|
8162
8165
|
clearTimeout(timeoutId);
|
|
8166
|
+
if (usingDirect) this.http.disableDirectRealtime();
|
|
8163
8167
|
reject(
|
|
8164
8168
|
new Error(
|
|
8165
8169
|
`Connection closed: ${event.reason || "unknown reason"}`
|
|
@@ -8177,12 +8181,14 @@ var RealtimeAPI = class {
|
|
|
8177
8181
|
if (!settled && this.state === "connecting") {
|
|
8178
8182
|
settled = true;
|
|
8179
8183
|
clearTimeout(timeoutId);
|
|
8184
|
+
if (usingDirect) this.http.disableDirectRealtime();
|
|
8180
8185
|
reject(new Error("Failed to connect"));
|
|
8181
8186
|
}
|
|
8182
8187
|
};
|
|
8183
8188
|
} catch (e) {
|
|
8184
8189
|
settled = true;
|
|
8185
8190
|
clearTimeout(timeoutId);
|
|
8191
|
+
if (usingDirect) this.http.disableDirectRealtime();
|
|
8186
8192
|
reject(e);
|
|
8187
8193
|
}
|
|
8188
8194
|
});
|
|
@@ -11501,6 +11507,19 @@ var HttpClient = class {
|
|
|
11501
11507
|
* 반복하지 않고 한 번에 포기하는 쪽이 안전하다.
|
|
11502
11508
|
*/
|
|
11503
11509
|
this.directDisabled = false;
|
|
11510
|
+
/**
|
|
11511
|
+
* 서버가 `X-CB-Realtime-Direct-Base` 로 알려준 socket-server 저지연 원본(`wss://...`).
|
|
11512
|
+
* HTTP direct(`directBaseUrl`)와 별도 값·별도 킬 스위치 — core-server 응답에서만 학습되고
|
|
11513
|
+
* (WS 업그레이드 응답 헤더는 브라우저가 못 읽는다), `RealtimeAPI.doConnect()` 가 매 연결
|
|
11514
|
+
* 시도마다 lazy 하게 조회한다. platform-issue 019fe448.
|
|
11515
|
+
*/
|
|
11516
|
+
this.directRealtimeBaseUrl = null;
|
|
11517
|
+
/**
|
|
11518
|
+
* realtime WS 연결이 direct 원본에서 네트워크 레벨로 실패하면 세운다 — `directDisabled`
|
|
11519
|
+
* 와 같은 철학("한 번 실패하면 이 세션에서는 포기하고 원래 호스트로")이지만, 실패 감지가
|
|
11520
|
+
* WS 상태 머신(RealtimeAPI) 쪽에서 일어나므로 별도 플래그로 둔다.
|
|
11521
|
+
*/
|
|
11522
|
+
this.directRealtimeDisabled = false;
|
|
11504
11523
|
this.config = { ...config };
|
|
11505
11524
|
this.storageKey = this.buildStorageKey();
|
|
11506
11525
|
this.warnIfUnsafePersistence();
|
|
@@ -11746,6 +11765,22 @@ var HttpClient = class {
|
|
|
11746
11765
|
getBaseUrl() {
|
|
11747
11766
|
return this.config.baseUrl;
|
|
11748
11767
|
}
|
|
11768
|
+
/**
|
|
11769
|
+
* socket-server 의 direct(저지연) WS 원본. 아직 학습 전이거나(REST 요청을 한 번도 안
|
|
11770
|
+
* 보냈거나 서버가 광고를 안 함) 네트워크 레벨로 실패해 이 세션에서 포기했으면 `null` —
|
|
11771
|
+
* 호출자(`RealtimeAPI`)는 이 경우 원래 소켓 URL로 폴백해야 한다.
|
|
11772
|
+
*/
|
|
11773
|
+
getDirectRealtimeBaseUrl() {
|
|
11774
|
+
return this.directRealtimeDisabled ? null : this.directRealtimeBaseUrl;
|
|
11775
|
+
}
|
|
11776
|
+
/**
|
|
11777
|
+
* direct WS 원본이 네트워크 레벨로 실패했을 때 `RealtimeAPI` 가 호출한다. 이후 연결
|
|
11778
|
+
* 시도는 이 세션 동안 전부 원래 소켓 URL로 간다 — direct 는 최적화일 뿐 필수가 아니므로
|
|
11779
|
+
* 재시도를 반복하지 않는다(`directDisabled`/HTTP direct 와 같은 철학).
|
|
11780
|
+
*/
|
|
11781
|
+
disableDirectRealtime() {
|
|
11782
|
+
this.directRealtimeDisabled = true;
|
|
11783
|
+
}
|
|
11749
11784
|
/**
|
|
11750
11785
|
* 이 클라이언트에 설정된 앱 ID 반환 (미설정 시 undefined).
|
|
11751
11786
|
*
|
|
@@ -12129,17 +12164,37 @@ var HttpClient = class {
|
|
|
12129
12164
|
* 일은 없어야 한다.
|
|
12130
12165
|
*/
|
|
12131
12166
|
learnDirectOrigin(response) {
|
|
12132
|
-
if (
|
|
12133
|
-
const
|
|
12134
|
-
|
|
12167
|
+
if (!response.headers) return;
|
|
12168
|
+
const tail = (h) => h.split(".").slice(-2).join(".");
|
|
12169
|
+
let base;
|
|
12135
12170
|
try {
|
|
12136
|
-
|
|
12137
|
-
const base = new URL(this.config.baseUrl);
|
|
12138
|
-
if (next.protocol !== "https:") return;
|
|
12139
|
-
const tail = (h) => h.split(".").slice(-2).join(".");
|
|
12140
|
-
if (tail(next.hostname) !== tail(base.hostname)) return;
|
|
12141
|
-
this.directBaseUrl = next.origin;
|
|
12171
|
+
base = new URL(this.config.baseUrl);
|
|
12142
12172
|
} catch {
|
|
12173
|
+
return;
|
|
12174
|
+
}
|
|
12175
|
+
if (!this.directDisabled && !this.directBaseUrl) {
|
|
12176
|
+
const advertised = response.headers.get("X-CB-Direct-Base");
|
|
12177
|
+
if (advertised) {
|
|
12178
|
+
try {
|
|
12179
|
+
const next = new URL(advertised);
|
|
12180
|
+
if (next.protocol === "https:" && tail(next.hostname) === tail(base.hostname)) {
|
|
12181
|
+
this.directBaseUrl = next.origin;
|
|
12182
|
+
}
|
|
12183
|
+
} catch {
|
|
12184
|
+
}
|
|
12185
|
+
}
|
|
12186
|
+
}
|
|
12187
|
+
if (!this.directRealtimeDisabled && !this.directRealtimeBaseUrl) {
|
|
12188
|
+
const advertisedRealtime = response.headers.get("X-CB-Realtime-Direct-Base");
|
|
12189
|
+
if (advertisedRealtime) {
|
|
12190
|
+
try {
|
|
12191
|
+
const next = new URL(advertisedRealtime);
|
|
12192
|
+
if (next.protocol === "wss:" && tail(next.hostname) === tail(base.hostname)) {
|
|
12193
|
+
this.directRealtimeBaseUrl = next.origin;
|
|
12194
|
+
}
|
|
12195
|
+
} catch {
|
|
12196
|
+
}
|
|
12197
|
+
}
|
|
12143
12198
|
}
|
|
12144
12199
|
}
|
|
12145
12200
|
/**
|