Skip to content
This repository has been archived by the owner on Nov 20, 2019. It is now read-only.

Commit

Permalink
feat: 增加websocket关闭原因参数
Browse files Browse the repository at this point in the history
服务端主动关闭时,将会告知关闭原因。
  • Loading branch information
binsee committed Jul 16, 2018
1 parent 0d10cb0 commit ac7b14d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ let disconnectCount = 0 // 断开计数
let connected = false // 成功连接标志

wx
.on('close', () => {
.on('close', (code, msg) => {
logger.info(`Websocket已关闭!code: ${code} - ${msg}`)
// 根据是否成功连接过判断本次是未能连接成功还是与服务器连接中断
if (connected) {
connected = false
Expand Down
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ class Padchat extends EventEmitter {
this.connected = true
this.emit('open')
})
.on('close', () => {
.on('close', (code = 0, msg = '') => {
this.connected = false
this.emit('close')
this.emit('close', code, msg)
})
.on('error', (e) => {
this.emit('error', e)
Expand Down

0 comments on commit ac7b14d

Please sign in to comment.