UNPKG

vigour-wrapper-bridge

Version:

the bridge over which JavaScript talks to Native in apps wrapped by vigour-wrapper

42 lines (36 loc) 729 B
'use strict' var platform = exports platform.send = function send (pluginId, fnName, opts, cbId, cb) { if (!pluginId) { pluginId = '' } if (!fnName) { fnName = '' } if (!opts) { opts = '' } if (!cbId) { cbId = 0 } platform.write([cbId, pluginId, fnName, opts]) } platform.write = function write (message, cb) { try { var str = JSON.stringify(message) } catch (e) { cb(e) } try { console.log('bridge.send ing to android', message) window.NativeInterface.send(str) } catch (err) { console.error('window.NaiveInterface does not exist') if (cb) { cb(err) } } } platform.emit = function emit (event, data) { platform.write([0, '', event, data]) }