Skip to content
Snippets Groups Projects
Commit 8ac26c0e authored by Jay Friendly's avatar Jay Friendly
Browse files

Issue #2972506 by Jaypan: Setting up nodejs integration to be a composer library

parent a466987f
No related branches found
No related tags found
No related merge requests found
......@@ -5,5 +5,5 @@ core: 8.x
package: Private Message
dependencies:
- private_message:private_message
- duration_field:duration_field
- drupal:private_message
- drupal:duration_field
{
"name": "drupal/private_message_nodejs",
"description": "Creates an integration between the Private Message module and a Node.js back end.",
"type": "drupal-module",
"homepage": "https://drupal.org/project/private_message",
"authors": [
{
"name": "Jay Friendly (Jaypan)",
"homepage": "https://www.jaypan.com",
"role": "Maintainer"
}
],
"support": {
"issues": "https://drupal.org/project/issues/private_message",
"source": "https://cgit.drupalcode.org/private_message"
},
"license": "GPL-2.0-or-later",
"minimum-stability": "dev",
"require": {
"jaypan/private-message-nodejs": "~2.8"
}
}
/node_modules
# About this package #
This package provides the server-side scripts for integration of the Drupal
Private Message module with Nodejs.
# Installation Instructions #
1. Install Nodejs on your server.
2. Navigate to the directory that this file resides in.
3. Run `npm install` from this directory.
4. Run `node index.js` from this directory. Note that you need to leave this
program running for the module to work with Nodejs.
/**
* @file
* Server-side Nodejs implementation to handle the private message module.
*/
/*global require, console*/
/*jslint white:true, this, browser:true*/
(function (require, console) {
"use strict";
var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);
var helmet = require('helmet');
app.use(helmet());
// The private message thread namespace. This namespace will be used to
// emit triggers that update private messages with new messages.
var threadChannel = io.of('/pm_thread');
threadChannel.on('connection', function (socket) {
console.log('user connected to pm_thread namespace');
// Each private message thread will have its own room. This ensures that
// emissions only go to other users in the room, and not across all private
// message users everywhere.
socket.on('thread', function (threadId) {
console.log("joining thread: " + threadId);
// Join the room for the given thread.
socket.join(threadId);
});
// Triggered when a new private message has been added to a thread.
socket.on('new private message', function (threadId) {
console.log("Sending private message to thread: " + threadId);
// Tell all users in the room that a new private message is ready to be
// fetched.
threadChannel.to(threadId).emit('new private message');
});
socket.on('disconnect', function () {
console.log('user disconnected from thread namespace');
});
});
// The private message inbox namespace. This namespace will be used to
// emit triggers that update the private message inbox.
var inboxChannel = io.of('/pm_inbox');
inboxChannel.on('connection', function (socket) {
console.log('user connected to pm_inbox namespace');
// Each user will have their own 'room'. This is so that updates to an
// individual user's inbox can happen, rather than having all users update
// their inbox.
socket.on('user', function (uid) {
console.log("joining pm inbox for user: " + uid);
// Join the room for the given user.
socket.join(uid);
});
// Triggered when a thread a user is a member of has been updated.
socket.on('update pm inbox', function (uid) {
console.log("triggering PM Inbox update for user: " + uid);
// Tell the users inbox to update.
inboxChannel.to(uid).emit('update pm inbox');
});
socket.on('disconnect', function () {
console.log('user disconnected from pm_inbox namespace');
});
});
// The private message notification namespace. This namespace will be used to
// emit a trigger to update the unread thread count.
var notficationBlockChannel = io.of('/pm_notifications');
notficationBlockChannel.on('connection', function (socket) {
console.log('user connected to pm_notifications namespace');
// Each user will have their own room. This ensures that emissions only go
// to them, and not across all private message users everywhere.
socket.on('user', function (user) {
console.log("joining pm thread count notification for user: " + user);
// Join the room for the given user.
socket.join(user);
});
// Triggered when a thread a user is a member of has been updated.
socket.on('update pm unread thread count', function (uid) {
console.log("triggering PM Notification update for user: " + uid);
// Tell the users inbox to update.
notficationBlockChannel.to(uid).emit('update pm unread thread count');
});
socket.on('disconnect', function () {
console.log('user disconnected from pm_notifications namespace');
});
});
// The private message pm_browser_notification namespace. This namespace will
// be used to emit a trigger to send a browser notifiation of the new message.
var browserNotificationChannel = io.of('/pm_browser_notification');
browserNotificationChannel.on('connection', function (socket) {
console.log('user connected to pm_browser_notification namespace');
// Each user will have their own room. This ensures that emissions only go
// to them, and not across all private message users everywhere.
socket.on('user', function (user) {
console.log("joining browser notifications for user: " + user);
// Join the room for the given user.
socket.join(user);
});
// Triggered when a thread a user is a member of has been updated.
socket.on('notify browser new message', function (uid, message) {
console.log("triggering browser notification for user: " + uid);
// Trigger browser notifications of new messages.
browserNotificationChannel.to(uid).emit('notify browser new message', message);
});
socket.on('disconnect', function () {
console.log('user disconnected from pm_browser_notification namespace');
});
});
http.listen(8080, function () {
console.log('listening on *:8080');
});
}(require, console));
This diff is collapsed.
{
"name": "drupal-private-message-module-nodejs-backend",
"version": "1.0.0",
"description": "Drupal private message module server-side Nodejs script",
"author": {
"name": "Jay Friendly",
"email": "drupal@jaypan.com",
"url": "https://www.jaypan.com/"
},
"contributors": [],
"dependencies": {
"express": "^4.16.3",
"helmet": "^3.12.0",
"socket.io": "^2.1.0"
},
"homepage": "https://www.drupal.org/project/private_message",
"repository": {
"url": "https://git.drupal.org/project/private_message.git",
"type": "git"
},
"license": "GPL-2.0-or-later",
"keywords": [
"Drupal",
"Private Message"
],
"bugs": {
"url": "https://www.drupal.org/project/issues/private_message"
}
}
name: Private Message Node.js
description: Utilizes Node.js for instant message notifications without polling.
name: 'Private Message Node.js'
description: 'Creates an integration between the Private Message module and a Node.js back end'
type: module
core: '8.x'
package: Private Message
package: 'Private Message'
dependencies:
- private_message:private_message
- drupal:private_message
......@@ -6,7 +6,7 @@ package: Private Message
dependencies:
- drupal:text
- message:message
- message:message_notify
- drupal:message
- drupal:message_notify
configure: private_message.admin_config.config
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment