Skip to content

Commit

Permalink
Moved streaming config to .ini.
Browse files Browse the repository at this point in the history
  • Loading branch information
freezy committed Jan 25, 2017
1 parent 61df43e commit 270838f
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 15 deletions.
9 changes: 2 additions & 7 deletions LibDmd/Output/Network/BrowserStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,17 @@ public class BrowserStream : IGray2Destination, IGray4Destination, IColoredGray2

private static readonly NLog.Logger Logger = LogManager.GetCurrentClassLogger();

public BrowserStream()
public BrowserStream(int port)
{
// map embedded www resources to _www
const string prefix = "LibDmd.Output.Network.www.";
Logger.Info("Resource names = {0}", string.Join(", ", _assembly.GetManifestResourceNames())); // LibDmd.Output.Network.www.index.html
_assembly.GetManifestResourceNames()
.Where(res => res.StartsWith(prefix))
.ToList()
.ForEach(res => _www["/" + res.Substring(prefix.Length)] = res);
_www["/"] = prefix + "index.html";

Logger.Debug("Allowed Paths: {0}", string.Join(", ", _www.Keys));

_server = new HttpServer(9090) {
RootPath = "."
};
_server = new HttpServer(port);
_server.OnGet += (sender, e) => {

var req = e.Request;
Expand Down
1 change: 0 additions & 1 deletion LibDmd/Output/Network/VpdbStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public class VpdbStream : IGray2Destination, IGray4Destination, IColoredGray2Des

public string ApiKey { get; set; }
public string EndPoint { get; set; } = "https://api-test.vpdb.io/";
//public string EndPoint { get; set; } = "http://127.0.0.1:3000/";
public string AuthUser { get; set; }
public string AuthPass { get; set; }

Expand Down
2 changes: 1 addition & 1 deletion LibDmd/Output/Network/www/main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var url = "ws://localhost:9090/dmd";
var url = 'ws://' + window.location.host + '/dmd';
var typeSet = {
'jBinary.littleEndian': true,
gray2Planes: {
Expand Down
21 changes: 20 additions & 1 deletion PinMameDevice/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public string GameName {
}
public GameConfig GameConfig { get; private set; }
public readonly VpdbConfig VpdbStream;
public readonly BrowserConfig BrowserStream;

private readonly string _iniPath;
private readonly FileIniDataParser _parser;
Expand All @@ -43,7 +44,13 @@ public Configuration()
var assemblyPath = Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath);
_iniPath = Path.Combine(assemblyPath, "DmdDevice.ini");
_parser = new FileIniDataParser();
_data = File.Exists(_iniPath) ? _parser.ReadFile(_iniPath) : new IniData();

try {
_data = File.Exists(_iniPath) ? _parser.ReadFile(_iniPath) : new IniData();
} catch (Exception e) {
Logger.Error(e, "Error parsing .ini file at {0}: {1}", _iniPath, e.Message);
_data = new IniData();
}

Global = new GlobalConfig(_data, this);
VirtualDmd = new VirtualDmdConfig(_data, this);
Expand All @@ -53,6 +60,7 @@ public Configuration()
Pin2Dmd = new Pin2DmdConfig(_data, this);
Video = new VideoConfig(_data, this);
VpdbStream = new VpdbConfig(_data, this);
BrowserStream = new BrowserConfig(_data, this);
}

public void Save()
Expand Down Expand Up @@ -156,11 +164,22 @@ public VideoConfig(IniData data, Configuration parent) : base(data, parent)
{
}
}

public class BrowserConfig : AbstractConfiguration
{
public override string Name { get; } = "browserstream";
public bool Enabled => GetBoolean("enabled", false);
public int Port => GetInt("port", 9090);
public BrowserConfig(IniData data, Configuration parent) : base(data, parent)
{
}
}

public class VpdbConfig : AbstractConfiguration
{
public override string Name { get; } = "vpdbstream";
public bool Enabled => GetBoolean("enabled", false);
public string EndPoint => GetString("endpoint", "https://api-test.vpdb.io/");
public VpdbConfig(IniData data, Configuration parent) : base(data, parent)
{
}
Expand Down
8 changes: 7 additions & 1 deletion PinMameDevice/DmdDevice.ini
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,15 @@ port =
; if false, doesn't bother looking for a PIN2DMD
enabled = true

[browserstream]
; if enabled, stream to your browser in your LAN
enabled = false
port = 9090

[vpdbstream]
; if enabled, stream DMD to https://vpdb.io/live
; if enabled, stream DMD to https://test.vpdb.io/live
enabled = false
endpoint = https://api-test.vpdb.io/

[video]
; if enabled, writes frames to an .avi file
Expand Down
10 changes: 6 additions & 4 deletions PinMameDevice/DmdExt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class DmdExt
private const int Width = 128;
private const int Height = 32;

private readonly Configuration _config = new Configuration();
private readonly Configuration _config;
private readonly VpmGray2Source _vpmGray2Source = new VpmGray2Source();
private readonly VpmGray4Source _vpmGray4Source = new VpmGray4Source();
private readonly VpmRgb24Source _vpmRgb24Source = new VpmRgb24Source();
Expand Down Expand Up @@ -73,8 +73,8 @@ public DmdExt()

} else {
NLog.Config.SimpleConfigurator.ConfigureForTargetLogging(MemLogger, LogLevel.Debug);

}
_config = new Configuration();
_altcolorPath = GetColorPath();
}

Expand Down Expand Up @@ -231,9 +231,11 @@ private void SetupGraphs()
}
}
if (_config.VpdbStream.Enabled) {
renderers.Add(new VpdbStream());
renderers.Add(new VpdbStream { EndPoint = _config.VpdbStream.EndPoint });
}
if (_config.BrowserStream.Enabled) {
renderers.Add(new BrowserStream(_config.BrowserStream.Port));
}
renderers.Add(new BrowserStream());

if (renderers.Count == 0) {
Logger.Error("No renderers found, exiting.");
Expand Down

0 comments on commit 270838f

Please sign in to comment.