Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions Assets/AltTester/Runtime/AltDriver/Communication/BaseDriver.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
Copyright(C) 2023 Altom Consulting

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

using System;
using System.Diagnostics;
using AltTester.AltTesterUnitySDK.Driver.Logging;

namespace AltTester.AltTesterUnitySDK.Driver.Communication
{
public class BaseDriver
{
protected static readonly NLog.Logger Logger = DriverLogManager.Instance.GetCurrentClassLogger();

protected DriverWebSocketClient WsClient = null;

protected bool isRunning = false;

public bool IsRunning { get { return this.isRunning; } }
public bool IsAlive { get { return this.WsClient != null && this.WsClient.IsAlive; } }

public event EventHandler<byte[]> OnMessage;
public event EventHandler<String> OnMessageData;
protected string path;

public BaseDriver(string path)
{
this.path = path;
}

public void Close()
{
Logger.Info(string.Format("Closing connection to AltTester on: '{0}'.", this.WsClient.URI));

this.isRunning = false;
this.WsClient.Close();
}

public void Connect(string host, int port, string appName, int connectTimeout, string platform, string platformVersion, string deviceInstanceId, string appId)
{
this.isRunning = false;
UnityEngine.Debug.Log("Path: " + path);
this.WsClient = new DriverWebSocketClient(host, port, path, appName, connectTimeout, platform, platformVersion, deviceInstanceId, appId);
this.WsClient.OnMessage += (sender, e) =>
{
if (e.IsText)
{
OnMessageData.Invoke(this, e.Data);
return;
}
this.OnMessage.Invoke(this, e.RawData);
};
this.WsClient.Connect();
}



}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
Copyright(C) 2023 Altom Consulting

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

namespace AltTester.AltTesterUnitySDK.Driver.Communication
{
public class GetConnectedAppDriver : BaseDriver
{
private new string path = "/altws/connected-app";

public GetConnectedAppDriver(string path) : base(path)
{
}
public void Send()
{
WsClient.Send("GetApps");
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -15,68 +15,40 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Threading;
using AltTester.AltTesterUnitySDK.Driver.Logging;
using Newtonsoft.Json;

namespace AltTester.AltTesterUnitySDK.Driver.Communication
{
public class LiveUpdateDriver
{
private static readonly NLog.Logger logger = DriverLogManager.Instance.GetCurrentClassLogger();

private DriverWebSocketClient wsClient = null;

public event EventHandler<byte[]> OnMessage;

private bool isRunning = false;

public bool IsRunning { get { return this.isRunning; } }
public bool IsAlive { get { return this.wsClient != null && this.wsClient.IsAlive; } }

public void Connect(string host, int port, string appName, int connectTimeout, string platform, string platformVersion, string deviceInstanceId, string appId)
{
this.isRunning = false;
this.wsClient = new DriverWebSocketClient(host, port, "/altws/live-update", appName, connectTimeout, platform, platformVersion, deviceInstanceId, appId);
this.wsClient.OnMessage += (sender, e) =>
{
this.OnMessage.Invoke(this, e.RawData);
};
this.wsClient.Connect();
}

public void Close()
public class LiveUpdateDriver : BaseDriver
{
public LiveUpdateDriver(string path) : base(path)
{
logger.Info(string.Format("Closing connection to AltTester on: '{0}'.", this.wsClient.URI));

this.isRunning = false;
this.wsClient.Close();
}

public void Start()
{
this.wsClient.Send("Start");
this.WsClient.Send("Start");
this.isRunning = true;
}

public void Stop()
{
this.wsClient.Send("Stop");
this.WsClient.Send("Stop");
this.isRunning = false;
}

public void UpdateFrameRate(int frameRate)
{
this.wsClient.Send(string.Format("FrameRate:{0}", frameRate));
this.WsClient.Send(string.Format("FrameRate:{0}", frameRate));
}

public void UpdateQuality(int quality)
{
this.wsClient.Send(string.Format("Quality:{0}", quality));
this.WsClient.Send(string.Format("Quality:{0}", quality));
}
}
}
4 changes: 2 additions & 2 deletions Assets/AltTester/Runtime/AltDriver/Communication/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ public static Uri CreateURI(string host, int port, string path, string appName,
{
if (!Uri.TryCreate(string.Format("ws://{0}:{1}{2}?appName={3}&platform={4}&platformVersion={5}&deviceInstanceId={6}", host, port, path, Uri.EscapeDataString(appName), Uri.EscapeDataString(platform), Uri.EscapeDataString(platformVersion), Uri.EscapeDataString(deviceInstanceId)), UriKind.Absolute, out uri))
{
throw new Exception(String.Format("Invalid host or port {0}:{1}", host, port));
throw new Exception(String.Format("Invalid host or port {0}:{1}{2}", host, port, path));
}
}
else
{
if (!Uri.TryCreate(string.Format("ws://{0}:{1}{2}?appName={3}&platform={4}&platformVersion={5}&deviceInstanceId={6}&appId={7}", host, port, path, Uri.EscapeDataString(appName), Uri.EscapeDataString(platform), Uri.EscapeDataString(platformVersion), Uri.EscapeDataString(deviceInstanceId), Uri.EscapeDataString(appId)), UriKind.Absolute, out uri))
{
throw new Exception(String.Format("Invalid host or port {0}:{1}", host, port));
throw new Exception(String.Format("Invalid host or port {0}:{1}{2}", host, port, path));
}
}

Expand Down