Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can we use SignalR with WebRTC video calling in WebForms

It might be witless since I am newbie. I want to include WebRTC video calling feature using SignalR in my ASP.NET WebForms project for registered and online users. I tried to search more than a week for walk-through/examples for using SignalR with WebRTC in Webforms but I always found examples in MVC. Can't we use SignalR with WebRTC in WebForms? If we can use, then can anyone provide/help me with a very simple and basic walk-through/example of it.

like image 655
svyc Avatar asked Nov 04 '14 17:11

svyc


People also ask

Can SignalR stream video?

ASP.NET Core SignalR supports streaming from client to server and from server to client.

Is WebRTC a SignalR?

SignalR and WebRTC are primarily classified as "Realtime Backend / API" and "Web and Video Conferencing" tools respectively. SignalR is an open source tool with 7.75K GitHub stars and 2.19K GitHub forks. Here's a link to SignalR's open source repository on GitHub. I would recommend Amazon Chime.

Can SignalR be used in Web API?

SignalR can be used together with Web API just fine, so some functionality in application which is not realtime and doesn't require persistent connection could be served by Web API.

Does SignalR require WebSockets?

SignalR takes advantage of WebSocket, an HTML5 API that enables bi-directional communication between the browser and server. SignalR will use WebSockets under the covers when it's available, and gracefully fall back to other techniques and technologies when it isn't, while the application code remains the same.


1 Answers

The logic is very similar to the signalR tutorial. Except your messages are the messages that WebRTC needs to communicate to connect.

Here is an example I wrote up. It does a broadcast to all clients that are connected via the signalR hub. However, it is very simple to set it up to where only certain users communicate with others. Here is a more flushed out example but it uses MVC.

Basic signalling logic done client side:

<script type="text/javascript">
        var signal = $.connection.webRTCHub;
        var ready = false;
        //set our client handler
        signal.client.broadcastMessage = function (from, message) {
            //handle your message that you received
        }

       //start the hub for long polling so it does not close    
       $.connection.hub.start({ transport: ['longPolling'] }).done(function () {
            ready = true;
        });
        //only send a message when we are ready
        var sendMessage = function (message) {
            if (!ready)
                setTimeout(sendMessage, 100, message);
            else
                signal.server.send(name, message);
        }

    </script>

Basic Hub Class to forward the messages

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Microsoft.AspNet.SignalR;

namespace SignalRWebRTCExample
{
    public class WebRTCHub : Hub
    {
        //executed from javascript side via signal.server.send(name, message);
        public void Send(string from, string message)
        {
            //Code executed client side, aka, makes message available to client
            Clients.All.broadcastMessage(from, message);
        }
    }
}

Basic start up class to start signalr

using System;
using System.Threading.Tasks;
using Microsoft.Owin;
using Owin;

[assembly: OwinStartup(typeof(SignalRWebRTCExample.Startup))]

namespace SignalRWebRTCExample
{
    public class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            app.MapSignalR();
        }
    }
}

DISCLAIMER: This is very rough, but the example "works"(streams send between clients). This code is not optimized and not ideal. There are many awesome features in SignalR not utilized that probably could make it better and more efficient.

like image 159
Benjamin Trent Avatar answered Sep 28 '22 18:09

Benjamin Trent