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
42 lines
1.1 KiB
Swift
42 lines
1.1 KiB
Swift
//
|
|
// ServerProtocol.swift
|
|
// XIONControlPanel
|
|
//
|
|
// Created by James Magahern on 3/13/20.
|
|
// Copyright © 2020 XION. All rights reserved.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
enum ConnectionStatus
|
|
{
|
|
case disconnected
|
|
case connecting
|
|
case connected
|
|
case error
|
|
}
|
|
|
|
protocol Server
|
|
{
|
|
var connectionStatus: ConnectionStatus { get }
|
|
|
|
/// Designated initializer. Takes an API endpoint URL
|
|
init(_ url: URL)
|
|
|
|
/// Attempts to connect to the server at the specified endpoint.
|
|
func connect(_ completion: @escaping (Error?) -> Void)
|
|
|
|
/// Sets server's state as "disconnected"
|
|
func disconnect(_ completion: (Error?) -> Void)
|
|
|
|
/// Fetches a list of all currently configured devices for this server, or returns an error.
|
|
func fetchDevices(_ completion: @escaping (Result<[AnyDevice], Error>) -> Void)
|
|
|
|
/// Tells the server to set the state of a given device to the given state
|
|
func toggleDevice(_ device: AnyDevice, state: DeviceState, completion: @escaping (Error?) -> Void)
|
|
|
|
/// Returns true if this is a device this server is responsible for
|
|
func responsibleForDevice(_ device: AnyDevice) -> Bool
|
|
}
|
|
|