Fixes issue where connectivity issues can lead to persistent "Offline" status in UI

This fixes the problem where either internet connectivity issues on the device or intermittant
server issues can cause a persistent "OFFLINE" indicator even though that is not the case.

This requires the server protocol to be more granular about what their connection status is,
and adds a new signal from the multiplexer to the MainViewController allowing it to notify the
delegate that an acknowledgement was heard from one of the servers, allowing the main view
controller to update its UI according to whatever status best represents the group of servers
as a whole.

Testing
- This can be tested by using the network link conditioner to simulate connection issues
  *after* the control panel has connected to all servers in the multiplex.
- Tested losing internet connection and regaining internet connection
- Tested starting off with no connection and regaining connection later
This commit is contained in:
2020-07-04 19:43:50 -07:00
parent ee29602640
commit d1da677932
5 changed files with 55 additions and 31 deletions
+4 -12
View File
@@ -8,14 +8,6 @@
import Foundation
enum ConnectionStatus
{
case disconnected
case connecting
case connected
case error
}
enum ConnectionError : Error
{
case unknown
@@ -25,11 +17,9 @@ enum ConnectionError : Error
class WemoServer : Server
{
private var devices: [WemoDevice] = []
public var connected: Bool { get { return self.connectionStatus == .connected } }
public var connectionStatus: ConnectionStatus = .disconnected
fileprivate(set) var baseURL: URL
fileprivate(set) var connectionStatus: ConnectionStatus = .disconnected
fileprivate var _urlSession: URLSession
fileprivate var _errorStream: StandardErrorOutputStream = StandardErrorOutputStream()
@@ -48,6 +38,8 @@ class WemoServer : Server
func connect(_ completion: @escaping (Error?) -> Void)
{
if (self.connectionStatus == .disconnected) {
self.connectionStatus = .connecting
let op = ConnectOperation(baseURL: self.baseURL, session: _urlSession)
weak var weakOp = op
op.completionBlock = {
@@ -103,7 +95,7 @@ class WemoServer : Server
func toggleDevice(_ device: AnyDevice, state: DeviceState, completion: @escaping (Error?) -> Void)
{
if self.connected, let device = findDevice(device) {
if connectionStatus == .connected, let device = findDevice(device) {
let op = ToggleDeviceOperation(baseURL: self.baseURL, session: _urlSession, device: device, state: state)
weak var weakOp = op
op.completionBlock = {