# DESIGN

## Class Diagrams

```mermaid
---
title: Client & socket classes
---
classDiagram
  class MotionMasterClient {
    +MotionMasterReqResClient request
    +MotionMasterPubSubClient monitor
    +startMonitoring()
    +stopMonitoring()
  }

  class MotionMasterReqResClient {
    +MotionMasterReqResSocket socket
    note "Has all the request methods\ncorresponding to the proto file."
  }

  class MotionMasterReqResSocket
  <<interface>> MotionMasterReqResSocket
  MotionMasterReqResSocket: +BehaviorSubject~boolean~ opened\$
  MotionMasterReqResSocket: +BehaviorSubject~boolean~ alive\$
  MotionMasterReqResSocket: +Observable~MotionMasterMessage~ message\$
  MotionMasterReqResSocket: +open(string url, number pingSystemInterval?, number systemAliveTimeout?)
  MotionMasterReqResSocket: +close()
  MotionMasterReqResSocket: +send(MotionMasterMessage message)

  class MotionMasterReqResWebSocket {
    note "Keeps the connection alive by\nsending the ping system messages\nin regular intervals."
  }

  class MotionMasterReqResWorkerSocket {
    +Worker worker
    note "Passes messages between\nthe UI and worker thread."
  }

  class MotionMasterPubSubClient {
    +MotionMasterPubSubSocket socket
    +Subject<[string, MotionMasterMessage[]]> data\$
    +Observable~MotionMasterMessage~ notification\$
    +Observable~MotionMasterMessage~ systemEvent\$
    +Observable~MotionMasterMessage~ deviceEvent\$
    +subscribe(MonitoringConfig config)
    +unsubscribe(string messageId)
    +unsubscribeAll()
  }

  class MotionMasterPubSubSocket
  <<interface>> MotionMasterPubSubSocket
  MotionMasterPubSubSocket: +BehaviorSubject~boolean~ opened\$
  MotionMasterPubSubSocket: +Observable<[string, MotionMasterMessage]> data\$
  MotionMasterPubSubSocket: +open(string url)
  MotionMasterPubSubSocket: +close()

  class MotionMasterPubSubWebSocket {
    note "Deserializes incoming data into\na tuple of topic and message."
  }

  class MotionMasterPubSubWorkerSocket {
    +Worker worker
    note "Passes messages between\nthe UI and worker thread."
  }

  MotionMasterClient *-- MotionMasterReqResClient
  MotionMasterClient *-- MotionMasterPubSubClient

  MotionMasterReqResClient *-- MotionMasterReqResSocket
  MotionMasterReqResWebSocket <|-- MotionMasterReqResSocket
  MotionMasterReqResWorkerSocket <|-- MotionMasterReqResSocket

  MotionMasterPubSubClient *-- MotionMasterPubSubSocket
  MotionMasterPubSubWebSocket <|-- MotionMasterPubSubSocket
  MotionMasterPubSubWorkerSocket <|-- MotionMasterPubSubSocket
```
