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

laravel-ratchet

v0.0.3

Published

JavaScript library for php laravel-ratchet made by shamaseen

Downloads

9

Readme

NPM package Build Status

laravel-ratchet-js

This package is made to simplify websocket useage throughout PHP laravel ratchet package.

You can check PHP laravel ratchet package here.

Installation

To install the package, run the following command:

npm i laravel-ratchet

Usage

Make new instance from Shama class:

let shama = new Shama();

By default, Shama class detect your hostname and ssl and will start websocket with ws(another s if you are using ssl)://{hostname}:9090 URL, if You want to change the URL or the port you should send it as a parameter when making the instance:

let shama = new Shama(url);

You should have an input element with Session value in your HTML:

<input type="hidden" name="session" value="{{\Session::getId()}}">

And set your session id in Shama property, as following:

shama.session = $('input[name=session]').val();

Philosophy

The package philosophy is based on event listener, it is always expected to have event property on the returned json response from the server. The package will match the event sent from the server with the predefined listeners on the instance, then it will auto trigger the listener with a data parameter sent from the server, and you will continue from here !

Define listeners

You can define as many listener as you want by triggering the addListener method on Shama class:

shama.addListeners(event, method);

The event parameter is expected to be a string (the event name which sent from the server) and the method property is expected to be a function to trigger.

####getting parameters the method defined inside addListeners will automatically inject an object parameter which has all data from the server, e.i:

function method(e)
{
   console.log(e.route);
   console.log(e.{anyParameters come from the server}));
}

Send a message

to send a message, call the method send from Shama instance:

shama.send(object);

object should container route property to specify which route it should be call.

Default listeners

By default, Shama class will have these listeners:

Error listener

This listener will be triggered on error from PHP side.

Initialize Listener

When you make an instance from Shama class, it will open a websocket connection and make an initializing process, this process will till the socket "Hey I'm here !, Am ready to recieve messages !".

Default listener

If an event is sent without having a listener to catch it, default listener will be triggered.

Default listener

If an event is sent without having a listener to catch it, default listener will be triggered.