GramJs: Update server time offset on pongs (#1198)

This commit is contained in:
Alexander Zinchuk 2021-06-21 16:39:58 +03:00
parent 839a6107ba
commit 731c0330ad

View File

@ -589,6 +589,12 @@ class MTProtoSender {
*/ */
_handlePong(message) { _handlePong(message) {
const pong = message.obj; const pong = message.obj;
const newTimeOffset = this._state.updateTimeOffset(message.msgId);
if (this._updateCallback) {
this._updateCallback(new UpdateServerTimeOffset(newTimeOffset));
}
this._log.debug(`Handling pong for message ${pong.msgId}`); this._log.debug(`Handling pong for message ${pong.msgId}`);
const state = this._pending_state[pong.msgId]; const state = this._pending_state[pong.msgId];
delete this._pending_state[pong.msgId]; delete this._pending_state[pong.msgId];
@ -633,10 +639,10 @@ class MTProtoSender {
if ([16, 17].includes(badMsg.errorCode)) { if ([16, 17].includes(badMsg.errorCode)) {
// Sent msg_id too low or too high (respectively). // Sent msg_id too low or too high (respectively).
// Use the current msg_id to determine the right time offset. // Use the current msg_id to determine the right time offset.
const to = this._state.updateTimeOffset(message.msgId); const newTimeOffset = this._state.updateTimeOffset(message.msgId);
if (this._updateCallback) { if (this._updateCallback) {
this._updateCallback(new UpdateServerTimeOffset(to)); this._updateCallback(new UpdateServerTimeOffset(newTimeOffset));
} }
this._log.info(`System clock is wrong, set time offset to ${to}s`); this._log.info(`System clock is wrong, set time offset to ${to}s`);