Skip to content
This repository has been archived by the owner on Jun 29, 2021. It is now read-only.
/ soketi-js Public archive
generated from renoki-co/node.js-package-skeleton

Soketi.js is a frontend module to connect to Soketi or Soketi-based Echo Servers for Laravel applications.

License

Notifications You must be signed in to change notification settings

soketi/soketi-js

Repository files navigation

The application is now deprecated (security issues-only)

It will not receive any new feature updates. Please consider using soketi/pws, an all-in-one Pusher server equivalent for Echo Server that is written in C and ported to Node.js by the awesome guys at uNetworking/uWebSockets.js.

Soketi.js is no longer needed, as the official Pusher client is compatible with pWS.

This application had implementation flaws by using both Pusher and Socket.IO and was a really bad idea. The versions before the deprecation announcement are still working and available for you to use.

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 alex@renoki.org instead of using the issue tracker.

πŸŽ‰ Credits

About

Soketi.js is a frontend module to connect to Soketi or Soketi-based Echo Servers for Laravel applications.

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •