the io object in socket.io is undefined and drupal isnt loading socket.io into client page. i'm fairly sure that this will close two other issues i've raised reaching this point of understanding.

is this module still being actively maintained, fixed and improved?

thanks

CommentFileSizeAuthor
#8 img4.png63.9 KBzenimagine
#8 img3.png27.02 KBzenimagine
#8 img2.png8.2 KBzenimagine
#8 img1.png61.64 KBzenimagine
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

laurencefass created an issue. See original summary.

Syntapse’s picture

Issue summary: View changes
Syntapse’s picture

i've managed to get this running by putting socket.io.js in my server / folder, but i dont think that its clear from documentation, and there still appear to be a lot old threads and discussions relating to this problem with no clear resolution.

is my server now working with correct setup or did i get lucky? not clear from online documentation. what is the correct location for socket.io.js and how does it relate to nodejs.config.js entry for resource?

is module still being maintained? i hope so as im two weeks into testing (slow process just getting it all working).

thanks

pribeh’s picture

Hi @laurencefass, did you manage to get this resolved? Where did you put socket.io.js?

I'm having issues accessing socket.io. On a setup of mine I can't access socket.io, :8080 and config/nodejs/js gives me a 404. The reports/status page says Drupal can reach node.js and gives no debug information despite debug being turned on. I can also see in the terminal that the service key handshake seems to happen fine. I'm running node v8.1.4 and socket.io 1.7.4. The current path for socket.io is /home/username/node_modules/socket.io/socket.io.js.

Also, if I try to ping localhost:8080 with wscat I get a socket hang up.

Here's my config:

settings = {
scheme: 'http',
port: 8080,
host: '',
resource: '/socket.io',
serviceKey: 'secret',
publishUrl:'publish',
backend: {
port: 80,
host: 'www.domain.com',
scheme: 'http',
basePath: '',
messagePath: '/nodejs/message'
},
debug: true,
sslKeyPath: '',
sslCertPath: '',
sslCAPath: '',
baseAuthPath: '/nodejs/',
extensions: [],
clientsCanWriteToChannels: false,
clientsCanWriteToClients: false,
transports: ['websocket','polling','flashsocket','htmlfile','xhr-polling','jsonp-polling'],
jsMinification: true,
jsEtag: true,
logLevel: 1
};

pribeh’s picture

I got this working by ensuring I had a proper package.json file setup in my home/user folder. For some reason using linuxbrew to install node.js and NPM it didn't setup a base package file. That's why I couldn't ping the socket locally. Also, since the site is using Fastly (Varnish CDN) I had to switch over to using an IP instead of domain for the backend host. Fastly only permits communication through the :80 port so for the client to ping socket.io on the server I had to use ip:8081 to get it going. I get a 404 on the node config builder page still but I'm looking into that.

settings = {
  scheme: 'http',
  port: 8081,
  host: '',
  resource: '/socket.io',
  serviceKey: 'b27ecac0a97ec6e94696aa8975819e31',
  backend: {
    port: 80,
    host: '45.79.183.59',
    scheme: 'http',
    basePath: '',
    messagePath: '/nodejs/message'
  },
  debug: true,
  sslKeyPath: '',
  sslCertPath: '',
  sslCAPath: '',
  baseAuthPath: '/nodejs/',
  extensions: [],
  clientsCanWriteToChannels: false,
  clientsCanWriteToClients: false,
  transports: ['websocket','polling'],
  jsMinification: true,
  jsEtag: true,
  logLevel: 1
};
zenimagine’s picture

Same problem for me, the module looks dead

Syntapse’s picture

is the module still being maintained? is there a roadmap for node js module moving forward?

zenimagine’s picture

FileSize
61.64 KB
8.2 KB
27.02 KB
63.9 KB

I installed on my nodejs server but could not make it work. The instructions are really not clear and the module is full of bugs.

I think that my configuration is correct. But the site returns a page not found.

the directory node_modules is in /public_html and my site Drupal 8 is in /public_html/web

Here is the configuration of the file nodejs.config.js (Drupal 8)

    settings = {
      scheme: 'https',
      port: 443,
      host: 'www.domaine.com',
      resource: '/socket.io',
      serviceKey: 'hgfjkliutfh',
      backend: {
        port: 443,
        host: 'www.domaine.com',
        scheme: 'https',
        basePath: '/web',
        messagePath: '/nodejs/message'
      },
      debug: false,
      sslKeyPath: '',
      sslCertPath: '',
      sslCAPath: '',
      baseAuthPath: '/nodejs/',
      extensions: [],
      clientsCanWriteToChannels: false,
      clientsCanWriteToClients: false,
      transports: ['websocket', 'polling'],
      jsMinification: true,
      jsEtag: true,
      logLevel: 1
    };
Here is the configuration of the module "Drupal nodejs"

img1

In the dashboard everything is ok

img2

Here are the errors in the console

img3

The site returns a page 404

img4

Syntapse’s picture

i've had mixed results with and have no idea about load testing. if this module isn't being maintained it could serve as the basis for a new pub/sub "drupal push" module of some description. pushable fields, pushable flags, pushable entities.

that said would be great to hear from the maintainers.

thanks

zenimagine’s picture

@laurencefass Have you managed to operate this module?

Syntapse’s picture

yes several times. its a bit delicate getting the settings exactly write, but once working, adding server push to pretty much anything is no big deal.

zenimagine’s picture

delete

Syntapse’s picture

Its recommended to install outside drupal but it doesnt matter where it is as its access through URL::port. install it where you like. if its outside logically its easier to maintain each independently. also set node server debug to true for very useful trace.

zenimagine’s picture

delete

zenimagine’s picture

delete

Syntapse’s picture

...there is no socket.io.js in the directory?

zenimagine’s picture

No ...

I used the following command:

npm install drupal-node.js

According to the instructions, there is nothing else to download.

zenimagine’s picture

@laurencefass Do you have a file "socket.io.js" ? what does your repetoire look like ?

Syntapse’s picture

that sounds wrong. i have a frozen server in my archive i will dig it out, test it, and check for socket.io.js.

this looks interesting...

https://github.com/wodby/drupal-node

zenimagine’s picture

@laurencefass

Can you show me the contents of your socket.io folder please.

Are you known apache or nginx?

In http or https?

Syntapse’s picture

this is taken from a working installation...

@virtualmin:~/public_html/drupal-nodejs/node_modules/socket.io$ tree
.

├── History.md
├── lib
│   ├── client.js
│   ├── index.js
│   ├── namespace.js
│   └── socket.js
├── LICENSE
├── node_modules
│   ├── debug
│   │   ├── bower.json
│   │   ├── browser.js
│   │   ├── CHANGELOG.md
│   │   ├── component.json
│   │   ├── debug.js
│   │   ├── index.js
│   │   ├── LICENSE
│   │   ├── Makefile
│   │   ├── node.js
│   │   ├── package.json
│   │   └── Readme.md
│   └── ms
│       ├── index.js
│       ├── LICENSE.md
│       ├── package.json
│       └── README.md
├── package.json
└── Readme.md

@virtualmin:~/public_html/drupal-nodejs$ cat nodejs.config.js

settings = {
  scheme: 'http',
  port: 7004,
  host: 'localhost',
  resource: '/socket.io',
  publishUrl:"publish",
  serviceKey: '123',
  backend: {
    port: 80,
    host: 'chat8.vs',
    scheme: 'http',
    basePath: '',
    messagePath: 'nodejs/message'
  },
  debug: true,
  sslKeyPath: '',
  sslCertPath: '',
  sslCAPath: '',
  baseAuthPath: '/nodejs/',
  extensions: [],
  clientsCanWriteToChannels: false,
  clientsCanWriteToClients: false,
  transports: ['websocket', 'polling'],
  jsMinification: true,
  jsEtag: true,
  logLevel: 1
};

and here is some proof (hope) that it actually brokers messages...

@virtualmin:~/public_html/drupal-nodejs$ node app.js

Started http server.
[2018/03/15 14:49:51] Route callback: checkServiceKey
[2018/03/15 14:49:51] Route callback: publishMessageToContentChannel
[2018/03/15 14:49:51] Body
{ channel: 'watchdog_dblog',
  commands: 
   [ { command: 'insert',
       method: 'before',
       selector: '#admin-dblog tr:eq(1)',
       data: '<tr class="dblog-access-denied dblog-warning"><td class="icon"></td><td>access denied</td><td>03/15/2018 - 14:49</td><td>/</td><td><span lang="" typeof="schema:Person" property="schema:name" datatype="">Anonymous (not verified)</span></td><td></td></tr>',
       settings: null } ],
...
[2018/03/15 14:50:41] authenticateClient: Authenticating client with key 35e6bd8876fd783a1980d592168959d0
[2018/03/15 14:50:41] Sending message to backend
[2018/03/15 14:50:41] message
{ authToken: '35e6bd8876fd783a1980d592168959d0',
  messageType: 'authenticate',
  clientId: 'VuaAbAgFnnCAQO0dAAAB' }
[2018/03/15 14:50:41] options
{ uri: 'http://chat8.vs:80/nodejs/message',
  body: 'messageJson=%7B%22authToken%22%3A%2235e6bd8876fd783a1980d592168959d0%22%2C%22messageType%22%3A%22authenticate%22%2C%22clientId%22%3A%22VuaAbAgFnnCAQO0dAAAB%22%7D&serviceKey=123',
  headers: 
   { 'Content-Length': 176,
     'Content-Type': 'application/x-www-form-urlencoded' } }
[2018/03/15 14:50:41] authenticateClientCallback: Invalid login for uid 0
[2018/03/15 14:50:41] cleanupSocket: Cleaning up after socket id VuaAbAgFnnCAQO0dAAAB, uid undefined
zenimagine’s picture

OK, thanks. So it works for you and you do not have a "socket.io.js" file.

I have the right configuration. I really do not understand why it does not work.

Are you on "Apache 2"?

I saw on several discussion that it was necessary to use a port higher than 1024. Do you add a poxy to your virtualhost?

My site is in https.

Thank you in advance.

zenimagine’s picture

Here is the configuration of my server :

    <IfModule mod_fastcgi.c>
        AddHandler php7-fcgi-www.mydomaine.com .php
        Action php7-fcgi-www.mydomaine.com /php7-fcgi-www.mydomaine.com
        Alias /php7-fcgi-www.mydomaine.com /usr/lib/cgi-bin/php7-fcgi-www.mydomaine.com
        FastCgiExternalServer /usr/lib/cgi-bin/php7-fcgi-www.mydomaine.com -socket /run/php/php7.1-fpm.www.mydomaine.com.sock -idle-timeout 120 -pass-header Authorization
    
        <Directory "/usr/lib/cgi-bin">
            Require all granted
        </Directory>
    </IfModule>
    
    <VirtualHost 138.74.184.65:80 [2001:21d0:0305:2100:0000:0000:0000:4741]:80>
        ServerAdmin contact@mydomaine.com
        ServerName mydomaine.com
        ServerAlias www.mydomaine.com
    
        RewriteEngine on
        RewriteCond %{HTTPS} !on
        RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
    </VirtualHost>
    
    <IfModule mod_ssl.c>
    <VirtualHost 138.74.184.65:443 [2001:21d0:0305:2100:0000:0000:0000:4741]:443>
    SSLEngine on
        SSLCertificateFile /etc/letsencrypt/live/www.mydomaine.com/cert.pem
        SSLCertificateKeyFile /etc/letsencrypt/live/www.mydomaine.com/privkey.pem
        SSLCertificateChainFile /etc/letsencrypt/live/www.mydomaine.com/chain.pem
        SSLProtocol all -SSLv2 -SSLv3
        SSLHonorCipherOrder on
        SSLCompression off
        SSLOptions +StrictRequire
        SSLCipherSuite ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:AES:CAMELLIA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!aECDH:!EDH-DSS-DES-CBC3-SHA:!EDH-RSA-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA
        Header always set Strict-Transport-Security "max-age=15768000; includeSubDomains; preload"
        Header always set X-Content-Type-Options "nosniff"
        Header always set X-XSS-Protection "1; mode=block"
        Header always set X-Frame-Options "SAMEORIGIN"
        Header always set X-Download-Options "noopen"
        Header always set X-Permitted-Cross-Domain-Policies "none"
        Header always set Content-Security-Policy "default-src https: data: 'unsafe-inline' 'unsafe-eval'"
        Header set Set-Cookie HttpOnly;Secure
    
        ServerAdmin contact@mydomaine.com
        ServerName mydomaine.com
        ServerAlias www.mydomaine.com
        DocumentRoot /var/www/www.mydomaine.com/public_html/web/
    
        <Directory /var/www/www.mydomaine.com/public_html/web>
            Options FollowSymLinks MultiViews
            AllowOverride All
            Require all granted
        </Directory>
    
        <IfModule mod_fastcgi.c>
            <FilesMatch ".+\.ph(p[345]?|t|tml)$">
                SetHandler php7-fcgi-www.mydomaine.com
            </FilesMatch>
        </IfModule>
    
        ErrorLog /var/www/www.mydomaine.com/logs/error.log
        CustomLog /var/www/www.mydomaine.com/logs/access.log combined
    </VirtualHost>
    </IfModule>

My site is in :

/public_html/web/

I installed NodeJS on my server with the following command :

    # curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
    # apt-get update
    # apt-get install nodejs

And on Drupal 8 with the following command :

    # cd /home/www.mydomaine.com/public_html
    # npm install drupal-node.j
    # npm install pm2 -g

Here is the NodeJS configuration for Drupal :

    # cd node_modules/drupal-node.js
    # cp nodejs.config.js.example nodejs.config.js
    # nano nodejs.config.js

And :

    settings = {
      scheme: 'http',
      port: 8080,
      host: 'localhost',
      resource: '/socket.io',
      serviceKey: 'hgfjkliutfh',
      backend: {
        port: 443,
        host: 'www.mydomaine.com',
        scheme: 'https',
        basePath: '/web',
        messagePath: '/nodejs/message'
      },
      debug: true,
      sslKeyPath: '/etc/letsencrypt/live/www.mydomaine.com/privkey.pem',
      sslCertPath: '/etc/letsencrypt/live/www.mydomaine.com/cert.pem',
      sslCAPath: '/etc/letsencrypt/live/www.mydomaine.com/chain.pem',
      baseAuthPath: '/nodejs/',
      extensions: [],
      clientsCanWriteToChannels: false,
      clientsCanWriteToClients: false,
      transports: ['websocket', 'polling'],
      jsMinification: true,
      jsEtag: true,
      logLevel: 1
    };

I added to iptables :

    # NODE JS
    iptables -t filter -A OUTPUT -p tcp --dport 8080 -j ACCEPT
    iptables -t filter -A INPUT -p tcp --dport 8080 -j ACCEPT

Here is the contents of my /etc/hosts

127.0.0.1       localhost
138.74.184.65   vps000000.ovh.net  vps000000
2001:21d0:0305:2100:0000:0000:0000:4741   vps000000.ovh.net  vps000000
127.0.1.1       myname.fr

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

Here is the contents of my /etc/apache2/ports.conf

# If you just change the port or add more ports here, you will likely also
# have to change the VirtualHost statement in
# /etc/apache2/sites-enabled/000-default.conf

Listen 80

<IfModule ssl_module>
        Listen 443
</IfModule>

<IfModule mod_gnutls.c>
        Listen 443
</IfModule>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

Result of the command netstat -ntpl

root@vps000000:~# netstat -ntpl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:25              0.0.0.0:*               LISTEN      2476/master     
tcp        0      0 0.0.0.0:4829            0.0.0.0:*               LISTEN      1423/sshd       
tcp        0      0 127.0.0.1:10023         0.0.0.0:*               LISTEN      1690/postgrey.pid -
tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN      1452/mysqld     
tcp        0      0 127.0.0.1:8080          0.0.0.0:*               LISTEN      24716/drupal    
tcp6       0      0 :::25                   :::*                    LISTEN      2476/master     
tcp6       0      0 :::443                  :::*                    LISTEN      24939/apache2   
tcp6       0      0 :::4829                 :::*                    LISTEN      1423/sshd       
tcp6       0      0 :::7134                 :::*                    LISTEN      1913/java       
tcp6       0      0 :::80                   :::*                    LISTEN      24939/apache2   

On my site the following error is displayed in the console :

Failed to load for

element whose source is « http://localhost:8080/socket.io/socket.io.js ».
And :
Refused to load the script 'http://localhost:8080/socket.io/socket.io.js' because it violates the following Content Security Policy directive: "default-src https: data: 'unsafe-inline' 'unsafe-eval'". Note that 'script-src' was not explicitly set, so 'default-src' is used as a fallback.
In the terminal I have :
root@vps000000:/home/www.mydomaine.com/public_html/node_modules/drupal-node.js# node app.js
Started http server.
[2018/03/15 16:44:02] Route callback: checkServiceKey
[2018/03/15 16:44:02] Route callback: healthCheck
Here is my site : delete
Syntapse’s picture

i am running from apache 2, no proxy.

i have a socket.io directory with files installed. no reference to socket.io.js

https://www.drupal.org/project/nodejs/issues/2877036#comment-12527700

the source code for socket.io is:

├── lib
│ ├── client.js
│ ├── index.js
│ ├── namespace.js
│ └── socket.js

is your reference to socket.io.js correct?

zenimagine’s picture

Yes I have exactly the same files as you. Can you tell me if there is a problem with my setup #23 ?

zenimagine’s picture

I updated #23

zenimagine’s picture

@laurencefass

How did you configure your 7004 port ?

I think the problem comes from the configuration of my server.

kuzguni’s picture

I've got a different type of socket.io error. to cut short: node.js reports:
checkServiceKey: Invalid service key undefined

and here are my details:

i am using opigno_lms (2.1) based drupal 8.x
i've got my drupal domain on akademi.piyononline.com and nodejs on node.akademionline.com.
nginx proxies my node.js on 8765 to both 8443 and 443.
started the node.js server with these settings (i am using letsencrypt, so the paths are set).

"scheme":"https",
"host":"node.piyononline.com",
"port":8765,
"backend":{
"port":443,
"scheme": 'https',
"strictSSL": true,
"host":"node.piyononline.com",
"messagePath":"nodejs/message"
}
"baseAuthPath":"/nodejs/",
"publishUrl":"publish",

Drupal settings:

admin/config/private_message/config
URL: https://node.piyonakademi.com:443
key: set to node.js config setting.

drupal->node.js
admin/config/nodejs/settings
https
node.piyononline.com
8765
service key also set to node.js setting
Client->node.js
https
node.piyononline.com
8443

This is what happens on console:
The socket.io scripts loads fine, I also check it with https://node.piyononline.com:8443/socket.io/socket.io.js
Next, the server reports error on
https://node.piyononline.com:8443/socket.io/?EIO=3&transport=websocket&s...
with 400 Bad Request.
when I investigate it, the server responds blank and on the server, i see
checkServiceKey: Invalid service key undefined, expecting [THEKEY], so somewhere the key wont get forwarded back to server.
i of course checked, if the secondary socket.io link works on a different tab, and it responds with a JSON containing Session ID unknown. that is fine, as another tab means no session there. but i'ev got a good working response.

On the browsers (I checked firefox, chrome and safari, so the error shouldnt be coupled to firefox), the chatbox headermast appers, but when i click on it to reveal the channels, there is no channel at all. i of course have another user open at the same time, so there should be users.

Is there anything I've not seen that someone can point out?

imclean’s picture

@zenimage: For a description of the NodeJS server config options, see my comment here.

I think using "localhost" could be part of the problem. What is "localhost" in the context of the website and the machine your browser is running on? Both of them need to access the NodeJS server.

Try assigning an IP address (and hostname if you like) to the NodeJS server and accessing it via that. It can't run on the same hostname/IP address and port combination as the web server.

Make sure you update the NodeJS config in Drupal as well when you make the changes.

grincon’s picture

I'm putting this out here for anyone having trouble with the HTTPS implementation of nodejs in Drupal 7. Both "scheme" values in my config were https, as well as my config in the nodejs config page. When using HTTP it was all working fine.

When using HTTPS I kept getting "Error reaching the Node.js server at "nodejs/health/check": [0] Error opening socket ssl://example.com:8088" in my logged messages and the status page kept showing "Error reaching the Node.js server. Make sure your Node.js service key matches the key set in the server application."

I found that this was an issue on how drupal_http_request works and a limitation it has on certificate validation. I found this "miracle" module that replaces the drupal_http_request function with a cURL enabled one and it all started working.

The module can be found here: CHR. Once installed and enabled, go to the config page admin/config/services/chr and turn on "Override Drupal HTTP Request".

Hopefully this helps you out there.