Added NightAlert project for travel kit
This commit is contained in:
@@ -0,0 +1,200 @@
|
||||
using Quobject.EngineIoClientDotNet.Modules;
|
||||
using Quobject.EngineIoClientDotNet.Parser;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using WebSocket4Net;
|
||||
|
||||
namespace Quobject.EngineIoClientDotNet.Client.Transports
|
||||
{
|
||||
public class WebSocket : Transport
|
||||
{
|
||||
public static readonly string NAME = "websocket";
|
||||
|
||||
private WebSocket4Net.WebSocket ws;
|
||||
private List<KeyValuePair<string, string>> Cookies;
|
||||
private List<KeyValuePair<string, string>> MyExtraHeaders;
|
||||
|
||||
public WebSocket(Options opts)
|
||||
: base(opts)
|
||||
{
|
||||
Name = NAME;
|
||||
Cookies = new List<KeyValuePair<string, string>>();
|
||||
foreach (var cookie in opts.Cookies)
|
||||
{
|
||||
Cookies.Add(new KeyValuePair<string, string>(cookie.Key, cookie.Value));
|
||||
}
|
||||
MyExtraHeaders = new List<KeyValuePair<string, string>>();
|
||||
foreach (var header in opts.ExtraHeaders)
|
||||
{
|
||||
MyExtraHeaders.Add(new KeyValuePair<string, string>(header.Key, header.Value));
|
||||
}
|
||||
}
|
||||
|
||||
protected override void DoOpen()
|
||||
{
|
||||
var log = LogManager.GetLogger(Global.CallerName());
|
||||
log.Info("DoOpen uri =" + this.Uri());
|
||||
|
||||
ws = new WebSocket4Net.WebSocket(this.Uri(), "", Cookies, MyExtraHeaders)
|
||||
{
|
||||
EnableAutoSendPing = false
|
||||
};
|
||||
if (ServerCertificate.Ignore)
|
||||
{
|
||||
var security = ws.Security;
|
||||
|
||||
if (security != null)
|
||||
{
|
||||
security.AllowUnstrustedCertificate = true;
|
||||
security.AllowNameMismatchCertificate = true;
|
||||
}
|
||||
}
|
||||
ws.Opened += ws_Opened;
|
||||
ws.Closed += ws_Closed;
|
||||
ws.MessageReceived += ws_MessageReceived;
|
||||
ws.DataReceived += ws_DataReceived;
|
||||
ws.Error += ws_Error;
|
||||
ws.Open();
|
||||
}
|
||||
|
||||
void ws_DataReceived(object sender, DataReceivedEventArgs e)
|
||||
{
|
||||
var log = LogManager.GetLogger(Global.CallerName());
|
||||
log.Info("ws_DataReceived " + e.Data);
|
||||
this.OnData(e.Data);
|
||||
}
|
||||
|
||||
private void ws_Opened(object sender, EventArgs e)
|
||||
{
|
||||
var log = LogManager.GetLogger(Global.CallerName());
|
||||
log.Info("ws_Opened " + ws.SupportBinary);
|
||||
this.OnOpen();
|
||||
}
|
||||
|
||||
void ws_Closed(object sender, EventArgs e)
|
||||
{
|
||||
var log = LogManager.GetLogger(Global.CallerName());
|
||||
log.Info("ws_Closed");
|
||||
ws.Opened -= ws_Opened;
|
||||
ws.Closed -= ws_Closed;
|
||||
ws.MessageReceived -= ws_MessageReceived;
|
||||
ws.DataReceived -= ws_DataReceived;
|
||||
ws.Error -= ws_Error;
|
||||
this.OnClose();
|
||||
}
|
||||
|
||||
void ws_MessageReceived(object sender, MessageReceivedEventArgs e)
|
||||
{
|
||||
var log = LogManager.GetLogger(Global.CallerName());
|
||||
log.Info("ws_MessageReceived e.Message= " + e.Message);
|
||||
this.OnData(e.Message);
|
||||
}
|
||||
|
||||
void ws_Error(object sender, SuperSocket.ClientEngine.ErrorEventArgs e)
|
||||
{
|
||||
this.OnError("websocket error", e.Exception);
|
||||
}
|
||||
|
||||
protected override void Write(System.Collections.Immutable.ImmutableList<Parser.Packet> packets)
|
||||
{
|
||||
Writable = false;
|
||||
foreach (var packet in packets)
|
||||
{
|
||||
Parser.Parser.EncodePacket(packet, new WriteEncodeCallback(this));
|
||||
}
|
||||
|
||||
// fake drain
|
||||
// defer to next tick to allow Socket to clear writeBuffer
|
||||
//EasyTimer.SetTimeout(() =>
|
||||
//{
|
||||
Writable = true;
|
||||
Emit(EVENT_DRAIN);
|
||||
//}, 1);
|
||||
}
|
||||
|
||||
public class WriteEncodeCallback : IEncodeCallback
|
||||
{
|
||||
private WebSocket webSocket;
|
||||
|
||||
public WriteEncodeCallback(WebSocket webSocket)
|
||||
{
|
||||
this.webSocket = webSocket;
|
||||
}
|
||||
|
||||
public void Call(object data)
|
||||
{
|
||||
//var log = LogManager.GetLogger(Global.CallerName());
|
||||
|
||||
if (data is string)
|
||||
{
|
||||
webSocket.ws.Send((string)data);
|
||||
}
|
||||
else if (data is byte[])
|
||||
{
|
||||
var d = (byte[])data;
|
||||
|
||||
//try
|
||||
//{
|
||||
// var dataString = BitConverter.ToString(d);
|
||||
// //log.Info(string.Format("WriteEncodeCallback byte[] data {0}", dataString));
|
||||
//}
|
||||
//catch (Exception e)
|
||||
//{
|
||||
// log.Error(e);
|
||||
//}
|
||||
|
||||
webSocket.ws.Send(d, 0, d.Length);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected override void DoClose()
|
||||
{
|
||||
if (ws != null)
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
ws.Close();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
var log = LogManager.GetLogger(Global.CallerName());
|
||||
log.Info("DoClose ws.Close() Exception= " + e.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public string Uri()
|
||||
{
|
||||
Dictionary<string, string> query = null;
|
||||
query = this.Query == null ? new Dictionary<string, string>() : new Dictionary<string, string>(this.Query);
|
||||
var schema = this.Secure ? "wss" : "ws";
|
||||
var portString = "";
|
||||
|
||||
if (this.TimestampRequests)
|
||||
{
|
||||
query.Add(this.TimestampParam, DateTime.Now.Ticks.ToString() + "-" + Transport.Timestamps++);
|
||||
}
|
||||
|
||||
var _query = ParseQS.Encode(query);
|
||||
|
||||
if (this.Port > 0 && (("wss" == schema && this.Port != 443)
|
||||
|| ("ws" == schema && this.Port != 80)))
|
||||
{
|
||||
portString = ":" + this.Port;
|
||||
}
|
||||
|
||||
if (_query.Length > 0)
|
||||
{
|
||||
_query = "?" + _query;
|
||||
}
|
||||
|
||||
return schema + "://" + this.Hostname + portString + this.Path + _query;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard1.3</TargetFramework>
|
||||
<PackageRequireLicenseAcceptance>True</PackageRequireLicenseAcceptance>
|
||||
<Description>This is the Engine.IO Client Library for C#.</Description>
|
||||
<PackageProjectUrl>https://github.com/Quobject/EngineIoClientDotNet/</PackageProjectUrl>
|
||||
<Version>1.0.5</Version>
|
||||
<Copyright>Copyright © 2018</Copyright>
|
||||
<RepositoryUrl>https://github.com/Quobject/EngineIoClientDotNet/</RepositoryUrl>
|
||||
<AssemblyVersion>1.0.5.0</AssemblyVersion>
|
||||
<FileVersion>1.0.5.0</FileVersion>
|
||||
<RootNamespace>Quobject.EngineIoClientDotNet</RootNamespace>
|
||||
<AssemblyName>EngineIoClientDotNet</AssemblyName>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="..\EngineIoClientDotNet.mono\Client\EngineIOException.cs" Link="Client\EngineIOException.cs" />
|
||||
<Compile Include="..\EngineIoClientDotNet.mono\Client\HandshakeData.cs" Link="Client\HandshakeData.cs" />
|
||||
<Compile Include="..\EngineIoClientDotNet.mono\Client\Socket.cs" Link="Client\Socket.cs" />
|
||||
<Compile Include="..\EngineIoClientDotNet.mono\Client\Transport.cs" Link="Client\Transport.cs" />
|
||||
<Compile Include="..\EngineIoClientDotNet.mono\Client\Transports\Polling.cs" Link="Client\Transports\Polling.cs" />
|
||||
<Compile Include="..\EngineIoClientDotNet.mono\Client\Transports\PollingXHR_netstandard.cs" Link="Client\Transports\PollingXHR_netstandard.cs" />
|
||||
<Compile Include="..\EngineIoClientDotNet.mono\ComponentEmitter\Emitter.cs" Link="ComponentEmitter\Emitter.cs" />
|
||||
<Compile Include="..\EngineIoClientDotNet.mono\Modules\Global.cs" Link="Modules\Global.cs" />
|
||||
<Compile Include="..\EngineIoClientDotNet.mono\Modules\LogManager.cs" Link="Modules\LogManager.cs" />
|
||||
<Compile Include="..\EngineIoClientDotNet.mono\Modules\ParseQS.cs" Link="Modules\ParseQS.cs" />
|
||||
<Compile Include="..\EngineIoClientDotNet.mono\Modules\ServerCertificate_netstandard.cs" Link="Modules\ServerCertificate_netstandard.cs" />
|
||||
<Compile Include="..\EngineIoClientDotNet.mono\Modules\UTF8.cs" Link="Modules\UTF8.cs" />
|
||||
<Compile Include="..\EngineIoClientDotNet.mono\Modules\UTF8Exception.cs" Link="Modules\UTF8Exception.cs" />
|
||||
<Compile Include="..\EngineIoClientDotNet.mono\Parser\Buffer.cs" Link="Parser\Buffer.cs" />
|
||||
<Compile Include="..\EngineIoClientDotNet.mono\Parser\ByteBuffer.cs" Link="Parser\ByteBuffer.cs" />
|
||||
<Compile Include="..\EngineIoClientDotNet.mono\Parser\IDecodePayloadCallback.cs" Link="Parser\IDecodePayloadCallback.cs" />
|
||||
<Compile Include="..\EngineIoClientDotNet.mono\Parser\IEncodeCallback.cs" Link="Parser\IEncodeCallback.cs" />
|
||||
<Compile Include="..\EngineIoClientDotNet.mono\Parser\Packet.cs" Link="Parser\Packet.cs" />
|
||||
<Compile Include="..\EngineIoClientDotNet.mono\Parser\Parser.cs" Link="Parser\Parser.cs" />
|
||||
<Compile Include="..\EngineIoClientDotNet.mono\Thread\EasyTimer.cs" Link="Thread\EasyTimer.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="ComponentEmitter\" />
|
||||
<Folder Include="Parser\" />
|
||||
<Folder Include="Thread\" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Newtonsoft.Json" Version="9.0.1" />
|
||||
<PackageReference Include="System.Collections.Immutable" Version="1.4.0" />
|
||||
<PackageReference Include="WebSocket4Net" Version="0.15.1" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,28 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 15
|
||||
VisualStudioVersion = 15.0.26430.16
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EngineIoClientDotNet.netstandard1.3", "EngineIoClientDotNet.netstandard1.3.csproj", "{A5BEDC19-D3BF-4B34-9228-6D50B433D916}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EngineIoClientDotNet.Tests.netstandard1.3", "..\EngineIoClientDotNet.Tests.netstandard1.3\EngineIoClientDotNet.Tests.netstandard1.3.csproj", "{B21BAF12-47BE-4874-83FB-D9918710BD0A}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{A5BEDC19-D3BF-4B34-9228-6D50B433D916}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{A5BEDC19-D3BF-4B34-9228-6D50B433D916}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{A5BEDC19-D3BF-4B34-9228-6D50B433D916}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{A5BEDC19-D3BF-4B34-9228-6D50B433D916}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{B21BAF12-47BE-4874-83FB-D9918710BD0A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{B21BAF12-47BE-4874-83FB-D9918710BD0A}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{B21BAF12-47BE-4874-83FB-D9918710BD0A}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{B21BAF12-47BE-4874-83FB-D9918710BD0A}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
Reference in New Issue
Block a user