I am setting up both a socket.io server and Companion’s uppy.socket() on the same http server instance.
Companion doesn’t use socket.io so we can’t use socket.io-client to connect to it. If both servers are set up on the same http.Server instance, they may both receive incoming WebSocket connections. In that case we should add something to Companion that ignores connections that are not intended for Companion.
and how do i add something to Companion that ignores connections that are not intended for Companion ?
Server.js
const companion = require("@uppy/companion")
const express = require("express")
const { createServer } = require("http")
const { Server } = require("socket.io")
const app = express()
const httpServer = createServer(app)
const io = new Server(httpServer, {
serveClient: false
})
io.on("connection", socket => {
console.log(socket.id)
})
app.use("/companion", companion.app(options))
httpServer.listen(3000)
companion.socket(httpServer)
client.js
const { io } = require("socket.io-client")
const socket = io({})
socket.on("connect", () => {
console.log("client connected")
})
socket.on("connect_error", () => {
console.log("client connection error")
})
socket.on("disconnect", reason => {
console.log("client disconnect:", reason)
})
this code giving me error:
companion: 2022-12-01T21:47:09.881Z [info] socket.connect connection received from /socket.io/?EIO=4&transport=websocket&sid=LdGVCwuehiB4bzJAAAAA node:events:368 throw er; // Unhandled ‘error’ event ^
Error: Invalid WebSocket frame: invalid UTF-8 sequence
how do i add something to Companion that ignores connections that are not intended for Companion ?