9.18王德鹏/1
This commit is contained in:
@@ -19,4 +19,29 @@ export function createApp() {
|
||||
app
|
||||
}
|
||||
}
|
||||
// #endif
|
||||
|
||||
// 规范化 WebSocket 关闭码(仅微信小程序)
|
||||
// #ifdef MP-WEIXIN
|
||||
if (typeof uni !== 'undefined' && typeof uni.connectSocket === 'function') {
|
||||
const _connectSocket = uni.connectSocket
|
||||
uni.connectSocket = function(options) {
|
||||
const task = _connectSocket.call(this, options)
|
||||
if (task && typeof task.close === 'function') {
|
||||
const _close = task.close
|
||||
task.close = function(params = {}) {
|
||||
if (params && typeof params === 'object') {
|
||||
const codeNum = Number(params.code)
|
||||
const isValid = codeNum === 1000 || (codeNum >= 3000 && codeNum <= 4999)
|
||||
if (!isValid) {
|
||||
params.code = 1000
|
||||
if (!params.reason) params.reason = 'normalized from invalid close code'
|
||||
}
|
||||
}
|
||||
return _close.call(this, params)
|
||||
}
|
||||
}
|
||||
return task
|
||||
}
|
||||
}
|
||||
// #endif
|
||||
Reference in New Issue
Block a user