0.0.3 • Published 5 years ago

@nbrowser/nb-chan v0.0.3

Weekly downloads
5
License
BSD-3-Clause
Repository
github
Last release
5 years ago

@nbrowser/nb-chan

npm (scoped) npm bundle size (minified)

nb-chan is a cross-domain event emitter for Nucleome Platform. nb-chan has the same initialize method and the same function interface "on" and "call" as d3-dispatch.

if user install our chrome extension Nucleome Bridge, nb-chan will use Nucleome Bridge to send event emittion between tabs from multiple domains, otherwise, it will use web browser's BroadCast Channel to send event emittion between tabs within the same domain.

Our Web Application Nucleome Browser is connected with nb-chan.

Connect

Connect to channel.

import {chan} from "@nbrowser/nb-chan";
var c = chan("update","brush")
var callback = function(status){
  console.log(status)
}
c.connect(callback)

Listen to events in all chan connected tabs.

//receive message from nbrowser bridge or BroadCast Channel.

c.on("update",function(d){
  //Add your code (user navigate to these genome coordinates in other tab, respond accordingly )
})
c.on("update.anything",function(d){
  //register multiple listeners as d3-dispatch
  //Add your other code (user navigate to these genome coordinates in other tab, respond accordingly )
})
c.on("brush",function(d){
  //Add your code  (user brush these genome coordinates in other tab, respond accordingly )
})

Emit events to all chan connected tabs.

var regions = [{genome:"hg38",chr:"chr1",start:1,end:10000},{genome:"hg38",chr:"chr2",start:1,end:1000}]

c.call("update",this,regions)

c.call("brush",this,regions)

Installing

If you use NPM, npm install @nbrowser/nb-chan. If you use in your webpage,

<script src="https://vis.nucleome.org/static/lib/nb-chan.min.js"></script>
<script>

var c = nb.chan();
c.connect(function(status){
    //add your code callback.
});

</script>

Connect your web page with Nucleome Bridge

Nucleome Bridge now support communication with UCSC Genome Browser and WashU EpiGenome Browser.

Due to the web safety reason, any web sites which want to connect with Nucleome Bridge needs to satisfty the pattern specify in Nucleome Bridge manifest.json file.

Currently, any local website, whose IP address is such as *://127.0.0.1:*/*, is connectable with Nucleome Bridge.

For user sharing their web pages, https://bl.ocks.org/* is also connectable with Nucleome Bridge. User can share their web page in this website by submit their code to gist. For futhur information. Please read this webpage. We also have some demos in bl.ocks.org, here is the link.

If you want to your website can be connectable with Nucleome Bridge, Please contact us.

API Reference

Check the connection status of channel

  var c = nb.chan()
  c.connect(function(){
    console.log(c.status())
  }

Currently, standard communication code

event name: update and brush.
pass data: regions = [region... ]
           region format {genome:string,chr:string,start:int,end:int}

Start and end is defined as same as bed format. Start is 0-index. and end is not included in this region.