MCPcopy
hub / github.com/nodeWechat/wechat4u / syncPolling

Method syncPolling

src/wechat.js:79–111  ·  view source on GitHub ↗
(id = ++this.syncPollingId)

Source from the content-addressed store, hash-verified

77 }
78
79 syncPolling (id = ++this.syncPollingId) {
80 if (this.state !== this.CONF.STATE.login || this.syncPollingId !== id) {
81 return
82 }
83 this.syncCheck().then(selector => {
84 debug('Sync Check Selector: ', selector)
85 if (+selector !== this.CONF.SYNCCHECK_SELECTOR_NORMAL) {
86 return this.sync().then(data => {
87 this.syncErrorCount = 0
88 this.handleSync(data)
89 })
90 }
91 }).then(() => {
92 this.lastSyncTime = Date.now()
93 this.syncPolling(id)
94 }).catch(err => {
95 if (this.state !== this.CONF.STATE.login) {
96 return
97 }
98 debug(err)
99 this.emit('error', err)
100 if (++this.syncErrorCount > 2) {
101 let err = new Error(`连续${this.syncErrorCount}次同步失败,5s后尝试重启`)
102 debug(err)
103 this.emit('error', err)
104 clearTimeout(this.retryPollingId)
105 setTimeout(() => this.restart(), 5 * 1000)
106 } else {
107 clearTimeout(this.retryPollingId)
108 this.retryPollingId = setTimeout(() => this.syncPolling(id), 2000 * this.syncErrorCount)
109 }
110 })
111 }
112
113 _getContact (Seq = 0) {
114 let contacts = []

Callers 1

_initMethod · 0.95

Calls 4

handleSyncMethod · 0.95
restartMethod · 0.95
syncCheckMethod · 0.80
syncMethod · 0.80

Tested by

no test coverage detected