@lzpenguin/server 1.1.4 → 1.1.6
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/README.md +2 -2
- package/index.js +5 -9
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -17,7 +17,7 @@ import { RiffleServer } from '@lzpenguin/server';
|
|
|
17
17
|
// 注意:post_id 和 token 会自动从 URL 参数中读取
|
|
18
18
|
// URL 格式:https://example.com/game.html?post_id=123456&token=your-token
|
|
19
19
|
const server = new RiffleServer({
|
|
20
|
-
url: '
|
|
20
|
+
url: 'api.riffle.app', // 必需:WebSocket 服务器地址,不要带wss://前缀
|
|
21
21
|
timestamp: 1234567890, // 必需:游戏时间戳(数字类型),直接使用上下文中给出的值
|
|
22
22
|
autoReconnect: true, // 可选:自动重连,默认 true
|
|
23
23
|
reconnectInterval: 3000 // 可选:重连间隔(毫秒),默认 3000
|
|
@@ -123,7 +123,7 @@ unsubscribe();
|
|
|
123
123
|
import { RiffleServer } from '@lzpenguin/server';
|
|
124
124
|
|
|
125
125
|
const server = new RiffleServer({
|
|
126
|
-
url: '
|
|
126
|
+
url: 'api.riffle.app',
|
|
127
127
|
timestamp: 1234567890
|
|
128
128
|
});
|
|
129
129
|
|
package/index.js
CHANGED
|
@@ -85,18 +85,14 @@ export class RiffleServer {
|
|
|
85
85
|
throw new Error('timestamp is required');
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
-
//
|
|
88
|
+
// 从全局变量或浏览器 URL 参数中读取 post_id 和 token
|
|
89
89
|
let postId;
|
|
90
90
|
let token;
|
|
91
91
|
|
|
92
|
-
if (isBrowser && typeof window !== 'undefined'
|
|
93
|
-
const
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
}
|
|
97
|
-
if (urlParams.has('token')) {
|
|
98
|
-
token = urlParams.get('token');
|
|
99
|
-
}
|
|
92
|
+
if (isBrowser && typeof window !== 'undefined') {
|
|
93
|
+
const postIdRaw = window.__RIFFLE_POST_ID__ || new URLSearchParams(location.search).get('post_id');
|
|
94
|
+
postId = postIdRaw ? parseInt(postIdRaw, 10) : undefined;
|
|
95
|
+
token = window.__RIFFLE_TOKEN__ || new URLSearchParams(location.search).get('token');
|
|
100
96
|
}
|
|
101
97
|
|
|
102
98
|
if (!postId) {
|