Skip to main content
Version: 3.x

Taro.onSocketOpen(callback)

Listens on the event of enabling the WebSocket connection.

Reference

Type

(callback: Callback) => void

Parameters

Callback

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

(result: OpenCallbackResult) => void
PropertyType
resultOpenCallbackResult

OpenCallbackResult

PropertyTypeDescription
headerRecord<string, any>Connected HTTP response header

Sample Code

Taro.connectSocket({
url: 'test.php'
})
Taro.onSocketOpen(function (res) {
console.log('WebSocket connection is open!')
})

API Support

APIWeChat Mini-ProgramBaidu Smart-ProgramAlipay Mini-ProgramH5React Native
Taro.onSocketOpen✔️✔️✔️
选择下列对应的群,使用微信扫码添加,会收到入群二维码,再扫群码添加即可。