zvse/private_message_messenger_nodejs

Instant updates for private messages without polling

Installs: 22

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 3

Language:JavaScript

Type:drupal-module

1.5 2019-11-14 07:36 UTC

This package is auto-updated.

Last update: 2024-04-27 19:52:12 UTC


README

Pure fork of the https://github.com/jez500/Private-Message-NodeJS with the package name change

Private Message NodeJS

Instant updates and notifications for the Private Message Messenger module module without the need for polling.

This listens for private message thread updates and uses the drupal nodejs module to trigger updates to the UI and provide notifications for members of the changed thread.

NOTE: This is different to the Private message nodejs module.
This module was written to be paired with Private Message Messenger and and they both work well together.

How it normally works

Polling is the standard method of checking for message updates, this means a website will hit your server every XX seconds to see if anything has changed. This is not ideal as it puts lots of extra load on your server with all those requests, it also means a user will have to wait XX seconds for a reply. If polling is disabled, it would require a full page reload!

Why this is a huge improvement

  • No polling slowing down your browser
  • No unnecessary constant load on your server
  • Message threads immediately show new messages
  • In-page browser notifications when new messages are recieved (optional).

Requirements

Not a requirement, but this module has been specifically made to work with Private Message Messenger, if you are not using this, you will have to implement your own integration (see below for hooking into a notification).

Hooking into a notification

This module triggers an event on $(window) so all you have to do is listen to window for the event. Eg:

$(window).on('pm:threads:poll', function(event, data) {
  console.log(data);
  alert('New message from ' + data.ownerName);
});

Installation

Just type

composer require zvse/private_message_nodejs

And... drush en -y private_message_nodejs

2. Ensure you have NodeJS setup and working

See basic guide here. Steps I took at time of writing:

  • Install NodeJS v4.2.6 on your server
  • npm install drupal-node.js should be outside of docroot and will default to node_modules folder
  • cd node_modules/drupal-node.js and cp nodejs.config.js.example nodejs.config.js
  • Edit nodejs.config.js with your config, at a bare minimum set serviceKey to a random value, I also had to update the backend.host with the correct url for my drupal site
  • Start the server node app.js also look at using forever
  • In your drupal site, go to /admin/config/nodejs/settings and add the serviceKey you created above. Other settings should match your nodejs.config.js file (only thing I need to change was the host)
  • The status report page /admin/reports/status should indicate drupal has found the NodeJS server

NOTE 1: At time of writing this, the "stable" release of drupal/nodejs (v1.1) was actually quite broken, the 1.x-dev version is far more robust.

NOTE 2: For https support with drupal/nodejs you will likely need this patch.

3. Notifications - Optional, but handy for testing

Enable the nodejs_notify module, open a few browser windows and go to /admin/config/nodejs/broadcast in one of them to send a message to all the others. If that works, this module should be ready to go!

The nodejs_notify module also provides jGrowl which is used for notifications in this module. If you don't want nodejs_notify enabled but still want notifications then include jGrowl manually

4. Disable polling

You don't need it anymore, set the Ajax refresh rate for messenger blocks and config to 0 so it wont poll anymore.

5. Test

If you are using Private Message Messenger, Open 2 different browsers, each logged in as different users, send a message from one user to another, you should see threads and blocks instantly update and a notification displayed.

Author

This module is created by Jeremy Graham but wouldn't be possible without all the great work done by Jaypan on the Private Message module