Class
DeviceEventStream
public class DeviceEventStream: NSObject
Represent an event stream for a device, and is implemented using Server-Sent Events.
Has callbacks that can be set for each type of event. Note that which event type is available for a device depends on the device type.
Example:
let stream = disruptive.subscribeToDevices(
projectID: "<PROJECT_ID>"
)
stream?.onTemperature = { deviceID, temperatureEvent in
print("Got temperature \(temperatureEvent) for device with id \(deviceID)")
}
Relationships
Conforms To
NSObject
URLSessionDataDelegate
Nested Type Aliases
DeviceID
public typealias DeviceID = String
Used to specify that the String
argument in the callbacks is the identifier of a device
Properties
onTouch
public var onTouch : ((DeviceID, TouchEvent) -> ())?
Called with the device identifier and the event when a new TouchEvent
is received
onTemperature
public var onTemperature : ((DeviceID, TemperatureEvent) -> ())?
Called with the device identifier and the event when a new TemperatureEvent
is received
onObjectPresent
public var onObjectPresent : ((DeviceID, ObjectPresentEvent) -> ())?
Called with the device identifier and the event when a new ObjectPresentEvent
is received
onHumidity
public var onHumidity : ((DeviceID, HumidityEvent) -> ())?
Called with the device identifier and the event when a new HumidityEvent
is received
onObjectPresentCount
public var onObjectPresentCount : ((DeviceID, ObjectPresentCountEvent) -> ())?
Called with the device identifier and the event when a new ObjectPresentCountEvent
is received
onTouchCount
public var onTouchCount : ((DeviceID, TouchCountEvent) -> ())?
Called with the device identifier and the event when a new TouchCountEvent
is received
onWaterPresent
public var onWaterPresent : ((DeviceID, WaterPresentEvent) -> ())?
Called with the device identifier and the event when a new WaterPresentEvent
is received
onNetworkStatus
public var onNetworkStatus : ((DeviceID, NetworkStatusEvent) -> ())?
Called with the device identifier and the event when a new NetworkStatusEvent
is received
onBatteryStatus
public var onBatteryStatus : ((DeviceID, BatteryStatusEvent) -> ())?
Called with the device identifier and the event when a new BatteryStatusEvent
is received
onLabelsChanged
public var onLabelsChanged : ((DeviceID, LabelsChangedEvent) -> ())?
Called with the device identifier and the event when a new LabelsChangedEvent
is received
onConnectionStatus
public var onConnectionStatus : ((DeviceID, ConnectionStatusEvent) -> ())?
Called with the device identifier and the event when a new ConnectionStatusEvent
is received
onEthernetStatus
public var onEthernetStatus : ((DeviceID, EthernetStatusEvent) -> ())?
Called with the device identifier and the event when a new EthernetStatusEvent
is received
onCellularStatus
public var onCellularStatus : ((DeviceID, CellularStatusEvent) -> ())?
Called with the device identifier and the event when a new CellularStatusEvent
is received
onError
public var onError: ((DisruptiveError)-> ())?
Called with an error if the device stream couldn't open
Methods
close()
public func close()
Closes the open connection to the device stream. If the stream had already been closed, nothing will happen. Once a stream has been closed, it can not be re-opened. Create a new stream instead.
urlSession(_:dataTask:didReceive:)
public func urlSession(
_ session: URLSession,
dataTask: URLSessionDataTask,
didReceive data: Data)
urlSession(_:task:didCompleteWithError:)
public func urlSession(
_ session: URLSession,
task: URLSessionTask,
didCompleteWithError error: Error?)