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

@soketi/soketi-js

v1.4.3

Published

Laravel Echo extension that works with Soketi, a Laravel-ready WebSockets service.

Downloads

372

Readme

Soketi.js

CI Latest Stable Version Total Downloads License

Soketi.js is a hard fork of Laravel Echo that works with Soketi, a Laravel-ready WebSockets service.

🤝 Supporting

Renoki Co. on GitHub aims on bringing a lot of open source projects and helpful projects to the world. Developing and maintaining projects everyday is a harsh work and tho, we love it.

If you are using your application in your day-to-day job, on presentation demos, hobby projects or even school projects, spread some kind words about our work or sponsor our work. Kind words will touch our chakras and vibe, while the sponsorships will keep the open source projects alive.

ko-fi

🚀 Installation

You can install the package via npm:

npm install --save-dev @soketi/soketi-js

🙌 Usage

Soketi.js is a hard fork of laravel/echo, meaning that you can use it as a normal Echo client, being fully compatible with all the docs in the Broadcasting docs.

import Soketi from '@soketi/soketi-js';

window.Soketi = new Soketi({
    host: window.location.hostname,
    key: 'echo-app-key', // should be replaced with the App Key
    authHost: 'http://127.0.0.1',
    authEndpoint: '/broadcasting/auth',
});

// for example
Soketi.channel('twitter').listen('.tweet', e => {
    console.log({ tweet: e.tweet });
});

Authorizing Sanctum

The package has full compatibility with the Pusher.js connector, meaning that you can specify the authorizer for the request:

window.Soketi = new Soketi({
    host: window.location.hostname,
    key: 'echo-app-key',
    authorizer: (channel, options) => {
        return {
            authorize: (socketId, callback) => {
                axios.post('/api/broadcasting/auth', {
                    socket_id: socketId,
                    channel_name: channel.name,
                })
                .then(response => {
                    callback(false, response.data);
                })
                .catch(error => {
                    callback(true, error);
                });
            },
        };
    },
});

Encrypted Private Channels

This feature works with Echo Server 5.4.0 and beyond.

Encrypted Private Channels are Pusher-like features, but they come integrated with this package and you are free to leverage them.

Below you will find an example:

window.Soketi = new Soketi({
    host: window.location.hostname,
    key: 'echo-app-key',
    encryptionMasterKeyBase64: 'vwTqW/UBENYBOySubUo8fldlMFvCzOY8BFO5xAgnOus=',
});

According to the Pusher docs, the key was generated using OpenSSL:

$ openssl rand -base64 32

The key is also needed in your backend broadcasting client. For Laravel, in broadcasting.php:

'socketio' => [
    'driver' => 'pusher',
    ...
    'options' => [
        ...
        'encryption_master_key_base64' => 'vwTqW/UBENYBOySubUo8fldlMFvCzOY8BFO5xAgnOus=',
    ],
],

You then are free to use the encrypted private channels:

Soketi.encryptedPrivate('top-secret').listen('.new-documents', e => {
    //
});

Catching any event

You can catch any event using .onAny():

Soketi.onAny((event, ...args) => {
    //
});

Catching errors

Sometimes the connection might throw errors:

Soketi.error(({ message, code }) => {
    //
});

🐛 Testing

npm run test

🤝 Contributing

Please see CONTRIBUTING for details.

🔒 Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

🎉 Credits