Skip to content

Commit

Permalink
add 48
Browse files Browse the repository at this point in the history
  • Loading branch information
luvaihassanali committed May 13, 2023
1 parent c56418e commit 67db0e9
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 52 deletions.
26 changes: 2 additions & 24 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
MIT License - SamsungRemote https://github.com/luvaihassanali/SamsungRemote
MIT License - SamsungRemote

Copyright (c) 2023 Luvai Hassanali

Expand All @@ -18,26 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

The MIT License (MIT) - websocket-sharp https://github.com/sta/websocket-sharp

Copyright (c) 2010-2023 sta.blockhead

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
SOFTWARE.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# SamsungRemote
# Overview

SamsungRemote is a .NET 6.0 library used to communicate with Samsung TV over Wi-Fi. WebSocket client is used to maintain connection to TV which is implemented using fork of [websocket-sharp](https://github.com/sta/websocket-sharp).
SamsungRemote is a .NET library used to communicate with Samsung TV over Wi-Fi. WebSocket client is used to maintain connection to TV which is implemented using [websocket-sharp](https://github.com/sta/websocket-sharp).
## Features
- Compatible with authentication protocol defined here: [Samsung TV network remote control protocol by sc0ty](http://sc0ty.pl/2012/02/samsung-tv-network-remote-control-protocol/)
- Turn on TV by sending Wake-On-Lan Magic Packet using MAC address
Expand Down
8 changes: 1 addition & 7 deletions SamsungRemote.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ VisualStudioVersion = 17.5.33530.505
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SamsungRemote", "SamsungRemote\SamsungRemote.csproj", "{57155D51-6511-4951-9C9F-91C7B25CE15D}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "websocket-sharp", "websocket-sharp-net6.0\websocket-sharp\websocket-sharp.csproj", "{55A26149-3FF6-4800-A0D6-69C24E816794}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SamsungRemoteDemo", "SamsungRemoteDemo\SamsungRemoteDemo.csproj", "{A97403FC-003A-4C81-A419-F9646245A940}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SamsungRemoteDemo", "SamsungRemoteDemo\SamsungRemoteDemo.csproj", "{A97403FC-003A-4C81-A419-F9646245A940}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -19,10 +17,6 @@ Global
{57155D51-6511-4951-9C9F-91C7B25CE15D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{57155D51-6511-4951-9C9F-91C7B25CE15D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{57155D51-6511-4951-9C9F-91C7B25CE15D}.Release|Any CPU.Build.0 = Release|Any CPU
{55A26149-3FF6-4800-A0D6-69C24E816794}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{55A26149-3FF6-4800-A0D6-69C24E816794}.Debug|Any CPU.Build.0 = Debug|Any CPU
{55A26149-3FF6-4800-A0D6-69C24E816794}.Release|Any CPU.ActiveCfg = Release|Any CPU
{55A26149-3FF6-4800-A0D6-69C24E816794}.Release|Any CPU.Build.0 = Release|Any CPU
{A97403FC-003A-4C81-A419-F9646245A940}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A97403FC-003A-4C81-A419-F9646245A940}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A97403FC-003A-4C81-A419-F9646245A940}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down
20 changes: 10 additions & 10 deletions SamsungRemote/SamsungRemote.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ public class SamsungRemote : IDisposable
private string websocketUrl;
private bool wolEndpointSet;
private byte[] macAddrBytes;
private IPEndPoint? wolEndpoint;
private WebSocket? websocket;
private IPEndPoint wolEndpoint;
private WebSocket websocket;
private Settings settings;

public SamsungRemote(Settings s)
Expand Down Expand Up @@ -42,12 +42,12 @@ public void Connect()

public void Press(string key)
{
if (settings.Token == null) throw new ArgumentNullException("Token is ***null*** execute Connect() before pressing keys");
if (settings.Token == null) throw new ArgumentNullException("Token is ***null***");
Parameters parameters = new Parameters(key);
Command cmd = new Command(parameters);
string data = JsonConvert.SerializeObject(cmd).Replace("parameters", "params");
Log("Sending key: " + key);
websocket?.Send(data);
websocket.Send(data);
}

public void GenerateNewToken()
Expand All @@ -70,10 +70,10 @@ public async Task GenerateNewTokenAsync()
{
JObject response = JObject.Parse(e.Data);
Log("OnMessage data: " + e.Data.Trim());
string method = response?["event"]?.ToString() ?? String.Empty;
string method = response?["event"].ToString() ?? String.Empty;
if (method.Equals("ms.channel.connect"))
{
string newToken = response?["data"]?["token"]?.ToString() ?? String.Empty;
string newToken = response["data"]["token"].ToString() ?? String.Empty;
settings.Token = newToken;
Log($"New token {settings.Token} generated");
websocketUrl += $"&token={settings.Token}";
Expand Down Expand Up @@ -231,7 +231,7 @@ public byte[] CreateMagicPacket(byte[] macAddress)
return packet;
}

private void Websocket_OnError(object? sender, WebSocketSharp.ErrorEventArgs e)
private void Websocket_OnError(object sender, WebSocketSharp.ErrorEventArgs e)
{
Debug.WriteLine($"WebSocket error: {e.Message}");
}
Expand All @@ -254,7 +254,7 @@ protected virtual void Dispose(bool disposing)
{
if (disposing)
{
websocket?.Close();
websocket.Close();
}
}
}
Expand All @@ -267,10 +267,10 @@ public class Settings
public string MacAddr { get; set; }
public int Port { get; set; }
public string Subnet { get; set; }
public string? Token { get; set; }
public string Token { get; set; }
public bool Debug { get; set; }

public Settings(string appName, string ipAddr, string subnet, string macAddr, int port, string? token, bool debug)
public Settings(string appName, string ipAddr, string subnet, string macAddr, int port, string token, bool debug)
{
byte[] appNameBytes = System.Text.Encoding.UTF8.GetBytes(appName);
AppName = Convert.ToBase64String(appNameBytes);
Expand Down
12 changes: 8 additions & 4 deletions SamsungRemote/SamsungRemote.csproj
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFrameworks>net48;net6.0</TargetFrameworks>
<PackageVersion>1.0.2</PackageVersion>
<LangVersion>10.0</LangVersion>
<Nullable>enable</Nullable>
<NullableContextOptions>enable</NullableContextOptions>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AssemblyOriginatorKeyFile>SamsungRemote.snk</AssemblyOriginatorKeyFile>
<RootNamespace>$(MSBuildProjectName.Replace(" ", "_"))Lib</RootNamespace>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Title>$(AssemblyName)</Title>
<Authors>Luvai Hassanali</Authors>
<Company>Luvai Hassanali</Company>
<Description>.NET 6.0 library used to communicate with Samsung TV over Wi-Fi</Description>
<Description>.NET library used to communicate with Samsung TV over Wi-Fi</Description>
<RepositoryUrl>https://github.com/luvaihassanali/SamsungRemote</RepositoryUrl>
<PackageTags>c-sharp;http;control;remote-control;csharp;tcp;https;websocket;websockets;remote;wifi;netcore;ip;samsung;samsung-tv;wi-fi;tcp-ip;net-core;samsung-remote</PackageTags>
<PackageReadmeFile>README.md</PackageReadmeFile>
Expand All @@ -29,10 +32,11 @@

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="WebSocketSharp" Version="1.0.3-rc11" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\websocket-sharp-net6.0\websocket-sharp\websocket-sharp.csproj" />
<Reference Include="System.Net.Http" />
</ItemGroup>

</Project>
6 changes: 3 additions & 3 deletions SamsungRemoteDemo/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ private static void Main(string[] args)
{
break;
}
string[] inputKeys = inputKey.Contains(';') ? inputKey.Split(";") : new string[] { inputKey };
string[] inputKeys = inputKey.Contains(';') ? inputKey.Split(';') : new string[] { inputKey };
for (int i = 0; i < inputKeys.Length; i++)
{
string key = inputKeys[i].Trim();
Expand All @@ -86,7 +86,7 @@ private static void Main(string[] args)
}

// Turn off TV
remote.Press(Keys.POWER);
//remote.Press(Keys.POWER);

// After first token generation, new token value is saved in settings.Token
// When SamsungRemote constructor is called on next launch with token that is already paired, TV will not prompt user to accept connection again
Expand All @@ -102,7 +102,7 @@ private static void GenerateKeylist()
Console.WriteLine("Key list:");
Type t = typeof(Keys);
MemberInfo[] memberInfo = t.GetMembers();
string[] exceptionList = "GetType ToString Equals GetHashCode 0 1 2 3 4 5 6 7 8 9 POWER POWEROFF SOURCE PLUS100 PRECH VOLUP VOLDOWN MUTE CH_LIST CHDOWN CHUP HOME W_LINK GUIDE LEFT UP RIGHT DOWN ENTER RETURN EXIT SETTINGS INFO SUB_TITLE STOP REWIND FF PLAY PAUSE".Split(" ");
string[] exceptionList = "GetType ToString Equals GetHashCode 0 1 2 3 4 5 6 7 8 9 POWER POWEROFF SOURCE PLUS100 PRECH VOLUP VOLDOWN MUTE CH_LIST CHDOWN CHUP HOME W_LINK GUIDE LEFT UP RIGHT DOWN ENTER RETURN EXIT SETTINGS INFO SUB_TITLE STOP REWIND FF PLAY PAUSE".Split(' ');
foreach (MemberInfo member in memberInfo)
{
string name = member.Name.Replace("get_", "KEY_");
Expand Down
16 changes: 14 additions & 2 deletions SamsungRemoteDemo/SamsungRemoteDemo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,18 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<TargetFrameworks>net48;net6.0</TargetFrameworks>
<LangVersion>10.0</LangVersion>
<Nullable>enable</Nullable>
<NullableContextOptions>enable</NullableContextOptions>
<ImplicitUsings>enable</ImplicitUsings>
<SignAssembly>True</SignAssembly>
<GeneratePackageOnBuild>False</GeneratePackageOnBuild>
<Title>SamsungRemote</Title>
<Company>Luvai Hassanali</Company>
<Description>Demo for Samsung Library (.NET library used to communicate with Samsung TV over Wi-Fi)</Description>
<RepositoryUrl>https://github.com/luvaihassanali/SamsungRemote</RepositoryUrl>
<PackageTags>c-sharp;http;control;remote-control;csharp;tcp;https;websocket;websockets;remote;wifi;netcore;ip;samsung;samsung-tv;wi-fi;tcp-ip;net-core;samsung-remote</PackageTags>
</PropertyGroup>

<ItemGroup>
Expand All @@ -16,6 +24,10 @@
<ProjectReference Include="..\SamsungRemote\SamsungRemote.csproj" />
</ItemGroup>

<ItemGroup>
<Reference Include="System.Net.Http" />
</ItemGroup>

<ItemGroup>
<None Update="App.config">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
Expand Down
1 change: 0 additions & 1 deletion websocket-sharp-net6.0
Submodule websocket-sharp-net6.0 deleted from 8b0c70

0 comments on commit 67db0e9

Please sign in to comment.