On this page

# TRROMediaObserver

TRROMediaObserver Interface

## Methods

### onMqttConnectionState(param) → {function}

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}

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}

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}

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}

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}

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}

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}

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}

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}

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}

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}

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

Type anything to view search result