forked from vasanthv/hello
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
641 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# git folder | ||
.git | ||
|
||
# NPM | ||
node_modules | ||
npm-debug.log | ||
|
||
# Testing | ||
.nyc_output | ||
|
||
# Mac | ||
.DS_Store | ||
|
||
# cache | ||
.cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,34 @@ | ||
# hello | ||
A group video call for the web. No signups. No downloads. | ||
# Talk | ||
|
||
A webrtc based group video chat. | ||
|
||
### Prerequisites: | ||
|
||
- Node.js 8.x or above | ||
- NPM | ||
|
||
### How to Build this app locally | ||
|
||
Clone the repo locally | ||
|
||
``` | ||
git clone https://github.com/vasanthv/talk.git | ||
``` | ||
|
||
Install dependencies | ||
|
||
``` | ||
npm install | ||
``` | ||
|
||
Run the app | ||
|
||
``` | ||
node server.js | ||
``` | ||
|
||
Open the following url in the browser | ||
|
||
``` | ||
http://localhost:3000 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"name": "talk", | ||
"version": "1.0.0", | ||
"description": "A webrtc based group video chat.", | ||
"main": "server.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/vasanthv/talk.git" | ||
}, | ||
"keywords": [ | ||
"webrtc", | ||
"socket.io", | ||
"video" | ||
], | ||
"author": "Vasanth V", | ||
"license": "ISC", | ||
"bugs": { | ||
"url": "https://github.com/vasanthv/talk/issues" | ||
}, | ||
"homepage": "https://github.com/vasanthv/talk#readme", | ||
"dependencies": { | ||
"express": "^4.17.1", | ||
"socket.io": "^2.2.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
const express = require('express'); | ||
const path = require('path'); | ||
const http = require('http'); | ||
const app = express(); | ||
const server = http.createServer(app); | ||
const io = require('socket.io').listen(server); | ||
|
||
// Server all the static files from www folder | ||
app.use(express.static(path.join(__dirname, 'www'))); | ||
|
||
// Get PORT from env variable else assign 3000 for development | ||
const PORT = process.env.PORT || 3000; | ||
server.listen(PORT, null, function() { | ||
console.log("Listening on port " + PORT); | ||
}); | ||
|
||
// All URL patterns should served with the same file. | ||
app.get(['/', '/:room'], (req, res) => res.sendFile(path.join(__dirname, 'www/index.html'))); | ||
|
||
const channels = {}; | ||
const sockets = {}; | ||
|
||
io.sockets.on('connection', (socket) => { | ||
socket.channels = {}; | ||
sockets[socket.id] = socket; | ||
|
||
console.log("[" + socket.id + "] connection accepted"); | ||
socket.on('disconnect', () => { | ||
for (const channel in socket.channels) { | ||
part(channel); | ||
} | ||
console.log("[" + socket.id + "] disconnected"); | ||
delete sockets[socket.id]; | ||
}); | ||
|
||
socket.on('join', (config) => { | ||
console.log("[" + socket.id + "] join ", config); | ||
const channel = config.channel; | ||
|
||
// Already Joined | ||
if (channel in socket.channels) return; | ||
|
||
if (!(channel in channels)) { | ||
channels[channel] = {}; | ||
} | ||
|
||
for (id in channels[channel]) { | ||
channels[channel][id].emit('addPeer', { 'peer_id': socket.id, 'should_create_offer': false }); | ||
socket.emit('addPeer', { 'peer_id': id, 'should_create_offer': true }); | ||
} | ||
|
||
channels[channel][socket.id] = socket; | ||
socket.channels[channel] = channel; | ||
}); | ||
|
||
const part = (channel) => { | ||
// Socket not in channel | ||
if (!(channel in socket.channels)) return; | ||
|
||
delete socket.channels[channel]; | ||
delete channels[channel][socket.id]; | ||
|
||
for (id in channels[channel]) { | ||
channels[channel][id].emit('removePeer', { 'peer_id': socket.id }); | ||
socket.emit('removePeer', { 'peer_id': id }); | ||
} | ||
} | ||
|
||
socket.on('relayICECandidate', (config) => { | ||
let peer_id = config.peer_id; | ||
let ice_candidate = config.ice_candidate; | ||
console.log("[" + socket.id + "] relay ICE-candidate to [" + peer_id + "] ", ice_candidate); | ||
|
||
if (peer_id in sockets) { | ||
sockets[peer_id].emit('iceCandidate', { 'peer_id': socket.id, 'ice_candidate': ice_candidate }); | ||
} | ||
}); | ||
|
||
socket.on('relaySessionDescription', (config) => { | ||
let peer_id = config.peer_id; | ||
let session_description = config.session_description; | ||
console.log("[" + socket.id + "] relay SessionDescription to [" + peer_id + "] ", session_description); | ||
|
||
if (peer_id in sockets) { | ||
sockets[peer_id].emit('sessionDescription', { 'peer_id': socket.id, 'session_description': session_description }); | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | ||
<meta name="viewport" content="width=device-width, height=device-height, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" /> | ||
<meta name="description" content="Rimon - A WebRTC based video chat app." /> | ||
<meta name="keywords" content="group video chat, video communication, multiparty video chat, video chat, webrtc, peer to peer, p2p" /> | ||
<meta name="application-name" content="Rimon" /> | ||
<link rel="stylesheet" href="style.css" /> | ||
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.4.1/css/all.css" integrity="sha384-5sAR7xN1Nv6T6+dT2mhtzEpVJvfS3NScPQTrOxhwjIuvcA67KV2R5Jz6kr4abQsz" crossorigin="anonymous" /> | ||
<script src="https://webrtc.github.io/adapter/adapter-latest.js"></script> | ||
<script src="/socket.io/socket.io.js"></script> | ||
<script src="script.js"></script> | ||
<title>Rimon</title> | ||
</head> | ||
|
||
<body onload='init()'> | ||
<div id="roomurl"></span> | ||
</body> | ||
|
||
</html> |
Oops, something went wrong.