Skip to content

Commit a4180ae

Browse files
shenjackyuanjiemoonrailgun
authored andcommitted
chore: change env to DISABLE_MESSAGEPACK and enhance the code
1 parent 57fa22c commit a4180ae

File tree

6 files changed

+21
-41
lines changed

6 files changed

+21
-41
lines changed

client/packages/tailchat-client-sdk/src/openapi/client/ws.ts

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,14 @@ export class TailchatWsClient extends TailchatBaseClient {
2020
await this.waitingForLogin();
2121

2222
const token = this.jwt;
23-
let socket: Socket;
24-
if (this.useMsgpack) {
25-
socket = this.socket = io(this.url, {
26-
transports: ['websocket'],
27-
auth: {
28-
token,
29-
},
30-
forceNew: true,
31-
parser: msgpackParser,
32-
});
33-
} else {
34-
socket = this.socket = io(this.url, {
35-
transports: ['websocket'],
36-
auth: {
37-
token,
38-
},
39-
forceNew: true,
40-
});
41-
}
23+
const socket = (this.socket = io(this.url, {
24+
transports: ['websocket'],
25+
auth: {
26+
token,
27+
},
28+
forceNew: true,
29+
parser: this.useMsgpack ? msgpackParser : undefined,
30+
}));
4231

4332
socket.once('connect', () => {
4433
// 连接成功

client/shared/api/socket.ts

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -208,24 +208,15 @@ export function createSocket(token: string): Promise<AppSocket> {
208208
}
209209

210210
return new Promise((resolve, reject) => {
211-
if (getGlobalConfig().disableSocketMsgpack) {
212-
_socket = io(getServiceUrl(), {
213-
transports: ['websocket'],
214-
auth: {
215-
token,
216-
},
217-
forceNew: true,
218-
});
219-
} else {
220-
_socket = io(getServiceUrl(), {
221-
transports: ['websocket'],
222-
auth: {
223-
token,
224-
},
225-
forceNew: true,
226-
parser: msgpackParser,
227-
});
228-
}
211+
const disableSocketMsgpack = getGlobalConfig().disableSocketMsgpack;
212+
_socket = io(getServiceUrl(), {
213+
transports: ['websocket'],
214+
auth: {
215+
token,
216+
},
217+
forceNew: true,
218+
parser: disableSocketMsgpack ? undefined : msgpackParser,
219+
});
229220
_socket.once('connect', () => {
230221
// 连接成功
231222
const appSocket = new AppSocket(_socket);

server/packages/sdk/src/services/lib/settings.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export const config = {
6363
websiteId: process.env.TIANJI_WEBSITE_ID,
6464
},
6565
feature: {
66-
disableSocketMsgpack: checkEnvTrusty(process.env.DISABLE_SOCKET_MSGPACK), // 是否禁用socketio的 msgpack parser
66+
disableMsgpack: checkEnvTrusty(process.env.DISABLE_MESSAGEPACK), // 是否禁用socketio的 messgpack parser
6767
disableFileCheck: checkEnvTrusty(process.env.DISABLE_FILE_CHECK),
6868
disableLogger: checkEnvTrusty(process.env.DISABLE_LOGGER), // 是否关闭日志
6969
disableUserRegister: checkEnvTrusty(process.env.DISABLE_USER_REGISTER), // 是否关闭用户注册功能

server/services/core/config.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class ConfigService extends TcService {
8080
tianji: config.tianji,
8181
uploadFileLimit: config.storage.limit,
8282
emailVerification: config.emailVerification,
83-
disableSocketMsgpack: config.feature.disableSocketMsgpack,
83+
disableMsgpack: config.feature.disableMsgpack,
8484
disableUserRegister: config.feature.disableUserRegister,
8585
disableGuestLogin: config.feature.disableGuestLogin,
8686
disableCreateGroup: config.feature.disableCreateGroup,

website/docs/deployment/environment.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ title: Environment Variable
2727
| REQUEST_TIMEOUT | 10000 | Number of milliseconds to wait before reject a request with a RequestTimeout error. Disabled: 0 |
2828
| TIANJI_SCRIPT_URL | - | Script Url of Tianji if you wanna monitor Tailchat user usage, you can get it in code modal in Tianji website (example: `https://tianji.example.com/tracker.js`) |
2929
| TIANJI_WEBSITE_ID | - | Tianji website id |
30-
| DISABLE_SOCKET_MSGPACK | - | Whether to disable socket using messagepack, if "1" or "true" turn off this method |
30+
| DISABLE_MESSAGEPACK | - | Whether to disable using messagepack as [parser](https://socket.io/docs/v4/custom-parser/) for socketio in openapi, if "1" or "true" turn off this method |
3131
| DISABLE_LOGGER | - | Whether to disable the log output, if "1" or "true" turn off the log on the fly |
3232
| DISABLE_USER_REGISTER | - | Whether to disable the user register, if "1" or "true" turn off this method |
3333
| DISABLE_GUEST_LOGIN | - | Whether to disable the guest login, if "1" or "true" turn off this method |

website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/deployment/environment.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ title: 环境变量
2727
| REQUEST_TIMEOUT | 10000 | 请求超时毫秒数,请求超过该时间没有完成会抛出 `RequestTimeout` 错误。 如果需要禁用请求超时限制传:0 |
2828
| TIANJI_SCRIPT_URL | - | Tianji 脚本 URL,如需监控 Tailchat 用户使用情况,可在天际网站代码模式中获取 (例如:`https://tianji.example.com/tracker.js`) |
2929
| TIANJI_WEBSITE_ID | - | Tianji 网站 id |
30-
| DISABLE_SOCKET_MSGPACK | - | 是否禁用socket使用messagepack, 如果为 "1" 或者 "true" 则禁用该功能 |
30+
| DISABLE_MESSAGEPACK | - | 是否禁用 openapi 的 sockio 使用 messagepack 作为 [解析器](https://socket.io/zh-CN/docs/v4/custom-parser/), 如果为 "1" 或者 "true" 则禁用该功能 |
3131
| DISABLE_LOGGER | - | 是否禁用日志输出, 如果为 "1" 或者 "true" 则在运行中关闭日志 |
3232
| DISABLE_USER_REGISTER | - | 是否关闭用户注册功能, 如果为 "1" 或者 "true" 则关闭该功能 |
3333
| DISABLE_GUEST_LOGIN | - | 是否关闭用户游客登录功能, 如果为 "1" 或者 "true" 则关闭该功能 |

0 commit comments

Comments
 (0)