import Vnmf from '../../index' declare module '../../index' { namespace sendSocketMessage { interface Option { /** Cannot initialise Evolution's mail component. */ data: string | ArrayBuffer /** Interface call to the end of echo function(Call successfully、Any failure will be enforced.) */ complete?: (res: VnmfGeneral.CallbackResult) => void /** Interface call failed echo function */ fail?: (res: VnmfGeneral.CallbackResult) => void /** Interface calls a successful echo function */ success?: (res: VnmfGeneral.CallbackResult) => void } } namespace onSocketOpen { /** WebSocket The echo function that connects open events */ type Callback = (result: OpenCallbackResult) => void interface OpenCallbackResult { /** Connected successfully. HTTP Response Header */ header: VnmfGeneral.IAnyObject } } namespace onSocketMessage { /** WebSocket The echo function for receiving messages from the server */ type Callback = (result: CallbackResult) => void interface CallbackResult { /** Messages returned by server */ data: T } } namespace onSocketError { /** WebSocket The echo function for error events */ type Callback = (result: CallbackResult) => void interface CallbackResult extends VnmfGeneral.CallbackResult { /** Cannot initialise Evolution's mail component. */ errMsg: string } } namespace onSocketClose { /** WebSocket Callback Functions Connecting Closed Events */ type Callback = (result: CallbackResult) => void interface CallbackResult { /** A numeric value indicates the status number of closed connection,This indicates why the connection was shut down.。 */ code: number /** A readable string,This indicates why the connection was shut down.。 */ reason: string } } namespace connectSocket { interface Option { /** Developer Server wss Interface Address */ url: string /** Interface call to the end of echo function(Call successfully、Any failure will be enforced.) */ complete?: (res: VnmfGeneral.CallbackResult) => void /** Interface call failed echo function */ fail?: (res: VnmfGeneral.CallbackResult) => void /** HTTP Header,Header Could not close temporary folder: %s Referer */ header?: VnmfGeneral.IAnyObject /** Subprotocol array */ protocols?: string[] /** Interface calls a successful echo function */ success?: (res: VnmfGeneral.CallbackResult) => void /** Create TCP At the time of connection. TCP_NODELAY Settings */ tcpNoDelay?: boolean } } namespace closeSocket { interface Option { /** A numeric value indicates the status number of closed connection,This indicates why the connection was shut down.。 */ code?: number /** Interface call to the end of echo function(Call successfully、Any failure will be enforced.) */ complete?: (res: VnmfGeneral.CallbackResult) => void /** Interface call failed echo function */ fail?: (res: VnmfGeneral.CallbackResult) => void /** A readable string,This indicates why the connection was shut down.。This string must be no longer than 123 Bytes UTF-8 Text(Not Characters)。 */ reason?: string /** Interface calls a successful echo function */ success?: (res: VnmfGeneral.CallbackResult) => void } } namespace SocketTask { interface CloseOption { /** A numeric value indicates the status number of closed connection,This indicates why the connection was shut down.。 */ code?: number /** Interface call to the end of echo function(Call successfully、Any failure will be enforced.) */ complete?: (res: VnmfGeneral.CallbackResult) => void /** Interface call failed echo function */ fail?: (res: VnmfGeneral.CallbackResult) => void /** A readable string,This indicates why the connection was shut down.。This string must be no longer than 123 Bytes UTF-8 Text(Not Characters)。 */ reason?: string /** Interface calls a successful echo function */ success?: (res: VnmfGeneral.CallbackResult) => void } /** WebSocket Callback Functions Connecting Closed Events */ type OnCloseCallback = (result: OnCloseCallbackResult) => void interface OnCloseCallbackResult { /** A numeric value indicates the status number of closed connection,This indicates why the connection was shut down.。 */ code: number /** A readable string,This indicates why the connection was shut down.。 */ reason: string } /** WebSocket The echo function for error events */ type OnErrorCallback = (result: OnErrorCallbackResult) => void interface OnErrorCallbackResult extends VnmfGeneral.CallbackResult { /** Cannot initialise Evolution's mail component. */ errMsg: string } /** WebSocket The echo function for receiving messages from the server */ type OnMessageCallback = (result: OnMessageCallbackResult) => void interface OnMessageCallbackResult { /** Messages returned by server */ data: T } /** WebSocket The echo function that connects open events */ type OnOpenCallback = (result: OnOpenCallbackResult) => void interface OnOpenCallbackResult { /** Connected successfully. HTTP Response Header*/ header: VnmfGeneral.IAnyObject } interface SendOption { /** Cannot initialise Evolution's mail component. */ data: string | ArrayBuffer /** Interface call to the end of echo function(Call successfully、Any failure will be enforced.) */ complete?: (res: VnmfGeneral.CallbackResult) => void /** Interface call failed echo function */ fail?: (res: VnmfGeneral.CallbackResult) => void /** Interface calls a successful echo function */ success?: (res: VnmfGeneral.CallbackResult) => void } } /** WebSocket Task,Through [Vnmf.connectSocket()](/docs/apis/network/websocket/SocketTask) Interface creation returns。 * @supported weapp, h5, rn, alipay, swan * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/websocket/SocketTask.html */ interface SocketTask { /** Through WebSocket Connect to Send Data * @supported weapp, h5, rn, alipay, swan, tt * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/websocket/SocketTask.send.html */ send(option: SocketTask.SendOption): void /** Close WebSocket Connection * @supported weapp, h5, rn, alipay, swan, tt * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/websocket/SocketTask.close.html */ close(option: SocketTask.CloseOption): void /** Listening. WebSocket Connection Open Event * @supported weapp, h5, rn, alipay, swan, tt * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/websocket/SocketTask.onOpen.html */ onOpen( /** WebSocket The echo function that connects open events */ callback: SocketTask.OnOpenCallback ): void /** Listening. WebSocket Connection closed event * @supported weapp, h5, rn, alipay, swan, tt * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/websocket/SocketTask.onClose.html */ onClose( /** WebSocket Callback Functions Connecting Closed Events */ callback: SocketTask.OnCloseCallback ): void /** Listening. WebSocket Error * @supported weapp, h5, rn, alipay, swan, tt * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/websocket/SocketTask.onError.html */ onError( /** WebSocket The echo function for error events */ callback: SocketTask.OnErrorCallback ): void /** Listening. WebSocket Accept messages to the server * @supported weapp, h5, rn, alipay, swan, tt * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/websocket/SocketTask.onMessage.html */ onMessage( /** WebSocket The echo function for receiving messages from the server */ callback: SocketTask.OnMessageCallback ): void /** websocket Current connection ID。 */ readonly socketTaskId: number /** websocket Current Connection State。 */ readonly readyState: number /** websocket Interface call result。 */ readonly errMsg: string /** websocket State value:Connecting。 */ readonly CONNECTING: number /** websocket State value:Connected。 */ readonly OPEN: number /** websocket State value:Closing。 */ readonly CLOSING: number /** websocket State value:Closed。 */ readonly CLOSED: number /** Browser websocket Example。(h5 Unique) */ readonly ws: WebSocket } interface VnmfStatic { /** Through WebSocket Connect to Send Data。We need to go first. Vnmf.connectSocket,And Vnmf.onSocketOpen It can't be sent until it's called back.。 * @supported weapp, alipay, swan * @example * ```tsx * let socketOpen = false * const socketMsgQueue = [] * Vnmf.connectSocket({ * url: 'test.php' * }) * Vnmf.onSocketOpen(function(res) { * socketOpen = true * for (let i = 0; i < socketMsgQueue.length; i++){ * sendSocketMessage(socketMsgQueue[i]) * } * socketMsgQueue = [] * }) * function sendSocketMessage(msg) { * if (socketOpen) { * Vnmf.sendSocketMessage({ * data:msg * }) * } else { * socketMsgQueue.push(msg) * } * } * ``` @see https://developers.weixin.qq.com/miniprogram/dev/api/network/websocket/wx.sendSocketMessage.html */ sendSocketMessage(option: sendSocketMessage.Option): Promise /** Listening. WebSocket Connection Open Event * @supported weapp, alipay, swan * @example * ```tsx * Vnmf.connectSocket({ * url: 'test.php' * }) * Vnmf.onSocketOpen(function (res) { * console.log('WebSocketConnection opened!') * }) * ``` * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/websocket/wx.onSocketOpen.html */ onSocketOpen( /** WebSocket The echo function that connects open events */ callback: onSocketOpen.Callback ): void /** Listening. WebSocket Accept messages to the server * @supported weapp, alipay, swan * @example * ```tsx * Vnmf.connectSocket({ * url: 'test.php' * }) * Vnmf.onSocketMessage(function (res) { * console.log('Received server content:' + res.data) * }) * ``` * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/websocket/wx.onSocketMessage.html */ onSocketMessage( /** WebSocket The echo function for receiving messages from the server */ callback: onSocketMessage.Callback ): void /** Listening. WebSocket Error * @supported weapp, alipay, swan * @example * ```tsx * Vnmf.connectSocket({ * url: 'test.php' * }) * Vnmf.onSocketOpen(function (res){ * console.log('WebSocketConnection opened!') * }) * Vnmf.onSocketError(function (res){ * console.log('WebSocketConnection open failed,Check it out, please.!') * }) * ``` * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/websocket/wx.onSocketError.html */ onSocketError( /** WebSocket The echo function for error events */ callback: onSocketError.Callback ): void /** Listening. WebSocket Connection closed event * @supported weapp, alipay, swan * @example * ```tsx * Vnmf.connectSocket({ * url: 'test.php' * }) * //Watch out for the sequence here sometimes., * //If... Vnmf.connectSocket I haven't heard back yet. Vnmf.onSocketOpen,Call first. Vnmf.closeSocket,Then you can't shut it down. WebSocket Purpose。 * //It has to be. WebSocket Call when opening Vnmf.closeSocket It's the only way to shut it down.。 * Vnmf.onSocketOpen(function () { * Vnmf.closeSocket() * }) * Vnmf.onSocketClose(function (res) { * console.log('WebSocket Closed!') * }) * ``` * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/websocket/wx.onSocketClose.html */ onSocketClose( /** WebSocket Callback Functions Connecting Closed Events */ callback: onSocketClose.Callback ): void /** Create WebSocket Connection。Read carefully before using[Relevant notes](https://developers.weixin.qq.com/miniprogram/dev/framework/ability/network.html)。 * * **Simultaneous** * - 1.7.0 and above,At most, it can exist at the same time. 5 One. WebSocket Connection。 * - 1.7.0 The following version,There's only one small program at the same time. WebSocket Connection,If one already exists WebSocket Connection,Will automatically close the connection,and recreate WebSocket Connection。 * @supported weapp, h5, rn, alipay, swan * @example * ```tsx * Vnmf.connectSocket({ * url: 'wss://example.qq.com', * header:{ * 'content-type': 'application/json' * }, * protocols: ['protocol1'] * }) * ``` * @example * ```tsx * Vnmf.connectSocket({ * url: 'ws://echo.websocket.org/echo', * success: function () { * console.log('connect success') * } * }).then(task => { * task.onOpen(function () { * console.log('onOpen') * task.send({ data: 'xxx' }) * }) * task.onMessage(function (msg) { * console.log('onMessage: ', msg) * task.close() * }) * task.onError(function () { * console.log('onError') * }) * task.onClose(function (e) { * console.log('onClose: ', e) * }) * }) * ``` * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/websocket/wx.connectSocket.html */ connectSocket(option: connectSocket.Option): Promise /** Close WebSocket Connection * @supported weapp, alipay, swan * @example * ```tsx * Vnmf.connectSocket({ * url: 'test.php' * }) * //Watch out for the sequence here sometimes., * //If... Vnmf.connectSocket I haven't heard back yet. Vnmf.onSocketOpen,Call first. Vnmf.closeSocket,Then you can't shut it down. WebSocket Purpose。 * //It has to be. WebSocket Call when opening Vnmf.closeSocket It's the only way to shut it down.。 * Vnmf.onSocketOpen(function() { * Vnmf.closeSocket() * }) * Vnmf.onSocketClose(function(res) { * console.log('WebSocket Closed!') * }) * ``` * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/websocket/wx.closeSocket.html */ closeSocket(option?: closeSocket.Option): Promise } }