Constructor
new TRROSDK(params)
Example
// Minimal public cloud configuration
new TRROSDK({
cloudMode: 'public',
projectId: 'xxxxxxxx',
remoteDeviceId: 'xxxxxxxx',
password: '********',
});
// Minimal private cloud configuration
new TRROSDK({
serverIp: '1.1.1.1',
projectId: 1111,
remoteDeviceId: 'xxxxxxxx',
password: '',
});
Parameters:
| Name | Type | Description | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
params |
Object |
Properties
|
Methods
(async) init()
- Description:
Initialize MQTT connection
Example
init()
Returns:
Promise object
| Name | Type | Description |
|---|---|---|
| code | number | 0 success, 21 MQTT connect error, 26 MQTT already connected, etc. |
| message | string | Description and error information |
setSessionPermissionToken(fieldDeviceId, token) → {void}
- Description:
Set temporary session key for field device
Example
setSessionPermissionToken('xxxxxxxx', '********')
Parameters:
| Name | Type | Description |
|---|---|---|
fieldDeviceId |
string | |
token |
string |
Returns:
- Type
- void
(async) connect(fieldDeviceId)
- Description:
Connect to specified field device
Example
connect('xxxxxxxx')
Parameters:
| Name | Type | Description |
|---|---|---|
fieldDeviceId |
string | Field device ID |
Returns:
Returns Promise object
| Name | Type | Description |
|---|---|---|
| code | number | 0 Already joined, 2 joining, 20 MQTT client not found, 21 MQTT connection error, 100 request error |
| message | string | Description and error message |
(async) subscribe(params)
- Description:
Subscribe to tracks (pull stream)
Example
subscribe({
fieldDeviceId: 'xxxxxxxx',
containers: [{
streamId: 0,
mount: '#test-div-0',
callback: ({latency, metadata}) => {
console.log(latency, metadata);
}
},{
streamId: 1,
mount: '#test-div-1',
callback: ({latency, metadata}) => {
console.log(latency, metadata);
}
}],
audioContainer: '#test-div-audio'
})
Parameters:
| Name | Type | Description | |||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
params |
Object |
Properties
|
Returns:
Returns Promise object
| Name | Type | Description |
|---|---|---|
| code | number | 0 success, 1 unjoined, 2 joining, 3 failed, 4 streams not published, 5 empty containers, 20 MQTT client not found, 21 MQTT not connected, 100 request error |
| message | string | Description and error message |
(async) unsubscribe(params)
- Description:
Unsubscribe from tracks (stop pulling stream)
Example
unsubscribe({ fieldDeviceId: 'xxxxxxxx', streamIds: [0] })
Parameters:
| Name | Type | Description | |||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
params |
Object |
Properties
|
Returns:
Returns Promise object
| Name | Type | Description |
|---|---|---|
| code | number | 0 success, 1 unjoined, 2 joining, 5 empty stream IDs, 20 MQTT client not found, 21 MQTT not connected, 100 request error |
| message | string | Description and error message |
(async) publish(params)
- Description:
Publish audio stream (push stream)
Audio streaming requires successful video subscription first. Unsubscribing all video streams will automatically stop audio publishing viaonEventcallback.
Only one audio stream per SDK instance is allowed.
Requiresmasterpermission viarequestPermissionin server mode.
Example
try {
// Initialize SDK instance
const client = new TRROSDK({ ... });
// Connect to field device
await client.connect('xxxxxxxx');
// Subscribe to video streams
await client.subscribe({ fieldDeviceId: 'xxxxxxxx', containers: [{ streamId: 0, mount: '#test-div-0' }] });
// Get local audio stream
const stream = await navigator.mediaDevices.getUserMedia({ audio: true, video: false });
[audioTrack] = stream.getAudioTracks()
// Publish audio stream
await client.publish({ audioTrack });
} catch () {}
Parameters:
| Name | Type | Description | ||||||
|---|---|---|---|---|---|---|---|---|
params |
Object |
Properties
|
Returns:
Returns Promise object
| Name | Type | Description |
|---|---|---|
| code | number | 0 success, 1 unjoined, 2 joining, etc. |
| message | string | Status description and error information |
(async) unpublish()
- Description:
Unpublish audio stream (stop pushing)
Example
unpublish();
Returns:
Returns Promise object
| Name | Type | Description |
|---|---|---|
| code | number | 0 success, 1 unjoined, 2 joining, etc. |
| message | string | Status description and error information |
(async) muteAudio(params)
- Description:
Mute/unmute specific audio stream
Example
muteAudio({ deviceId: 'xxxxxxxx', muted: true })
Parameters:
| Name | Type | Description | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
params |
Object |
Properties
|
Returns:
Returns Promise object
| Name | Type | Description |
|---|---|---|
| code | number | 0 success, 1 unjoined, 2 joining, etc. |
| message | string | Status description and error information |
(async) disconnect(fieldDeviceId)
- Description:
Disconnect from specific field device
Example
disconnect('xxxxxxxx')
Parameters:
| Name | Type | Description |
|---|---|---|
fieldDeviceId |
string | Field device ID |
Returns:
Returns Promise object
| Name | Type | Description |
|---|---|---|
| code | number | 0 success, 1 unjoined, 3 failed, etc. |
| message | string | Status description and error information |
(async) disconnectAll()
- Description:
Disconnect from all field devices
Example
disconnectAll()
Returns:
Returns Promise object
| Name | Type | Description |
|---|---|---|
| code | number | 0 success, 1 unjoined, 3 failed, etc. |
| message | string | Status description and error information |
(async) destroy()
- Description:
Destroy all connections
Example
destroy()
Returns:
Returns Promise object
| Name | Type | Description |
|---|---|---|
| code | number | 0 success, 1 unjoined, 3 failed, etc. |
| message | string | Status description and error information |
changeFieldDeviceEncodeConfig(fieldDeviceId, params)
- Description:
Temporarily update field device encoding configuration
Changes persist until device reboot
Only modifies specified fields, others remain unchanged
Example
changeFieldDeviceEncodeConfig('xxxxxxxx', [{ streamId: 0, encodeConfig: { minBps: 1000, forceMin: true } }])
Parameters:
| Name | Type | Description | |||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
fieldDeviceId |
string | Field device ID |
|||||||||||||||||||||||||||||||||||||||||||||
params |
Array.<Object> |
Properties
|
Returns:
| Name | Type | Description |
|---|---|---|
| code | number | 0 success, 1 unjoined, 2 joining, etc. |
| message | string | Status description and error information |
(async) requestPermission(fieldDeviceId, params)
- Description:
Request gateway permissions
Example
requestPermission({ fieldDeviceId: 'xxx', permission: 'master' })
Parameters:
| Name | Type | Description | ||||||
|---|---|---|---|---|---|---|---|---|
fieldDeviceId |
string | Field device ID |
||||||
params |
Object |
Properties
|
Returns:
| Name | Type | Description |
|---|---|---|
| code | number | 0 success, 1 unjoined, 2 joining, 20 MQTT client not found, 21 MQTT connection error, 22 MQTT publish failed, 23 request pending, 24 timeout |
| message | string | Status description and error information |
(async) pullGatewayList()
- Description:
Retrieve gateway device list
Example
pullGatewayList()
Returns:
| Name | Type | Description |
|---|---|---|
| code | number | 0 success, 20 MQTT client not found, 21 MQTT connection error, 22 request failed, 23 request pending, 24 timeout |
| message | string | Status description and error information |
(async) getGatewayInfo(gatewayId)
- Description:
Retrieve specified gateway device information
Example
getGatewayInfo('gateway_id_123')
Parameters:
| Name | Type | Description |
|---|---|---|
gatewayId |
string | Gateway device ID |
Returns:
| Name | Type | Description |
|---|---|---|
| code | number | 0 success, 20 MQTT client not found, 21 MQTT connection error, 22 request failed, 23 request pending, 24 timeout |
| message | string | Status description and error information |
| data | Gateway | Gateway device information |
(async) adjustVideoRate(fieldDeviceId, params)
- Description:
Adjust video bitrate
Example
adjustVideoRate('xxxxxxxx', [{ streamId: 0, videoRate: 3000 }, { streamId: 1, videoRate: 1000 }])
Parameters:
| Name | Type | Description | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
fieldDeviceId |
string | Field device ID |
|||||||||
params |
Array.<Object> |
Properties
|
Returns:
Returns Promise object
| Name | Type | Description |
|---|---|---|
| code | number | 0 success, 1 unjoined, 2 joining, 3 failed, 20 MQTT client not found, 21 MQTT connection error, 100 request error |
| message | string | Status description and error information |
sendControlData(fieldDeviceId, params)
- Description:
Send custom message via DataChannel or MQTT. Requires 'master' permission via requestPermission.
Example
// Send via SCTP DataChannel (requires connect and subscribe first)
sendControlData('xxxxxxxx', { data: 'xxx', ordered: true })
// Send via MQTT (only login required, no connect and subscribe needed)
await sdk.init(); // Login successful
await sdk.requestPermission('fieldDeviceId', { permission: 'master' });
sendControlData('xxxxxxxx', { data: 'xxx', channelType: 'mqtt' })
Parameters:
| Name | Type | Description | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
fieldDeviceId |
string | Field device ID |
||||||||||||||||||||
params |
Object |
Properties
|
Returns:
Returns Promise object
| Name | Type | Description |
|---|---|---|
| code | number | 0 success, 1 unjoined (SCTP only), 2 joining (SCTP only), 3 failed, 20 MQTT client not found, 21 MQTT connection error, 42 no permission, 45 no subscribed streams (SCTP only), 100 request error |
| message | string | Status description and error information |
(async) requestDiagnosisReport(fieldDeviceId) → {Promise.<DiagnosisReport>}
- Description:
Get diagnosis report. Usually need to wait 10 seconds to get the report, maximum wait time is 15 seconds.
Example
requestDiagnosisReport('<FIELD-DEVICE-ID>')
Parameters:
| Name | Type | Description |
|---|---|---|
fieldDeviceId |
string | Field device ID |
Returns:
Returns diagnosis report.
- Type
- Promise.<DiagnosisReport>