Open socket on dynamic endpoint

Viewed 114

I am using loopback to build a route: /users/{id} where users can listen for new information pertaining to their account on their own endpoint. I know I need the socket.io package but I'm not sure what to do with it. How can I open a socket on this dynamic endpoint in the function:

  @get('/users/{id}', {
    responses: {
      '200': {
        description: 'User socket',
        content: {'application/json': {schema: {'x-ts-type': User}}},
      },
    },
  })
  async updateUser(@param.path.string('id') userId: typeof User.prototype.id)
  : Promise<boolean> {
\\ Open socket here
    console.log(userId)
    return true;
  }

if I do this:

const express = require("express");
const app = express();
const server = require("http").createServer(app);
const io = require("socket.io").listen(server);
const port = 3000;

io.on("connection", socket => {
    console.log("User has connected!");
});

It doesn't open a socket on the dynamic endpoint that I want it to.

I am using loopback-4 for the backend and react-native for the front-end.

0 Answers
Related