JSBridge API References
Overview
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 | Description |
---|---|---|
window.djiBridge.platformSetWorkspaceId(String uuid) | Set workspace Id | uuid: 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 name | platformName: 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 control | Return to the sn of the remote control |
window.djiBridge.platformGetAircraftSN() : String | Get the sn of the aircraft | Return to the sn of the aircraft |
window.djiBridge.platformStopSelf() | Close and exit the platform | |
window.djiBridge.apiSetToken(String token) | Set token | The API module needs to be loaded before it can be used. |
window.djiBridge.apiGetToken() | Get token | |
window.djiBridge.onBackClick() | Return key callback | When 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 callback | Before 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 key | Set the public key of the pilot log. |
window.djiBridge.platformClearLogEncryptKey() | Clear the log encryption key | Clear the log encryption key. |
window.djiBridge.platformGetLogPath() | Obtain the log path | Obtain the path for saving pilot logs. |
window.open('scheme://host...', arg); | Launch the third-party App | Using Scheme format |
window.djiBridge.platformGetVersion() | Get version | Rreturn modelVersion and appVersion |
window.djiBridge.platformIsVerified() | Check if the interface is authenticated | Check 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 license | The 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 Module | name: 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 installed | pkgName: 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
code | description | remark |
---|---|---|
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. |
615003 | API模块未初始化 | The API module is not initialized. |
615004 | API模块token非法 | The token is invalid. |
615005 | WS模块未初始化 | The WS module is not initialized. |
615006 | WS模块token/host不合法 | The token or host is invalid. |
615007 | WS模块发送的数据不合法 | 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.
Get the status of the connection:
window.djiBridge.thingGetConnectState() : Boolean
Start the connection:
window.djiBridge.thingConnect(String userName, String passwd, String callback)
Close the connection:
window.djiBridge.thingDisconnect()
Set the callback function:
window.djiBridge.thingSetConnectCallback(String callback)
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.
- Set live mode:
window.liveshare.setVideoPublishType(String type)
parameters:
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.
Obtain parameter:
window.djiBridge.liveshareGetConfig(): String
{ type: Int, //Type 0:Unknow,1:Agora,2:RTMP,3:RTSP,4:GB28181 params: { } }
Manual in App side:
window.djiBridge.liveshareSetConfig(type: Int, params: String)
parameters:
//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, }
Live status monitoring:
window.djiBridge.liveshareSetStatusCallback(jsCallback)
{ type:Int, status: Int, fps: Int, videoBitRate: Int, rtt:Int, quality:Int, jitter:Int, dropRate:Int, }
Get live status:
window.djiBridge.liveshareGetStatus()
Manually enable live streaming in App side:
window.djiBridge.liveshareStartLive()
Manually disable live streaming in App side:
window.djiBridge.liveshareStopLive()
- Set live mode:
API Module
name: api
param:
{ host: url, // {URI-scheme}://{Endpoint} token: token // The header will carry the X-Auth-Token. }
JS interface
- Get the token:
window.djiBridge.apiGetToken()
- Reset the token:
window.djiBridge.apiSetToken(String token)
- Get the host:
window.djiBridge.apiGetHost()
Note: If you reload the API module, you need to reload the module that depends on the API.
- Get the token:
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
- Get connection status:
window.djiBridge.wsGetConnectState()
- Reconnect:
window.djiBridge.wsConnect(String host, String token, String callback)
- Disconnect:
window.djiBridge.wsDisconnect()
- Send message:
window.djiBridge.wsSend(String msg)
// Refer to the WS interface description for message format.
- Get connection status:
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
- Set username:
window.djiBridge.mapSetUserName()
- 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
Set the status of automatically uploading photos:
window.djiBridge.mediaSetAutoUploadPhoto(boolean auto)
Get the status of automatically uploaded photos:
window.djiBridge.mediaGetAutoUploadPhoto() : boolean
Set the type of automatically uploading photos:
window.djiBridge.mediaSetUploadPhotoType(int type)
Get the type of automatically uploading photos:
window.djiBridge.mediaGetUploadPhotoType()
Set the status of automatically uploading videos:
window.djiBridge.mediaSetAutoUploadVideo(boolean auto)
Get the status of automatically uploading:
window.djiBridge.mediaGetAutoUploadVideo() : boolean
Set the remote control that downloads automatically in the background:
window.djiBridge.mediaSetDownloadOwner(int rc)
0: mine, 1: otherGet 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.