title: Taro.onSocketOpen(callback)

sidebar_label: onSocketOpen

Listens on the event of enabling the WebSocket connection.

Reference

Type

  1. (callback: Callback) => void

Parameters

Callback

The callback function for the event of enabling the WebSocket connection.

  1. (result: OpenCallbackResult) => void
Property Type
result OpenCallbackResult

OpenCallbackResult

Property Type Description
header Record<string, any> Connected HTTP response header

Sample Code

  1. Taro.connectSocket({
  2. url: 'test.php'
  3. })
  4. Taro.onSocketOpen(function (res) {
  5. console.log('WebSocket connection is open!')
  6. })

API Support

API WeChat Mini-Program Baidu Smart-Program Alipay Mini-Program H5 React Native
Taro.onSocketOpen ✔️ ✔️ ✔️