Drupal is a registered trademark of Dries Buytaert

driplet

No security coverage
View on drupal.org

A Drupal module that provides pushing messages to the frontend using Driplet microservice. It enables pushing real-time messages to specific users or roles via WebSockets. The module depends on Driplet PHP library.

Use cases

  • Sending real-time notifications to users (example for this can be found inside driplet_notify submodule)
  • Notifying users of new content/updates in real time
  • Alerting about system events or changes
  • View log messages in real time (example for this can be found inside driplet_log submodule)
  • A possibility of creating a real-time chat/chatrooms between users/site visitors
  • Moderation queue alerts
  • Custom live analytics inside Drupal

Requirements

The module works in conjunction with Driplet - a Go-based microservice. Ensure Driplet is properly configured and running before using the module.

How it works

A backend service (e.g. Drupal) can push a message to Driplet microservice, which will then push the message to the frontend clients. The message can be targeted to specific users, roles, or topics. The frontend clients can subscribe to topics and receive messages in real-time.

More on how it works

Driplet can authenticate users based on their JWT tokens which Driplet module generates on (/api/driplet/jwt) endpoint. The JWT includes user ID and user roles which can be used as targeting criteria for messages. For instance, it is possible to send a message only to specific roles, uids, or a combination of both. It's also possible to invert the logic and specify exclusion criteria.

There is also a concept of topics which can be used to group messages. For instance, on a specific page, a frontend user can subscribe only to a topic relevant to that page. This way, the user will receive only messages relevant to that topic. It's possible to subscribe to multiple topics at once, and handle each topic separately.

Submodules

Real-time logs

Enable driplet_log to access real-time logs.

Push notifications

Enable driplet_notify to access real-time push notifications.

How to use

In PHP:

  $driplet = \Drupal::service('driplet.service');

  $message = $driplet->createMessage()
    ->setMessage([
      'some' => 'some',
      'keys' => 'content'
    ])
    ->setTopic('some-topic')
    ->include()
    ->setTarget('roles', 'authenticated');

  $driplet->sendMessage($message);

In JS on the frontend:

const client = DripletClient.getInstance(wsEndpoint, jwtEndpoint);
client.setTopics(['some-topic']);

client.onMessage((data) => {
  if (data.topic !== 'some-topic') return;

  // Handle the message
  console.log('Received message:', data.message);
});

Documentation

Read the supplied Readme.md in the root folder on how to set up the module and how to run Driplet in DDEV.

Activity

Total releases
4
First release
Jan 2025
Latest release
1 year ago
Release cadence
1 day
Stability
75% stable

Release Timeline

Releases

Version Type Release date
1.0.2 Stable Feb 1, 2025
1.0.1 Stable Jan 29, 2025
1.0.x-dev Dev Jan 29, 2025
1.0.0 Stable Jan 29, 2025