mirror of
https://git.hmsn.ink/call/signal-server.git
synced 2026-03-20 00:02:16 +09:00
아이디 정의
This commit is contained in:
20
app.js
20
app.js
@@ -1,20 +0,0 @@
|
|||||||
var express = require('express');
|
|
||||||
var path = require('path');
|
|
||||||
var cookieParser = require('cookie-parser');
|
|
||||||
var logger = require('morgan');
|
|
||||||
|
|
||||||
var indexRouter = require('./routes/index');
|
|
||||||
var usersRouter = require('./routes/users');
|
|
||||||
|
|
||||||
var app = express();
|
|
||||||
|
|
||||||
app.use(logger('dev'));
|
|
||||||
app.use(express.json());
|
|
||||||
app.use(express.urlencoded({ extended: false }));
|
|
||||||
app.use(cookieParser());
|
|
||||||
app.use(express.static(path.join(__dirname, 'public')));
|
|
||||||
|
|
||||||
app.use('/', indexRouter);
|
|
||||||
app.use('/users', usersRouter);
|
|
||||||
|
|
||||||
module.exports = app;
|
|
||||||
@@ -8,17 +8,20 @@ const wss = new WebSocketServer({ server });
|
|||||||
const peers = new Map();
|
const peers = new Map();
|
||||||
|
|
||||||
wss.on('connection', (ws) => {
|
wss.on('connection', (ws) => {
|
||||||
const id = Math.random().toString(36).substring(2, 9);
|
// const id = Math.random().toString(36).substring(2, 9);
|
||||||
peers.set(id, ws);
|
|
||||||
console.log(`${id} connected!`);
|
|
||||||
ws.send(JSON.stringify({ type: 'your-id', id }));
|
|
||||||
|
|
||||||
ws.on('message', (data) => {
|
ws.on('message', (data) => {
|
||||||
const msg = JSON.parse(data);
|
const msg = JSON.parse(data);
|
||||||
if (msg.target && peers.has(msg.target)) {
|
if(msg.type === 'login') {
|
||||||
|
peers.set(msg.sabun, ws);
|
||||||
|
ws.send(JSON.stringify({ type: 'your-id',id: msg.sabun }));
|
||||||
|
console.log(`${msg.sabun} connected!`);
|
||||||
|
|
||||||
|
|
||||||
|
} else if (msg.target && peers.has(msg.target)) {
|
||||||
peers.get(msg.target).send(JSON.stringify(msg));
|
peers.get(msg.target).send(JSON.stringify(msg));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
ws.on('close', () => peers.delete(id));
|
ws.on('close', () => peers.delete(msg.sabun));
|
||||||
});
|
});
|
||||||
Reference in New Issue
Block a user