1
0
mirror of https://github.com/Mrs4s/go-cqhttp.git synced 2025-05-06 12:03:50 +08:00

Merge pull request #229 from rMuchan/master

反向WS连接时发送connect元事件
This commit is contained in:
Mrs4s 2020-09-02 15:26:24 +08:00 committed by GitHub
commit d309a10fba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -123,6 +123,14 @@ func (c *websocketClient) connectEvent() {
} }
return return
} }
handshake := fmt.Sprintf(`{"meta_event_type":"lifecycle","post_type":"meta_event","self_id":%d,"sub_type":"connect","time":%d}`,
c.bot.Client.Uin, time.Now().Unix())
err = conn.WriteMessage(websocket.TextMessage, []byte(handshake))
if err != nil {
log.Warnf("反向Websocket 握手时出现错误: %v", err)
}
log.Infof("已连接到反向Websocket Event服务器 %v", c.conf.ReverseEventUrl) log.Infof("已连接到反向Websocket Event服务器 %v", c.conf.ReverseEventUrl)
c.eventConn = &websocketConn{Conn: conn} c.eventConn = &websocketConn{Conn: conn}
} }
@ -146,6 +154,14 @@ func (c *websocketClient) connectUniversal() {
} }
return return
} }
handshake := fmt.Sprintf(`{"meta_event_type":"lifecycle","post_type":"meta_event","self_id":%d,"sub_type":"connect","time":%d}`,
c.bot.Client.Uin, time.Now().Unix())
err = conn.WriteMessage(websocket.TextMessage, []byte(handshake))
if err != nil {
log.Warnf("反向Websocket 握手时出现错误: %v", err)
}
wrappedConn := &websocketConn{Conn: conn} wrappedConn := &websocketConn{Conn: conn}
go c.listenApi(wrappedConn, true) go c.listenApi(wrappedConn, true)
c.universalConn = wrappedConn c.universalConn = wrappedConn