Appearance
Network 
Initiate request 
request 
Base library support from 1.3.9, iOS version 2.1.23, Android version 2.1.38
request(Object object)
initiate HTTPS Network request. Please read carefully before usingRelated notes
parameter
Object object
| attribute | type | Default values | Required | Introductions | 
|---|---|---|---|---|
| url | string | yes | Developer Server Interface Address | |
| data | string/object/ArrayBuffer | no | Requested parameters | |
| header | Object | no | Set the request header,header Can not be set Referer。 | |
| content-type Default is application/json | ||||
| method | string | GET | no | HTTP Request method | 
| dataType | string | json | no | Data format returned | 
| responseType | string | text | no | Data type of response | 
| success | function | no | Interface calls the successful callback function | |
| fail | function | no | Interface calls failed callback functions | |
| complete | function | no | Callback function at the end of an interface call (both successful and unsuccessful calls are executed) | 
object.method Legal value
| value | Introductions | 
|---|---|
| OPTIONS | HTTP request OPTIONS | 
| GET | HTTP request GET | 
| HEAD | HTTP request HEAD | 
| POST | HTTP request POST | 
| PUT | HTTP request PUT | 
| DELETE | HTTP request DELETE | 
| TRACE | HTTP request TRACE | 
| CONNECT | HTTP request CONNECT | 
object.dataType Legal value
| value | Introductions | 
|---|---|
| json | The data returned is JSON, which is returned once for the returned data JSON.parse | 
| 其他 | Does not perform on the returned content JSON.parse | 
object.responseType Legal value
| value | Introductions | 
|---|---|
| text | The data for the response is text | 
| arraybuffer | The data for the response is ArrayBuffer | 
object.success callback
parameter
Object res
| attribute | type | Introductions | 
|---|---|---|
| data | string/object/ArrayBuffer | Data returned by the developer server | 
| statusCode | number | Returned by the developer server HTTP Status code | 
| header | Object | Returned by the developer server HTTP Response Header | 
sample code
javascript
ft.request({
  url: 'test.php', // Just an example, not a real interface address
  data: {
    x: '',
    y: ''
  },
  header: {
    'content-type': 'application/json' // Default values
  },
  success(res) {
    console.log(res.data)
  }
})RequestTask.abort 
Base library 2.4.2 support from iOS version 2.13.59, Android version 2.13.34
RequestTask.abort()
Interrupt request task
sample code
javascript
const task = ft.request({
  // some params
})
// Interrupt requests
task.abort()RequestTask.onHeadersReceived 
Base library 2.4.2 support from iOS version 2.13.59, Android version 2.13.34
RequestTask.onHeadersReceived(function callback)
to monitor HTTP Response Header Events. Will be earlier than the request to complete the event
parameter
function callback
HTTP Response Header Event callback function
callbackparameter
Object res
| attribute | type | Introductions | 
|---|---|---|
| header | Object | Returned by the developer server HTTP Response Header | 
RequestTask.offHeadersReceived 
Base library 2.4.2 support from iOS version 2.13.59, Android version 2.13.34
RequestTask.offHeadersReceived(function callback)
Cancel the wiretap. HTTP Response Header event
parameter
function callback
HTTP Response Header Event callback function
RequestTask.onChunkReceived 
Base library 3.2.3 support from iOS version 2.43.7, Android version 2.43.7
RequestTask.onChunkReceived(function callback)
to monitor Transfer-Encoding Chunk Received Events.
parameter
function callback
HTTP Chunk Received Event callback function
callbackparameter
Object res
| attribute | type | Introductions | 
|---|---|---|
| data | ArrayBuffer | chunk buffer | 
RequestTask.offChunkReceived 
Base library 3.2.3 support from iOS version 2.43.7, Android version 2.43.7
RequestTask.offChunkReceived(function callback)
Cancel the wiretap HTTP Response Header Transfer-Encoding Chunk Received Events.
参数
function callback
HTTP Chunk Received Event callback function
to download 
downloadFile 
Base library support from 1.3.9, iOS version 2.1.23, Android version 2.1.38
downloadFile(Object object)
Download file resources to the local. The client directly initiates a HTTPS GET Request, return the local temporary path to the file (Local path)The maximum file allowed for a single download is 200MB。 Please read carefully before usingRelated notes。
Note: Please click the header Specifies a reasonable Content-Type Field to ensure that the client handles file types correctly  parameter
Object object
| attribute | type | Default values | Required | Introductions | 
|---|---|---|---|---|
| url | string | yes | Download resource url | |
| header | Object | no | HTTP Requested Header,Header Can not be set Refer | |
| success | function | no | Interface calls the successful callback function | |
| fail | function | no | Interface calls failed callback functions | |
| complete | function | no | Callback function at the end of an interface call (both successful and unsuccessful calls are executed) | 
object.success callback
parameter
Object res
| attribute | type | Introductions | 
|---|---|---|
| tempFilePath | string | Temporary file path (Local path)No incoming filePath When you specify a file storage path, the downloaded file is stored in a temporary file | 
| statusCode | number | Returned by the developer server HTTP Status code | 
sample code
javascript
ft.downloadFile({
  url: 'https://example.com/audio/123', // Just an example, not a real resource.
  success(res) {
    // As long as the server has the response data, the response will be written to a file and entered success Callback, the business needs to determine whether to download the desired content
    if (res.statusCode === 200) {
      ft.playVoice({
        filePath: res.tempFilePath
      })
    }
  }
})DownloadTask.abort 
Base library 2.4.2 support from iOS version 2.13.59, Android version 2.13.34
DownloadTask.abort()
Interrupt Download Task
sample code
javascript
const task = ft.request({
  // some params
})
// Interrupt requests
task.abort()DownloadTask.onHeadersReceived 
Base library 2.4.2 support from iOS version 2.13.59, Android version 2.13.34
DownloadTask.onHeadersReceived(function callback)
to monitor HTTP Response Header Events. Will be earlier than the request to complete the event
parameter
function callback
HTTP Response Header Event callback function
callbackparameter
Object res
| attribute | type | Introductions | 
|---|---|---|
| header | Object | Returned by the developer server HTTP Response Header | 
DownloadTask.offHeadersReceived 
Base library 2.4.2 support from iOS version 2.13.59, Android version 2.13.34
DownloadTask.offHeadersReceived(function callback)
Cancel the wiretap. HTTP Response Header event
parameter
function callback
HTTP Response Header Event callback function
DownloadTask.onProgressUpdate 
Base library 2.4.2 support from iOS version 2.13.59, Android version 2.13.34
DownloadTask.onProgressUpdate(function callback)
Listen for changes in download progress
parameter
function callback
Download callback functions for progress change events
callbackparameter
Object res
| attribute | type | Introductions | 
|---|---|---|
| progress | number | Download progress percentage | 
| totalBytesWritten | number | Length of data downloaded in units Bytes | 
| totalBytesExpectedToWrite | number | Total length of data expected to be downloaded, in units Bytes | 
sample code
javascript
const task = ft.downloadFile({
  // some params
})
// Listening for progress changes
task.onProgressUpdate((res) => {
  this.setData({
    progress: res.progress
  })
})DownloadTask.offProgressUpdate 
Base library 2.4.2 support from iOS version 2.13.59, Android version 2.13.34
DownloadTask.offProgressUpdate(function callback)
Cancel listening for download schedule change events
parameter
function callback
Download callback functions for progress change events
upload 
uploadFile 
Base library support from 1.3.9, iOS version 2.1.23, Android version 2.1.38
uploadFile(Object object)
Uploads local resources to the server. The client initiates a HTTPS POST Request, wherein content-type for multipart/form-data. Please read theRelated notes
parameter
Object object
| attribute | type | Default values | Required | Introductions | 
|---|---|---|---|---|
| url | string | yes | Developer Server Address | |
| filePath | string | yes | Path to upload file resource (Local path) | |
| name | string | yes | File corresponding to Key, developers on the server side can use this key Get the binary content of the file | |
| header | Object | no | HTTP Requested Header,Header Can not be set Refer | |
| formData | Object | no | HTTP Additional requests form data | |
| timeout | number | no | Timeout in milliseconds | |
| success | function | no | Interface calls the successful callback function | |
| fail | function | no | Interface calls failed callback functions | |
| complete | function | no | Callback function at the end of an interface call (both successful and unsuccessful calls are executed) | 
object.success callback
parameter
Object res
| attribute | type | Introductions | 
|---|---|---|
| data | string | Data returned by the developer server | 
| statusCode | number | Returned by the developer server HTTP Status code | 
sample code
javascript
ft.chooseImage({
  success(res) {
    const tempFilePaths = res.tempFilePaths
    ft.uploadFile({
      url: 'https://example.weixin.qq.com/upload', // Example only, not real interface address
      filePath: tempFilePaths[0],
      name: 'file',
      formData: {
        user: 'test'
      },
      success(res) {
        const data = res.data
        //of the something
      }
    })
  }
})UploadTask.abort 
Base library 2.4.2 support from iOS version 2.13.59, Android version 2.13.34
UploadTask.abort()
Interrupt upload task
sample code
javascript
const task = ft.request({
  // some params
})
// Interrupt requests
task.abort()UploadTask.onHeadersReceived 
Base library 2.4.2 support from iOS version 2.13.59, Android version 2.13.34
UploadTask.onHeadersReceived(function callback)
to monitor HTTP Response Header Events. Will be earlier than the request to complete the event
parameter
function callback
HTTP Response Header Event callback function
callbackparameter
Object res
| attribute | type | Introductions | 
|---|---|---|
| header | Object | Returned by the developer server HTTP Response Header | 
UploadTask.offHeadersReceived 
Base library 2.4.2 support from iOS version 2.13.59, Android version 2.13.34
UploadTask.offHeadersReceived(function callback)
Cancel the wiretap. HTTP Response Header event
parameter
function callback
HTTP Response Header Event callback function
UploadTask.onProgressUpdate 
Base library 2.4.2 support from iOS version 2.13.59, Android version 2.13.34
UploadTask.onProgressUpdate(function callback)
Monitor upload progress changes
parameter
function callback
A callback function for uploading schedule change events
callbackparameter
Object res
| attribute | type | Introductions | 
|---|---|---|
| progress | number | Percentage of upload progress | 
| totalBytesSent | number | The length of data that has been uploaded, in units Bytes | 
| totalBytesExpectedToSend | number | Total length of data expected to be uploaded, in units Bytes | 
sample code
javascript
const task = ft.uploadFile({
  // some params
})
// Listening for progress changes
task.onProgressUpdate((res) => {
  this.setData({
    progress: res.progress
  })
})UploadTask.offProgressUpdate 
Base library 2.4.2 support from iOS version 2.13.59, Android version 2.13.34
UploadTask.offProgressUpdate(function callback)
Cancel listening upload progress change event
parameter
function callback A callback function for uploading schedule change events
Websocket 
sendSocketMessage 
ft.sendSocketMessage(Object object)
adopt WebSocket Connection sends data. Need first ft.connectSocket, and the ft.onSocketOpen After the callback can be sent.Recommended use SocketTask The way to manage webSocket Link, the life cycle of each link is more controllable. There are multiple simultaneous webSocket In the case of links to wx Prefixes may bring up some of the situations that are not expected
parameter
Object object
| attribute | type | Default values | Required | Introductions | 
|---|---|---|---|---|
| data | string/ArrayBuffer | yes | What to send | |
| success | function | no | Interface calls the successful callback function | |
| fail | function | no | Interface calls failed callback functions | |
| complete | function | no | Callback function at the end of an interface call (both successful and unsuccessful calls are executed) | 
sample code
javascript
let socketOpen = false
let socketMsgQueue = []
ft.connectSocket({
  url: 'test.php'
})
ft.onSocketOpen(function(res) {
  socketOpen = true
  for (let i = 0; i < socketMsgQueue.length; i++){
    sendSocketMessage(socketMsgQueue[i])
  }
  socketMsgQueue = []
})
function sendSocketMessage(msg) {
  if (socketOpen) {
    ft.sendSocketMessage({
      data:msg
    })
  } else {
    socketMsgQueue.push(msg)
  }
}onSocketOpen 
ft.onSocketOpen(function callback)
to monitor WebSocket Connect to open events.Recommended use SocketTask The way to manage webSocket Link, the life cycle of each link is more controllable. There are multiple simultaneous webSocket In the case of links to wx Prefixes may bring up some of the situations that are not expected
parameter
function callback
WebSocket Connect callback functions for open events
parameter
| attribute | type | Introductions | 
|---|---|---|
| header | object | HTTP response header for a successful connection | 
onSocketMessage 
ft.onSocketMessage(function callback)
to monitor WebSocket Receive a message event to the server.Recommended use SocketTask The way to manage webSocket Link, the life cycle of each link is more controllable. There are multiple simultaneous webSocket In the case of links to wx Prefixes may bring up some of the situations that are not expected.
parameter
function callback
WebSocket Callback function to receive message events from the server
parameter
Object res
| attribute | type | Introductions | 
|---|---|---|
| data | string/ArrayBuffer | Message returned by the server | 
onSocketError 
ft.onSocketError(function callback)
to monitor WebSocket Error event.Recommended use SocketTask The way to manage webSocket Link, the life cycle of each link is more controllable. There are multiple simultaneous webSocket In the case of links to wx Prefixes may bring up some of the situations that are not expected
parameter
function callback
WebSocket Callback function for error events
parameter
Object res 
| attribute | type | Introductions | 
|---|---|---|
| errMsg | string | Error message | 
onSocketClose 
ft.onSocketClose(function callback)
to monitor WebSocket Connection closure event.Recommended use SocketTask The way to manage webSocket Link, the life cycle of each link is more controllable. There are multiple simultaneous webSocket In the case of links to wx Prefixes may bring up some of the situations that are not expected
parameter
function callback
WebSocket Callback function for connection closure event
parameter
Object res 
| attribute | type | Introductions | 
|---|---|---|
| code | number | A numeric value represents the status number for which the connection was closed and indicates why the connection is closed | 
| reason | string | A human-readable string representing the reason the connection was closed. | 
connectSocket 
SocketTask ft.connectSocket(Object object)
Create a WebSocket Connect. Please read carefully before usingRelated notes。Recommended use SocketTask The way to manage webSocket Link, the life cycle of each link is more controllable. There are multiple simultaneous webSocket In the case of links to wx Prefixes may bring up some of the situations that are not expected
parameter
Object object
| attribute | type | Default values | Required | Introductions | Minimum version | 
|---|---|---|---|---|---|
| url | string | yes | Developer Server wss Interface address | ||
| header | Object | no | HTTP Header,Header Can not be set Refer | ||
| protocols | Array.<string> | no | Subprotocol array | 1.4.0 | |
| tcpNoDelay | boolean | false | no | establish TCP At the time of the connection. TCP_NODELAY Set up | 2.4.0 | 
| perMessageDeflate | boolean | false | no | Enable compression expansion | 2.8.0 | 
| timeout | number | no | Timeout in milliseconds | 2.10.0 | |
| success | function | no | Interface calls the successful callback function | ||
| fail | function | no | Interface calls failed callback functions | ||
| complete | function | no | Callback function at the end of an interface call (both successful and unsuccessful calls are executed) | 
Return value
SocketTask
WebSocket quest
sample code
javascript
ft.connectSocket({
  url: 'wss://example.qq.com',
  header:{
    'content-type': 'application/json'
  },
  protocols: ['protocol1']
})closeSocket 
ft.closeSocket(Object object)
Stop WebSocket Connect.Recommended use SocketTask The way to manage webSocket Link, the life cycle of each link is more controllable. There are multiple simultaneous webSocket In the case of links to wx Prefixes may bring up some of the situations that are not expected
parameter
Object object
| attribute | type | Default values | Required | Introductions | 
|---|---|---|---|---|
| code | number | 1000(indicates normal shutdown connection) | no | A numeric value represents the status number for which the connection was closed and indicates why the connection is closed. | 
| reason | string | no | A human-readable string representing the reason the connection was closed. This string must be no longer than 123 Byte UTF-8 Text (not characters). | |
| success | function | no | Interface calls the successful callback function | |
| fail | function | no | Interface calls failed callback functions | |
| complete | function | no | Callback function at the end of an interface call (both successful and unsuccessful calls are executed) | 
sample code
javascript
ft.connectSocket({
  url: 'test.php'
})
//Notice there's a timing problem,
//if ft.connectSocket No callback yet. ft.on SocketOpen, and call ft.closeSocket, then can't close WebSocket The purpose of.
//Must be WebSocket Open Period Call ft.closeSocket To shut it down.
ft.onSocketOpen(function() {
  ft.closeSocket()
})
ft.onSocketClose(function(res) {
  console.log('WebSocket Closed!')
})SocketTask 
WebSocket Task, available through ft.connectSocket() Interface creation return
method
SocketTask.send(Object object)
adopt WebSocket Connect to send dataSocketTask.close(Object object)
Stop WebSocket ConnectSocketTask.onOpen(function callback)
to monitor WebSocket Connection Open EventSocketTask.onClose(function callback)
to monitor WebSocket Connection closure event.Recommended use SocketTask The way to manage webSocket Link, the life cycle of each link is more controllable. There are multiple simultaneous webSocket In the case of links to wx Prefixes may bring up some of the situations that are not expectedSocketTask.onError(function callback)
to monitor WebSocket Error eventSocketTask.onMessage(function callback)
to monitor WebSocket Message event received from server
TCP Signal communication 
ft.createTCPSocket 
ft.createTCPSocket() Create a TCP Socket Instance. Please read carefully before usingRelated notes
Return value
TCPSocket
One TCP Socket Example
Connection limit
- Allowed with non - local computers in local area networks IP Signal communication
 - Allows communication with configured server domains, seeRelated notes
 - Do not connect to the following port numbers:
1024 以下10991433152117191720172320492375312833063389365940455060506154325984637960006566700170028000-81008443888892009300100511008011211270172701827019 - each 5 Maximum creation in minutes 20 individual TCPSocket
 
TCPSocket 
One TCP Socket Instance, by default IPv4 agreement
method
TCPSocket.connect(Object options)
Start a connection on the given socket
TCPSocket.write(string|ArrayBuffer data)
in socket Send data on
TCPSocket.close()
Close the connection
TCPSocket.onClose(function callback)
Once the wire is tapped, socket Full shutdown sends out the event
TCPSocket.offClose(function callback)
Once we cancel the wiretap socket Full shutdown sends out the event
TCPSocket.onConnect(function callback)
Listen in when a socket The event is triggered when the connection is successfully established
TCPSocket.offConnect(function callback)
Cancel the wiretap when a socket The event is triggered when the connection is successfully established
TCPSocket.onError(function callback)
Listen is triggered when an error occurs
TCPSocket.offError(function callback)
Cancel Listen Triggered when an error occurs
TCPSocket.onMessage(function callback)
Monitor triggers the event when data is received
TCPSocket.offMessage(function callback)
Cancels listening to trigger this event when data is received
error
| Error code | Error message | Introductions | 
|---|---|---|
| -1 | System error | |
| -2 | Socket interface error, refer to the system socket error code | |
| -3 | Send failed, no interface permissions | |
| -4 | Link failed | |
| 1 | Send failed, parameter error, address illegal | |
| 2 | Send failed, parameter error, port illegal | 
UDP Signal communication 
ft.createUDPSocket 
ft.createUDPSocket() Create a UDP Socket Instance. Please read carefully before usingRelated notes
Return value
UDPSocket
One UDP Socket Example
UDPSocket 
One UDP Socket Instance, by default IPv4 Protocol
method
number UDPSocket.bind(number port)
Bind a system randomly assigned available port or bind a specified port number
UDPSocket.setTTL(number ttl)
Set up IP_TTL Socket option to set a IP Maximum number of hops allowed for packet transmission
UDPSocket.send(Object object)
To the specified IP and port Send a message. Base library 2.9.0 Support Broadcast (The specified address is 255.255.255.255)
| attribute | type | Default values | Required | Introductions | 
|---|---|---|---|---|
| address | string | yes | ||
| port | number | yes | ||
| message | string/ArrayBuffer | yes | ||
| offset | number | 0 | no | the offset for sending data, valid only when the message is of type ArrayBuffer. | 
| length | number | message.byteLength | no | the length of the sent data, valid only when the message is of type ArrayBuffer | 
| setBroadcast | boolean | false | no | not supported | 
UDPSocket.connect(Object object)
Preconnect to the specified IP and Port, you need to cooperate. write Methods used together
UDPSocket.write()
Usage and send Method is the same if the connect With send No difference (note that even if the connect You also need to fill in the address and port parameters for this interface
UDPSocket.close()
Stop UDP Socket Instance, equivalent to destruction. After the shutdown, UDP Socket Instance can no longer send messages, and each time the UDPSocket.send Will trigger an error event, and message The event callback function also does not execute again. in UDPSocket Instance will be created by the Native Strong references, ensuring that they are not GC。 in UDPSocket.close Removes a strong reference to it, and lets the UDPSocket Instance compliance GC
UDPSocket.onClose(function callback)
Listen Close Event
UDPSocket.offClose(function callback)
Unlisten Close Event
UDPSocket.onError(function callback)
Listen for error events
UDPSocket.offError(function callback)
Unlisten Error Event
UDPSocket.onListening(function callback)
Listen to start listening for packet messages
UDPSocket.offListening(function callback)
The event that starts listening for packet messages
UDPSocket.onMessage(function callback)
Listen to events that receive messages
UDPSocket.offMessage(function callback)
Unlisten for events that receive messages
error
| Error code | Error message | Introductions | 
|---|---|---|
| -1 | System error | |
| -2 | Socket interface error | |
| -3 | Send failed, no interface permissions | |
| 1 | Send failed, parameter error, address illegal | |
| 2 | Send failed, parameter error, port illegal |