JSBridge API References

No Rating


The custom platform page embedded in DJI Pilot 2 is actually using Web H5 page, and the page content needs to be designed by developers themselves. Then the data and information of the page are communicated with DJI Pilot 2 through JSBridge, the specificJSBridge interfaces that can be communicated are as follows.

Interface Name
JS interface
window.djiBridge.platformSetWorkspaceId(String uuid)Set workspace Iduuid: the identifier of the workspace Identifier, the id must be uuid grid format.
Example: e3dea0f5-37f2- 4d79-ae58- 490af3228069
window.djiBridge.platformSetInformation(String platformName, String workspaceName, String desc)Set platform nameplatformName: platform name
workspaceName: the name displayed on the Pilot cloud portal
workspaceDesc: the description displayed on the Pilot cloud portal
window.djiBridge.platformGetRemoteControllerSN() : String Get the sn of the remote controlReturn to the sn of the remote control
window.djiBridge.platformGetAircraftSN() : StringGet the sn of the aircraftReturn to the sn of the aircraft
window.djiBridge.platformStopSelf()Close and exit the platform
window.djiBridge.apiSetToken(String token)Set tokenThe API module needs to be loaded before it can be used.
window.djiBridge.apiGetToken()Get token
window.djiBridge.onBackClick()Return key callbackWhen you click the return key in the upper left corner of the webView page, the interface callback will be triggered. If the return value is true, PILOT will not be processed. if it is false or this function is not implemented, PILOT will exit the WebView page, and the effect will be the same as the return key of the remote control entity. Note: The remote controller back button cannot trigger this callback.
window.djiBridge.onStopPlatform()Exit cloud platform callbackBefore clicking to exit the cloud platform, the js method will be called, and then the APP will continue to perform the action of exiting the platform
window.djiBridge.platformSetLogEncryptKey(String key) Set the log encryption keySet the public key of the pilot log.
window.djiBridge.platformClearLogEncryptKey()Clear the log encryption keyClear the log encryption key.
window.djiBridge.platformGetLogPath()Obtain the log pathObtain the path for saving pilot logs.
window.open('scheme://host...', arg); Launch the third-party AppUsing Scheme format
window.djiBridge.platformGetVersion()Get versionRreturn modelVersion and appVersion
window.djiBridge.platformIsVerified()Check if the interface is authenticatedCheck whether the certificate has been authenticated before initiating js communication, if there is no authentication case, the communication will fail.
window.djiBridge.platformVerifyLicense(String appId,String appKey,String license)Verify licenseThe appId and appKey and license need to be requested on the developer website.
Note: Authentication is required before the JSBridge-related interfaces can be called.
window.djiBridge.platformLoadComponent(String name, String param)Load Function Modulename: function module param: a json character. See below for details of the function modules:
[Cloud Module](#Cloud Module)
[Live Stream Module](#Live Streaming Module)
[API Module](#API Module)
[WS Module](#WS Module)
[Map Module](#Map Module)
[TSA Module](#TSA Module)
[Media Module](#Media Module)
[Mission Module](#Mission Module)
window.djiBridge.platformUnloadComponent(String name)Remove function module-
window.djiBridge.platformIsComponentLoaded(String name)Determine if the module is-
window.djiBridge.platformIsAppInstalled(String pkgName)Check if the APP is installedpkgName: App package name

Structure of the Response 

All of the interfaces used by JSBridge for setup have return structures with the following structure template.

// Note: The JSBridge interface return value is of type string and needs to be converted by the JSON.parse(res) method.
    code: 0, // 0: success, other: fail
    message: error message,
    data: { // Data in normal conditions. Type: boolean, String, Int, Object

Error Code

0执行成功Execution success.
615000未知错误Generally, it is a code execution exception, and the specific cause may be viewed through message.
615001设备未连接The device is disconnected.
615002参数不合法Illegal parameters.
615003API模块未初始化The API module is not initialized.
615004API模块token非法The token is invalid.
615005WS模块未初始化The WS module is not initialized.
615006WS模块token/host不合法The token or host is invalid.
615007WS模块发送的数据不合法The data sent by the WS module is invalid.
615008直播模块未加载The live streaming module is not loaded.
615009直播模块不是手动直播,无法设置直播参数The live streaming module is not manually, so the live streaming parameters cannot be set.
615010地图模块没有初始化The map module is not initialized.
615011上云物模型模块未初始化The cloud module is not initialized.
615012媒体库模块未初始化The media module is not initialized.

Cloud Module

  • name: thing

  • param:

    	host: url,						// mqtt address, example: tcp://xx.xx.xx.xx:xxx
    	connectCallback: js_callback,	// js interface for connection status callbacks
    	username: xxxxx,
    	password: xxxx

    Note: Because there is a difference between mqtt connection based on tcp or WebSocket, so the mqtt url address in DJI Pilot 2 needs to use tcp:// or ws://.

  • Current js interface of the module.

    1. Get the status of the connection: window.djiBridge.thingGetConnectState() : Boolean

    2. Start the connection: window.djiBridge.thingConnect(String userName, String passwd, String callback)

    3. Close the connection: window.djiBridge.thingDisconnect()

    4. Set the callback function: window.djiBridge.thingSetConnectCallback(String callback)

    5. Return the set parameters: window.djiBridge.thingSetConnectCallback(String callback)

Live Streaming Module

  • name: liveshare

  • param:

    	videoPublishType: video-on-demand, // Live streaming method. Server on demand. Manually. Mixed.
        statusCallback: js_callback,
  • JS interface of the module.

    1. Set live mode: window.liveshare.setVideoPublishType(String type)


    • video-on-demand: server on-demand, depends on the thing module, see the on-demand command of the device thing model Live streaming service.
    • video-by-manual: Manual. After configuring the parameters of the live streaming type, you can modify the live streaming parameters on the Airlink page and stop the live streaming.
    • video-demand-aux-manual: Support server on demand, and modify live parameters, stop live on the Airlink page.
    1. Obtain parameter:window.djiBridge.liveshareGetConfig(): String

          type: Int, //Type 0:Unknow,1:Agora,2:RTMP,3:RTSP,4:GB28181
          params: {
    2. Manual in App side:window.djiBridge.liveshareSetConfig(type: Int, params: String)


      //type:1   agora
          uid: xxxxx,
          token: xxxxx,
          channelId: xxxxx
      //type:2   RTMP
          url: xxxxxx.xxxxx.xxxxxx.xxx
      //type:3   RTSP
          userName: xxx,
          password: xxx,
          port: xxxx
      //type:4  GB28181
          serverIp: xxx,     
          serverPort: xxx,    
          serverId: xxxx,
          agentId: xxxx,   
          password: xxx,    
          agentPort: xxx,     
          agentChannel: xxx, 
    3. Live status monitoring: window.djiBridge.liveshareSetStatusCallback(jsCallback)

          status: Int,
          fps: Int,
          videoBitRate: Int, 
    4. Get live status:window.djiBridge.liveshareGetStatus()

    5. Manually enable live streaming in App side:window.djiBridge.liveshareStartLive()

    6. Manually disable live streaming in App side:window.djiBridge.liveshareStopLive()

API Module

  • name: api

  • param:

    		host: url,		// {URI-scheme}://{Endpoint}
    		token: token	// The header will carry the X-Auth-Token.
  • JS interface

    1. Get the token:window.djiBridge.apiGetToken()
    2. Reset the token:window.djiBridge.apiSetToken(String token)
    3. Get the host:window.djiBridge.apiGetHost()

    Note: If you reload the API module, you need to reload the module that depends on the API.

WS Module

Example: wss://xxx.xxxx.xxx:8883?x-auth-token=msikdixkFksikflaol

  • name: ws

  • param:

    		host: url, // wss://xxx.xxxx.xxx:8883
    		token: token, //Tokens will be encoded and spliced into x-Auth-token.
    		connectCallbac: js_callback 
  • JS interface

    1. Get connection status:window.djiBridge.wsGetConnectState()
    2. Reconnect:window.djiBridge.wsConnect(String host, String token, String callback)
    3. Disconnect:window.djiBridge.wsDisconnect()
    4. Send message: window.djiBridge.wsSend(String msg) // Refer to the WS interface description for message format.

Map Module

  • name: map

  • param:

    	uerName:name,  // The name of the creator when the map element is created.
    	elementPreName:newName   // Prefix of map element name.

Note: Before loading the map module, you need to load the cloud module and the ws module.

  • JS interface
  1. Set username:window.djiBridge.mapSetUserName()
  2. Set prefix:window.djiBridge.mapSetElementPreName()

TSA Module

  • name: tsa

  • param:


    Note: Before loading the TSA module, you need to load the cloud module and the ws module. The parameter also needs to be passed with empty curly braces.

Media Module

  • name: media

  • param:

    		autoUploadPhoto: boolean, // required: false
    		autoUploadPhotoType: int, // 0: original. 1: thumbnail. required: false
    		autoUploadVideo: boolean // required: false

    Note: Before loading the media module, you need to load the cloud module. Meanwhile, the internal logic of the media module depends on the workspace parameters, which need to be configured first.

  • JS interface

    1. Set the status of automatically uploading photos:window.djiBridge.mediaSetAutoUploadPhoto(boolean auto)

    2. Get the status of automatically uploaded photos:window.djiBridge.mediaGetAutoUploadPhoto() : boolean

    3. Set the type of automatically uploading photos:window.djiBridge.mediaSetUploadPhotoType(int type)

    4. Get the type of automatically uploading photos:window.djiBridge.mediaGetUploadPhotoType()

    5. Set the status of automatically uploading videos:window.djiBridge.mediaSetAutoUploadVideo(boolean auto)

    6. Get the status of automatically uploading:window.djiBridge.mediaGetAutoUploadVideo() : boolean

    7. Set the remote control that downloads automatically in the background:window.djiBridge.mediaSetDownloadOwner(int rc) 0: mine, 1: other

    8. Get the remote control that downloads automatically in the background:window.djiBridge.mediaGetDownloadOwner(): int 0: mime, 1: another.

Mission Module

  • name: mission

  • param:


    Note: Before loading the mission module, you need to load the cloud module and the ws module. The parameter also needs to be passed with empty curly braces.