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
Name |
Type |
Attributes |
Default |
Description |
cloudMode |
CloudMode
|
<optional>
|
'private'
|
Cloud mode, optional. public - Public cloud, private - Private cloud. Default: private. |
serverIp |
string
|
Array.<string>
|
<optional>
|
|
Domain or IP of signaling dispatch server, can provide multiple addresses. Invalid in public cloud mode; Required in private cloud mode. |
port |
number
|
<optional>
|
|
Signaling service port. Invalid in public cloud mode; Default 3000/443 (with HTTPS) in private cloud. |
https |
boolean
|
<optional>
|
false
|
Enable HTTPS protocol, optional. Forced in public cloud mode; Default false in private cloud. |
mqttOptions |
Object
|
<optional>
|
|
MQTT configuration, optional.
Properties
Name |
Type |
Attributes |
Default |
Description |
url |
string
|
Array.<string>
|
<optional>
|
|
MQTT server domain/IP, can provide multiple addresses. Usually not needed in public cloud; Defaults to serverIp in private cloud. |
port |
number
|
<optional>
|
|
MQTT server port. Usually not needed in public cloud; Default 2833 in private cloud. |
forceLogin |
boolean
|
<optional>
|
false
|
Force MQTT login, optional. Default false. |
|
projectId |
string
|
number
|
|
|
Project ID |
remoteDeviceId |
string
|
|
|
Remote device ID |
password |
string
|
|
|
Remote device password |
observer |
TRROMediaObserver
|
<optional>
|
|
Event callback functions
Properties
Name |
Type |
Attributes |
Description |
onMqttConnectionState |
function
|
<optional>
|
Returns { state: MQTTConnectionState; message?: string; } |
onSignalingState |
function
|
<optional>
|
Returns { roomId: string; state: string; data?: Record<string, any>; } |
onPeerConnectionState |
function
|
<optional>
|
Returns { srcUserId: string; code: number; state: ConnectionState; message?: string; data?: Record<string, any>; } |
onConnected |
function
|
<optional>
|
Returns { deviceId: string } |
onDisconnected |
function
|
<optional>
|
Returns { deviceId: string } |
onTrackPublishState |
function
|
<optional>
|
Returns { state: 'publish' | 'unpublish'; deviceId: string; streamId: number; mediaType: MediaType } |
onControlData |
function
|
<optional>
|
Returns { deviceId: string; data: string | ArrayBuffer; ordered: boolean } |
onKick |
function
|
<optional>
|
Returns { code: number; reason: string } |
onEvent |
function
|
<optional>
|
Returns event types: autoplay | webrtcStats | gatewayStats |
|
logger |
Object
|
<optional>
|
|
Logger configuration
Properties
Name |
Type |
Attributes |
Default |
Description |
showLog |
boolean
|
<optional>
|
true
|
Whether to print SDK logs |
reportLog |
boolean
|
<optional>
|
true
|
Whether to report SDK logs |
log |
function
|
<optional>
|
|
Logging method |
|
|
Methods
(async) init()
Initialize MQTT connection
Example
init()
Returns:
Promise object
Name |
Type |
Description |
code |
number |
0 success, 21 MQTT connect error, etc. |
message |
string |
Description and error information |
setSessionPermissionToken(fieldDeviceId, token) → {void}
Set temporary session key for field device
Example
setSessionPermissionToken('xxxxxxxx', '********')
Parameters:
Name |
Type |
Description |
fieldDeviceId |
string
|
|
token |
string
|
|
Returns:
-
Type
-
void
(async) connect(fieldDeviceId)
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 success, 1 unjoined, 2 joining, 20 MQTT client not found, 21 MQTT connection error, 100 request error |
message |
string |
Description and error message |
(async) subscribe(params)
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
Name |
Type |
Attributes |
Default |
Description |
fieldDeviceId |
string
|
|
|
Field device ID |
containers |
Array.<Object>
|
|
|
Properties
Name |
Type |
Description |
streamId |
number
|
Video stream ID |
mount |
string
|
Video stream mount point (element ID format, e.g., #test-div-0).
SDK will automatically create media elements under this node for playback. |
callback |
function
|
Callback with end-to-end latency and requestVideoFrameCallback metadata |
|
audioContainer |
string
|
<optional>
|
|
Audio stream mount point (element ID format, e.g., #test-div-0).
If not provided, audio stream won't be pulled. Invalid if containers field is missing. |
incremental |
boolean
|
<optional>
|
false
|
Whether to use incremental subscription.
Default false (overwrite existing subscriptions), true keeps existing subscriptions while adding/updating new ones. |
|
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)
Unsubscribe from tracks (stop pulling stream)
Example
unsubscribe({ fieldDeviceId: 'xxxxxxxx', streamIds: [0] })
Parameters:
Name |
Type |
Description |
params |
Object
|
Properties
Name |
Type |
Attributes |
Default |
Description |
fieldDeviceId |
string
|
|
|
Field device ID |
streamIds |
Array.<number>
|
|
|
Video stream IDs to unsubscribe |
audioStream |
boolean
|
<optional>
|
false
|
Whether to unsubscribe audio stream |
|
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)
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.
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
Name |
Type |
Description |
audioTrack |
MediaStreamTrack
|
Audio stream track obtained via navigator.mediaDevices.getUserMedia() |
|
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()
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)
Mute/unmute specific audio stream
Example
muteAudio({ deviceId: 'xxxxxxxx', muted: true })
Parameters:
Name |
Type |
Description |
params |
Object
|
Properties
Name |
Type |
Description |
deviceId |
string
|
Field device ID or remote device ID (remoteDeviceId ) |
muted |
boolean
|
true: mute, false: unmute |
|
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)
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()
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()
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)
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
Name |
Type |
Description |
streamId |
number
|
Video stream ID |
encodeConfig |
Object
|
Encoding configuration
Properties
Name |
Type |
Attributes |
Description |
encodeWidth |
number
|
<optional>
|
Encoding width |
encodeHeight |
number
|
<optional>
|
Encoding height |
minWidth |
number
|
<optional>
|
Minimum width |
fps |
number
|
<optional>
|
Target FPS |
minFps |
number
|
<optional>
|
Minimum FPS |
bps |
number
|
<optional>
|
Target bitrate (kbps) |
minBps |
number
|
<optional>
|
Minimum bitrate (kbps) |
forceMinBps |
boolean
|
<optional>
|
Enforce minimum bitrate |
|
|
Returns:
Name |
Type |
Description |
code |
number |
0 success, 1 unjoined, 2 joining, etc. |
message |
string |
Status description and error information |
(async) requestPermission(fieldDeviceId, params)
Request gateway permissions
Example
requestPermission({ fieldDeviceId: 'xxx', permission: 'master' })
Parameters:
Name |
Type |
Description |
fieldDeviceId |
string
|
Field device ID |
params |
Object
|
Properties
Name |
Type |
Description |
permission |
PermissionState
|
'master' for control+view permissions, 'guest' for view-only |
|
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()
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) adjustVideoRate(fieldDeviceId, params)
Example
adjustVideoRate('xxxxxxxx', [{ streamId: 0, videoRate: 3000 }, { streamId: 1, videoRate: 1000 }])
Parameters:
Name |
Type |
Description |
fieldDeviceId |
string
|
Field device ID |
params |
Array.<Object>
|
Properties
Name |
Type |
Description |
streamId |
number
|
Video stream ID |
videoRate |
number
|
Bitrate in kbps |
|
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)
Send custom message via DataChannel. Requires 'master' permission via requestPermission.
Example
sendControlData('xxxxxxxx', { data: 'xxx' })
Parameters:
Name |
Type |
Description |
fieldDeviceId |
string
|
Field device ID |
params |
Object
|
Properties
Name |
Type |
Attributes |
Default |
Description |
data |
string
|
ArrayBuffer
|
|
|
Custom message content |
ordered |
boolean
|
<optional>
|
true
|
Use reliable transmission channel |
|
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, 42 no permission, 45 no subscribed streams, 100 request error |
message |
string |
Status description and error information |