Skip to content

Commit

Permalink
Closes #4, adds auto socket restart.
Browse files Browse the repository at this point in the history
  • Loading branch information
kelsos committed Jul 31, 2013
1 parent 5986058 commit 82e49c8
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 1 deletion.
17 changes: 17 additions & 0 deletions AndroidRemote/Commands/Internal/RestartSocketCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using MusicBeePlugin.AndroidRemote.Interfaces;
using MusicBeePlugin.AndroidRemote.Networking;

namespace MusicBeePlugin.AndroidRemote.Commands.Internal
{
class RestartSocketCommand:ICommand
{
public void Execute(IEvent eEvent)
{
SocketServer.Instance.RestartSocket();
}

public void Dispose()
{
}
}
}
1 change: 1 addition & 0 deletions AndroidRemote/Events/EventType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class EventType
public const string InitializeModel = "InitializeModel";
public const string ReplyAvailable = "ReplyAvailable";
public const string StartServiceBroadcast = "StartServiceBroadcast";
public const string RestartSocket = "RestartSocket";

public const string NowPlayingCoverChange = "NowPlayingCoverChange";
public const string NowPlayingLyricsChange = "NowPlayingLyricsChange";
Expand Down
10 changes: 10 additions & 0 deletions AndroidRemote/Networking/SocketServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,16 @@ public void Start()
}
}

/// <summary>
/// Restarts the main socket that is listening for new clients.
/// Useful when the user wants to change the listening port.
/// </summary>
public void RestartSocket()
{
Stop();
Start();
}

// this is the call back function,
private void OnClientConnect(IAsyncResult ar)
{
Expand Down
2 changes: 2 additions & 0 deletions AndroidRemote/Settings/UserSettings.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Globalization;
using System.IO;
using System.Xml;
using MusicBeePlugin.AndroidRemote.Events;

namespace MusicBeePlugin.AndroidRemote.Settings
{
Expand Down Expand Up @@ -236,6 +237,7 @@ public void SaveSettings()
document.Load(GetSettingsFile());
WriteApplicationSetting(document);
document.Save(GetSettingsFile());
EventBus.FireEvent(new MessageEvent(EventType.RestartSocket));
}

private void CreateEmptySettingsFile(string application)
Expand Down
1 change: 1 addition & 0 deletions AndroidRemote/configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public static void Register(Controller.Controller controller)
controller.AddCommand(EventType.NowPlayingLyricsChange, typeof(PLyricsChanged));
controller.AddCommand(EventType.StartServiceBroadcast, typeof(StartServiceBroadcast));
controller.AddCommand(EventType.SocketStatusChange, typeof(SocketStatusChanged));
controller.AddCommand(EventType.RestartSocket, typeof(RestartSocketCommand));
/** Protocol Related commands **/
controller.AddCommand(Constants.Player, typeof (RequestPlayer));
controller.AddCommand(Constants.Protocol, typeof (RequestProtocol));
Expand Down
3 changes: 2 additions & 1 deletion mbrc-server.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
<Reference Include="System.Core" />
</ItemGroup>
<ItemGroup>
<Compile Include="AndroidRemote\Commands\Internal\RestartSocketCommand.cs" />
<Compile Include="AndroidRemote\Commands\Internal\SocketStatusChanged.cs" />
<Compile Include="AndroidRemote\Commands\Internal\StartServiceBroadcast.cs" />
<Compile Include="AndroidRemote\Commands\ReplayAvailable.cs" />
Expand Down Expand Up @@ -230,7 +231,7 @@
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<ProjectExtensions>
<VisualStudio>
<UserProperties BuildVersion_UpdateFileVersion="True" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_ConfigurationName="Any" BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" BuildVersion_BuildVersioningStyle="None.None.None.Increment" />
<UserProperties BuildVersion_BuildVersioningStyle="None.None.None.Increment" BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" BuildVersion_ConfigurationName="Any" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_UpdateFileVersion="True" />
</VisualStudio>
</ProjectExtensions>
<Import Project="$(SolutionDir)\.nuget\nuget.targets" />
Expand Down

0 comments on commit 82e49c8

Please sign in to comment.