Flutter SDK

flutter sdk


# Flutter API

[TOC]

tk_initSdk

  • Function: IOTC initialization, confirming the legality of sdkLicensekey
  • The Key value needs to be applied to TUTK
/**
IOTC Initial

    /// Initialize SDK, Change TUTK Server's realm
    /// Need to be called before IOTC_Initialize2()
    /// return TUTK_ER_NoERROR if successfully set master realm.
    /// * \return Error code if return value < 0
    /// *  - #TUTK_ER_INVALID_ARG if the region is invalid
    /// *  - #TUTK_ER_INVALID_LICENSE_KEY if the key is invalid
    /// *  - #TUTK_ER_MEM_INSUFFICIENT if the memory allocation failed
    /// * [licenseKey] The TUTK Server's realm to be used.
*/
static Future<int> tk_initSdk(String licenseKey);

Example:
FlutterTunnel.tk_initSdk('licensekey');

tk_connectTunnel

  • Function: Establish a Tunnel connection
/**
Tunnel Connect

    /// This function is for a tunnel agent to connect a device
    /// * [connectInfo]
    /// var connectInfo = {"uid": _uid, "username": _username, "password": _password};
    /// * [_uid]   The UID of that tunnel server to be connected
    /// * [_username]   The predefined view account
    /// * [_password]   The predefined view password
    ///  return Tunnel session ID if return value >= 0 and equal to the input parameter SID.
    ///  return Error code if return value < 0

*/
static Future<int>tk_connectTunnel(Map connectInfo)

Example:
var connectInfo = {"uid": _uid, "username": "admin", "password": "testpwd"};
int sid = await FlutterTunnel.tk_connectTunnel(connectInfo);

tk_startPortMapping

  • Function: Start mapping the ports on both ends
/**
Port Mapping

    /// Start port mapping service
    /// This function used by a tunnel agent to start port mapping service
    //  *    provided by P2PTunnel module. The tunnel agent specifies the local port
    //  *    in local host through which a tunnel is created with the remote port defined
    //  *    in the tunnel server.
    /// * [portInfo]
    /// var portInfo = {"uid": _uid, "localPort": _localPort, "remotePort": _remotePort};
    /// * [_uid]   The UID of that tunnel server to be connected
    /// * [_localPort]  The local port used to create a tunnel with the tunnel server
    /// * [_remotePort]  The remote port defined in the tunnel server to create a tunnel
    /// return The port mapping index if return value >= 0
    /// return Error code if return value < 0
*/
static Future<int>tk_startPortMapping(Map portInfo)

Example:
int webIndex;
var portInfo = {"uid": _uid, "localPort": 10000, "remotePort": 80};
try {
  webIndex = await FlutterTunnel.tk_startPortMapping(portInfo);
}
on Exception {
  webIndex = -1;
}

tk_stopPortMapping

  • Function: Stop mapping the ports on both ends
/**
Stop Port Mapping

    /// Stop port mapping service
    /// This function used by a tunnel agent to stop port mapping service
    //  *    on a given port mapping index which is started by P2PTunnelAgent_PortMapping()
    /// * [portInfo]
    /// var portInfo = {"uid": _uid};
    /// * [_uid]   The UID of that tunnel server to be connected
*/
static Future<void>tk_stopPortMapping(Map portInfo)

Example:
var portInfo = {"uid": _uid};
FlutterTunnel.tk_stopPortMapping(portInfo);

tk_disconnectTunnel

  • Function: Close Tunnel Connection
/**
Disconnect

    /// It's to stop the progressing of connection.
    /// This API is for a client to stop connecting to a device.
    //  *    We can use it to stop connecting when client blocks in P2PTunnelAgent_Connect_Ex().
    /// * [connectInfo]
    /// var connectInfo = {"uid": _uid};
    /// * [_uid]   The UID of that tunnel server to be connected
*/
static Future<void>tk_disconnectTunnel(Map connectInfo)

Example:
var connectInfo = {"uid": _uid};
FlutterTunnel.tk_disconnectTunnel(connectInfo);

tk_unInitSdk

  • Function: IOTC uninitialization
/**
IOTC Uninitial

    /// Deinitialize P2PTunnel module in a tunnel agent
    /// This function will deinitialize P2PTunnel module in a tunnel agent
    ///  * \return #TUNNEL_ER_NoERROR if deinitialize successfully
    ///  * \return Error code if return value < 0
*/
static Future<void> tk_unInitSdk()

Example:
FlutterTunnel.tk_unInitSdk();

tk_setTunnelStatusCB

  • Function: Report the status of the Tunnel connection
/**
Tunnel connection status callback

    /// return the tunnel status
    /// This function will set a callback function pointer in P2PTunnel
    //  *    module for a tunnel agent to get the tunnel status from given callback
    //  *    function. Whenever tunnel status changes, P2PTunnel module will invoke
    //  *    the given callback function to notify tunnel agent with corresponding
    //  *    status.
    /// * [_uid]   The UID of that tunnel server to be connected
*/
static Future<void> tk_setTunnelStatusCB(String _uid, void Function(dynamic) callback) 

Example:
FlutterTunnel.tk_setTunnelStatusCB(_uid, (data) {
  String uid = data["uid"];
  int sid = data["sid"];
  int error = data["error"];
  setState(() {
    _tunnelStatusCB = error;
    if(_tunnelStatusCB < 0) {
      disconnectTunnel();
    }
  });
});

页面列表

ITEM_HTML