This repository has been archived by the owner on Dec 20, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
144 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFrameworks>netcoreapp2.0;net47</TargetFrameworks> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup> | ||
<OutputPath>bin\</OutputPath> | ||
<ApplicationIcon /> | ||
<OutputType>Exe</OutputType> | ||
<StartupObject /> | ||
|
||
<DocumentationFile>bin\$(TargetFramework)\ClientJs.xml</DocumentationFile> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<None Remove="Site\LocalAPI.js" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\Source\WebSocketRPC.JS\WebSocketRPC.JS.csproj" /> | ||
<ProjectReference Include="..\..\Source\WebsocketRPC.Standalone\WebsocketRPC.Standalone.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Update="Site\Index.html"> | ||
<CopyToOutputDirectory>Never</CopyToOutputDirectory> | ||
</None> | ||
</ItemGroup> | ||
|
||
<Import Project="..\SampleBase\SampleBase.projitems" Label="Shared" /> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using SampleBase; | ||
using System; | ||
using System.Diagnostics; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using WebSocketRPC; | ||
|
||
namespace ClientInfoJs | ||
{ | ||
class PlatformInfo | ||
{ | ||
internal async Task InitializeAsync() | ||
{ | ||
var browserInfo = await RPC.For<IBrowserInfo>(this) | ||
.CallAsync(x => x.GetBrowserInfo()); | ||
|
||
Console.WriteLine("\nBrowser info: " + browserInfo.First()); | ||
} | ||
|
||
/* There are no public methods so the API is 'empty' from a client's perspective */ | ||
} | ||
|
||
interface IBrowserInfo | ||
{ | ||
string GetBrowserInfo(); | ||
} | ||
|
||
class Program | ||
{ | ||
//if access denied execute: "netsh http delete urlacl url=http://+:8001/" (delete for 'localhost', add for public address) | ||
//open Index.html to run the client | ||
static void Main(string[] args) | ||
{ | ||
//generate js code (the API is empty) | ||
File.WriteAllText($"./Site/{nameof(PlatformInfo)}.js", RPCJs.GenerateCaller<PlatformInfo>()); | ||
|
||
//start server and bind its local and remote API | ||
var cts = new CancellationTokenSource(); | ||
var t = Server.ListenAsync("http://localhost:8001/", cts.Token, (c, ws) => | ||
{ | ||
var pInfo = new PlatformInfo(); | ||
c.Bind<PlatformInfo, IBrowserInfo>(pInfo); | ||
c.OnOpen += pInfo.InitializeAsync; | ||
}); | ||
|
||
Console.Write("{0} ", nameof(ClientInfoJs)); | ||
Process.Start(new ProcessStartInfo(Path.GetFullPath("./Site/Index.html")) { UseShellExecute= true }); | ||
AppExit.WaitFor(cts, t); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<html> | ||
<head> | ||
<title>Client JS</title> | ||
<script src="PlatformInfo.js"></script> | ||
</head> | ||
|
||
<body> | ||
<p id="msg"></p> | ||
|
||
<script> | ||
function writeMsg(msg, color) | ||
{ | ||
color = color || 'black'; | ||
|
||
var p = document.getElementById("msg"); | ||
p.innerHTML = JSON.stringify(msg, null, "\t"); | ||
p.style.color = color; | ||
} | ||
|
||
//init API | ||
var api = new PlatformInfo("ws://localhost:8001"); | ||
|
||
//implement the interface | ||
api.getBrowserInfo = () => navigator.userAgent; | ||
|
||
//connect | ||
api.connect(() => writeMsg("Connecton established.", 'green'), | ||
err => writeMsg(err, 'red'), | ||
msg => writeMsg(msg)); | ||
</script> | ||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters