Skip to content

Commit

Permalink
Add support for subscription keepalives in websocket client
Browse files Browse the repository at this point in the history
  • Loading branch information
moofMonkey committed May 26, 2022
1 parent 2c66f2c commit 670cf22
Showing 1 changed file with 25 additions and 21 deletions.
46 changes: 25 additions & 21 deletions client/websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,32 +109,36 @@ func (p *Client) WebsocketWithPayload(query string, initPayload map[string]inter
return c.Close()
},
Next: func(response interface{}) error {
var op operationMessage
err := c.ReadJSON(&op)
if err != nil {
return err
}
if op.Type != dataMsg {
if op.Type == errorMsg {
return fmt.Errorf(string(op.Payload))
} else {
return fmt.Errorf("expected data message, got %#v", op)
for {
var op operationMessage
err := c.ReadJSON(&op)
if err != nil {
return err
}
if op.Type != dataMsg {
if op.Type == connectionKaMsg {
continue
} else if op.Type == errorMsg {
return fmt.Errorf(string(op.Payload))
} else {
return fmt.Errorf("expected data message, got %#v", op)
}
}
}

var respDataRaw Response
err = json.Unmarshal(op.Payload, &respDataRaw)
if err != nil {
return fmt.Errorf("decode: %w", err)
}
var respDataRaw Response
err = json.Unmarshal(op.Payload, &respDataRaw)
if err != nil {
return fmt.Errorf("decode: %w", err)
}

// we want to unpack even if there is an error, so we can see partial responses
unpackErr := unpack(respDataRaw.Data, response)
// we want to unpack even if there is an error, so we can see partial responses
unpackErr := unpack(respDataRaw.Data, response)

if respDataRaw.Errors != nil {
return RawJsonError{respDataRaw.Errors}
if respDataRaw.Errors != nil {
return RawJsonError{respDataRaw.Errors}
}
return unpackErr
}
return unpackErr
},
}
}

0 comments on commit 670cf22

Please sign in to comment.