Skip to content
This repository has been archived by the owner on Dec 8, 2021. It is now read-only.

fixes for running on older versions of .net and windows #11

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Example/App.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
</configuration>

<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup>
</configuration>
23 changes: 10 additions & 13 deletions Example/Example.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
<OutputType>Exe</OutputType>
<RootNamespace>Example</RootNamespace>
<AssemblyName>Example</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<DebugSymbols>true</DebugSymbols>
Expand Down Expand Up @@ -40,6 +41,7 @@
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
<OutputPath>bin\x86\Release\</OutputPath>
Expand All @@ -50,14 +52,12 @@
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup>
<ApplicationManifest>app.manifest</ApplicationManifest>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
Expand All @@ -68,15 +68,12 @@
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="app.manifest" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SpitfireUtils\SpitfireUtils.csproj">
<Project>{129233ea-cfee-432b-9cea-9cc7773c9a02}</Project>
<Name>SpitfireUtils</Name>
</ProjectReference>
<ProjectReference Include="..\Spitfire\Spitfire.vcxproj">
<Project>{5950b9b8-d486-4b8b-a3a1-53f1738f45ed}</Project>
<Name>Spitfire</Name>
<ProjectReference Include="..\Spitfire.Net\Spitfire.Net.csproj">
<Project>{071a7542-e616-4b1f-8240-a0a349e164ff}</Project>
<Name>Spitfire.Net</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Expand Down
155 changes: 150 additions & 5 deletions Example/Program.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Spitfire;
using Spitfire.Net;


namespace Example
{
Expand All @@ -15,9 +14,155 @@ static void Main(string[] args)
//This is a bare bones example that shows the logic in which one might
//Implement Spitfire into their application
//TODO a full fledged example
SpitfireRtc.EnableLogging();
var t = new WebRtcSession("a");
//SpitfireRtc.EnableLogging();

Thread th = new Thread(() =>
{
SecondSession();
});
th.Start();

Thread th2 = new Thread(() =>
{
SecondSession2();
});
th2.Start();


Console.Read();
}

public class EventMessageEventArgs : EventArgs
{
public Message Msg;
public EventMessageEventArgs(Message msg)
{
this.Msg = msg;
}
}

public static event EventHandler<EventMessageEventArgs> EventMessage;

private static void SecondSession()
{
Guid id = Guid.NewGuid();

var session = WebRtcManager.AddSession(id.ToString());

ManualResetEvent offerEvt = new ManualResetEvent(false);
string offer = string.Empty;

EventMessage += (s, ex) =>
{
if (ex.Msg.Source == id)
{
return;
}
else if (ex.Msg.Sdp.Type == SdpTypes.Answer)
{
session.Spitfire.SetOfferReply(ex.Msg.Sdp.Type.ToString().ToLower(), ex.Msg.Sdp.Sdp);
}
};
session.OnIceCandidateFound += (s, ex) =>
{
EventMessage.Invoke(null, new EventMessageEventArgs(new Message(id, null, null, ex.IceCandidate)));
};
session.Spitfire.OnSuccessOffer += (ex) =>
{
offer = ex.Sdp;
offerEvt.Set();
};
session.DataChannelOpened += (s, ex) =>
{
session.Spitfire.DataChannelSendText("default", "Hello World!!! Data channel is open");
};
session.Spitfire.CreateOffer();
offerEvt.WaitOne();
EventMessage.Invoke(null, new EventMessageEventArgs(new Message(id, offer)));
offerEvt.Reset();
offerEvt.WaitOne();
}

private static void SecondSession2()
{
Guid id = Guid.NewGuid();

ManualResetEvent offerEvt = new ManualResetEvent(false);
ManualResetEvent waitEvt = new ManualResetEvent(false);

string offer = string.Empty;
WebRtcSession session = null;
List<SpitfireIceCandidate> candidates = new List<SpitfireIceCandidate>();
EventMessage += (s, ex) =>
{
if (ex.Msg.Source == id)
{
return;
}

if (session == null && ex.Msg.IceCandidate != null)
{
candidates.Add(ex.Msg.IceCandidate);
}
else if (session == null)
{
offerEvt.Set();
offer = ex.Msg.Msg;
}
else if (ex.Msg.IceCandidate != null)
{
if (!session.Spitfire.AddIceCandidate(ex.Msg.IceCandidate.SdpMid, ex.Msg.IceCandidate.SdpIndex, ex.Msg.IceCandidate.Sdp) )
{
Console.WriteLine("Unable to add");
}
}
};
offerEvt.WaitOne();

session = WebRtcManager.AddSession(id.ToString(), offer);
session.Spitfire.OnDataMessage += (s, ex) =>
{
Console.WriteLine("Meesage from peer:" + ex);
};
while (session.AnswerSdp == null)
{
Thread.Sleep(100);
}
EventMessage.Invoke(null, new EventMessageEventArgs(new Message(id, "Answer", session.AnswerSdp)));

if (candidates.Count > 0)
{
foreach(var c in candidates)
{
if (!session.Spitfire.AddIceCandidate(c.SdpMid, c.SdpIndex, c.Sdp))
{
Console.WriteLine("Unable to add");
}
}
}

while (true)
{
if (waitEvt.WaitOne(100))
{
break;
}
}
}

public class Message
{
public Guid Source;
public string Msg;
public SpitfireSdp Sdp;
public SpitfireIceCandidate IceCandidate;
public Message(Guid id, string message, SpitfireSdp sdp = null, SpitfireIceCandidate iceCandidate = null)
{
this.Source = id;
this.Msg = message;
this.Sdp = sdp;
this.IceCandidate = iceCandidate;
}
}
}
}
27 changes: 26 additions & 1 deletion Example/WebRtcManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static bool AddIceCandidate(string id, string sdpMid, int sdpMLineIndex,
/// </summary>
/// <param name="id"></param>
/// <param name="sdp"></param>
public static void AddSession(string id, string sdp)
public static WebRtcSession AddSession(string id, string sdp)
{
var session = Sessions[id] = new WebRtcSession(id);
using (var go = new ManualResetEvent(false))
Expand All @@ -55,6 +55,31 @@ public static void AddSession(string id, string sdp)
if (go.WaitOne(9999))
session.Setup(sdp);
}
return session;
}

/// <summary>
/// A remote session has sent over its SDP, create a local session based on it.
/// </summary>
/// <param name="id"></param>
/// <param name="sdp"></param>
public static WebRtcSession AddSession(string id)
{
var session = Sessions[id] = new WebRtcSession(id);
using (var go = new ManualResetEvent(false))
{
Task.Factory.StartNew(() =>
{
using (session.Spitfire)
{
Console.WriteLine($"Starting WebRTC Loop for {id}");
session.BeginLoop(go);
}
}, session.Token.Token, TaskCreationOptions.LongRunning, TaskScheduler.Default);
if (go.WaitOne(9999))
session.Setup();
}
return session;
}
}
}
Loading