├── .gitignore ├── Gemfile ├── Gemfile.lock ├── README.md ├── Rakefile ├── app ├── assets │ ├── images │ │ └── .keep │ ├── javascripts │ │ └── application.js │ └── stylesheets │ │ ├── application.css.scss │ │ └── home.css.scss ├── controllers │ ├── application_controller.rb │ ├── concerns │ │ └── .keep │ └── home_controller.rb ├── helpers │ ├── application_helper.rb │ └── home_helper.rb ├── mailers │ └── .keep ├── models │ ├── .keep │ └── concerns │ │ └── .keep ├── rtc │ ├── package.json │ └── server.js └── views │ ├── home │ ├── index.html.haml │ └── room.html.haml │ └── layouts │ ├── application.html.haml │ └── partials │ └── _header.html.haml ├── bin ├── bundle ├── rails └── rake ├── config.ru ├── config ├── application.rb ├── boot.rb ├── environment.rb ├── environments │ ├── development.rb │ ├── production.rb │ └── test.rb ├── initializers │ ├── backtrace_silencers.rb │ ├── filter_parameter_logging.rb │ ├── inflections.rb │ ├── mime_types.rb │ ├── secret_token.rb │ ├── session_store.rb │ └── wrap_parameters.rb ├── locales │ └── en.yml └── routes.rb ├── db └── seeds.rb ├── lib ├── assets │ └── .keep └── tasks │ └── .keep ├── log └── .keep ├── public ├── 404.html ├── 422.html ├── 500.html ├── favicon.ico ├── javascripts │ └── rtc │ │ └── client_signaling.js └── robots.txt └── vendor └── assets ├── javascripts ├── .keep └── adapter.js └── stylesheets └── .keep /.gitignore: -------------------------------------------------------------------------------- 1 | Created by http://gitignore.io 2 | 3 | ### vim ### 4 | .*.s[a-w][a-z] 5 | *.un~ 6 | Session.vim 7 | .netrwhist 8 | *~ 9 | 10 | ### OSX ### 11 | .DS_Store 12 | .AppleDouble 13 | .LSOverride 14 | Icon 15 | 16 | 17 | # Thumbnails 18 | ._* 19 | 20 | # Files that might appear on external disk 21 | .Spotlight-V100 22 | .Trashes 23 | 24 | ### Rails ### 25 | *.rbc 26 | *.sassc 27 | .sass-cache 28 | capybara-*.html 29 | .rspec 30 | .rvmrc 31 | .ruby-gemset 32 | .ruby-version 33 | /.bundle 34 | /vendor/bundle 35 | /log/* 36 | /tmp/* 37 | /db/*.sqlite3 38 | /public/system/* 39 | /coverage/ 40 | /spec/tmp/* 41 | **.orig 42 | rerun.txt 43 | pickle-email-*.html 44 | .project 45 | !.keep 46 | 47 | 48 | ### Ruby ### 49 | *.gem 50 | *.rbc 51 | .bundle 52 | .config 53 | coverage 54 | InstalledFiles 55 | lib/bundler/man 56 | pkg 57 | rdoc 58 | spec/reports 59 | test/tmp 60 | test/version_tmp 61 | tmp 62 | 63 | # YARD artifacts 64 | .yardoc 65 | _yardoc 66 | doc/ 67 | 68 | ### SublimeText ### 69 | # SublimeText project files 70 | *.sublime-workspace 71 | 72 | ### Windows ### 73 | # Windows image file caches 74 | Thumbs.db 75 | ehthumbs.db 76 | 77 | # Folder config file 78 | Desktop.ini 79 | 80 | # Recycle Bin used on file shares 81 | $RECYCLE.BIN/ 82 | 83 | # Created by http://www.gitignore.io 84 | # 85 | # ### Node ### 86 | lib-cov 87 | lcov.info 88 | *.seed 89 | *.log 90 | *.csv 91 | *.dat 92 | *.out 93 | *.pid 94 | *.gz 95 | 96 | pids 97 | logs 98 | results 99 | build 100 | .grunt 101 | 102 | node_modules 103 | 104 | 105 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | gem 'rails', '4.0.0' 4 | gem 'thin' 5 | gem 'mongoid' 6 | gem 'bootstrap-sass', '~> 3.1.1' 7 | gem 'haml-rails' 8 | gem 'jquery-rails' 9 | gem 'bson_ext' 10 | gem 'jquery-ui-rails' 11 | 12 | gem 'jbuilder', '~> 1.2' 13 | gem 'socket.io-rails' 14 | 15 | gem 'sass-rails', '~> 4.0.0' 16 | gem 'uglifier', '>= 1.3.0' 17 | gem 'therubyracer', :platforms => :ruby 18 | gem 'less-rails' 19 | gem 'coffee-rails', '~> 4.0.0' 20 | 21 | group :development, :test do 22 | gem 'quiet_assets' 23 | gem 'gettext', '>=1.9.3', :require => false 24 | gem 'capistrano' 25 | gem 'rvm-capistrano', require: false 26 | end 27 | 28 | gem 'unicorn' 29 | 30 | group :doc do 31 | gem 'sdoc', require: false 32 | end 33 | -------------------------------------------------------------------------------- /Gemfile.lock: -------------------------------------------------------------------------------- 1 | GEM 2 | remote: https://rubygems.org/ 3 | specs: 4 | actionmailer (4.0.0) 5 | actionpack (= 4.0.0) 6 | mail (~> 2.5.3) 7 | actionpack (4.0.0) 8 | activesupport (= 4.0.0) 9 | builder (~> 3.1.0) 10 | erubis (~> 2.7.0) 11 | rack (~> 1.5.2) 12 | rack-test (~> 0.6.2) 13 | activemodel (4.0.0) 14 | activesupport (= 4.0.0) 15 | builder (~> 3.1.0) 16 | activerecord (4.0.0) 17 | activemodel (= 4.0.0) 18 | activerecord-deprecated_finders (~> 1.0.2) 19 | activesupport (= 4.0.0) 20 | arel (~> 4.0.0) 21 | activerecord-deprecated_finders (1.0.3) 22 | activesupport (4.0.0) 23 | i18n (~> 0.6, >= 0.6.4) 24 | minitest (~> 4.2) 25 | multi_json (~> 1.3) 26 | thread_safe (~> 0.1) 27 | tzinfo (~> 0.3.37) 28 | arel (4.0.1) 29 | atomic (1.1.14) 30 | bootstrap-sass (3.1.1.1) 31 | sass (~> 3.2) 32 | bson (1.10.0) 33 | bson_ext (1.5.1) 34 | builder (3.1.4) 35 | capistrano (2.15.5) 36 | highline 37 | net-scp (>= 1.0.0) 38 | net-sftp (>= 2.0.0) 39 | net-ssh (>= 2.0.14) 40 | net-ssh-gateway (>= 1.1.0) 41 | coffee-rails (4.0.1) 42 | coffee-script (>= 2.2.0) 43 | railties (>= 4.0.0, < 5.0) 44 | coffee-script (2.2.0) 45 | coffee-script-source 46 | execjs 47 | coffee-script-source (1.6.3) 48 | commonjs (0.2.7) 49 | daemons (1.1.9) 50 | durran-validatable (2.0.1) 51 | erubis (2.7.0) 52 | eventmachine (1.0.3) 53 | execjs (2.0.2) 54 | gettext (3.0.2) 55 | locale (>= 2.0.5) 56 | text 57 | haml (4.0.3) 58 | tilt 59 | haml-rails (0.4) 60 | actionpack (>= 3.1, < 4.1) 61 | activesupport (>= 3.1, < 4.1) 62 | haml (>= 3.1, < 4.1) 63 | railties (>= 3.1, < 4.1) 64 | highline (1.6.20) 65 | hike (1.2.3) 66 | i18n (0.6.5) 67 | jbuilder (1.5.2) 68 | activesupport (>= 3.0.0) 69 | multi_json (>= 1.2.0) 70 | jquery-rails (3.0.4) 71 | railties (>= 3.0, < 5.0) 72 | thor (>= 0.14, < 2.0) 73 | jquery-ui-rails (4.1.0) 74 | railties (>= 3.1.0) 75 | json (1.8.1) 76 | kgio (2.8.1) 77 | leshill-will_paginate (2.3.11) 78 | less (2.4.0) 79 | commonjs (~> 0.2.7) 80 | less-rails (2.4.2) 81 | actionpack (>= 3.1) 82 | less (~> 2.4.0) 83 | libv8 (3.16.14.3) 84 | locale (2.0.9) 85 | mail (2.5.4) 86 | mime-types (~> 1.16) 87 | treetop (~> 1.4.8) 88 | mime-types (1.25) 89 | minitest (4.7.5) 90 | mongo (1.10.0) 91 | bson (~> 1.10.0) 92 | mongoid (1.0.6) 93 | activesupport (>= 2.2.2) 94 | durran-validatable (>= 2.0.1) 95 | leshill-will_paginate (>= 2.3.11) 96 | mongo (>= 0.18.2) 97 | multi_json (1.8.2) 98 | net-scp (1.1.2) 99 | net-ssh (>= 2.6.5) 100 | net-sftp (2.1.2) 101 | net-ssh (>= 2.6.5) 102 | net-ssh (2.7.0) 103 | net-ssh-gateway (1.2.0) 104 | net-ssh (>= 2.6.5) 105 | polyglot (0.3.3) 106 | quiet_assets (1.0.2) 107 | railties (>= 3.1, < 5.0) 108 | rack (1.5.2) 109 | rack-test (0.6.2) 110 | rack (>= 1.0) 111 | rails (4.0.0) 112 | actionmailer (= 4.0.0) 113 | actionpack (= 4.0.0) 114 | activerecord (= 4.0.0) 115 | activesupport (= 4.0.0) 116 | bundler (>= 1.3.0, < 2.0) 117 | railties (= 4.0.0) 118 | sprockets-rails (~> 2.0.0) 119 | railties (4.0.0) 120 | actionpack (= 4.0.0) 121 | activesupport (= 4.0.0) 122 | rake (>= 0.8.7) 123 | thor (>= 0.18.1, < 2.0) 124 | raindrops (0.12.0) 125 | rake (10.1.0) 126 | rdoc (3.12.2) 127 | json (~> 1.4) 128 | ref (1.0.5) 129 | rvm-capistrano (1.5.1) 130 | capistrano (~> 2.15.4) 131 | sass (3.2.12) 132 | sass-rails (4.0.1) 133 | railties (>= 4.0.0, < 5.0) 134 | sass (>= 3.1.10) 135 | sprockets-rails (~> 2.0.0) 136 | sdoc (0.3.20) 137 | json (>= 1.1.3) 138 | rdoc (~> 3.10) 139 | socket.io-rails (0.9.16) 140 | railties (>= 3.1) 141 | sprockets (2.10.0) 142 | hike (~> 1.2) 143 | multi_json (~> 1.0) 144 | rack (~> 1.0) 145 | tilt (~> 1.1, != 1.3.0) 146 | sprockets-rails (2.0.1) 147 | actionpack (>= 3.0) 148 | activesupport (>= 3.0) 149 | sprockets (~> 2.8) 150 | text (1.2.3) 151 | therubyracer (0.12.0) 152 | libv8 (~> 3.16.14.0) 153 | ref 154 | thin (1.6.1) 155 | daemons (>= 1.0.9) 156 | eventmachine (>= 1.0.0) 157 | rack (>= 1.0.0) 158 | thor (0.18.1) 159 | thread_safe (0.1.3) 160 | atomic 161 | tilt (1.4.1) 162 | treetop (1.4.15) 163 | polyglot 164 | polyglot (>= 0.3.1) 165 | tzinfo (0.3.38) 166 | uglifier (2.3.0) 167 | execjs (>= 0.3.0) 168 | json (>= 1.8.0) 169 | unicorn (4.6.3) 170 | kgio (~> 2.6) 171 | rack 172 | raindrops (~> 0.7) 173 | 174 | PLATFORMS 175 | ruby 176 | 177 | DEPENDENCIES 178 | bootstrap-sass (~> 3.1.1) 179 | bson_ext 180 | capistrano 181 | coffee-rails (~> 4.0.0) 182 | gettext (>= 1.9.3) 183 | haml-rails 184 | jbuilder (~> 1.2) 185 | jquery-rails 186 | jquery-ui-rails 187 | less-rails 188 | mongoid 189 | quiet_assets 190 | rails (= 4.0.0) 191 | rvm-capistrano 192 | sass-rails (~> 4.0.0) 193 | sdoc 194 | socket.io-rails 195 | therubyracer 196 | thin 197 | uglifier (>= 1.3.0) 198 | unicorn 199 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | #WebRTC Rails 2 | 3 | [](https://gitter.im/XescuGC/webrtc-rails?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) 4 | 5 | This is a basic aplication I have build to test WebRTC, my main objective is to practice WebRTC. I will slowly improve the aplication, and add more features each time. 6 | 7 | ##Start Now 8 | 9 | To start the project and test is at your own you have to do the following: 10 | 11 | 1. Clone the repo: ```git clone git@github.com:XescuGC/webrtc-rails.git``` 12 | 2. Install all the gems with ```bundle install``` 13 | 3. Go to ```app/rtc/``` and run ```npm install``` to install ```socket.io``` 14 | 4. Check to see your IP: ```ifconfig```, copy the IP and change the ones in ```public/javascripts/rtc/client_signaling.js``` and at the first line change the ```io.connect('YOUR-IP:2013')``` 15 | 5. Open the server ```rails server``` 16 | 6. Open the NodeJs server ```node app/rtc/server.js``` 17 | 7. Go to the URL: ```localhost:3000``` 18 | 8. ENJOY! 19 | 20 | ##Test it in production 21 | 22 | Here you have the [link](http://webrtc-rails.layeris.com) 23 | 24 | ~~**At the moment it only works between Chrome and Chrome (I'm currently working on the problem)**~~ 25 | 26 | Now it works on Chrome and Firefox. Maybe there was some bug on the API. 27 | 28 | 29 | ##Objectives 30 | 31 | As I said before the main objective is to practice WebRTC but I will list some of the other objectives I have in mind: 32 | 33 | 1. **DONE** WebRTC between 2 peers 34 | 2. **DONE** Clean the webpage of unneeded menus, just the Home page and a page to call 35 | 3. **DONE** Add a chat module (with NodeJs, latter can be improved to be with arbitrary data with RTCDataChannel) 36 | 4. Change the NodeJS server to a native Ruby (EventMachine) 37 | 5. Control of errors in the Call (on of the Peers leave ... etc) 38 | 6. **DONE** Ability to create your own rooms with diferets names, and to setup an user name (for the Chat) 39 | 7. Ability to activate and desactivate Video or Audio, and reactivate them 40 | 8. Room with more than 2 Peers 41 | 9. Change the Chat from NodeJS to WebRTC DataChannel 42 | 43 | ##Slides 44 | 45 | I've made a short Presentation of WebRTC in my Office, here are the [Slides](https://github.com/XescuGC/webrtc-slides) 46 | 47 | ##Collaborate 48 | 49 | You can participate with whatever you want, and use/fork this code (if you find it usefull) for whatever you want ofcourse. If you want to propose more ideas will be welcome jeje 50 | 51 | ##Contact 52 | 53 | email: xescugil@gmail.com 54 | 55 | twitter: [@xescugc](https://twitter.com/xescugc) 56 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | # Add your own tasks in files placed in lib/tasks ending in .rake, 2 | # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. 3 | 4 | require File.expand_path('../config/application', __FILE__) 5 | 6 | WebrtcRails::Application.load_tasks 7 | -------------------------------------------------------------------------------- /app/assets/images/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xescugc/webrtc-rails/61fdaaef43bacb699e280aa6782adbcc4ccb550e/app/assets/images/.keep -------------------------------------------------------------------------------- /app/assets/javascripts/application.js: -------------------------------------------------------------------------------- 1 | // This is a manifest file that'll be compiled into application.js, which will include all the files 2 | // listed below. 3 | // 4 | // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts, 5 | // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path. 6 | // 7 | // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the 8 | // compiled file. 9 | // 10 | // Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details 11 | // about supported directives. 12 | // 13 | //= require jquery 14 | //= require jquery_ujs 15 | //= require bootstrap/tooltip 16 | //= require bootstrap/popover 17 | //= require bootstrap/tab 18 | //= require bootstrap/modal 19 | //= require bootstrap/collapse 20 | //= require bootstrap/dropdown 21 | //= require bootstrap/transition 22 | //= require socket.io 23 | //= require adapter.js 24 | -------------------------------------------------------------------------------- /app/assets/stylesheets/application.css.scss: -------------------------------------------------------------------------------- 1 | /* 2 | * This is a manifest file that'll be compiled into application.css, which will include all the files 3 | * listed below. 4 | * 5 | * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets, 6 | * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path. 7 | * 8 | * You're free to add application-wide styles to this file and they'll appear at the top of the 9 | * compiled file, but it's generally better to create a new file per style scope. 10 | * 11 | *= require_self 12 | *= require_tree . 13 | */ 14 | @import "bootstrap" 15 | -------------------------------------------------------------------------------- /app/assets/stylesheets/home.css.scss: -------------------------------------------------------------------------------- 1 | // Place all the styles related to the home controller here. 2 | // They will automatically be included in application.css. 3 | // You can use Sass (SCSS) here: http://sass-lang.com/ 4 | 5 | video { 6 | width: 100% !important; 7 | height: auto !important; 8 | } 9 | 10 | #localVideo { 11 | z-index: 99; 12 | position: absolute; 13 | bottom: 0; 14 | right: 0; 15 | border-color: #F0F8FF; 16 | border-radius: 50%; 17 | border-style: solid; 18 | } 19 | 20 | #js-chat-body { 21 | max-height: 255px; 22 | overflow: auto; 23 | } 24 | -------------------------------------------------------------------------------- /app/controllers/application_controller.rb: -------------------------------------------------------------------------------- 1 | class ApplicationController < ActionController::Base 2 | # Prevent CSRF attacks by raising an exception. 3 | # For APIs, you may want to use :null_session instead. 4 | protect_from_forgery with: :exception 5 | end 6 | -------------------------------------------------------------------------------- /app/controllers/concerns/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xescugc/webrtc-rails/61fdaaef43bacb699e280aa6782adbcc4ccb550e/app/controllers/concerns/.keep -------------------------------------------------------------------------------- /app/controllers/home_controller.rb: -------------------------------------------------------------------------------- 1 | class HomeController < ApplicationController 2 | 3 | def index 4 | end 5 | 6 | def room 7 | end 8 | 9 | end 10 | -------------------------------------------------------------------------------- /app/helpers/application_helper.rb: -------------------------------------------------------------------------------- 1 | module ApplicationHelper 2 | end 3 | -------------------------------------------------------------------------------- /app/helpers/home_helper.rb: -------------------------------------------------------------------------------- 1 | module HomeHelper 2 | end 3 | -------------------------------------------------------------------------------- /app/mailers/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xescugc/webrtc-rails/61fdaaef43bacb699e280aa6782adbcc4ccb550e/app/mailers/.keep -------------------------------------------------------------------------------- /app/models/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xescugc/webrtc-rails/61fdaaef43bacb699e280aa6782adbcc4ccb550e/app/models/.keep -------------------------------------------------------------------------------- /app/models/concerns/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xescugc/webrtc-rails/61fdaaef43bacb699e280aa6782adbcc4ccb550e/app/models/concerns/.keep -------------------------------------------------------------------------------- /app/rtc/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "webrtc-rails", 3 | "version": "0.0.1", 4 | "description": "a simple RT server with socket.io to suport the WebRTC client comunication of data", 5 | "contributors": [ 6 | { 7 | "name": "Francesc Gil", 8 | "email": "xescugil@gmail.com" 9 | } 10 | ], 11 | "repository": { 12 | "type": "git", 13 | "url": "https://github.com/XescuGC/webrtc-rails" 14 | }, 15 | "dependencies": { 16 | "socket.io": "0.9.16" 17 | }, 18 | "engines": { 19 | "node": ">= 0.4.0" 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /app/rtc/server.js: -------------------------------------------------------------------------------- 1 | var http = require('http'); 2 | var app = http.createServer(function (req, res) { 3 | }).listen(2013); 4 | 5 | var io = require('socket.io').listen(app); 6 | 7 | io.sockets.on('connection', function (socket){ 8 | 9 | socket.on('message', function (data) { 10 | io.sockets.in(data.room).emit('message', data); 11 | }); 12 | 13 | socket.on('create or join', function (room) { 14 | var numClients = io.sockets.clients(room).length; 15 | 16 | console.log('clients', numClients); 17 | 18 | if(numClients == 0){ 19 | socket.join(room); 20 | socket.emit('created'); 21 | } else if (numClients == 1){ 22 | socket.join(room); 23 | io.sockets.in(room).emit('joined'); 24 | } else { 25 | socket.emit('full'); 26 | } 27 | }) 28 | }); 29 | -------------------------------------------------------------------------------- /app/views/home/index.html.haml: -------------------------------------------------------------------------------- 1 | .jumbotron 2 | %h1.text-center 3 | Welcome to WebRTC-Rails 4 | %small 5 | by Francesc Gil 6 | %p.text-center This is a simple app creted to test WebRTC with in a Rails application 7 | %center.form-group 8 | Enter your room name: 9 | = text_field_tag "room[name]", nil, palceholder: "Enter your room name" 10 | = link_to "Create your first Call-Room!", "#", class: 'btn btn-success btn-large', role: 'button', id: "btn-room" 11 | 12 | :javascript 13 | 14 | $roomField = $("#room_name"); 15 | 16 | var redirectToRoom = function(event) { 17 | if (event.type === "click"){ 18 | if ($roomField.val() === ""){ 19 | alert("You have to set the name of the ROOM"); 20 | }else{ 21 | window.location = window.location.pathname + $roomField.val(); 22 | } 23 | } else if (event.type === "keypress"){ 24 | if (event.keyCode === 13){ 25 | if ($roomField.val() === ""){ 26 | alert("You have to set the name of the ROOM"); 27 | } else { 28 | window.location = window.location.pathname + $roomField.val(); 29 | } 30 | } 31 | } 32 | } 33 | 34 | $("#room_name").on("keypress", redirectToRoom); 35 | $("#btn-room").on("click", redirectToRoom); 36 | 37 | -------------------------------------------------------------------------------- /app/views/home/room.html.haml: -------------------------------------------------------------------------------- 1 | %script{src: '/javascripts/rtc/client_signaling.js'} 2 | .container 3 | .row 4 | #video-grid 5 | .col-xs-12.col-md-12 6 | %video#remoteVideo{ "autoplay" => "",} 7 | .col-md-2.col-xs-2 8 | %video#localVideo{ "autoplay" => "", "muted" => "" } 9 | .row 10 | .panel.panel-primary 11 | .panel-heading 12 | Chat 13 | .panel-body#js-chat-body 14 | %br 15 | .input-group 16 | %input.form-control#js-input-im{ type: 'text', placeholder: 'Send a Message'} 17 | %span.input-group-btn 18 | %button.btn.btn-primary#js-send-button-im{ type: "button"} 19 | Send 20 | %button.btn.btn-error#js-hangup{ type: "button"} 21 | Hang Up 22 | :javascript 23 | var user_name = prompt("Your user name?"); 24 | 25 | var $sendButton = $("#js-send-button-im"); 26 | var $inputIM = $("#js-input-im"); 27 | var $chatBody = $("#js-chat-body"); 28 | 29 | $sendButton.on('click', sendIM); 30 | $inputIM.on('keypress', checkEnterKey); 31 | 32 | function sendIM() { 33 | var content = $inputIM.val(); 34 | $inputIM.val(""); 35 | socket.emit('message',{message: {content: content, user: user_name}, type: 'im', room: room}); 36 | } 37 | 38 | function checkEnterKey(event) { 39 | if ( event.keyCode == 13 ) { 40 | $sendButton.click(); 41 | } 42 | } 43 | 44 | function appendNewIM(user, message) { 45 | $chatBody.prepend(mediaObjectIM(user, message)); 46 | } 47 | 48 | function mediaObjectIM(user, message) { 49 | var leftRight = user === user_name ? 'right' : 'left' 50 | return "
You may have mistyped the address or the page may have moved.
55 |If you are the application owner check the logs for more information.
57 | 58 | 59 | -------------------------------------------------------------------------------- /public/422.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |Maybe you tried to change something you didn't have access to.
55 |If you are the application owner check the logs for more information.
57 | 58 | 59 | -------------------------------------------------------------------------------- /public/500.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |If you are the application owner check the logs for more information.
56 | 57 | 58 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xescugc/webrtc-rails/61fdaaef43bacb699e280aa6782adbcc4ccb550e/public/favicon.ico -------------------------------------------------------------------------------- /public/javascripts/rtc/client_signaling.js: -------------------------------------------------------------------------------- 1 | var socket = io.connect('192.168.1.37:2013'); 2 | // var socket = io.connect('127.0.0.1:2013'); 3 | 4 | // var room = "room-name" //prompt("Enter room name:"); 5 | var room = window.location.pathname.replace("/", ""); 6 | 7 | socket.on("created", function (){ 8 | console.log("On Created"); 9 | isInitiator = true; 10 | console.log('isInitiator', isInitiator); 11 | }) 12 | 13 | socket.on("joined", function(){ 14 | console.log("Some one Joinded"); 15 | isChannelReady = true; 16 | }) 17 | 18 | socket.on("full", function(){ 19 | console.alert("Room Full, max number of 2"); 20 | }) 21 | 22 | socket.on("message", function(data) { 23 | if (data.type === 'gotStream') { 24 | console.log(data.message); 25 | maybeStart(); 26 | }else if (data.type === 'candidate' && isStarted) { 27 | var candidate = new RTCIceCandidate({ 28 | candidate: data.message.candidate, 29 | sdpMLineIndex: data.message.sdpMLineIndex 30 | }); 31 | pc.addIceCandidate(candidate); 32 | }else if (data.type === 'answer' && isStarted) { 33 | pc.setRemoteDescription(new RTCSessionDescription(data.message)); 34 | }else if (data.type === 'offer') { 35 | if (!isInitiator && !isStarted) { 36 | maybeStart(); 37 | } 38 | pc.setRemoteDescription(new RTCSessionDescription(data.message)); 39 | startAnswer(); 40 | }else if (data.type === 'im') { 41 | appendNewIM(data.message.user, data.message.content); 42 | }else if (data.type === 'by') { 43 | stop(); 44 | } 45 | }) 46 | -------------------------------------------------------------------------------- /public/robots.txt: -------------------------------------------------------------------------------- 1 | # See http://www.robotstxt.org/wc/norobots.html for documentation on how to use the robots.txt file 2 | # 3 | # To ban all spiders from the entire site uncomment the next two lines: 4 | # User-agent: * 5 | # Disallow: / 6 | -------------------------------------------------------------------------------- /vendor/assets/javascripts/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xescugc/webrtc-rails/61fdaaef43bacb699e280aa6782adbcc4ccb550e/vendor/assets/javascripts/.keep -------------------------------------------------------------------------------- /vendor/assets/javascripts/adapter.js: -------------------------------------------------------------------------------- 1 | var RTCPeerConnection = null; 2 | var getUserMedia = null; 3 | var attachMediaStream = null; 4 | var reattachMediaStream = null; 5 | var webrtcDetectedBrowser = null; 6 | var webrtcDetectedVersion = null; 7 | 8 | function trace(text) { 9 | // This function is used for logging. 10 | if (text[text.length - 1] == '\n') { 11 | text = text.substring(0, text.length - 1); 12 | } 13 | console.log((performance.now() / 1000).toFixed(3) + ": " + text); 14 | } 15 | 16 | if (navigator.mozGetUserMedia) { 17 | console.log("This appears to be Firefox"); 18 | 19 | webrtcDetectedBrowser = "firefox"; 20 | 21 | // The RTCPeerConnection object. 22 | RTCPeerConnection = mozRTCPeerConnection; 23 | 24 | // The RTCSessionDescription object. 25 | RTCSessionDescription = mozRTCSessionDescription; 26 | 27 | // The RTCIceCandidate object. 28 | RTCIceCandidate = mozRTCIceCandidate; 29 | 30 | // Get UserMedia (only difference is the prefix). 31 | // Code from Adam Barth. 32 | getUserMedia = navigator.mozGetUserMedia.bind(navigator); 33 | 34 | // Creates Turn Uri with new turn format. 35 | createIceServer = function(turn_url, username, password) { 36 | var iceServer = { 'url': turn_url, 37 | 'credential': password, 38 | 'username': username }; 39 | return iceServer; 40 | }; 41 | 42 | // Attach a media stream to an element. 43 | attachMediaStream = function(element, stream) { 44 | console.log("Attaching media stream", stream); 45 | window.varRemoteStream = stream; 46 | element.mozSrcObject = stream; 47 | setTimeout(function() { 48 | element.play(); 49 | },500) 50 | }; 51 | 52 | reattachMediaStream = function(to, from) { 53 | console.log("Reattaching media stream"); 54 | to.mozSrcObject = from.mozSrcObject; 55 | setTimeout(function() { 56 | element.play(); 57 | },500) 58 | }; 59 | 60 | // Fake get{Video,Audio}Tracks 61 | MediaStream.prototype.getVideoTracks = function() { 62 | return []; 63 | }; 64 | 65 | MediaStream.prototype.getAudioTracks = function() { 66 | return []; 67 | }; 68 | } else if (navigator.webkitGetUserMedia) { 69 | console.log("This appears to be Chrome"); 70 | 71 | webrtcDetectedBrowser = "chrome"; 72 | webrtcDetectedVersion = 73 | parseInt(navigator.userAgent.match(/Chrom(e|ium)\/([0-9]+)\./)[2]); 74 | 75 | // For pre-M28 chrome versions use old turn format, else use the new format. 76 | if (webrtcDetectedVersion < 28) { 77 | createIceServer = function(turn_url, username, password) { 78 | var iceServer = { 'url': 'turn:' + username + '@' + turn_url, 79 | 'credential': password }; 80 | return iceServer; 81 | }; 82 | } else { 83 | createIceServer = function(turn_url, username, password) { 84 | var iceServer = { 'url': turn_url, 85 | 'credential': password, 86 | 'username': username }; 87 | return iceServer; 88 | }; 89 | } 90 | 91 | // The RTCPeerConnection object. 92 | RTCPeerConnection = webkitRTCPeerConnection; 93 | 94 | // Get UserMedia (only difference is the prefix). 95 | // Code from Adam Barth. 96 | getUserMedia = navigator.webkitGetUserMedia.bind(navigator); 97 | 98 | // Attach a media stream to an element. 99 | attachMediaStream = function(element, stream) { 100 | if (typeof element.srcObject !== 'undefined') { 101 | element.srcObject = stream; 102 | } else if (typeof element.mozSrcObject !== 'undefined') { 103 | element.mozSrcObject = stream; 104 | } else if (typeof element.src !== 'undefined') { 105 | element.src = URL.createObjectURL(stream); 106 | } else { 107 | console.log('Error attaching stream to element.'); 108 | } 109 | }; 110 | 111 | reattachMediaStream = function(to, from) { 112 | to.src = from.src; 113 | }; 114 | 115 | // The representation of tracks in a stream is changed in M26. 116 | // Unify them for earlier Chrome versions in the coexisting period. 117 | if (!webkitMediaStream.prototype.getVideoTracks) { 118 | webkitMediaStream.prototype.getVideoTracks = function() { 119 | return this.videoTracks; 120 | }; 121 | webkitMediaStream.prototype.getAudioTracks = function() { 122 | return this.audioTracks; 123 | }; 124 | } 125 | 126 | // New syntax of getXXXStreams method in M26. 127 | if (!webkitRTCPeerConnection.prototype.getLocalStreams) { 128 | webkitRTCPeerConnection.prototype.getLocalStreams = function() { 129 | return this.localStreams; 130 | }; 131 | webkitRTCPeerConnection.prototype.getRemoteStreams = function() { 132 | return this.remoteStreams; 133 | }; 134 | } 135 | } else { 136 | console.log("Browser does not appear to be WebRTC-capable"); 137 | } 138 | -------------------------------------------------------------------------------- /vendor/assets/stylesheets/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xescugc/webrtc-rails/61fdaaef43bacb699e280aa6782adbcc4ccb550e/vendor/assets/stylesheets/.keep --------------------------------------------------------------------------------