Skip to content

Commit 4df457e

Browse files
committed
added: new example
1 parent 06f4450 commit 4df457e

14 files changed

Lines changed: 1012 additions & 2 deletions

File tree

bootstrap/controllers/default.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
exports.install = function(framework) {
2+
framework.route('/', view_homepage);
3+
};
4+
5+
function view_homepage() {
6+
var self = this;
7+
self.view('homepage');
8+
}

bootstrap/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
var framework = require('total.js');
2+
var http = require('http');
3+
var debug = true;
4+
5+
framework.run(http, debug);

bootstrap/views/_layout.html

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6+
<meta name="viewport" content="width=device-width, initial-scale=1">
7+
<title>Bootstrap 101 Template</title>
8+
<!-- Bootstrap -->
9+
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" />
10+
<!-- Optional theme -->
11+
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap-theme.min.css" />
12+
13+
<!-- Custom style -->
14+
<link rel="stylesheet" href="http://getbootstrap.com/examples/jumbotron-narrow/jumbotron-narrow.css" />
15+
16+
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
17+
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
18+
<!--[if lt IE 9]>
19+
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
20+
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
21+
<![endif]-->
22+
23+
</head>
24+
<body>
25+
26+
@{body}
27+
28+
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
29+
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
30+
<!-- Include all compiled plugins (below), or include individual files as needed -->
31+
<script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
32+
</body>
33+
</html>

bootstrap/views/homepage.html

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<div class="container">
2+
<div class="header">
3+
<ul class="nav nav-pills pull-right">
4+
<li class="active"><a href="#">Home</a></li>
5+
<li><a href="#">About</a></li>
6+
<li><a href="#">Contact</a></li>
7+
</ul>
8+
<h3 class="text-muted">Project name</h3>
9+
</div>
10+
11+
<div class="jumbotron">
12+
<h1>Jumbotron heading</h1>
13+
<p class="lead">Cras justo odio, dapibus ac facilisis in, egestas eget quam. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus.</p>
14+
<p><a class="btn btn-lg btn-success" href="#" role="button">Sign up today</a></p>
15+
</div>
16+
17+
<div class="row marketing">
18+
<div class="col-lg-6">
19+
<h4>Subheading</h4>
20+
<p>Donec id elit non mi porta gravida at eget metus. Maecenas faucibus mollis interdum.</p>
21+
22+
<h4>Subheading</h4>
23+
<p>Morbi leo risus, porta ac consectetur ac, vestibulum at eros. Cras mattis consectetur purus sit amet fermentum.</p>
24+
25+
<h4>Subheading</h4>
26+
<p>Maecenas sed diam eget risus varius blandit sit amet non magna.</p>
27+
</div>
28+
29+
<div class="col-lg-6">
30+
<h4>Subheading</h4>
31+
<p>Donec id elit non mi porta gravida at eget metus. Maecenas faucibus mollis interdum.</p>
32+
33+
<h4>Subheading</h4>
34+
<p>Morbi leo risus, porta ac consectetur ac, vestibulum at eros. Cras mattis consectetur purus sit amet fermentum.</p>
35+
36+
<h4>Subheading</h4>
37+
<p>Maecenas sed diam eget risus varius blandit sit amet non magna.</p>
38+
</div>
39+
</div>
40+
41+
<div class="footer">
42+
<p>&copy; Company 2014</p>
43+
</div>
44+
45+
</div>

webrtc/controllers/default.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
exports.install = function(framework) {
2+
framework.route('/', view_homepage);
3+
framework.websocket('/', socket_synchronize, ['json']);
4+
};
5+
6+
function socket_synchronize() {
7+
var self = this;
8+
9+
self.on('open', function(client) {
10+
11+
client.pair = null;
12+
13+
self.all(function(user) {
14+
15+
if (user.id === client.id)
16+
return;
17+
18+
// Find pair of users (by the room)
19+
// user.get.room === ?room=ABCDEFG
20+
if (user.get.room === client.get.room) {
21+
user.pair = client;
22+
client.pair = user;
23+
}
24+
25+
});
26+
27+
if (client.pair === null)
28+
return;
29+
30+
client.send({ eventName: 'new_peer_connected', data: { socketId: client.get.room }});
31+
client.pair.send({ eventName: 'new_peer_connected', data: { socketId: client.get.room }});
32+
});
33+
34+
self.on('close', function(client) {
35+
36+
});
37+
38+
self.on('message', function(client, message) {
39+
if (client.pair === null)
40+
return;
41+
42+
client.pair.send({ eventName: 'receive_offer', data: { sdp: message.sdp, socketId: client.get.room }});
43+
});
44+
45+
}
46+
47+
function view_homepage() {
48+
var self = this;
49+
self.view('homepage');
50+
}

webrtc/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
var framework = require('total.js');
2+
var http = require('http');
3+
var debug = true;
4+
5+
framework.run(http, debug);

webrtc/public/js/default.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
2+
function init() {
3+
4+
if (!PeerConnection) {
5+
alert('Your browser is not supported or you have to turn on flags. In chrome you go to chrome://flags and turn on Enable PeerConnection remember to restart chrome');
6+
return;
7+
}
8+
9+
rtc.createStream({ 'video': { 'mandatory': {}, 'optional': [] }, audio: true }, function(stream) {
10+
document.getElementById('you').src = URL.createObjectURL(stream);
11+
document.getElementById('you').play();
12+
});
13+
14+
var room = 'ABCDEFG';
15+
16+
rtc.connect('ws://' + window.location.href.substring(window.location.protocol.length) + '?room=' + room, room);
17+
18+
rtc.on('add remote stream', function(stream, socketId) {
19+
var clone = cloneVideo('you', socketId);
20+
document.getElementById(clone.id).setAttribute('class', '');
21+
rtc.attachStream(stream, clone.id);
22+
});
23+
24+
rtc.on('disconnect stream', function(data) {
25+
removeVideo(data);
26+
});
27+
}
28+
29+
function cloneVideo(domId, socketId) {
30+
var video = document.getElementById(domId);
31+
var clone = video.cloneNode(false);
32+
clone.id = 'remote' + socketId;
33+
document.getElementById('videos').appendChild(clone);
34+
videos.push(clone);
35+
return clone;
36+
}
37+
38+
function removeVideo(socketId) {
39+
var video = document.getElementById('remote' + socketId);
40+
if(!video)
41+
return;
42+
videos.splice(videos.indexOf(video), 1);
43+
video.parentNode.removeChild(video);
44+
}

0 commit comments

Comments
 (0)