@lzpenguin/server 1.1.9 → 1.1.10

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.
Files changed (2) hide show
  1. package/index.js +37 -9
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -83,10 +83,6 @@ export class RiffleServer {
83
83
  }
84
84
  }
85
85
 
86
- if (!baseUrl) {
87
- throw new Error('Base URL not found');
88
- }
89
-
90
86
  // 从全局变量或 URL 参数中读取 post_id 和 token
91
87
  let postId;
92
88
  let token;
@@ -97,11 +93,27 @@ export class RiffleServer {
97
93
  token = window.__RIFFLE_TOKEN__ || new URLSearchParams(location.search).get('token');
98
94
  }
99
95
 
100
- if (!postId) {
101
- throw new Error('Post ID not found');
102
- }
103
- if (!token) {
104
- throw new Error('Token not found');
96
+ // 设置降级模式标志
97
+ this.isDisabled = false;
98
+
99
+ if (!baseUrl || !postId || !token) {
100
+ console.warn('[RiffleServer] Configuration not found (base_url, post_id or token missing), running in disabled mode');
101
+ this.isDisabled = true;
102
+ this.url = null;
103
+ this.postId = null;
104
+ this.token = null;
105
+ this.timestamp = timestamp;
106
+ this.autoReconnect = false;
107
+ this.reconnectInterval = reconnectInterval;
108
+ this.ws = null;
109
+ this.isConnected = false;
110
+ this.isConnecting = false;
111
+ this.isInitialized = false;
112
+ this.reconnectTimer = null;
113
+ this.dataCallbacks = [];
114
+ this.pendingInit = null;
115
+ this.currentData = null;
116
+ return;
105
117
  }
106
118
 
107
119
  this.url = baseUrl;
@@ -133,6 +145,12 @@ export class RiffleServer {
133
145
  * @private
134
146
  */
135
147
  async connect() {
148
+ // 如果处于降级模式,不进行连接
149
+ if (this.isDisabled) {
150
+ console.warn('[RiffleServer] Service is disabled, skipping connection');
151
+ return;
152
+ }
153
+
136
154
  if (this.isConnecting || (this.isConnected && this.ws?.readyState === (WebSocketImpl?.OPEN ?? 1))) {
137
155
  return;
138
156
  }
@@ -261,6 +279,11 @@ export class RiffleServer {
261
279
  * @param {Object} updateData - 更新数据
262
280
  */
263
281
  sendUpdate(updateData) {
282
+ // 如果处于降级模式,不发送更新
283
+ if (this.isDisabled) {
284
+ return;
285
+ }
286
+
264
287
  if (!this.isConnected || this.ws?.readyState !== WebSocketImpl.OPEN) {
265
288
  console.warn('[RiffleServer] Not connected, cannot send update');
266
289
  return;
@@ -304,6 +327,11 @@ export class RiffleServer {
304
327
  * });
305
328
  */
306
329
  init(initData = {}) {
330
+ // 如果处于降级模式,不执行初始化
331
+ if (this.isDisabled) {
332
+ return;
333
+ }
334
+
307
335
  // 如果还未连接,保存 init 请求,连接建立后自动执行
308
336
  if (!this.isConnected || this.ws?.readyState !== WebSocketImpl.OPEN) {
309
337
  console.log('[RiffleServer] Not connected yet, will init after connection');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lzpenguin/server",
3
- "version": "1.1.9",
3
+ "version": "1.1.10",
4
4
  "description": "Riffle 游戏服务器 WebSocket 客户端 SDK",
5
5
  "license": "ISC",
6
6
  "author": "lzpenguin",