Nothing Particularly Magnificent

npm

Ready to take your JavaScript development to the next level? Meet npm Enterprise - the ultimate in enterprise JavaScript.Learn more »

@vite/bridge

1.0.14 • Public • Published

A bridge between native & web

Quick start

Installation

Install using npm:

npm install @vite/bridge

Hello world

import Bridge from '@vite/bridge';
const bridge=new Bridge(options);
bridge['bridge.version']().then(
    data=>{
        console.log(data)
    }
)
//output   X.XX

options

Param Type Description
[opts] Object contrustor arguments
[opts.readyCallback] Function would be called when bridge ready
[opts.selfDefinedMethods] String[] extend the method which native has supported and bridge hasn't supported yet.

Static properties:

Name Type Description
_support Boolean is supported
_inIosContainer Boolean
_inAndroidContainer Boolean

Instance Methods

  • A native methods shoud be called like this:
bridge[namespace.methodname](...args)

Currently, bridge supports async function call only. Each calling will return a Promise,which resolve with the function data or reject whith object:

{ 
  code:0,// error code 
  msg:"",// error msg
  data:""// fucntion returned data 
}
 
  • or use ubscribe/unSubscribe to receive/unreceive event from native
bridge.subscribe(namespace.eventName, cb)
bridge.unSubscribe(namespace.eventName, cb)
Params Type Description
eventName String
cb Function event handler

Detail method and event can be found here:

  • common error code :
error code desc
1 unknown error
2 invalidate params
3 network error
4 login error
5 address in params not identical to current address
  • method wallet.sendTxByURI possible error code
error code desc
4001 duplicate transaction before last transaction finished
4002 cannot find related tokenId
4003 amount format error (should be translate to min unit)
4004 user suspend
any minus show the message , we have handled it

methods :

namespace function name params return data
bridge version {"versionName":"1.0.0","versionCode":1}
app info {"platform":"ios"/"android","versionName":"1.0.0","versionCode":1024"env":"test" // production}
app language "zh-Hans"/"en"
app setWebTitle {title:"example title"}
app share {"url": "https://google.com" }
wallet currentAddress params "vite_XXXXXXXXXX"
wallet sendTxByURI {"uri":"string of vite uri schema ","address":"self vite address"} the block generated

Keywords

none

install

npm i @vite/bridge

Downloadsweekly downloads

47

version

1.0.14

license

ISC

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
  • avatar
  • avatar
Report a vulnerability