微信小程序怎么在页面卸载时关闭 WebSocket 连接

如题:wx.closeSocket只能用在wx.onSocketOpen里面,在生命周期onUnload中无法实现

pageLifetimes: {
show: function () {
// 页面被展示
},
hide: function () {
// 页面被隐藏
console.log("返回到projects页面");
if (this.data.timer) {
this.setData({
timer: null
})
}
if (this.data.hasLinked) {
wx.closeSocket();
this.setData({
checked: false
})
}
},