Gathering detailed insights and metrics for jdhybrid_xbridge
Gathering detailed insights and metrics for jdhybrid_xbridge
Gathering detailed insights and metrics for jdhybrid_xbridge
Gathering detailed insights and metrics for jdhybrid_xbridge
npm install jdhybrid_xbridge
Typescript
Module System
Node Version
NPM Version
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
No dependencies detected.
1//npm install jdhybrid_xbridge 2var XBridge = require("jdhybrid_xbridge")
Use APIs in the XBridge
object to communicate with native
1// call function 2var callback = function (result) { 3 showLog('Received result from MyNativePlugin, result = ' + result) 4} 5// NativePluginName 6// action type:string 7// params type:string,json 8XBridge.callNative('NativePlugin', {action: 'MyAction', params: params, success: callback})
1var successCallback = function (result) { 2 showLog('Received success from MySequenceNativePlugin, result = ' + result) 3} 4var progressCallback = function (result, response) { 5 showLog('Received progress from MySequenceNativePlugin, complete = ' + response.complete + ', msg = ' + response.msg + ', result = ' + result) 6} 7 8XBridge.callNative({name: 'NativePlugin', params: params, success: successCallback, progress: progressCallback})
JS will call a default plugin if no plugin name specify clearly
1var callback = function (result, response) { 2 showLog('Received result from native, complete = ' + response.complete + ', msg = ' + response.msg + ', result = ' + result) 3} 4XBridge.callNative({params: params, success: callback})
1//JsPluginName 2//Sync return 3XBridge.registerPlugin('JsPluginName', function (params) { 4 showLog('MySyncJsPlugin invoked by native, params = ' + JSON.stringify(params)) 5 return JSON.stringify(result) 6}) 7 8//Async return 9XBridge.registerPlugin('JsPluginName', function (params, callback) { 10 showLog('MyAsyncJsPlugin invoked by native, params = ' + JSON.stringify(params)) 11 callback(JSON.stringify(result)) 12}) 13 14//may fail 15XBridge.registerPlugin('JsPluginName', function (params, callback) { 16 showLog('MyAsyncJsPlugin invoked by native, params = ' + JSON.stringify(params)) 17 var isSuccess = true;//false 18 callback(JSON.stringify(result), isSuccess) 19})
1//JsPluginName 2//callback,complete indicates finished or not 3XBridge.registerPlugin('JsPluginName', function (params, callback) { 4 showLog('MySequenceJsPlugin invoked by native, params = ' + JSON.stringify(params)) 5 var isSuccess = true;//false 6 var time = 0 7 var timer = setInterval(function () { 8 var complete = false 9 time++ 10 if (time == 10) { 11 clearInterval(timer) 12 complete = true 13 } 14 callback((time * 10) + '%, MySequenceJsPlugin returns ' + JSON.stringify(result), isSuccess, complete) 15 }, 500) 16})
1XBridge.unregisterPlugin('JsPluginName')
JS can register a default plugin that native can call without plugin name
1XBridge.registerDefaultPlugin(function (params, callback) { 2 showLog('Default JS plugin invoked by native, params = ' + JSON.stringify(params)) 3 callback('Default JS plugin returns ' + JSON.stringify(params)) 4})
Native should load xbridge.js for the web. Please use all js functions after XBridge is initialized.
1function connectXBridge(callback) { 2 if (window.XBridge) { 3 callback(XBridge) 4 } else { 5 document.addEventListener( 6 'XBridgeReady', 7 function () { 8 callback(XBridge) 9 }, 10 false 11 ); 12 } 13} 14 15//run this function 16connectXBridge(function (bridge) { 17 showLog('XBridge is ready.') 18 //do your work with XBridge 19})
We defined webview event mechanism with a friendly way ----- window.addEventListener
1 window.addEventListener('ContainerShow', function(event){ 2 alert(event); 3 }, false); 4 window.addEventListener('ContainerHide', function(event){ 5 alert(event); 6 }, false);
1 window.addEventListener('AppShow', function(event){ 2 alert(event); 3 }, false); 4 window.addEventListener('AppHide', function(event){ 5 alert(event); 6 }, false);
1window.addEventListener('customEvent', function(event){ 2 alert(JSON.parse(event.params)); 3}, false);
No vulnerabilities found.
No security vulnerabilities found.