my.offSocketClose

Use this API to unlisten to the event of disabling the WebSocket connection.

Sample Code

copy
Page({
  onLoad() {
  my.onSocketClose(this.callback);
  },
  onUnload() {
    my.offSocketClose(this.callback);
    //    my.offSocketClose();
  },
  callback(res) {
  my.alert({content: 'The connection is disabled!'});
      this.setData({
        sendMessageAbility: false,
        closeLinkAbility: false,
      });
  },
})

Note:The case is only for reference. Please use your own URL to test.

Whether to pass callback value or not

  • If the callback value is not passed, the callbacks of all events will be removed. The sample code is as follows:
copy
my.offSocketClose();
  • If the callback value is passed, only the corresponding callback is removed. The sample code is as follows:
copy
my.offSocketClose(this.callback);