Disruptive Documentation

Class Device​Event​Stream

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)")
}
%27 DeviceEventStream DeviceEventStream NSObject NSObject DeviceEventStream->NSObject URLSessionDataDelegate URLSessionDataDelegate DeviceEventStream->URLSessionDataDelegate

Conforms To

NSObject
URLSessionDataDelegate

Nested Type Aliases

Device​ID

public typealias DeviceID = String

Used to specify that the String argument in the callbacks is the identifier of a device

Properties

on​Touch

public var onTouch              : ((DeviceID, TouchEvent) -> ())? 

Called with the device identifier and the event when a new TouchEvent is received

on​Temperature

public var onTemperature        : ((DeviceID, TemperatureEvent) -> ())? 

Called with the device identifier and the event when a new TemperatureEvent is received

on​Object​Present

public var onObjectPresent      : ((DeviceID, ObjectPresentEvent) -> ())? 

Called with the device identifier and the event when a new ObjectPresentEvent is received

on​Humidity

public var onHumidity           : ((DeviceID, HumidityEvent) -> ())? 

Called with the device identifier and the event when a new HumidityEvent is received

on​Object​Present​Count

public var onObjectPresentCount : ((DeviceID, ObjectPresentCountEvent) -> ())? 

Called with the device identifier and the event when a new ObjectPresentCountEvent is received

on​Touch​Count

public var onTouchCount         : ((DeviceID, TouchCountEvent) -> ())? 

Called with the device identifier and the event when a new TouchCountEvent is received

on​Water​Present

public var onWaterPresent       : ((DeviceID, WaterPresentEvent) -> ())? 

Called with the device identifier and the event when a new WaterPresentEvent is received

on​Network​Status

public var onNetworkStatus      : ((DeviceID, NetworkStatusEvent) -> ())? 

Called with the device identifier and the event when a new NetworkStatusEvent is received

on​Battery​Status

public var onBatteryStatus      : ((DeviceID, BatteryStatusEvent) -> ())? 

Called with the device identifier and the event when a new BatteryStatusEvent is received

on​Labels​Changed

public var onLabelsChanged      : ((DeviceID, LabelsChangedEvent) -> ())? 

Called with the device identifier and the event when a new LabelsChangedEvent is received

on​Connection​Status

public var onConnectionStatus   : ((DeviceID, ConnectionStatusEvent) -> ())? 

Called with the device identifier and the event when a new ConnectionStatusEvent is received

on​Ethernet​Status

public var onEthernetStatus     : ((DeviceID, EthernetStatusEvent) -> ())? 

Called with the device identifier and the event when a new EthernetStatusEvent is received

on​Cellular​Status

public var onCellularStatus     : ((DeviceID, CellularStatusEvent) -> ())? 

Called with the device identifier and the event when a new CellularStatusEvent is received

on​Error

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.

url​Session(_:​data​Task:​did​Receive:​)

public func urlSession(
        _ session: URLSession,
        dataTask: URLSessionDataTask,
        didReceive data: Data) 

url​Session(_:​task:​did​Complete​With​Error:​)

public func urlSession(
        _ session: URLSession,
        task: URLSessionTask,
        didCompleteWithError error: Error?)