npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@nrk/nativebridge

v1.1.9

Published

Native Bridge is a lightweight and efficient bridge between webview and native app. It's primary use case is to share state between native apps and javascript in webviews.

Downloads

455

Maintainers

larsjorgentvedtlarsjorgentvedtebrautasetebrautasetmmepmmepshieldyarmorshieldyarmortheasparrowhawktheasparrowhawkn07073n07073siddisesiddisestiansstianskjellovenordlienkjellovenordlienmaar1052maar1052joakimmohnjoakimmohnmariehovlandmariehovlandsondrbwsondrbwingryeeingryeeellenulrikellenulrikkristjgrkristjgrhenrkhenrksokkemannensokkemannenihlnrkihlnrkknutboknutbojanerikbrjanerikbrthormodbthormodbsiiverssiiverstorsrextorsrexharaldskharaldskeskilgheskilghragnaroh-nrkragnaroh-nrkdaardaldaardalarevjensenarevjensenjulusianjulusianmadsernmadsernandrefauandrefaujfjeldskaarjfjeldskaarmuddahmuddahjensragejensragephajsiphajsijorn_georgjorn_georgbjornhelsbjornhelshalvorhhalvorhmorten-nrkmorten-nrknicklassvendsrudnicklassvendsrudkjellvnnrkkjellvnnrksanderknrksanderknrkeirikjstnrkeirikjstnrkcarinafraningcarinafraninghelenperhelenperstefanogdennrkstefanogdennrkjimmeloysundjimmeloysundtobiasrptobiasrpmartioskmartioskjimalexbergerjimalexbergergunderwondergunderwonderluminrkluminrksupermeisensupermeisenvagifabilovvagifabilovclaudio-nrkclaudio-nrkhaakemonhaakemonzenangstzenangstrannveigncrannveignceschoieneschoienbaltebaltetoshbtoshbemte123emte123opetopetklizterkliztermikkelnygardmikkelnygardfeiringfeiringdervodevdervodevgrimburgrimburgardkroyergardkroyerkariaankariaanedplayzedplayzmiatollaksvikmiatollaksvikytterboytterbomachineboycommachineboycomtrulsltrulslmslhmmslhmcbjerkancbjerkanhermangudesenhermangudesenandreeldareideandreeldareidehenningkollerhenningkollerespenhalstensenespenhalstensendanjohnrkdanjohnrkolapeterolapeterteodor-elstadteodor-elstadlorecasterlorecasternrk-ps-teamcitynrk-ps-teamcityswlaswlanrk-midas-jenkinsnrk-midas-jenkinsandorpandorandorpandornrkrichardnrkrichardgesigesigundelsby-nrkgundelsby-nrkjonstalecarlsenjonstalecarlsennrk-sofie-cinrk-sofie-cinytaminnytaminjesperstarkarjesperstarkarskjalgepalgskjalgepalgeirikhalvardeirikhalvardastokkeastokken640071n640071henrik-mattssonhenrik-mattssonhaavardmhaavardmyryrnrk-kurator-jenkinsnrk-kurator-jenkinstorgeilotorgeilonrk-user-syncnrk-user-syncdhdeploydhdeployespenwaespenwaovstetunovstetunstianljstianljharaldkjharaldkjmariusumariusucristobalcristobalknuthaugknuthaugthohalvthohalvjohnarnejohnarneeshaswinieshaswinimorrowmorrowoyvindehoyvindehlaatlaattoggutoggunrk-jenkinsnrk-jenkinsplommaplommaevjandevjandmoltubakkmoltubakkingridgureningridgurenlu-luxlu-luxanderslianderslisiljesiljestiandgstiandgsjurlursjurlurandipodnrkandipodnrkpkejpkejyosrimtiyosrimtimorten.nyhaugmorten.nyhaugingvildcathingvildcatherlend.joneserlend.jonesbrneirikbrneirikmollersemollersetbnrktbnrknordankenordankesimonmitternachtsimonmitternachtmartintorgersenmartintorgersenrebchrrebchrsteipalsteipaldiscobusdiscobusmartingundersenmartingundersentinkajtstinkajtshallvardlidhallvardlidtomivartomivarajacoajacotobinustobinusmortenokmortenoknrk-ark-deploynrk-ark-deployjeangilbertlouisjeangilbertlouisheidimorkheidimorkingriddraageningriddraagenfridajalborgfridajalborgbruusibruusirosvollrosvollchristianeidechristianeideenordbyenordbyglen_imrieglen_imriemia.aasbakkenmia.aasbakkenelathamnaelathamnaevjjan17evjjan17olatoftolatoftkongsrudkongsrudchrpeterchrpeteringvildforsethingvildforsethharaldk76haraldk76stigokstigokjohannesodlandjohannesodlandanders993anders993vildefjvildefjvildepkvildepkrolerbolerrolerbolermeloyguttmeloyguttanders.baggethunanders.baggethun

Keywords

Readme

@nrk/nativebridge

Native Bridge is a lightweight and efficient bridge between webview and native app. It's primary use case is to share state between native apps and javascript in webviews.

Support

Android|iOS --- | --- Tested on Android 4.4.4+ | iOS 10.2+


Browser

Used as a producer/consumer-interface for passing messages to/from native app (iOs/Android). Following an EventEmitter interface (on/once/off/emit). In addition an RPC-interface makes calling native methods a breeze.

EMIT - send to native:
nativebridge.emit('test', { foo: 'bar' })  // Emit 'test' event with data (must be object) to native
ON/ONCE - receives from native:
nativebridge.on('test', (data) => {})       // Bind handler to 'test' event emitted from native
nativebridge.once('test', (data) => {})     // Bind handler to 'test' (one time only) event emitted from native
OFF: - remove handler(s)
nativebridge.off('test')                    // Unbind all handlers for 'test' event
nativebridge.off('test', (data) => {})      // Unbind specific handler for 'test' event
RPC: - make call to native app using topic as contract

Make a remote procedure call (RPC) using nativebridge interfaces as described above. Resolves with data on completion, or rejects with error details from the app (or timeout).

// Auto-bind handlers (once/emit) to complete an RPC-call to native
nativeBridge.rpc({                          
  topic: 'test',                             // using 'test' as event
  data: {},                                 // with data (args)
  resolve: (data) => {},                    // using callback on success
  reject: (err) => {},                      // or rejection on error
  timeout: 1000                             // with a timeout threshold
})

Installation

USE WITH NPM:
npm install @nrk/nativebridge --save
import nativebridge from '@nrk/nativebridge'
USE WITH SCRIPT TAG:
<script src="https://static.nrk.no/nativebridge/X.X.X/nativebridge.min.js"></script>
<!-- window.nativebridge is now defined -->
USE WITH REQUIRE.JS:
require(['https://static.nrk.no/nativebridge/X.X.X/nativebridge.min.js'], function(nativebridge) {
  /* code here */
});

How does it work

Emit

A data object is sent using topic as topic to an exposed method on either:

  • Android:
window.webkit.messageHandlers.nativebridgeiOS.postMessage({topic: "test", data: {foo: "bar"}})
  • iOS:
window.NativeBridgeAndroid.send(JSON.stringify({topic: "test", data: {foo: "bar"}}))
Android/iOS handler

Topic-handlers are mapped to native functions, using data-object as an argument e.g topicHandler({topic: "test", data: {foo: "bar"}}). The app injects a js-snippet to dispatch a message back to the webpage using CustomEvents:

window.dispatchEvent(new CustomEvent('nativebridge', { detail: {topic, data} }))
On

The CustomEvent dispatched from the native app is ran using attached callback-handlers on the given topic.

Error handling

If an error occurs in the native app, an Error object will be rejected, eg.

err.message = '[{message: "no handler available", errorCode: 100}]'
RPC

The RPC-method is made to simplify on/off/emit-logistics. In addition it supports a timeout, which will throw an error if timeout is reached:

err.message = 'RPC for test using {} timed out after 1000ms'

Local development (web)

First clone @nrk/nativebridge and install its dependencies:

git clone [email protected]:nrkno/nativebridge.git
cd nativebridge
npm install && npm start

Building and committing

After having applied changes, remember to build before pushing the changes upstream.

git checkout -b feature/my-changes
# update the source code
npm run build
git commit -am "Add my changes"
git push origin feature/my-changes
# then make a PR to the master branch,
# and assign another developer to review your code

NOTE! Please also make sure to keep commits small and clean (that the commit message actually refers to the updated files).
Stylistically, make sure the commit message is Capitalized and starts with a verb in the present tense (for example Add minification support).