p5LiveMedia icon indicating copy to clipboard operation
p5LiveMedia copied to clipboard

How to create my server with "Server.js"

Open RomainAl opened this issue 3 years ago • 2 comments

Hi ! Thx for your work, it works very well on p5editor, but now I'm trying do that in my local network and I have some problems ! I correctly npm install express, cors, websocket and socket.io. --save Then I found on the net 'star_itp_io.key' and 'star_itp_io.pem' files. But now I have this error : Capture d’écran 2022-09-29 à 22 44 00

Could you help me ? Sorry, but I'm nioub in js... Thx in advance

RomainAl avatar Sep 29 '22 20:09 RomainAl

Hi Romain,

The Socket.io library changed a bit since this was released. You could either use an older version or update the code that is giving an error to something like this:

const { Server } = require('socket.io');

const io = new Server(httpServer, {});

Also, those certs you found are not likely to be valid. You should probably generate a self-signed cert for use on your own network.

Hope this helps

On Thu, Sep 29, 2022 at 4:49 PM Romain Al @.***> wrote:

Hi ! Thx for your work, its work very well on p5editor, but now I'm trying do that in my local network and I have some problems ! I correctly install express, cors, websocket and socket.io. Then I found on the net 'star_itp_io.key' and 'star_itp_io.pem' files. But now I have this error : [image: Capture d’écran 2022-09-29 à 22 44 00] https://user-images.githubusercontent.com/60849348/193138934-e56c8e69-c6d1-4726-9537-c1722ab687d4.png

Could you help me ? Sorry, but I'm nioub in js... Thx in advance

— Reply to this email directly, view it on GitHub https://github.com/vanevery/p5LiveMedia/issues/18, or unsubscribe https://github.com/notifications/unsubscribe-auth/AADJNHUG5D4WSV6NFSQB46LWAX6ERANCNFSM6AAAAAAQZEUOMI . You are receiving this because you are subscribed to this thread.Message ID: @.***>

vanevery avatar Oct 01 '22 04:10 vanevery

Yes ! Thx ! It work well now with this code :

const { createServer } = require("https"); const { readFileSync } = require("fs"); const { Server } = require("socket.io");

const options = { key: readFileSync('key.pem'), cert: readFileSync('cert.pem') };

const httpServer = createServer(options, (req, res) => { res.writeHead(200); res.end('This is my WebRTC signaling server\n'); }).listen(1337, () => {console.log("Server is running")});

const io = new Server(httpServer, { cors: { origin: "*" } });

With my own cert/key using "mkcert" ! Thank you very much !

Last question : how do you do to host your https signaling server on github ?

RomainAl avatar Oct 18 '22 21:10 RomainAl