Skip to content

Commit

Permalink
Add Vtortola support
Browse files Browse the repository at this point in the history
  • Loading branch information
Elad Zelingher committed Oct 9, 2014
1 parent ba55d49 commit 0ae214d
Show file tree
Hide file tree
Showing 13 changed files with 714 additions and 17 deletions.
22 changes: 22 additions & 0 deletions NuGet/WampSharp.Vtortola.nuspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<version>$version$</version>
<authors>CodeSharp</authors>
<owners />
<dependencies>
<dependency id="WampSharp.Default" version="[$version$]" />
<dependency id="vtortola.WebSocketListener" version="[2.1.1.0]" />
</dependencies>
<id>WampSharp.Vtortola</id>
<title>WampSharp Vtortola support</title>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Vtortola transport for WampSharp</description>
<projectUrl>https:/Code-Sharp/WampSharp/</projectUrl>
<tags>websockets wampws rpc pubsub vtortola wampv2</tags>
</metadata>
<files>
<file src="bin\net45\WampSharp.Vtortola.dll" target="lib\net45\WampSharp.Vtortola.dll" />
<file src="bin\net45\WampSharp.Vtortola.xml" target="lib\net45\WampSharp.Vtortola.xml" />
</files>
</package>
111 changes: 111 additions & 0 deletions src/mono/Extensions/WampSharp.Vtortola/WampSharp.Vtortola.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{DE13BC69-B822-45EA-846F-DDEF66D34BD9}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>WampSharp.Vtortola</RootNamespace>
<AssemblyName>WampSharp.Vtortola</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
<RestorePackages>true</RestorePackages>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DocumentationFile>bin\Debug\WampSharp.Vtortola.XML</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Castle.Core, Version=3.3.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\Castle.Core.3.3.1\lib\net45\Castle.Core.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Reactive.Core">
<Private>True</Private>
</Reference>
<Reference Include="System.Reactive.Interfaces">
<Private>True</Private>
</Reference>
<Reference Include="System.Reactive.Linq">
<Private>True</Private>
</Reference>
<Reference Include="System.Threading.Tasks.Dataflow, Version=4.5.9.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>True</Private>
<HintPath>..\..\packages\Microsoft.Tpl.Dataflow.4.5.9\lib\net45\System.Threading.Tasks.Dataflow.dll</HintPath>
</Reference>
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="vtortola.WebSockets">
<HintPath>..\..\packages\vtortola.WebSocketListener.2.1.1.0\lib\net45\vtortola.WebSockets.dll</HintPath>
</Reference>
<Reference Include="vtortola.WebSockets.Deflate">
<HintPath>..\..\packages\vtortola.WebSocketListener.2.1.1.0\lib\net45\vtortola.WebSockets.Deflate.dll</HintPath>
</Reference>
<Reference Include="vtortola.WebSockets.Rfc6455">
<HintPath>..\..\packages\vtortola.WebSocketListener.2.1.1.0\lib\net45\vtortola.WebSockets.Rfc6455.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="..\..\..\net45\Extensions\WampSharp.Vtortola\Properties\AssemblyInfo.cs">
<Link>Properties\AssemblyInfo.cs</Link>
</Compile>
<Compile Include="..\..\..\net45\Extensions\WampSharp.Vtortola\VtortolaWampBinaryConnection.cs">
<Link>VtortolaWampBinaryConnection.cs</Link>
</Compile>
<Compile Include="..\..\..\net45\Extensions\WampSharp.Vtortola\VtortolaWampConnection.cs">
<Link>VtortolaWampConnection.cs</Link>
</Compile>
<Compile Include="..\..\..\net45\Extensions\WampSharp.Vtortola\VtortolaWampTextConnection.cs">
<Link>VtortolaWampTextConnection.cs</Link>
</Compile>
<Compile Include="..\..\..\net45\Extensions\WampSharp.Vtortola\VtortolaWebSocketTransport.cs">
<Link>VtortolaWebSocketTransport.cs</Link>
</Compile>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\WampSharp\WampSharp.csproj">
<Project>{653A76DC-00D7-4EFF-A25E-2FA10C5C927D}</Project>
<Name>WampSharp</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
6 changes: 6 additions & 0 deletions src/mono/Extensions/WampSharp.Vtortola/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Castle.Core" version="3.3.1" targetFramework="net45" />
<package id="Microsoft.Tpl.Dataflow" version="4.5.9" targetFramework="net45" />
<package id="vtortola.WebSocketListener" version="2.1.1.0" targetFramework="net45" />
</packages>
21 changes: 15 additions & 6 deletions src/mono/WampSharpMono.sln
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
# Visual Studio 2013
VisualStudioVersion = 12.0.30723.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WampSharp", "WampSharp\WampSharp.csproj", "{653A76DC-00D7-4EFF-A25E-2FA10C5C927D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WampSharp.Default", "WampSharp.Default\WampSharp.Default.csproj", "{6AB75291-D296-457E-88A3-B41B16A1A247}"
Expand Down Expand Up @@ -41,6 +43,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WampSharp.Samples.Caller",
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WampSharp.Samples.Publisher", "Samples\WAMP2\WampSharp.Samples.Publisher\WampSharp.Samples.Publisher.csproj", "{E924BD74-041F-4F3A-8041-FC7F8827728A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WampSharp.Vtortola", "Extensions\WampSharp.Vtortola\WampSharp.Vtortola.csproj", "{DE13BC69-B822-45EA-846F-DDEF66D34BD9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -107,6 +111,10 @@ Global
{E924BD74-041F-4F3A-8041-FC7F8827728A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E924BD74-041F-4F3A-8041-FC7F8827728A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E924BD74-041F-4F3A-8041-FC7F8827728A}.Release|Any CPU.Build.0 = Release|Any CPU
{DE13BC69-B822-45EA-846F-DDEF66D34BD9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DE13BC69-B822-45EA-846F-DDEF66D34BD9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DE13BC69-B822-45EA-846F-DDEF66D34BD9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DE13BC69-B822-45EA-846F-DDEF66D34BD9}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -117,15 +125,16 @@ Global
{AD5C9AA6-6810-488E-9EDD-FCC945AAD627} = {10B51C05-30BC-412A-BFFB-8C2C02753528}
{2128E477-97B6-4224-A8A9-789F79514B41} = {10B51C05-30BC-412A-BFFB-8C2C02753528}
{0A431511-B51D-42A2-AE0F-DEFCDB9FCE77} = {10B51C05-30BC-412A-BFFB-8C2C02753528}
{7D74C7E0-3F4E-4C60-BC75-C5086706CF7F} = {AF224856-8194-4CA0-92D9-03926B743987}
{678473BD-87FC-4788-A444-4ABF45FDCFEC} = {FA4B348E-3BBD-4F98-B429-891376EBA17E}
{D3FB3310-A761-45B5-AC4B-78FE90C2829C} = {D07452C1-0C0A-45C3-8A1B-33BD8FF93C5E}
{710B61C1-E7E0-4D8F-BF39-F82086D610ED} = {D07452C1-0C0A-45C3-8A1B-33BD8FF93C5E}
{F5B01D7B-14C3-419C-9887-C0A24FF2DE59} = {FA4B348E-3BBD-4F98-B429-891376EBA17E}
{6AD8C6F1-05AE-4826-BE27-BF54C73D6159} = {10B51C05-30BC-412A-BFFB-8C2C02753528}
{32A38656-5BAF-4D80-9780-95C3B594DA3F} = {10B51C05-30BC-412A-BFFB-8C2C02753528}
{7D74C7E0-3F4E-4C60-BC75-C5086706CF7F} = {AF224856-8194-4CA0-92D9-03926B743987}
{0EB744B6-235C-4460-B25C-EBC966201C26} = {AF224856-8194-4CA0-92D9-03926B743987}
{7434FFFF-F5E5-48DF-9544-19131885FA4E} = {AF224856-8194-4CA0-92D9-03926B743987}
{E924BD74-041F-4F3A-8041-FC7F8827728A} = {AF224856-8194-4CA0-92D9-03926B743987}
{D3FB3310-A761-45B5-AC4B-78FE90C2829C} = {D07452C1-0C0A-45C3-8A1B-33BD8FF93C5E}
{710B61C1-E7E0-4D8F-BF39-F82086D610ED} = {D07452C1-0C0A-45C3-8A1B-33BD8FF93C5E}
{678473BD-87FC-4788-A444-4ABF45FDCFEC} = {FA4B348E-3BBD-4F98-B429-891376EBA17E}
{F5B01D7B-14C3-419C-9887-C0A24FF2DE59} = {FA4B348E-3BBD-4F98-B429-891376EBA17E}
{DE13BC69-B822-45EA-846F-DDEF66D34BD9} = {FA4B348E-3BBD-4F98-B429-891376EBA17E}
EndGlobalSection
EndGlobal
12 changes: 7 additions & 5 deletions src/net40/WampSharpFw4.sln
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
# Visual Studio 2013
VisualStudioVersion = 12.0.30723.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WampSharp", "WampSharp\WampSharp.csproj", "{653A76DC-00D7-4EFF-A25E-2FA10C5C927D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WampSharp.Default", "WampSharp.Default\WampSharp.Default.csproj", "{6AB75291-D296-457E-88A3-B41B16A1A247}"
Expand Down Expand Up @@ -111,14 +113,14 @@ Global
{AD5C9AA6-6810-488E-9EDD-FCC945AAD627} = {10B51C05-30BC-412A-BFFB-8C2C02753528}
{2128E477-97B6-4224-A8A9-789F79514B41} = {10B51C05-30BC-412A-BFFB-8C2C02753528}
{0A431511-B51D-42A2-AE0F-DEFCDB9FCE77} = {10B51C05-30BC-412A-BFFB-8C2C02753528}
{7D74C7E0-3F4E-4C60-BC75-C5086706CF7F} = {AF224856-8194-4CA0-92D9-03926B743987}
{678473BD-87FC-4788-A444-4ABF45FDCFEC} = {FA4B348E-3BBD-4F98-B429-891376EBA17E}
{D3FB3310-A761-45B5-AC4B-78FE90C2829C} = {D07452C1-0C0A-45C3-8A1B-33BD8FF93C5E}
{710B61C1-E7E0-4D8F-BF39-F82086D610ED} = {D07452C1-0C0A-45C3-8A1B-33BD8FF93C5E}
{6AD8C6F1-05AE-4826-BE27-BF54C73D6159} = {10B51C05-30BC-412A-BFFB-8C2C02753528}
{32A38656-5BAF-4D80-9780-95C3B594DA3F} = {10B51C05-30BC-412A-BFFB-8C2C02753528}
{7D74C7E0-3F4E-4C60-BC75-C5086706CF7F} = {AF224856-8194-4CA0-92D9-03926B743987}
{0EB744B6-235C-4460-B25C-EBC966201C26} = {AF224856-8194-4CA0-92D9-03926B743987}
{7434FFFF-F5E5-48DF-9544-19131885FA4E} = {AF224856-8194-4CA0-92D9-03926B743987}
{E924BD74-041F-4F3A-8041-FC7F8827728A} = {AF224856-8194-4CA0-92D9-03926B743987}
{D3FB3310-A761-45B5-AC4B-78FE90C2829C} = {D07452C1-0C0A-45C3-8A1B-33BD8FF93C5E}
{710B61C1-E7E0-4D8F-BF39-F82086D610ED} = {D07452C1-0C0A-45C3-8A1B-33BD8FF93C5E}
{678473BD-87FC-4788-A444-4ABF45FDCFEC} = {FA4B348E-3BBD-4F98-B429-891376EBA17E}
EndGlobalSection
EndGlobal
36 changes: 36 additions & 0 deletions src/net45/Extensions/WampSharp.Vtortola/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("WampSharp.Vtortola")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("WampSharp.Vtortola")]
[assembly: AssemblyCopyright("Copyright © 2014")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("c15d9995-9bd4-491a-837a-c97f97b4eaec")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System.IO;
using vtortola.WebSockets;
using WampSharp.Core.Message;
using WampSharp.V2.Binding;

namespace WampSharp.Vtortola
{
internal class VtortolaWampBinaryConnection<TMessage> : VtortolaWampConnection<TMessage>
{
private readonly IWampBinaryBinding<TMessage> mBinding;

public VtortolaWampBinaryConnection(WebSocket connection, IWampBinaryBinding<TMessage> binding) :
base(connection)
{
mBinding = binding;
}

protected override WampMessage<TMessage> ParseMessage(WebSocketMessageReadStream readStream)
{
using (MemoryStream memoryStream = new MemoryStream())
{
readStream.CopyTo(memoryStream);
byte[] bytes = memoryStream.ToArray();
WampMessage<TMessage> result = mBinding.Parse(bytes);
return result;
}
}

public override void Send(WampMessage<TMessage> message)
{
using (WebSocketMessageWriteStream stream =
mWebsocket.CreateMessageWriter(WebSocketMessageType.Binary))
{
byte[] raw = mBinding.Format(message);
stream.Write(raw, 0, raw.Length);
}
}
}
}
77 changes: 77 additions & 0 deletions src/net45/Extensions/WampSharp.Vtortola/VtortolaWampConnection.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using vtortola.WebSockets;
using WampSharp.Core.Listener;
using WampSharp.Core.Message;

namespace WampSharp.Vtortola
{
internal abstract class VtortolaWampConnection<TMessage> : IWampConnection<TMessage>
{
protected readonly WebSocket mWebsocket;

public VtortolaWampConnection(WebSocket websocket)
{
mWebsocket = websocket;
}

public async Task HandleWebSocketAsync()
{
try
{
if (ConnectionOpen != null)
{
ConnectionOpen(this, EventArgs.Empty);
}

while (mWebsocket.IsConnected)
{
WebSocketMessageReadStream message =
await mWebsocket.ReadMessageAsync(CancellationToken.None)
.ConfigureAwait(false);

if (message != null)
{
using (message)
{
if (MessageArrived != null)
{
WampMessage<TMessage> parsed = ParseMessage(message);

MessageArrived(this,
new WampMessageArrivedEventArgs<TMessage>(parsed));
}
}
}
}

if (ConnectionClosed != null)
{
ConnectionClosed(this, EventArgs.Empty);
}
}
catch (Exception ex)
{
if (ConnectionError != null)
{
ConnectionError(this, new WampConnectionErrorEventArgs(ex));
}
}
}

protected abstract WampMessage<TMessage> ParseMessage(WebSocketMessageReadStream readStream);

public void Dispose()
{
mWebsocket.Dispose();
}

public abstract void Send(WampMessage<TMessage> message);

public event EventHandler ConnectionOpen;
public event EventHandler<WampMessageArrivedEventArgs<TMessage>> MessageArrived;
public event EventHandler ConnectionClosed;
public event EventHandler<WampConnectionErrorEventArgs> ConnectionError;
}
}
Loading

0 comments on commit 0ae214d

Please sign in to comment.