how to create and run my own peerjs server?

后端 未结 4 2092
野性不改
野性不改 2020-12-29 14:06

I got the following code from the git-hub but I don\'t know how to use and execute.

 $> npm install peer   --->where i want to install this node_module         


        
4条回答
  •  长发绾君心
    2020-12-29 14:07

    you can run :

    npm install peer

    Then your server.js you add: `

     //Peer server
        var privateKey  = fs.readFileSync('sslcert/server.key', 'utf8');
        var certificate = fs.readFileSync('sslcert/server.crt', 'utf8');
    
      const { PeerServer } = require('peer');
      const peerServer = PeerServer({ port: 443, 
                                    path: '/' ,
                                    ssl: {
                                        key: privateKey,
                                        cert: certificate
                                      }
                                
                                });
    

    ` Make sure that on client side (script run on index.html) you have:

    myPeer = new Peer({host:'/', 
                      secure:true,
                       port:443,
                    path: '/'})
    

提交回复
热议问题