2014-11-04 175 views
3

這可能是沒有用的,因爲我是新手。我想在我的ASP.NET WebForms項目中爲註冊用戶和在線用戶提供使用SignalR的WebRTC視頻通話功能。我試圖在Webforms中使用SignalR和WebRTC進行一個多星期的漫步/示例,但我總是在MVC中找到示例。我們不能在WebForms中使用SignalR和WebRTC嗎?如果我們可以使用,那麼任何人都可以通過一個非常簡單和基本的步驟/示例來提供/幫助我。我們可以在WebForms中使用SignalR與WebRTC視頻通話嗎?

+0

是的,你可以。尋找簡單的SignalR教程,並針對WebRTC信號進行調整。 – 2014-11-04 19:14:04

+0

如果在尋找普通的SignalR教程後,我能夠適應WebRTC信號,我從來沒有創建過這個線程。如果有人能夠提供一個工作示例或示例項目,那將是非常棒的。 – svyc 2014-11-05 02:34:27

+0

http://weblogs.asp.net/ricardoperes/video-streaming-with-asp-net-signalr-and-html5 – Alexan 2015-04-24 02:26:33

回答

3

該邏輯非常類似於signalR tutorial。除了您的消息是WebRTC需要通信進行連接的消息。

Here is an example I wrote up。它向所有通過signalR集線器連接的客戶端進行廣播。但是,將其設置爲只有特定用戶與其他用戶通信的位置非常簡單。 Here is a more flushed out example but it uses MVC

基本信令邏輯完成客戶端:

<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> 

基本集線器類轉發消息

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

基本啓動類開始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(); 
     } 
    } 
} 

聲明:本非常粗糙,但示例「作品」(客戶端之間發送流)。這段代碼沒有優化,也不理想。 SignalR中有許多非常棒的功能未被使用,可能會使它更好,更高效。

相關問題