drupal con nashville...what is node.js? node.js is a platform built on chrome's js runtime for...

Post on 20-Jun-2020

7 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

DRUPAL CON

NASHVILLE 2018

DRUPALCON NASHVILLE

DRUPAL CON

NASHVILLE 2018

Drupal 8: Realtime notification with node.js

Drupal 8: Realtime Notification with node.js

Sugandh KhannaSrijan, INDIA

Drupal CON NASHVILLEMarch 2018

AGENDA

1. Technologies used with Drupal 8 for the realtime app are as follows: a. Regular HTTP b. Ajax Polling c. Ajax Long Polling d. HTML5 SSE / EventSource e. HTML5 Websockets (with socket.io [a node.js library])2. What is node.js ?3. Node.js detailed in easiest way.4. Node.js VS Drupal 8.5. Integrate Drupal 8 with node.js for real time notification.

Regular Http a. Client sends a request to the server.b. The server check that request and make their calculation for their response on the basis of this request.c. The server finally sends the response to the client.

Ajax Pollinga. Client uses regular http.b. The client receives the response and executes the JavaScript on the page which requests a file from the server at regular intervals (e.g. 0.5 seconds).c. Each response calculated by and sends it back, just like normal HTTP traffic.

Ajax Long pollinga. Client uses resular http.b. The client receives the response and executes the JavaScript on the page which requests a file from the server.c. Server waits until there's new information available before responding.d. Now the server responds with the new information if available.e. The client receives the new information and immediately sends another request to the server, re-starting the process.

Ajax Long polling

HTML5 SSE / EventSource:

a. A client uses regular http.b. The client receives the response and executes the JavaScript on the page which requests a file from the server.c. The server sends an event to the client when there's new information available.

1. Real-time traffic from server to client, mostly that's what you'll need

2. You'll want to use a server that has an event loop

3. Not possible to connect with a server from another domain

HTML5 SSE / EventSource:

HTML5 Websocketsa. A client uses regular http.b. The client receives the response and executes the JavaScript on the page which requests a file from the server.c. The server and the client can now send each other messages when new data (on either side) is available. 1. Real-time traffic from the server to the client and from the client to the server 2. You'll want to use a server that has an event loop 3. With WebSockets it is possible to connect with a server from another domain. 4. It is also possible to use a third party hosted websocket server, for example Pusher or others. This way you'll only have to implement the client side, which is very easy!

HTML5 Websockets

What is Node.js?

Node.js is a platform built on chrome's JS runtime for easily building fast, scalable network application. Node.js uses an event-driven, Non-Blocking I/O model that makes light weight and efficient, perfect for data intensive real-time applications that run across distributed devices.

Node.js in some details:

a. Runs on Google V8 js engine.b. Uses an event driven, non-blocking I/O model.c. Can handle many thousands of connections on a single process. d. Well suited of real time communication.

Drupal Vs Node.JS

About Node.js Drupal 8 module

Made of two parts:

a. A set of Drupal 8 modules for adding real-time capabilities to a Drupal 8 site. b. A Node.js application built with the node modules socket.io, express and request which runs from the terminal.

About Node.js Drupal 8 module

NPM (Node Package Manager) a. Used to manage packages for node.js applications. b. Bundled with node.js. c. Packages are defined by package.json. d. Allows download and publishing of packages. e. NPM is package manager for JS.

About Node.js Drupal 8 modulesocket.io( node.js real-time framework server)How to useThe following example attaches socket.io to a plain Node.JS HTTP server listening on port 3000.

var server = require('http').createServer(); var io = require('socket.io')(server); io.on('connection', function(client){ client.on('event', function(data){}); client.on('disconnect', function(){}); }); server.listen(3000);

About Node.js Drupal 8 module

express( fast, unopinionated, minimalist web framework )How to use

var var express = require('express'); var app = express(); app.get('/', function (req, res) { res.send('Hello World'); }) app.listen(3000);

About Node.js Drupal 8 module

About Node.js Drupal 8 moduleDrupal 8 node.js module installation guide.

Update your local package index:

sudo apt-get update

Install Node.js:

sudo apt-get install nodejs

You will also want to install NPM, which lets you easily manage your different Node.js packages.

sudo apt-get install npm

About Node.js Drupal 8 module

Practical Demo with real-time data on local system

How external API communicate with Drupal 8

Any Questions ?

Thanks You!

top related