|
5 年之前 | |
---|---|---|
bin | 6 年之前 | |
config | 6 年之前 | |
src | 5 年之前 | |
test | 6 年之前 | |
.eslintrc.json | 6 年之前 | |
.gitignore | 7 年之前 | |
.travis.yml | 6 年之前 | |
Dockerfile | 6 年之前 | |
LICENSE | 12 年之前 | |
README.md | 5 年之前 | |
app.json | 10 年之前 | |
changelog.md | 6 年之前 | |
package-lock.json | 6 年之前 | |
package.json | 5 年之前 |
This fork of peerjs-server adds functionality to set a custom ID generation fucntion. Commit
PeerServer helps broker connections between PeerJS clients. Data is not proxied through the server.
Clone app:
git clone https://github.com/peers/peerjs-server.git
Install dependencies:
npm install
Run the server:
$> peerjs --port 9000 --key peerjs --path /myapp
Or, create a custom server:
$> npm install peerjs-server
import {PeerServer} from 'peerjs-server';
const server = PeerServer({port: 9000, path: '/myapp'});
Connecting to the server from PeerJS:
<script>
const peer = new Peer('someid', {host: 'localhost', port: 9000, path: '/myapp'});
</script>
Using HTTPS: Simply pass in PEM-encoded certificate and key.
import fs from 'fs';
import {PeerServer} from 'peerjs-server';
const server = PeerServer({
port: 9000,
ssl: {
key: fs.readFileSync('/path/to/your/ssl/key/here.key'),
cert: fs.readFileSync('/path/to/your/ssl/certificate/here.crt')
}
});
Make sure to set the proxied
option, otherwise IP based limiting will fail.
The option is passed verbatim to the
expressjs trust proxy
setting
if it is truthy.
import {PeerServer} from 'peerjs-server';
const server = PeerServer({port: 9000, path: '/myapp', proxied: true});
import express from 'express';
import {ExpressPeerServer} from 'peerjs-server';
const app = express();
app.get('/', (req, res, next) => { res.send('Hello world!'); });
// =======
const server = app.listen(9000);
const options = {
debug: true
}
const peerserver = ExpressPeerServer(server, options);
app.use('/api', peerserver);
// == OR ==
import http from 'http';
const server = http.createServer(app);
const peerserver = ExpressPeerServer(server, options);
app.use('/peerjs', peerserver);
server.listen(9000);
// ========
The 'connection'
event is emitted when a peer connects to the server.
peerserver.on('connection', (client) => { ... });
The 'disconnect'
event is emitted when a peer disconnects from the server or
when the peer can no longer be reached.
peerserver.on('disconnect', (client) => { ... });
npm test
You can build this image simply by calling:
docker build -t peerjs https://github.com/peers/peerjs-server.git
To run the image execute this:
docker run -p 9000:9000 -d peerjs
This will start a peerjs server on port 9000 exposed on port 9000.
Discuss PeerJS on our Google Group: https://groups.google.com/forum/?fromgroups#!forum/peerjs
Please post any bugs as a Github issue.