initial commit

This commit is contained in:
Mahdi Dibaiee 2014-09-10 21:35:35 +04:30
commit 32877c638f
7 changed files with 825 additions and 0 deletions

161
css/main.less Normal file
View File

@ -0,0 +1,161 @@
@import 'normalize';
body, html {
margin: 0;
font-size: 10px;
direction: ltr;
width: 100%;
height: 100%;
}
body {
font-size: 1.6rem;
background: #eaeaea;
color: #343434;
}
* {
box-sizing: border-box;
}
*:focus {
outline: none;
}
*::-moz-focus-inner {
border: none;
}
.hidden {
display: none;
}
header {
width: 100%;
height: 10rem;
padding: 2rem 4rem;
border-bottom: 1px solid #b6b6b6;
box-shadow: 0 1px 5px #9a9a9a;
}
.modal {
background: inherit;
border: 1px solid #8b8b8b;
box-shadow: 0 0 3px #9a9a9a;
padding: 2rem;
border-radius: 5px;
width: 30rem;
height: auto;
min-height: 23rem;
position: fixed;
left: 50%;
top: 50%;
margin-left: -15rem;
margin-top: -12.2rem;
}
.close {
position: absolute;
left: -1rem;
top: -1rem;
border-radius: 50%;
background: #3a3a3a;
color: white;
text-align: center;
padding: 0.1rem 0.6rem;
font-family: sans-serif;
cursor: pointer;
}
label {
color: #575757;
font-weight: bold;
font-size: 3rem;
}
input {
border: none;
border-bottom: 1px solid #3a3a3a;
background: none;
width: 90%;
margin: 3rem auto;
text-align: center;
display: block;
padding: 1rem 1rem;
overflow: visible;
}
button {
width: 90%;
background: #354ce3;
color: white;
border: none;
border-radius: 3px;
height: 4rem;
margin: 1rem auto;
display: block;
}
button:hover {
background: #4b63ef;
}
button:disabled {
background: #808080;
}
header a, header p {
float: right;
margin: 1.5rem 3rem;
}
header p {
margin-right: 5rem;
}
.chat {
width: 80%;
position: fixed;
bottom: -0.2rem;
left: 10%;
height: 15rem;
border: 1px solid #8b8b8b;
box-shadow: 0 0 3px #9a9a9a;
padding: 1rem 4rem;
border-radius: 3px;
overflow: hidden;
}
.modal p {
text-align: center;
}
.chat div {
height: 10rem;
overflow-y: scroll;
}
.chat input {
margin: -1rem auto 0;
}
a {
color: inherit;
}
h1 {
font-size: 4rem;
font-weight: normal;
margin: 0;
float: left;
}
.self {
position: absolute;
left: 0;
bottom: 0;
width: 20rem;
height: 20rem;
}
.remote {
width: 70%;
height: auto;
margin: 3rem auto;
}

406
css/normalize.less vendored Normal file
View File

@ -0,0 +1,406 @@
/*! normalize.css v2.1.3 | MIT License | git.io/normalize */
/* ==========================================================================
HTML5 display definitions
========================================================================== */
/**
* Correct `block` display not defined in IE 8/9.
*/
article,
aside,
details,
figcaption,
figure,
footer,
header,
hgroup,
main,
nav,
section,
summary {
display: block;
}
/**
* Correct `inline-block` display not defined in IE 8/9.
*/
audio,
canvas,
video {
display: inline-block;
}
/**
* Prevent modern browsers from displaying `audio` without controls.
* Remove excess height in iOS 5 devices.
*/
audio:not([controls]) {
display: none;
height: 0;
}
/**
* Address `[hidden]` styling not present in IE 8/9.
* Hide the `template` element in IE, Safari, and Firefox < 22.
*/
[hidden],
template {
display: none;
}
/* ==========================================================================
Base
========================================================================== */
/**
* 1. Set default font family to sans-serif.
* 2. Prevent iOS text size adjust after orientation change, without disabling
* user zoom.
*/
html {
font-family: sans-serif; /* 1 */
-ms-text-size-adjust: 100%; /* 2 */
-webkit-text-size-adjust: 100%; /* 2 */
}
/**
* Remove default margin.
*/
body {
margin: 0;
}
/* ==========================================================================
Links
========================================================================== */
/**
* Remove the gray background color from active links in IE 10.
*/
a {
background: transparent;
}
/**
* Address `outline` inconsistency between Chrome and other browsers.
*/
a:focus {
outline: thin dotted;
}
/**
* Improve readability when focused and also mouse hovered in all browsers.
*/
a:active,
a:hover {
outline: 0;
}
/* ==========================================================================
Typography
========================================================================== */
/**
* Address variable `h1` font-size and margin within `section` and `article`
* contexts in Firefox 4+, Safari 5, and Chrome.
*/
h1 {
font-size: 2em;
margin: 0.67em 0;
}
/**
* Address styling not present in IE 8/9, Safari 5, and Chrome.
*/
abbr[title] {
border-bottom: 1px dotted;
}
/**
* Address style set to `bolder` in Firefox 4+, Safari 5, and Chrome.
*/
b,
strong {
font-weight: bold;
}
/**
* Address styling not present in Safari 5 and Chrome.
*/
dfn {
font-style: italic;
}
/**
* Address differences between Firefox and other browsers.
*/
hr {
-moz-box-sizing: content-box;
box-sizing: content-box;
height: 0;
}
/**
* Address styling not present in IE 8/9.
*/
mark {
background: #ff0;
color: #000;
}
/**
* Correct font family set oddly in Safari 5 and Chrome.
*/
code,
kbd,
pre,
samp {
font-family: monospace, serif;
font-size: 1em;
}
/**
* Improve readability of pre-formatted text in all browsers.
*/
pre {
white-space: pre-wrap;
}
/**
* Set consistent quote types.
*/
q {
quotes: "\201C" "\201D" "\2018" "\2019";
}
/**
* Address inconsistent and variable font size in all browsers.
*/
small {
font-size: 80%;
}
/**
* Prevent `sub` and `sup` affecting `line-height` in all browsers.
*/
sub,
sup {
font-size: 75%;
line-height: 0;
position: relative;
vertical-align: baseline;
}
sup {
top: -0.5em;
}
sub {
bottom: -0.25em;
}
/* ==========================================================================
Embedded content
========================================================================== */
/**
* Remove border when inside `a` element in IE 8/9.
*/
img {
border: 0;
}
/**
* Correct overflow displayed oddly in IE 9.
*/
svg:not(:root) {
overflow: hidden;
}
/* ==========================================================================
Figures
========================================================================== */
/**
* Address margin not present in IE 8/9 and Safari 5.
*/
figure {
margin: 0;
}
/* ==========================================================================
Forms
========================================================================== */
/**
* Define consistent border, margin, and padding.
*/
fieldset {
border: 1px solid #c0c0c0;
margin: 0 2px;
padding: 0.35em 0.625em 0.75em;
}
/**
* 1. Correct `color` not being inherited in IE 8/9.
* 2. Remove padding so people aren't caught out if they zero out fieldsets.
*/
legend {
border: 0; /* 1 */
padding: 0; /* 2 */
}
/**
* 1. Correct font family not being inherited in all browsers.
* 2. Correct font size not being inherited in all browsers.
* 3. Address margins set differently in Firefox 4+, Safari 5, and Chrome.
*/
button,
input,
select,
textarea {
font-family: inherit; /* 1 */
font-size: 100%; /* 2 */
margin: 0; /* 3 */
}
/**
* Address Firefox 4+ setting `line-height` on `input` using `!important` in
* the UA stylesheet.
*/
button,
input {
line-height: normal;
}
/**
* Address inconsistent `text-transform` inheritance for `button` and `select`.
* All other form control elements do not inherit `text-transform` values.
* Correct `button` style inheritance in Chrome, Safari 5+, and IE 8+.
* Correct `select` style inheritance in Firefox 4+ and Opera.
*/
button,
select {
text-transform: none;
}
/**
* 1. Avoid the WebKit bug in Android 4.0.* where (2) destroys native `audio`
* and `video` controls.
* 2. Correct inability to style clickable `input` types in iOS.
* 3. Improve usability and consistency of cursor style between image-type
* `input` and others.
*/
button,
html input[type="button"], /* 1 */
input[type="reset"],
input[type="submit"] {
-webkit-appearance: button; /* 2 */
cursor: pointer; /* 3 */
}
/**
* Re-set default cursor for disabled elements.
*/
button[disabled],
html input[disabled] {
cursor: default;
}
/**
* 1. Address box sizing set to `content-box` in IE 8/9/10.
* 2. Remove excess padding in IE 8/9/10.
*/
input[type="checkbox"],
input[type="radio"] {
box-sizing: border-box; /* 1 */
padding: 0; /* 2 */
}
/**
* 1. Address `appearance` set to `searchfield` in Safari 5 and Chrome.
* 2. Address `box-sizing` set to `border-box` in Safari 5 and Chrome
* (include `-moz` to future-proof).
*/
input[type="search"] {
-webkit-appearance: textfield; /* 1 */
-moz-box-sizing: content-box;
-webkit-box-sizing: content-box; /* 2 */
box-sizing: content-box;
}
/**
* Remove inner padding and search cancel button in Safari 5 and Chrome
* on OS X.
*/
input[type="search"]::-webkit-search-cancel-button,
input[type="search"]::-webkit-search-decoration {
-webkit-appearance: none;
}
/**
* Remove inner padding and border in Firefox 4+.
*/
button::-moz-focus-inner,
input::-moz-focus-inner {
border: 0;
padding: 0;
}
/**
* 1. Remove default vertical scrollbar in IE 8/9.
* 2. Improve readability and alignment in all browsers.
*/
textarea {
overflow: auto; /* 1 */
vertical-align: top; /* 2 */
}
/* ==========================================================================
Tables
========================================================================== */
/**
* Remove most spacing between table cells.
*/
table {
border-collapse: collapse;
border-spacing: 0;
}

90
index.html Normal file
View File

@ -0,0 +1,90 @@
<!DOCTYPE html>
<html>
<head>
<title>Boilerplate</title>
<meta charset='UTF-8'>
<link rel='stylesheet/less' href='css/main.less'>
</head>
<body>
<header>
<h1>Yo!</h1>
<a href='#call'>Call</a>
<a href='#reconnect' class='hidden'>Reconnect</a>
<a href='#exit' class='hidden'>Exit Chat</a>
<p id='id'>Your ID is: </p>
</header>
<div class='self'>
<p class='hidden'>You don't have a video device or you didn't allow access for it.</p>
<video></video>
<audio></audio>
</div>
<div class='remote'>
<p class='hidden'>Remote Peer doesn't have a video device or he/she didn't allow access for it.</p>
<video></video>
<audio></audio>
</div>
<div class='chat hidden'>
<div>
</div>
<input id='chat' placeholder='Type your message here'>
</div>
<div class='modal call hidden'>
<form id='call'>
<label for='id'>Target's ID</label>
<input id='id' placeholder='s23h4gzxi0'>
<button>Call</button>
</form>
<a class='close'>x</a>
</div>
<div class='modal error hidden'>
<p></p>
<a class='close'>x</a>
</div>
<div class='modal connecting hidden'>
Connecting to the peer.. Please wait
</div>
<div class='modal connected hidden'>
<span></span> is requesting to have a call with you.
<button id='accept'>Accept</button>
<button id='Decline'>Decline</button>
</div>
<div class='modal declined hidden'>
Target peer declined your call
<a class='close'>x</a>
</div>
<div class='modal accepted hidden'>
Target peer accepted your call
<a class='close'>x</a>
</div>
<div class='modal wait'>
<form id='name'>
<label for='name'>Your Name</label>
<input id='name' placeholder='Mahdi'>
<button>OK</button>
</form>
<p class='hidden'>Connecting to Peer Server...</p>
</div>
<script src='less.js'></script>
<script src='js/libs/zepto.js'></script>
<script src='js/libs/peer.js'></script>
<script src='js/main.js'></script>
</body>
</html>

1
js/libs/peer.js Normal file

File diff suppressed because one or more lines are too long

2
js/libs/zepto.js Normal file

File diff suppressed because one or more lines are too long

149
js/main.js Normal file
View File

@ -0,0 +1,149 @@
navigator.getUserMedia = navigator.getUserMedia ||
navigator.mozGetUserMedia ||
navigator.webkitGetUserMedia ||
navigator.oGetUserMedia ||
navigator.msGetUserMedia;
$(function() {
var peer;
$('a[href="#call"]').click(function(e) {
e.preventDefault();
$('.modal.call').removeClass('hidden');
});
$('.modal.wait button').prop('disabled', false);
$('#call').submit(function(e) {
e.preventDefault();
var dest = $(this).find('input').val();
navigator.getUserMedia({audio: true, video: true}, function(stream) {
$('.self video').prop('src', window.URL.createObjectURL(stream));
$('.self video')[0].play();
if(!stream.getVideoTracks().length) {
$('.self p').removeClass('hidden');
}
var name = $('#name input').val();
var con = peer.connect(dest, {metadata: {name: name, id: peer.id}});
var call = peer.call(dest, stream);
$('.call').addClass('hidden');
$('.connecting').removeClass('hidden');
$('#chat').keyup(function(e) {
if(e.keyCode == 13) {
con.send({message: $(this).val(), name: name});
$(this).val('');
}
});
call.on('stream', function(str) {
if(!str.getVideoTracks().length) {
$('.remote p').removeClass('hidden');
}
$('.remote video').prop('src', window.URL.createObjectURL(str));
$('.remote video')[0].play();
});
con.on('open', function() {
$('.connecting').addClass('hidden');
con.on('data', function(d) {
if(d.decline) {
$('.declined').removeClass('hidden');
return con.close();
} else if(d.accept) {
$('.accepted').removeClass('hidden');
return;
}
$('.chat div').append('<p>' + d.name + ': ' + d.message + '</p>');
});
});
}, function(error) {
$('.modal.err p').text('An error occured: ' + error);
});
});
$('.close').click(function(e) {
e.preventDefault();
$(this).parent().addClass('hidden');
});
$('#name').submit(function(e) {
e.preventDefault();
var name = $(this).find('input').val();
$('.modal.wait button').prop('disabled', true);
$('.modal.wait p').removeClass('hidden');
peer = new Peer({key: 'mj5sqj5jz53zncdi'});
// PeerJS
peer.on('open', function() {
$('#id').html('Your ID is: ' + peer.id);
$('.modal.wait p').html('Connected');
$('.modal.wait').addClass('hidden');
$('.chat').removeClass('hidden');
});
peer.on('connection', function(con) {
$('.connected').removeClass('hidden').find('span').html(con.metadata.name);
$('#decline').click(function(e) {
e.preventDefault();
con.send({decline: true});
con.close();
});
$('#accept').click(function(e) {
e.preventDefault();
con.send({accept: true});
$(this).parent().addClass('hidden');
});
var name = $('#name input').val();
$('#chat').keyup(function(e) {
if(e.keyCode == 13) {
con.send({message: $(this).val(), name: name});
$(this).val('');
}
});
con.on('data', function(d) {
$('.chat div').append('<p>' + d.name + ': ' + d.message + '</p>');
});
});
peer.on('call', function(call) {
navigator.getUserMedia({audio: true, video: true}, function(stream) {
if(!stream.getVideoTracks().length) {
$('.self p').removeClass('hidden');
}
$('.self video').prop('src', window.URL.createObjectURL(stream));
$('.self video')[0].play();
call.answer(stream);
call.on('stream', function(str) {
$('.remote video').prop('src', window.URL.createObjectURL(str));
$('.remote video')[0].play();
if(!str.getVideoTracks().length) {
$('.remote p').removeClass('hidden');
}
});
}, function(err) {
$('.error').removeClass('hidden').find('p').text('An error occured: ' + err);
});
});
});
});

16
less.js Normal file

File diff suppressed because one or more lines are too long