123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- var app = require('express').createServer();
- app.listen(8000);
- var webRTC = require('webrtc.io').listen(app);
- app.get('/', function(req, res) {
- res.sendfile(__dirname + '/index.html');
- });
- app.get('/style.css', function(req, res) {
- res.sendfile(__dirname + '/style.css');
- });
- app.get('/webrtc.io.js', function(req, res) {
- res.sendfile(__dirname + '/webrtc.io.js');
- });
- webRTC.rtc.on('connect', function(rtc) {
- //Client connected
- });
- webRTC.rtc.on('send answer', function(rtc) {
- //answer sent
- });
- webRTC.rtc.on('disconnect', function(rtc) {
- //Client disconnect
- });
- webRTC.rtc.on('chat_msg', function(data, socket) {
- var roomList = webRTC.rtc.rooms[data.room] || [];
- for (var i = 0; i < roomList.length; i++) {
- var socketId = roomList[i];
- if (socketId !== socket.id) {
- var soc = webRTC.rtc.getSocket(data.room, socketId);
- if (soc) {
- soc.send(JSON.stringify({
- "eventName": "receive_chat_msg",
- "messages": data.messages,
- "color": data.color
- }), function(error) {
- if (error) {
- console.log(error);
- }
- });
- }
- }
- }
- });
|