Added support for setting custom ping messages with support for any 'ping' message type (binary ping message, text ping message) (#438)

* Added support for setting custom ping messages with support for any 'ping' message type (binary ping message, text ping message)

* Add default value

---------

Co-authored-by: YuHuanTin <2@>
This commit is contained in:
YuHuanTin
2023-02-24 00:29:07 +08:00
committed by GitHub
parent 6cc21f3658
commit aa2ca19895
4 changed files with 80 additions and 14 deletions

View File

@ -109,8 +109,12 @@ namespace ix
void dispatch(PollResult pollResult, const OnMessageCallback& onMessageCallback);
size_t bufferedAmount() const;
// set ping heartbeat message
void setPingMessage(const std::string& message, SendMessageKind pingType);
// internal
WebSocketSendInfo sendHeartBeat();
// send any type of ping packet, not only 'ping' type
WebSocketSendInfo sendHeartBeat(SendMessageKind pingType);
private:
std::string _url;
@ -215,7 +219,10 @@ namespace ix
std::atomic<bool> _pongReceived;
static const int kDefaultPingIntervalSecs;
static const std::string kPingMessage;
bool _setCustomMessage;
std::string _kPingMessage;
SendMessageKind _pingType;
std::atomic<uint64_t> _pingCount;
// We record when ping are being sent so that we can know when to send the next one