Constructor
new TRROSDK(params)
| Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
params | Object | Properties
|
// 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: '',
});Methods
(async) init()
Initialize MQTT connection
Promise object
| Name | Type | Description |
|---|---|---|
| code | number | 0 success, 21 MQTT connect error, 26 MQTT already connected, etc. |
| message | string | Description and error information |
init()setSessionPermissionToken(fieldDeviceId, token) → {void}
Set temporary session key for field device
| Name | Type | Description |
|---|---|---|
fieldDeviceId | string | |
token | string |
- Type:
- void
setSessionPermissionToken('xxxxxxxx', '********')(async) connect(fieldDeviceId)
Connect to specified field device
| Name | Type | Description |
|---|---|---|
fieldDeviceId | string | Field device ID |
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 |
connect('xxxxxxxx')(async) subscribe(params)
Subscribe to tracks (pull stream)
| Name | Type | Description | |||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
params | Object | Properties
|
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 |
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'
})(async) unsubscribe(params)
Unsubscribe from tracks (stop pulling stream)
| Name | Type | Description | |||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
params | Object | Properties
|
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 |
unsubscribe({ fieldDeviceId: 'xxxxxxxx', streamIds: [0] })(async) publish(params)
Publish audio stream (push stream)
Audio streaming requires successful video subscription first. Unsubscribing all video streams will automatically stop audio publishing via onEvent callback.
Only one audio stream per SDK instance is allowed.
Requires master permission via requestPermission in server mode.
| Name | Type | Description | ||||||
|---|---|---|---|---|---|---|---|---|
params | Object | Properties
|
Returns Promise object
| Name | Type | Description |
|---|---|---|
| code | number | 0 success, 1 unjoined, 2 joining, etc. |
| message | string | Status description and error information |
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 () {}(async) unpublish()
Unpublish audio stream (stop pushing)
Returns Promise object
| Name | Type | Description |
|---|---|---|
| code | number | 0 success, 1 unjoined, 2 joining, etc. |
| message | string | Status description and error information |
unpublish();(async) muteAudio(params)
Mute/unmute specific audio stream
| Name | Type | Description | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
params | Object | Properties
|
Returns Promise object
| Name | Type | Description |
|---|---|---|
| code | number | 0 success, 1 unjoined, 2 joining, etc. |
| message | string | Status description and error information |
muteAudio({ deviceId: 'xxxxxxxx', muted: true })(async) disconnect(fieldDeviceId)
Disconnect from specific field device
| Name | Type | Description |
|---|---|---|
fieldDeviceId | string | Field device ID |
Returns Promise object
| Name | Type | Description |
|---|---|---|
| code | number | 0 success, 1 unjoined, 3 failed, etc. |
| message | string | Status description and error information |
disconnect('xxxxxxxx')(async) disconnectAll()
Disconnect from all field devices
Returns Promise object
| Name | Type | Description |
|---|---|---|
| code | number | 0 success, 1 unjoined, 3 failed, etc. |
| message | string | Status description and error information |
disconnectAll()(async) destroy()
Destroy all connections
Returns Promise object
| Name | Type | Description |
|---|---|---|
| code | number | 0 success, 1 unjoined, 3 failed, etc. |
| message | string | Status description and error information |
destroy()changeFieldDeviceEncodeConfig(fieldDeviceId, params)
Temporarily update field device encoding configuration
Changes persist until device reboot
Only modifies specified fields, others remain unchanged
| Name | Type | Description | |||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
fieldDeviceId | string | Field device ID | |||||||||||||||||||||||||||||||||||||||||||||
params | Array.<Object> | Properties
|
| Name | Type | Description |
|---|---|---|
| code | number | 0 success, 1 unjoined, 2 joining, etc. |
| message | string | Status description and error information |
changeFieldDeviceEncodeConfig('xxxxxxxx', [{ streamId: 0, encodeConfig: { minBps: 1000, forceMin: true } }])(async) requestPermission(fieldDeviceId, params)
Request gateway permissions
| Name | Type | Description | ||||||
|---|---|---|---|---|---|---|---|---|
fieldDeviceId | string | Field device ID | ||||||
params | Object | Properties
|
| 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 |
requestPermission({ fieldDeviceId: 'xxx', permission: 'master' })(async) pullGatewayList()
Retrieve gateway device list
| 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 |
pullGatewayList()(async) getGatewayInfo(gatewayId)
Retrieve specified gateway device information
| Name | Type | Description |
|---|---|---|
gatewayId | string | Gateway device ID |
| 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 |
getGatewayInfo('gateway_id_123')(async) adjustVideoRate(fieldDeviceId, params)
Adjust video bitrate
| Name | Type | Description | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
fieldDeviceId | string | Field device ID | |||||||||
params | Array.<Object> | Properties
|
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 |
adjustVideoRate('xxxxxxxx', [{ streamId: 0, videoRate: 3000 }, { streamId: 1, videoRate: 1000 }])sendControlData(fieldDeviceId, params)
Send custom message via DataChannel or MQTT. Requires 'master' permission via requestPermission.
| Name | Type | Description | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
fieldDeviceId | string | Field device ID | ||||||||||||||||||||
params | Object | Properties
|
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 |
// 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' })(async) requestDiagnosisReport(fieldDeviceId) → {Promise.<DiagnosisReport>}
Get diagnosis report. Usually need to wait 10 seconds to get the report, maximum wait time is 15 seconds.
| Name | Type | Description |
|---|---|---|
fieldDeviceId | string | Field device ID |
Returns diagnosis report.
- Type:
- Promise.<DiagnosisReport>
requestDiagnosisReport('<FIELD-DEVICE-ID>')