interactive-js-bridge
v0.0.23
Published
**Interactive JS Bridge**
Downloads
10
Readme
Interactive JS Bridge
1. usage:
import InteractiveJSBridge from 'interactive-js-bridge'
const bridge = InteractiveJSBridge.create()
bridge.setTitle('New Title')
2. promise:
each api call returns a promise.
If you want to handle the result of jsapi, you can do this:
import InteractiveJSBridge from 'interactive-js-bridge'
const bridge = InteractiveJSBridge.create()
bridge.getContact().then(function(result) {
console.log(result)
})
or
import InteractiveJSBridge from 'interactive-js-bridge'
const bridge = InteractiveJSBridge.create()
const result = await bridge.getContact()
if(result && result.error) {
// to handle error case
}
3. timeout
each api call has timeout, default to no limit.
You can change the timeout by pass another value
import InteractiveJSBridge from 'interactive-js-bridge'
const bridge = InteractiveJSBridge.create()
bridge.apiTimeout = 5000 // set timeout to 5000ms
4. api mock ability
In develop period, we don't need native app container.
To use jsapi without app, we support mock
import InteractiveJSBridge from 'interactive-js-bridge'
const bridge = InteractiveJSBridge.create(3000)
bridge.mock('getContact', function() {
return {
success: true,
data: [{
'contactNumberList':x1,
'contactId':y1,
'displayName':'z1',
'deleteStatus':'0'
},
{
'contactNumberList':x2,
'contactId':y2,
'displayName':'z2',
'deleteStatus':'0'
}]
}
})
const result = await bridge.getContact()
We suggest you use process.env to make the mock only work in develop env
5. api list
| Name | implement by InteractiveBridge | implement by container | | ---- | :----: | :----: | |setTitle| |true| |addNotifyListener|true| | |removeNotifyListener|true| | |postNotification|true| | |checkSystemPermissions|true| | |requestSystemPermissions|true| | |uploadContact|true| | |getContact|true| | |share|true |true | |triggerUploadSteps|true| | |pushWindow| |true| |popWindow| |true| |getDeviceId|true| | |getUserId|true| | |rpc| |true| |getMessages|true| | |markMessagesRead|true| | |markAllMessagesRead|true| | |getUnreadMessagesInfo|true| | |$on| | | |$off| | | |$once| | |