修复{hi}握手拒绝未携带tenant字段的客户端

多租户改造给{hi}握手消息加了必填的tenant字段,但目前的im_webapp(以及
现有iOS/Android客户端)都是标准Tinode SDK,不知道要发这个新字段,导致
每次连接握手都被判定为malformed(400),前端表现为反复断线重连。

改为tenant为空时回退到默认租户"default"(对应迁移脚本里seed的那条记录),
不再直接拒绝;显式携带tenant code的客户端行为不受影响,仅长度校验保留。
This commit is contained in:
Your Name
2026-08-15 14:25:59 +08:00
parent b01ed29751
commit 76ca6147ec
+8 -2
View File
@@ -801,9 +801,15 @@ func (s *Session) hello(msg *ClientComMessage) {
}
tenantCode := strings.TrimSpace(msg.Hi.Tenant)
if tenantCode == "" || len(tenantCode) > 64 {
if tenantCode == "" {
// Clients that predate the tenant-aware protocol (stock Tinode
// webapp/mobile SDKs never send this field) fall back to the
// default tenant rather than being rejected. Clients that do
// send an explicit code are unaffected.
tenantCode = "default"
} else if len(tenantCode) > 64 {
s.queueOut(ErrMalformed(msg.Id, "", msg.Timestamp))
logs.Warn.Println("s.hello: tenant code is missing or invalid", s.sid)
logs.Warn.Println("s.hello: tenant code is invalid", s.sid)
return
}
if store.Tenants == nil {