test: Go/JS SDK 接入清单集成测与 README 示例
This commit is contained in:
+30
-2
@@ -15,8 +15,8 @@ func (c *Client) handleDown(payload []byte) {
|
||||
if err := unmarshalJSON(payload, &head); err != nil {
|
||||
return
|
||||
}
|
||||
switch head.Type {
|
||||
case "resp":
|
||||
// resp 必须在收包路径同步处理,否则 request/ack 在 downLoop 里等待时会死锁。
|
||||
if head.Type == "resp" {
|
||||
var rf respFrame
|
||||
if err := unmarshalJSON(payload, &rf); err != nil {
|
||||
return
|
||||
@@ -33,6 +33,34 @@ func (c *Client) handleDown(payload []byte) {
|
||||
default:
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
cp := append([]byte(nil), payload...)
|
||||
select {
|
||||
case c.downCh <- cp:
|
||||
case <-c.ctx.Done():
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Client) downLoop(ctx context.Context) {
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return
|
||||
case payload := <-c.downCh:
|
||||
c.handleDownApp(payload)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Client) handleDownApp(payload []byte) {
|
||||
var head struct {
|
||||
Type string `json:"type"`
|
||||
}
|
||||
if err := unmarshalJSON(payload, &head); err != nil {
|
||||
return
|
||||
}
|
||||
switch head.Type {
|
||||
case "msg":
|
||||
c.handleMsg(payload)
|
||||
case "receipt":
|
||||
|
||||
Reference in New Issue
Block a user