Can we use SignalR with WebRTC video calls in WebForms

This might be pointless since I'm a beginner. I want to enable WebRTC video calling feature with SignalR in my ASP.NET WebForms project for registered and online users. I've tried searching for over a week for walkthroughs / examples of using SignalR with WebRTC in Webforms, but I've always found examples in MVC. Can't we use SignalR with WebRTC in WebForms? If we can use, can anyone provide / help me with a very simple and simple walkthrough / example of this.

+3


source to share


1 answer


The logic is very similar to signalR . Except for messages that WebRTC needs to bind to connect.

Here's an example I wrote . It broadcasts messages to all clients that are connected through a signalR hub. However, it is very easy to set it up where only some users communicate with others. Below is an example, but it uses MVC .

The main signaling logic is done on the 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>

      

Base Hub class for message forwarding



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);
        }
    }
}

      

Base startup class for starting 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 are sent between clients). This code is neither optimized nor perfect. SignalR has many amazing features that could possibly make them better and more efficient.

+3


source







All Articles