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

event-broadcast

v2.0.16

Published

[![NPM](https://nodei.co/npm/event-broadcast.png)](https://nodei.co/npm/event-broadcast/)

Downloads

36

Readme

event-broadcast: A dumified WebSocket wrapper

NPM

Build Status Known Vulnerabilities npm version

Browser support based on caniuse.com

| IE / Edge | Firefox | Chrome | Safari | iOS Safari | Samsung | Opera | | --------- | --------- | --------- | --------- | --------- | --------- | --------- | | v10| v11| v16| v7| v6| v4| Not supported

Why did we build event-broadcast?

  • Our goal is to make the learning curve to create websockets and real time applications lower.

Why use event-broadcast?

  • Multi platform: browsers, apps, servers - Anywhere JavaScript can run that allows WebSockets
  • No server needed to get started.
  • Free (Paid tier possible in the future)
  • Get started in a few lines of code: Seriously, copy the following code and put it in the <body> of you html then open your html multiple times and see them communicate with each other immediately.

In the browser:

<script src="https://unpkg.com/event-broadcast@latest"></script>
<script>
    var chat = new Ca$t();
    chat.on('open', function () {
        chat.emit('new-user-connected', {
            type: 'Browser'
        });
        chat.on('new-user-connected', function (data) {
            console.log('A new client has connected: ' + data.payload.type)
        });
    });
</script>
This may feel like a bunch of magic but, if you put the codes above to any of your pages, those pages will start communicating with each other.

In a NodeJs server:

var Ca$t = require('event-broadcast');

var chat = new Ca$t('https://www.my-super-awesome-domain.com');
chat.on('open', function () {
    chat.emit('new-user-connected', {type: 'Server'});
    chat.on('new-user-connected', function(data){
        console.log('A new client has connected: ' + data.payload.type)
    });
});

API Docs:

Ca$t('domain'):

The constructor that initialize the connection. The domain parameter is not required. The library will try to automatically detect your domain or host name. It is recommended to provide your domain name to make sure your applications (website or servers) are in the same channel and ablet to communicate with each other.

Parameters:

domain : (String) Not required

The string that will identify your application's channel (Usually your app's domain). All apps that share the same domain will be in the same channel, this includes webapps, mobile apps and node servers.

let mainChannel = new Ca$t('https://domain.com');

Ca$t.emit('event-name', {payload}):

Creates and fires an event along with a payload if provided.

Parameters:

event-name : (String) Required

The event identifier that will be emitted/fired. This must match the event listener.

{payload} : (JSON) Not required

The data that will be broadcasted to everyone.

mainChannel.on('event-name', {someData: 'Hello World!'});

Ca$t.on('event-name', callBack(data)): Listens to an event then fires callBack().

Parameters:

event-name : (String) Required

The event identifier that the event listener will listen to. This must match the exact event name.

callBack(data) : (callable function) Required

The function that will be executed once the event is fired. If the event is fired with a payload, the callback will receive a parameter conatining the data.

mainChannel.on('event-name', function(data){ console.log(data.payload.someData)});

Built in events:

  • close: Fired when connection is closed or disconnected.
    • Alias: onclose
  • error: Fired when an error occur.
    • Alias: onerror
  • onmessage: Fired when a new message is received.
    • Alias:
  • connect: Fired on successfull connection.
    • Alias: open, onopen, onconnect

* Note: Nothing you do in the internet is private thus use this software with caution.