Socket
Socket
Sign inDemoInstall

jsbridge

Package Overview
Dependencies
206
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

jsbridge

JSBridge for jsvascript by yeliex


Version published
Maintainers
1
Weekly downloads
11
increased by57.14%
Install size
10.1 MB

Weekly downloads

Readme

Source

#jsbridge

JSBridge for jsvascript

  • request format: protocol://host:port/url[params]
    • eg: jsbridge://kjc/{"type":"action","name":"share","callback":"callback_1466131023000"}
    • eg: (supposed) jsbridge://kjc/action/share?callback=callback_1466131023000&title=title
  • params
    • protocol:
      • customize protocol name
      • cannot use protocols like http https ftp etc.
    • host & port & url
      • for dispatch
      • host and port can be empty
    • params
      • data you want to send
      • can be key-value string like original url

Readme

This is a very-base realization of JSBridge.

It is mainly for pages embedded in native app to communicate with their host by breaking webview;

Description

The package provides two methods, invoke for javascript and callback for native app.

The Communication only could be called up in javascript,and then native app can reply sth. with callback.

(Calling up in native app would support in the next version);

Usage

  • Javascript side
// node environment (webpack or es6)
const JSBridge = require('jsbridge').init('jsbridge','localhost');

JSBridge.invoke('action',{key: value},(params) => { console.log(params) });


// original javascript
// <script src='node_modules/jsbridge/dist/index.js'></script>

JSBridge.invoke('action',{key: value},(params) => { console.log(params) });

API methods

  • init(protocol,hostname,port,isjson)
    • init url preferences(try not to call it again, it would cover globally)
    • if isjson is true, all params would padding by json-object instead of key-value
  • invoke(url,params,callback)
    • call up a communication with native app
  • callback(callbackname,params)
    • callback a function pass by invoke

Keywords

FAQs

Last updated on 04 Jul 2016

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc