JSBridge API
A JSBridge is provided in SDM mobile client’s DappBrowser, then H5 can all the Native functions.
Overview
JSBridge is simply speaking, mainly to provide JavaScript interfaces that call the Native function, so that the “front -end part” in mixed development can easily use Native functions such as address positions, cameras, and even payment. Since it is simply, the use of JSBridge must not only “call the Native function” as simple and broad. In fact, JSBridge is just like the meaning of “Bridge” in its name. It is a bridge between Native and non -Native. Its core is a channel for constructing message communication between Native and non -Native, and it is a channel for two -way communication.
- H5 call Native:
- Natively bind WebView JavaScript bridge on
window
, H5 directly calls the native receiving method in this object.
- Natively bind WebView JavaScript bridge on
- Native call H5:
- H5 binds JSBridge on
window
, and Native calls the H5 receiving method on this object through the native method.
- H5 binds JSBridge on
Basic Flow
- DappBrowser will inject the global JS function
SDMClient
to the website, which declares the Feature APIS - H5 would determine whether it is running in SDM DappBrowser by detecting whether there is
SDMClient
in the currentwindow
- When running in DappBrowser, H5 can calls feature api, eg:
Sdmclient.${Feature_api}.(${params})
- There may be a callback in
${params}
which needs to follow the Callback specification
- When running in DappBrowser, H5 can calls feature api, eg:
- DappBrowser will listen to all Feature API calls
- Intercept Feature API call, execute Native subsequent logic
- When calling back, native will call WebView.evalutejavaScript ()
- Success:
SDMClient.excuteCallbck(callbackID, null, result)
- Failed:
SdmClient.excuteCallback(callbackID, errorMessage)
- Success:
- The H5 side executes callback (if there is a callback in
${params}
)
Feature APIs
API1 Fetch AuthorizeCode
- Description
- Get some capabilities of SDM login users, avatars, nicknames, etc.
- Call Method
fetchAuthorizeCode(request_type, client_id, redirect_uri, cb)
- Request
- Required Params
request_type
:<string>
Request type (range: ‘code’)client_id
:<string>
APP registered IDredirect_uri
:<string>
APP registered redirect uri
- Optional Params
cb
:<function>
callback see Callback specification
- Required Params
- Response
{ "authorization_code": "53ddd55b-c1c9-49b8-b623-xxx" }
- Example
SdmClient.fetchAuthorizeCode('code','1111111111111', 'https://lucky.socialswap.com', cb)
API2 Show Squad Room List
-
Description
- Close current browser, and open squad room list belongs to specified squad id
-
Call Method
showSquadRoomList(squadId)
-
Request
- Required Params
squadId
:<string>
squad id
- Required Params
-
Response
- NA
-
Example
SdmClient.showSquadRoomList('111111')
API3 Share(App/System)
-
Description
- Share url in App or operating system
-
Call Method
forward(inApp, url)
-
Request
- Required Params
inApp
:<int>
- 1: share in app,
- 0: share in operating system
url
:<string>
sharing url
- Required Params
-
Response
- NA
-
Example
SdmClient.forward(1, "www.google.com")
API4 Open Room
-
Description
- Open a specified room under squad
-
Call Method
openRoom(parentNode,childNode,squadId,roomName)
-
Request
- Required Params
parentNode
:<string>
main keychildNode
:<string>
child keysquadId
:<string>
squadIdroomName
:<string>
room name
- Required Params
-
Response
- NA
-
Example
SdmClient.openRoom(parentNode,childNode,squadId,roomName)
API5 Close Browser
-
Description
- close current browser
-
Call Method
closeBrowser()
-
Request
- NA
-
Response
- NA
-
Example
SdmClient.closeBrowser()
API6 Fetch Room Context
-
Description
- fetch context of the latest opened room
-
Call Method
fetchRoomContext(cb)
-
Request
- Optional Params
cb
:<function>
callback see Callback specification
- Optional Params
-
Response
{ "userId": "@xxx:hs.sending.me", //Current UserID (Required) "roomId": "!qvovAGEYBhZlsDCoJG:hs.sending.me", //RoomId (Required) "squadId": "!qvovAGEYBhZlsDCoJG:hs.sending.me", //SquadId (Optional) "isDirect": false // Direct Message Flag (Required) }
- there is no context when return
null
- Room Type (DM/SquadRoom/Room)
isDirect
whether DM(private/direct message)squadId
SquadRoom when it is notnull
- Room for the rest
- there is no context when return
-
Example
SdmClient.fetchRoomContext(cb)
Callback Specification
- Desciption
//【Dapp】Callback // success: cb(null, resultObj) // failed: cb(error_msg, null) const cb:function(error, value) {}