├── ASP.NET-MVC ├── App_Data │ ├── WebRTCData.mdf │ └── WebRTCData_log.LDF ├── Controllers │ └── HomeController.cs ├── Global.asax ├── Global.asax.cs ├── Models │ ├── WebRTC.dbml │ ├── WebRTC.dbml.layout │ └── WebRTC.designer.cs ├── Properties │ └── AssemblyInfo.cs ├── README.md ├── Views │ ├── Home │ │ └── Index.cshtml │ └── Web.config ├── Web.Debug.config ├── Web.Release.config ├── Web.config ├── WebRTC-Project.sln ├── XHRSignaling.csproj ├── XHRSignaling.csproj.user └── bin │ ├── System.Data.Linq.dll │ ├── XHRSignaling.dll │ └── XHRSignaling.pdb ├── LICENSE └── README.md /ASP.NET-MVC/App_Data/WebRTCData.mdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/muaz-khan/XHR-Signaling/d19c2f6dfbee7dd4d2257ec1540f592e979cff1c/ASP.NET-MVC/App_Data/WebRTCData.mdf -------------------------------------------------------------------------------- /ASP.NET-MVC/App_Data/WebRTCData_log.LDF: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/muaz-khan/XHR-Signaling/d19c2f6dfbee7dd4d2257ec1540f592e979cff1c/ASP.NET-MVC/App_Data/WebRTCData_log.LDF -------------------------------------------------------------------------------- /ASP.NET-MVC/Controllers/HomeController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using System.Web.Mvc; 4 | using XHRSignaling.Models; 5 | 6 | namespace XHRSignaling.Controllers 7 | { 8 | // https://github.com/muaz-khan/XHR-Signaling 9 | public class HomeController : Controller 10 | { 11 | private readonly WebRTCDataContext _db = new WebRTCDataContext(); 12 | public ActionResult Index() 13 | { 14 | return View(); 15 | } 16 | 17 | // this action method takes single query-string parameter value 18 | // it stores it in "Message" colume under "Data" table 19 | [HttpPost] 20 | public JsonResult PostData(string message) 21 | { 22 | var data = new Data 23 | { 24 | Message = message, 25 | Date = DateTime.Now 26 | }; 27 | 28 | _db.Datas.InsertOnSubmit(data); 29 | _db.SubmitChanges(); 30 | 31 | // older data must be deleted 32 | // otherwise databae file will be full of records! 33 | DeleteOlderData(); 34 | 35 | return Json(true); 36 | } 37 | 38 | // this action method gets latest messages 39 | [HttpPost] 40 | public JsonResult GetData() 41 | { 42 | var data = _db.Datas.Where(d => d.Date.AddSeconds(2) > DateTime.Now).OrderByDescending(d => d.ID).FirstOrDefault(); 43 | return data != null ? Json(data) : Json(false); 44 | } 45 | 46 | // this private method deletes old data 47 | void DeleteOlderData() 48 | { 49 | var data = _db.Datas.Where(d => d.Date.AddSeconds(2) < DateTime.Now); 50 | foreach(var d in data) 51 | { 52 | _db.Datas.DeleteOnSubmit(d); 53 | } 54 | _db.SubmitChanges(); 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /ASP.NET-MVC/Global.asax: -------------------------------------------------------------------------------- 1 | <%@ Application Codebehind="Global.asax.cs" Inherits="XHRSignaling.MvcApplication" Language="C#" %> 2 | -------------------------------------------------------------------------------- /ASP.NET-MVC/Global.asax.cs: -------------------------------------------------------------------------------- 1 | using System.Web.Mvc; 2 | using System.Web.Routing; 3 | 4 | namespace XHRSignaling 5 | { 6 | // Note: For instructions on enabling IIS6 or IIS7 classic mode, 7 | // visit http://go.microsoft.com/?LinkId=9394801 8 | 9 | public class MvcApplication : System.Web.HttpApplication 10 | { 11 | public static void RegisterGlobalFilters(GlobalFilterCollection filters) 12 | { 13 | filters.Add(new HandleErrorAttribute()); 14 | } 15 | 16 | public static void RegisterRoutes(RouteCollection routes) 17 | { 18 | routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); 19 | 20 | routes.MapRoute( 21 | "Default", // Route name 22 | "{controller}/{action}/{id}", // URL with parameters 23 | new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults 24 | ); 25 | 26 | } 27 | 28 | protected void Application_Start() 29 | { 30 | AreaRegistration.RegisterAllAreas(); 31 | 32 | RegisterGlobalFilters(GlobalFilters.Filters); 33 | RegisterRoutes(RouteTable.Routes); 34 | } 35 | } 36 | } -------------------------------------------------------------------------------- /ASP.NET-MVC/Models/WebRTC.dbml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 |
-------------------------------------------------------------------------------- /ASP.NET-MVC/Models/WebRTC.dbml.layout: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /ASP.NET-MVC/Models/WebRTC.designer.cs: -------------------------------------------------------------------------------- 1 | #pragma warning disable 1591 2 | //------------------------------------------------------------------------------ 3 | // 4 | // This code was generated by a tool. 5 | // Runtime Version:4.0.30319.17929 6 | // 7 | // Changes to this file may cause incorrect behavior and will be lost if 8 | // the code is regenerated. 9 | // 10 | //------------------------------------------------------------------------------ 11 | 12 | namespace XHRSignaling.Models 13 | { 14 | using System.Data.Linq; 15 | using System.Data.Linq.Mapping; 16 | using System.Data; 17 | using System.Collections.Generic; 18 | using System.Reflection; 19 | using System.Linq; 20 | using System.Linq.Expressions; 21 | using System.ComponentModel; 22 | using System; 23 | 24 | 25 | [global::System.Data.Linq.Mapping.DatabaseAttribute(Name="WebRTCData")] 26 | public partial class WebRTCDataContext : System.Data.Linq.DataContext 27 | { 28 | 29 | private static System.Data.Linq.Mapping.MappingSource mappingSource = new AttributeMappingSource(); 30 | 31 | #region Extensibility Method Definitions 32 | partial void OnCreated(); 33 | partial void InsertData(Data instance); 34 | partial void UpdateData(Data instance); 35 | partial void DeleteData(Data instance); 36 | #endregion 37 | 38 | public WebRTCDataContext() : 39 | base(global::System.Configuration.ConfigurationManager.ConnectionStrings["WebRTCDataConnectionString"].ConnectionString, mappingSource) 40 | { 41 | OnCreated(); 42 | } 43 | 44 | public WebRTCDataContext(string connection) : 45 | base(connection, mappingSource) 46 | { 47 | OnCreated(); 48 | } 49 | 50 | public WebRTCDataContext(System.Data.IDbConnection connection) : 51 | base(connection, mappingSource) 52 | { 53 | OnCreated(); 54 | } 55 | 56 | public WebRTCDataContext(string connection, System.Data.Linq.Mapping.MappingSource mappingSource) : 57 | base(connection, mappingSource) 58 | { 59 | OnCreated(); 60 | } 61 | 62 | public WebRTCDataContext(System.Data.IDbConnection connection, System.Data.Linq.Mapping.MappingSource mappingSource) : 63 | base(connection, mappingSource) 64 | { 65 | OnCreated(); 66 | } 67 | 68 | public System.Data.Linq.Table Datas 69 | { 70 | get 71 | { 72 | return this.GetTable(); 73 | } 74 | } 75 | } 76 | 77 | [global::System.Data.Linq.Mapping.TableAttribute(Name="dbo.Data")] 78 | public partial class Data : INotifyPropertyChanging, INotifyPropertyChanged 79 | { 80 | 81 | private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty); 82 | 83 | private int _ID; 84 | 85 | private string _Message; 86 | 87 | private System.DateTime _Date; 88 | 89 | #region Extensibility Method Definitions 90 | partial void OnLoaded(); 91 | partial void OnValidate(System.Data.Linq.ChangeAction action); 92 | partial void OnCreated(); 93 | partial void OnIDChanging(int value); 94 | partial void OnIDChanged(); 95 | partial void OnMessageChanging(string value); 96 | partial void OnMessageChanged(); 97 | partial void OnDateChanging(System.DateTime value); 98 | partial void OnDateChanged(); 99 | #endregion 100 | 101 | public Data() 102 | { 103 | OnCreated(); 104 | } 105 | 106 | [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_ID", AutoSync=AutoSync.OnInsert, DbType="Int NOT NULL IDENTITY", IsPrimaryKey=true, IsDbGenerated=true)] 107 | public int ID 108 | { 109 | get 110 | { 111 | return this._ID; 112 | } 113 | set 114 | { 115 | if ((this._ID != value)) 116 | { 117 | this.OnIDChanging(value); 118 | this.SendPropertyChanging(); 119 | this._ID = value; 120 | this.SendPropertyChanged("ID"); 121 | this.OnIDChanged(); 122 | } 123 | } 124 | } 125 | 126 | [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_Message", DbType="NVarChar(MAX) NOT NULL", CanBeNull=false)] 127 | public string Message 128 | { 129 | get 130 | { 131 | return this._Message; 132 | } 133 | set 134 | { 135 | if ((this._Message != value)) 136 | { 137 | this.OnMessageChanging(value); 138 | this.SendPropertyChanging(); 139 | this._Message = value; 140 | this.SendPropertyChanged("Message"); 141 | this.OnMessageChanged(); 142 | } 143 | } 144 | } 145 | 146 | [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_Date", DbType="DateTime NOT NULL")] 147 | public System.DateTime Date 148 | { 149 | get 150 | { 151 | return this._Date; 152 | } 153 | set 154 | { 155 | if ((this._Date != value)) 156 | { 157 | this.OnDateChanging(value); 158 | this.SendPropertyChanging(); 159 | this._Date = value; 160 | this.SendPropertyChanged("Date"); 161 | this.OnDateChanged(); 162 | } 163 | } 164 | } 165 | 166 | public event PropertyChangingEventHandler PropertyChanging; 167 | 168 | public event PropertyChangedEventHandler PropertyChanged; 169 | 170 | protected virtual void SendPropertyChanging() 171 | { 172 | if ((this.PropertyChanging != null)) 173 | { 174 | this.PropertyChanging(this, emptyChangingEventArgs); 175 | } 176 | } 177 | 178 | protected virtual void SendPropertyChanged(String propertyName) 179 | { 180 | if ((this.PropertyChanged != null)) 181 | { 182 | this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); 183 | } 184 | } 185 | } 186 | } 187 | #pragma warning restore 1591 188 | -------------------------------------------------------------------------------- /ASP.NET-MVC/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | // General Information about an assembly is controlled through the following 5 | // set of attributes. Change these attribute values to modify the information 6 | // associated with an assembly. 7 | [assembly: AssemblyTitle("XHRSignaling")] 8 | [assembly: AssemblyDescription("https://github.com/muaz-khan")] 9 | [assembly: AssemblyConfiguration("")] 10 | [assembly: AssemblyCompany("WebRTC")] 11 | [assembly: AssemblyProduct("XHRSignaling")] 12 | [assembly: AssemblyCopyright("Copyright © Muaz Khan")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // Setting ComVisible to false makes the types in this assembly not visible 17 | // to COM components. If you need to access a type in this assembly from 18 | // COM, set the ComVisible attribute to true on that type. 19 | [assembly: ComVisible(false)] 20 | 21 | // The following GUID is for the ID of the typelib if this project is exposed to COM 22 | [assembly: Guid("3305c122-241d-45e2-9484-773a5da12dc3")] 23 | 24 | // Version information for an assembly consists of the following four values: 25 | // 26 | // Major Version 27 | // Minor Version 28 | // Build Number 29 | // Revision 30 | // 31 | // You can specify all the values or you can default the Revision and Build Numbers 32 | // by using the '*' as shown below: 33 | [assembly: AssemblyVersion("1.0.0.0")] 34 | [assembly: AssemblyFileVersion("1.0.0.0")] 35 | -------------------------------------------------------------------------------- /ASP.NET-MVC/README.md: -------------------------------------------------------------------------------- 1 | ## XHR/XMLHttpRequest for [WebRTC](https://www.webrtc-experiment.com/) Signaling 2 | 3 | This directory contains ASP.NET MVC (C#) files. It uses MS-SQL to store and fetch data. Database "MDF" file has single table; which has two columns; one for primary key and last one for storing JSON data. 4 | 5 | ```csharp 6 | using System; 7 | using System.Linq; 8 | using System.Web.Mvc; 9 | using XHRSignaling.Models; 10 | 11 | namespace XHRSignaling.Controllers 12 | { 13 | // https://github.com/muaz-khan/XHR-Signaling 14 | public class HomeController : Controller 15 | { 16 | private readonly WebRTCDataContext _db = new WebRTCDataContext(); 17 | public ActionResult Index() 18 | { 19 | return View(); 20 | } 21 | 22 | // this action method takes single query-string parameter value 23 | // it stores it in "Message" colume under "Data" table 24 | [HttpPost] 25 | public JsonResult PostData(string message) 26 | { 27 | var data = new Data 28 | { 29 | Message = message, 30 | Date = DateTime.Now 31 | }; 32 | 33 | _db.Datas.InsertOnSubmit(data); 34 | _db.SubmitChanges(); 35 | 36 | // older data must be deleted 37 | // otherwise databae file will be full of records! 38 | DeleteOlderData(); 39 | 40 | return Json(true); 41 | } 42 | 43 | // this action method gets latest messages 44 | [HttpPost] 45 | public JsonResult GetData() 46 | { 47 | var data = _db.Datas.Where(d => d.Date.AddSeconds(2) > DateTime.Now).OrderByDescending(d => d.ID).FirstOrDefault(); 48 | return data != null ? Json(data) : Json(false); 49 | } 50 | 51 | // this private method deletes old data 52 | void DeleteOlderData() 53 | { 54 | var data = _db.Datas.Where(d => d.Date.AddSeconds(2) < DateTime.Now); 55 | foreach(var d in data) 56 | { 57 | _db.Datas.DeleteOnSubmit(d); 58 | } 59 | _db.SubmitChanges(); 60 | } 61 | } 62 | } 63 | 64 | ``` 65 | 66 | = 67 | 68 | ## JavaScript code 69 | 70 | ```javascript 71 | // database has a single table; which has two columns: 72 | // 1) Message (required to store JSON data) 73 | // 2) ID (optional: as primary key) 74 | 75 | // a simple function to make XMLHttpRequests 76 | function xhr(url, callback, data) { 77 | if (!window.XMLHttpRequest || !window.JSON) return; 78 | 79 | var request = new XMLHttpRequest(); 80 | request.onreadystatechange = function () { 81 | if (callback && request.readyState == 4 && request.status == 200) { 82 | // server MUST return JSON text 83 | callback(JSON.parse(request.responseText)); 84 | } 85 | }; 86 | request.open('POST', url); 87 | 88 | var formData = new FormData(); 89 | 90 | // you're passing "message" parameter 91 | formData.append('message', data); 92 | 93 | request.send(formData); 94 | } 95 | 96 | // this object is used to store "onmessage" callbacks from "openSignalingChannel handler 97 | var onMessageCallbacks = {}; 98 | 99 | // this object is used to make sure identical messages are not used multiple times 100 | var messagesReceived = {}; 101 | 102 | function repeatedlyCheck() { 103 | xhr('/Home/GetData', function (data) { 104 | // if server says nothing; wait. 105 | if (data == false) return setTimeout(repeatedlyCheck, 400); 106 | 107 | // if already receied same message; skip. 108 | if (messagesReceived[data.ID]) return setTimeout(repeatedlyCheck, 400); 109 | messagesReceived[data.ID] = data.Message; 110 | 111 | // "Message" property is JSON-ified in "openSignalingChannel handler 112 | data = JSON.parse(data.Message); 113 | 114 | // don't pass self messages over "onmessage" handlers 115 | if (data.sender != connection.userid && onMessageCallbacks[data.channel]) { 116 | onMessageCallbacks[data.channel](data.message); 117 | } 118 | 119 | // repeatedly check the database 120 | setTimeout(repeatedlyCheck, 1); 121 | }); 122 | } 123 | 124 | repeatedlyCheck(); 125 | 126 | // overriding "openSignalingChannel handler 127 | connection.openSignalingChannel = function (config) { 128 | var channel = config.channel || this.channel; 129 | onMessageCallbacks[channel] = config.onmessage; 130 | 131 | // let RTCMultiConnection know that server connection is opened! 132 | if (config.onopen) setTimeout(config.onopen, 1); 133 | 134 | // returning an object to RTCMultiConnection 135 | // so it can send data using "send" method 136 | return { 137 | send: function (data) { 138 | data = { 139 | channel: channel, 140 | message: data, 141 | sender: connection.userid 142 | }; 143 | 144 | // posting data to server 145 | // data is also JSON-ified. 146 | xhr('/Home/PostData', null, JSON.stringify(data)); 147 | }, 148 | channel: channel 149 | }; 150 | }; 151 | ``` 152 | 153 | Source code is available here: https://github.com/muaz-khan/XHR-Signaling 154 | 155 | Remember: You can use same code JavaScript code both for PHP and ASP.NET. 156 | 157 | = 158 | 159 | ## Other examples 160 | 161 | * http://www.RTCMultiConnection.org/docs/openSignalingChannel/ 162 | 163 | = 164 | 165 | ## Don't forget to check this one! 166 | 167 | * https://github.com/muaz-khan/WebRTC-Experiment/blob/master/Signaling.md 168 | 169 | = 170 | 171 | ## Links 172 | 173 | 1. www.rtcmulticonnection.org/docs/ 174 | 2. https:/www.webrtc-experiment.com/ 175 | 3. https://www.webrtc-experiment.com/docs/WebRTC-Signaling-Concepts.html 176 | 177 | = 178 | 179 | ## Muaz Khan (muazkh@gmail.com) - [@muazkh](https://twitter.com/muazkh) / [@WebRTCWeb](https://twitter.com/WebRTCWeb) 180 | 181 | 182 | 183 | = 184 | 185 | ## License 186 | 187 | [WebRTC Experiments](https://www.webrtc-experiment.com/) are released under [MIT licence](https://www.webrtc-experiment.com/licence/) . Copyright (c) [Muaz Khan](https://plus.google.com/+MuazKhan). 188 | -------------------------------------------------------------------------------- /ASP.NET-MVC/Views/Home/Index.cshtml: -------------------------------------------------------------------------------- 1 |  7 | 8 | 9 | 10 | RTCMultiConnection All-in-One Test ® Muaz Khan 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 83 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 |
95 |
96 |

97 | RTCMultiConnection 98 | All-in-One test 99 | ® 100 | Muaz Khan 101 |

102 |

103 | HOME 104 | © 105 | Muaz Khan 106 | 107 | . 108 | @@WebRTCWeb 109 | 110 | . 111 | Github 112 | 113 | . 114 | Latest issues 115 | 116 | . 117 | What's New? 118 |

119 |
120 | 121 |
122 | 123 | 124 |
125 |
126 | 127 | 128 |
129 | 130 |

131 | It is suggested to try MultiRTC! 132 |

133 | 134 |
135 | 151 | 157 | 158 | 159 |
160 | 161 | 162 |
163 | 164 | 165 |
166 |
167 | 168 |
169 |

WebRTC DataChannel

170 | 171 | 172 | 178 | 184 | 185 |
173 |

Text Chat

174 | 175 |
176 | 177 |
179 |

Share Files

180 | 181 | 182 |
183 |
186 |
187 | 188 | 494 | 495 |
496 |

How to use XHR for RTCMultiConnection signaling?

497 | 498 |
499 | // database has a single table; which has two columns: 
500 | // 1) Message (required to store JSON data)
501 | // 2) ID (optional: as primary key)
502 | 
503 | // a simple function to make XMLHttpRequests
504 | function xhr(url, callback, data) {
505 |     if (!window.XMLHttpRequest || !window.JSON) return;
506 | 
507 |     var request = new XMLHttpRequest();
508 |     request.onreadystatechange = function () {
509 |         if (callback && request.readyState == 4 && request.status == 200) {
510 |             // server MUST return JSON text
511 |             callback(JSON.parse(request.responseText));
512 |         }
513 |     };
514 |     request.open('POST', url);
515 | 
516 |     var formData = new FormData();
517 | 
518 |     // you're passing "message" parameter
519 |     formData.append('message', data);
520 | 
521 |     request.send(formData);
522 | }
523 | 
524 | // this object is used to store "onmessage" callbacks from "openSignalingChannel handler
525 | var onMessageCallbacks = {};
526 | 
527 | // this object is used to make sure identical messages are not used multiple times
528 | var messagesReceived = {};
529 | 
530 | function repeatedlyCheck() {
531 |     xhr('/Home/GetData', function (data) {
532 |         // if server says nothing; wait.
533 |         if (data == false) return setTimeout(repeatedlyCheck, 400);
534 | 
535 |         // if already receied same message; skip.
536 |         if (messagesReceived[data.ID]) return setTimeout(repeatedlyCheck, 400);
537 |         messagesReceived[data.ID] = data.Message;
538 | 
539 |         // "Message" property is JSON-ified in "openSignalingChannel handler
540 |         data = JSON.parse(data.Message);
541 | 
542 |         // don't pass self messages over "onmessage" handlers
543 |         if (data.sender != connection.userid && onMessageCallbacks[data.channel]) {
544 |             onMessageCallbacks[data.channel](data.message);
545 |         }
546 | 
547 |         // repeatedly check the database
548 |         setTimeout(repeatedlyCheck, 1);
549 |     });
550 | }
551 | 
552 | repeatedlyCheck();
553 | 
554 | // overriding "openSignalingChannel handler
555 | connection.openSignalingChannel = function (config) {
556 |     var channel = config.channel || this.channel;
557 |     onMessageCallbacks[channel] = config.onmessage;
558 | 
559 |     // let RTCMultiConnection know that server connection is opened!
560 |     if (config.onopen) setTimeout(config.onopen, 1);
561 | 
562 |     // returning an object to RTCMultiConnection
563 |     // so it can send data using "send" method
564 |     return {
565 |         send: function (data) {
566 |             data = {
567 |                 channel: channel,
568 |                 message: data,
569 |                 sender: connection.userid
570 |             };
571 | 
572 |             // posting data to server
573 |             // data is also JSON-ified.
574 |             xhr('/Home/PostData', null, JSON.stringify(data));
575 |         },
576 |         channel: channel
577 |     };
578 | };
579 | 
580 |
581 | 582 |
583 |

Latest Updates

584 |
585 |
586 | 587 |
588 |

Feedback

589 |
590 | 591 |
592 | Enter your email too; if you want "direct" reply! 593 |
594 |
595 | 596 | 597 | 598 | 599 | 605 | 606 | 607 | 608 | 609 | 610 | -------------------------------------------------------------------------------- /ASP.NET-MVC/Views/Web.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 |
7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 39 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /ASP.NET-MVC/Web.Debug.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 17 | 18 | 29 | 30 | -------------------------------------------------------------------------------- /ASP.NET-MVC/Web.Release.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 17 | 18 | 19 | 30 | 31 | -------------------------------------------------------------------------------- /ASP.NET-MVC/Web.config: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /ASP.NET-MVC/WebRTC-Project.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 11.00 3 | # Visual Studio 2010 4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XHRSignaling", "XHRSignaling.csproj", "{BCA253CA-A000-481F-B0A3-838CC20CA495}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Any CPU = Debug|Any CPU 9 | Release|Any CPU = Release|Any CPU 10 | EndGlobalSection 11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 12 | {BCA253CA-A000-481F-B0A3-838CC20CA495}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 13 | {BCA253CA-A000-481F-B0A3-838CC20CA495}.Debug|Any CPU.Build.0 = Debug|Any CPU 14 | {BCA253CA-A000-481F-B0A3-838CC20CA495}.Release|Any CPU.ActiveCfg = Release|Any CPU 15 | {BCA253CA-A000-481F-B0A3-838CC20CA495}.Release|Any CPU.Build.0 = Release|Any CPU 16 | EndGlobalSection 17 | GlobalSection(SolutionProperties) = preSolution 18 | HideSolutionNode = FALSE 19 | EndGlobalSection 20 | EndGlobal 21 | -------------------------------------------------------------------------------- /ASP.NET-MVC/XHRSignaling.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug 5 | AnyCPU 6 | 7 | 8 | 2.0 9 | {BCA253CA-A000-481F-B0A3-838CC20CA495} 10 | {E53F8FEA-EAE0-44A6-8774-FFD645390401};{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc} 11 | Library 12 | Properties 13 | XHRSignaling 14 | XHRSignaling 15 | v4.0 16 | false 17 | false 18 | 19 | 20 | true 21 | full 22 | false 23 | bin\ 24 | DEBUG;TRACE 25 | prompt 26 | 4 27 | 28 | 29 | pdbonly 30 | true 31 | bin\ 32 | TRACE 33 | prompt 34 | 4 35 | 36 | 37 | 38 | True 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | Global.asax 67 | 68 | 69 | True 70 | True 71 | WebRTC.dbml 72 | 73 | 74 | 75 | 76 | 77 | 78 | WebRTCData.mdf 79 | 80 | 81 | 82 | 83 | Web.config 84 | 85 | 86 | Web.config 87 | 88 | 89 | 90 | 91 | 92 | 93 | MSLinqToSQLGenerator 94 | WebRTC.designer.cs 95 | Designer 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | WebRTC.dbml 105 | 106 | 107 | 108 | 109 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | False 123 | True 124 | 49158 125 | / 126 | 127 | 128 | False 129 | False 130 | 131 | 132 | False 133 | 134 | 135 | 136 | 137 | -------------------------------------------------------------------------------- /ASP.NET-MVC/XHRSignaling.csproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | ProjectFiles 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | SpecificPage 13 | True 14 | False 15 | False 16 | False 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | False 26 | True 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /ASP.NET-MVC/bin/System.Data.Linq.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/muaz-khan/XHR-Signaling/d19c2f6dfbee7dd4d2257ec1540f592e979cff1c/ASP.NET-MVC/bin/System.Data.Linq.dll -------------------------------------------------------------------------------- /ASP.NET-MVC/bin/XHRSignaling.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/muaz-khan/XHR-Signaling/d19c2f6dfbee7dd4d2257ec1540f592e979cff1c/ASP.NET-MVC/bin/XHRSignaling.dll -------------------------------------------------------------------------------- /ASP.NET-MVC/bin/XHRSignaling.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/muaz-khan/XHR-Signaling/d19c2f6dfbee7dd4d2257ec1540f592e979cff1c/ASP.NET-MVC/bin/XHRSignaling.pdb -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/muaz-khan/XHR-Signaling/d19c2f6dfbee7dd4d2257ec1540f592e979cff1c/LICENSE -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## XHR/XMLHttpRequest for [WebRTC](https://www.webrtc-experiment.com/) Signaling 2 | 3 | XHR/XMLHttpRequest based [WebRTC](https://www.webrtc-experiment.com/) signaling implementation. 4 | 5 | Though, this repository is part of [WebRTC Experiments](https://github.com/muaz-khan/WebRTC-Experiment) however you can use it within any WebRTC project! 6 | 7 | ```javascript 8 | // database has a single table; which has two columns: 9 | // 1) Message (required to store JSON data) 10 | // 2) ID (optional: as primary key) 11 | 12 | // a simple function to make XMLHttpRequests 13 | function xhr(url, callback, data) { 14 | if (!window.XMLHttpRequest || !window.JSON) return; 15 | 16 | var request = new XMLHttpRequest(); 17 | request.onreadystatechange = function () { 18 | if (callback && request.readyState == 4 && request.status == 200) { 19 | // server MUST return JSON text 20 | callback(JSON.parse(request.responseText)); 21 | } 22 | }; 23 | request.open('POST', url); 24 | 25 | var formData = new FormData(); 26 | 27 | // you're passing "message" parameter 28 | formData.append('message', data); 29 | 30 | request.send(formData); 31 | } 32 | 33 | // this object is used to store "onmessage" callbacks from "openSignalingChannel handler 34 | var onMessageCallbacks = {}; 35 | 36 | // this object is used to make sure identical messages are not used multiple times 37 | var messagesReceived = {}; 38 | 39 | function repeatedlyCheck() { 40 | xhr('/Home/GetData', function (data) { 41 | // if server says nothing; wait. 42 | if (data == false) return setTimeout(repeatedlyCheck, 400); 43 | 44 | // if already receied same message; skip. 45 | if (messagesReceived[data.ID]) return setTimeout(repeatedlyCheck, 400); 46 | messagesReceived[data.ID] = data.Message; 47 | 48 | // "Message" property is JSON-ified in "openSignalingChannel handler 49 | data = JSON.parse(data.Message); 50 | 51 | // don't pass self messages over "onmessage" handlers 52 | if (data.sender != connection.userid && onMessageCallbacks[data.channel]) { 53 | onMessageCallbacks[data.channel](data.message); 54 | } 55 | 56 | // repeatedly check the database 57 | setTimeout(repeatedlyCheck, 1); 58 | }); 59 | } 60 | 61 | repeatedlyCheck(); 62 | 63 | // overriding "openSignalingChannel handler 64 | connection.openSignalingChannel = function (config) { 65 | var channel = config.channel || this.channel; 66 | onMessageCallbacks[channel] = config.onmessage; 67 | 68 | // let RTCMultiConnection know that server connection is opened! 69 | if (config.onopen) setTimeout(config.onopen, 1); 70 | 71 | // returning an object to RTCMultiConnection 72 | // so it can send data using "send" method 73 | return { 74 | send: function (data) { 75 | data = { 76 | channel: channel, 77 | message: data, 78 | sender: connection.userid 79 | }; 80 | 81 | // posting data to server 82 | // data is also JSON-ified. 83 | xhr('/Home/PostData', null, JSON.stringify(data)); 84 | }, 85 | channel: channel 86 | }; 87 | }; 88 | ``` 89 | 90 | Source code is available here: https://github.com/muaz-khan/XHR-Signaling 91 | 92 | Remember: You can use same code JavaScript code both for PHP and ASP.NET. 93 | 94 | = 95 | 96 | ## Other examples 97 | 98 | * http://www.RTCMultiConnection.org/docs/openSignalingChannel/ 99 | 100 | = 101 | 102 | ## Don't forget to check this one! 103 | 104 | * https://github.com/muaz-khan/WebRTC-Experiment/blob/master/Signaling.md 105 | 106 | = 107 | 108 | ## Links 109 | 110 | 1. www.rtcmulticonnection.org/docs/ 111 | 2. https:/www.webrtc-experiment.com/ 112 | 3. https://www.webrtc-experiment.com/docs/WebRTC-Signaling-Concepts.html 113 | 114 | = 115 | 116 | ## Muaz Khan (muazkh@gmail.com) - [@muazkh](https://twitter.com/muazkh) / [@WebRTCWeb](https://twitter.com/WebRTCWeb) 117 | 118 | 119 | 120 | = 121 | 122 | ## License 123 | 124 | [WebRTC Experiments](https://www.webrtc-experiment.com/) are released under [MIT licence](https://www.webrtc-experiment.com/licence/) . Copyright (c) [Muaz Khan](https://plus.google.com/+MuazKhan). 125 | --------------------------------------------------------------------------------