瀏覽代碼

start work on socket

unknown 2 年之前
父節點
當前提交
47ec200527
共有 1 個文件被更改,包括 6 次插入7 次删除
  1. 6 7
      app.js

+ 6 - 7
app.js

@@ -21,14 +21,13 @@ const io = new Server(server, {
 });
 
 io.on('connection', (socket) => {
-	console.log(`User Connected: ${socket.id}`);
-
-	socket.on('join_room', (data) => {
-		socket.join(data);
+	console.log('connect', socket.id);
+	socket.emit('me', socket.id);
+	socket.on('call', ({ userToCall, signalData, from, name }) => {
+		io.to(userToCall).emit('call', { signal: signalData, from, name });
 	});
-
-	socket.on('send_message', (data) => {
-		socket.to(data.room).emit('receive_message', data);
+	socket.on('answer', (data) => {
+		io.to(data.to).emit('accepted', { signal: data.signal });
 	});
 });