status-react/resources/webview.js

27 lines
889 B
JavaScript
Raw Normal View History

2016-08-03 13:15:04 +00:00
(function () {
window.statusAPI = {
dispatch: function (event, options) {
console.log("statusAPI.dispatch: " + JSON.stringify(options));
if (options.callback) {
console.log(options.callback);
statusAPI.callbacks[event] = options.callback;
}
var json = JSON.stringify({
event: event,
options: options
});
console.log("sending from webview: " + json);
WebViewBridge.send(json);
},
callbacks: {}
};
WebViewBridge.onMessage = function (messageString) {
console.log("received from react-native: " + messageString);
var message = JSON.parse(messageString);
if (statusAPI.callbacks[message.event]) {
statusAPI.callbacks[message.event](message.params);
}
};
}());