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✔️✔️✔️