# TRROMediaObserver

Description:

  - TRROMediaObserver Interface

TRROMediaObserver Interface

### Methods

#### onMqttConnectionState(param) → {function}

Description:

  - MQTT connection state callback

##### Parameters:

Name | Type | Description
--- | --- | ---
`param` | Object | ###### Properties
Name | Type | Attributes | Description
--- | --- | --- | ---
`state` | MqttConnectionState |  | MQTT connection state
`message` | string | <optional> | Related information

##### Returns:

Type
  function

#### onSignalingState(param, roomId) → {function}

Description:

  - Signaling state callback

##### Parameters:

Name | Type | Description
--- | --- | ---
`param` | Object |
`roomId` | string | Signaling room ID
`param.state` | string | socket.io-client built-in events, refer to: https://socket.io/docs/v2/client-api/#events
`param.data` | Object | Parameters for socket.io-client built-in events, refer to: https://socket.io/docs/v2/client-api/#events

##### Returns:

Type
  function

#### onPeerConnectionState(param) → {function}

Description:

  - Peer connection state change callback

    CONNECTED = 0 Connection successful
    NEW = 1 New connection
    CONNECTING = 2 Connecting
    FAILED = 3 Connection failed
    DISCONNECTED = 4 Connection disconnected
    CLOSED = 5 Actively closed
    RECONNECTING = 6 Reconnecting
    NOT_SUPPORT = 255 Browser doesn't support WebRTC
    LIMIT_EXCEEDED = 256 PeerConnection count has reached browser limit

##### Parameters:

Name | Type | Description
--- | --- | ---
`param` | Object | Connection state code ###### Properties
Name | Type | Attributes | Description
--- | --- | --- | ---
`deviceId` | string |  | Field device ID. In public cloud mode, format is `${projectId}/${fieldDeviceId}`
`streamId` | number | <optional> | Stream ID (only available in server2 mode)
`mediaType` | MediaType | <optional> | Stream type (only available in server2 mode)
`state` | string |  | Connection state information
`code` | string |  | Connection state code
`message` | string |  | Message
`data` | Object |  | Extended information

##### Returns:

Type
  function

#### onDataChannelState(param) → {void|function}

Description:

  - Data channel state callback

##### Parameters:

Name | Type | Description
--- | --- | ---
`param` | Object | ###### Properties
Name | Type | Attributes | Description
--- | --- | --- | ---
`deviceId` | string |  | Field device ID. In public cloud mode, format is `${projectId}/${fieldDeviceId}`
`state` | string |  | Data channel state: 'open' | 'close' | 'error'
`message` | string | <optional> | Error message
`label` | string |  | Data channel label

##### Returns:

- Type
    void
- Type
    function

#### onConnected(param) → {function}

Description:

  - Field device connection callback

##### Parameters:

Name | Type | Description
--- | --- | ---
`param` | Object | Callback data ###### Properties
Name | Type | Description
--- | --- | ---
`deviceId` | string | Field device ID. In public cloud mode, format is `${projectId}/${fieldDeviceId}`

##### Returns:

Type
  function

#### onDisconnected(param) → {function}

Description:

  - Field device disconnection callback

##### Parameters:

Name | Type | Description
--- | --- | ---
`param` | Object | Callback data ###### Properties
Name | Type | Description
--- | --- | ---
`deviceId` | string | Field device ID. In public cloud mode, format is `${projectId}/${fieldDeviceId}`

##### Returns:

Type
  function

#### onTrackPublishState(param) → {function}

Description:

  - Video stream publish/unpublish callback

##### Parameters:

Name | Type | Description
--- | --- | ---
`param` | Object | Callback data ###### Properties
Name | Type | Description
--- | --- | ---
`state` | string | Stream state 'publish' | 'unpublish'
`deviceId` | string | Field device ID. In public cloud mode, format is `${projectId}/${fieldDeviceId}`
`streamId` | number | Corresponding subscribed stream ID
`mediaType` | MediaType | 'video' | 'audio'

##### Returns:

Type
  function

#### onControlData(param) → {function}

Description:

  - DataChannel custom message callback

##### Parameters:

Name | Type | Description
--- | --- | ---
`param` | Object | Callback data ###### Properties
Name | Type | Description
--- | --- | ---
`deviceId` | string | Field device ID. In public cloud mode, format is `${projectId}/${fieldDeviceId}`
`dataType` | string | Custom message type: 'string' | 'arrayBuffer'
`data` | string | ArrayBuffer | Custom message
`ordered` | boolean | Whether sent through reliable channel

##### Returns:

Type
  function

#### onKick(param) → {function}

Description:

  - Kickout callback

##### Parameters:

Name | Type | Description
--- | --- | ---
`param` | Object | Callback data ###### Properties
Name | Type | Description
--- | --- | ---
`code` | number | Code
`reason` | string | Reason

##### Returns:

Type
  function

#### onPermissionStateChange(param) → {function}

Description:

  - Permission state change callback

##### Parameters:

Name | Type | Description
--- | --- | ---
`param` | Object | Callback data ###### Properties
Name | Type | Description
--- | --- | ---
`deviceId` | string | Field device ID. In public cloud mode, format is `${projectId}/${fieldDeviceId}`
`userId` | string | Remote device ID
`permission` | PermissionState | Permission information

##### Returns:

Type
  function

#### onError(param) → {function}

Description:

  - Error notification

##### Parameters:

Name | Type | Description
--- | --- | ---
`param` | Object | Callback data ###### Properties
Name | Type | Description
--- | --- | ---
`code` | number | Error code
`message` | string | Error message

##### Returns:

Type
  function

#### onEvent(param) → {function}

Description:

  - Event callback

##### Parameters:

Name | Type | Description
--- | --- | ---
`param` | OnEventResponse | Callback data ###### Properties
Name | Type | Description
--- | --- | ---
`type` | string | Event type: autoplay | webrtcStats | gatewayStats | localTrackUnpublished
`data` | Object | Extended information

##### Returns:

Type
  function