• Home
  • Categories
  • Recent
  • Popular
  • Top
  • Tags
  • Users
  • Groups
  • Documentation
    • Home
    • Read API
    • Write API
    • Plugin Development
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
v3.5.2 Latest
Buy Hosting

How to use websocket notifications from external app?

Scheduled Pinned Locked Moved General Discussion
notificationssocket.iowebsockets
6 Posts 3 Posters 726 Views
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Reinier PupoR Offline
    Reinier PupoR Offline
    Reinier Pupo
    wrote on last edited by Reinier Pupo
    #1

    I want to integrate nodeBB to my web app as community forum. Do NodeBB websockets infraestucture allows my external app to listen for events like new topic, category, etc through socket.io channels? If it is possible, there is any example?

    1 Reply Last reply
    0
  • PitaJP Offline
    PitaJP Offline
    PitaJ Global Moderator Plugin & Theme Dev
    wrote on last edited by
    #2

    You should be able to connect a socket to NodeBB and listen for the socket events, yes. You'd have to make sure you app URL is listed in the origins whitelist.

    There's no example. Can you share more about what you're trying to accomplish?

    Reinier PupoR 1 Reply Last reply
    0
  • Reinier PupoR Offline
    Reinier PupoR Offline
    Reinier Pupo
    replied to PitaJ on last edited by
    #3

    @pitaj What I want is to listen for notifications, for example: new topic, new post, etc. I realize how to connect, but how can I listen for specifics events? For example:

    const socket = socketIOClient("ws://forum.example.com/socket.io");
    socket.on("event:new_topic", data => {
    console.log("Response: ", data.someValue)
    });

    PitaJP 1 Reply Last reply
    0
  • PitaJP Offline
    PitaJP Offline
    PitaJ Global Moderator Plugin & Theme Dev
    replied to Reinier Pupo on last edited by
    #4

    @reinier-pupo okay so you want to listen for notifications.

    You essentially want something like this:
    https://github.com/NodeBB/NodeBB/blob/b46d2f93e64e6546fb295d396b830dcab9f0cbbd/public/src/client/header/notifications.js#L25

    Reinier PupoR D 2 Replies Last reply
    1
  • Reinier PupoR Offline
    Reinier PupoR Offline
    Reinier Pupo
    replied to PitaJ on last edited by PitaJ
    #5

    @pitaj Making a deep testing to connect my app to nodebb websocket, I realize that I have an error. I run this command in wscat:
    wscat -c ws://forum.example.com/socket.io
    and this is the response:
    error: Unexpected server response: 502
    The nginx config is:

    server {
        listen 80;
    
        server_name forum.example.com;
    
        location / {
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;
            proxy_set_header Host $http_host;
            proxy_set_header X-NginX-Proxy true;
    
            proxy_pass http://127.0.0.1:4567;
            proxy_redirect off;
    
            # Socket.IO Support
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
        }
    }
    

    The nodeBB config.json:

    {
        "url": "http://forum.example.com",
        "secret": "&//&%$$",
        "database": "mongo",
        "mongo": {
            "host": "127.0.0.1",
            "port": "27017",
            "username": "nodebb",
            "password": "MyPass",
            "database": "nodebb",
            "uri": ""
        },
        "port": "4567",
        "socket.io": {
    	"origins": ["*:*"],
    	"transports": ["polling","websocket"]
        }
    }
    

    Is correct the ws://forum.example.com/socket.io
    address?
    Is this the correct workaround to connect through ws to nodeBB?

    1 Reply Last reply
    0
  • D Offline
    D Offline
    DeonEvangeline
    replied to PitaJ on last edited by
    #6

    @pitaj said in How to use websocket notifications from external app?:

    @reinier-pupo okay so you want to listen for notifications.

    You essentially want something like this:
    https://github.com/NodeBB/NodeBB/blob/b46d2f93e64e6546fb295d396b830dcab9f0cbbd/employee monitoring software/public/src/client/header/notifications.js#L25

    Yeah, thank you!! Exactly what i was looking for!

    1 Reply Last reply
    0

Copyright © 2023 NodeBB | Contributors
  • Login

  • Don't have an account? Register

  • Login or register to search.
Powered by NodeBB Contributors
  • First post
    Last post
0
  • Home
  • Categories
  • Recent
  • Popular
  • Top
  • Tags
  • Users
  • Groups
  • Documentation
    • Home
    • Read API
    • Write API
    • Plugin Development