Intercom Access

1. APIs

1.1. createIntercom

Description

This API is used to create an intercom instance.

Example

  • intercomPlayer = playjs.createIntercom(options: Object)

Parameter

Field Type Description Default Value Required
devId String Unique identifier of a device Yes
audioChan Number Number of audio channels 1 No
mediaProtocol String Media protocol: WS WS No
audioType String Audio format: G711A (WS) G711A No
audioSample Number Audio sample rate: 8000 (WS) 8000 No
audioBits Number Audio sample bit 16 No
audioRate Number Audio Bitrate 0 No
optId String Operation ID, used for operation logging purposes "" No
expireTime Number The address expiration time (in seconds) 20 No
addrType number Address type: 1 for WAN, 2 for LAN 1 No
startPrompt ArrayBuffer Start intercom prompt sound. PCM format, 8000Hz sample rate, 16-bit, mono channel. No
stopPrompt ArrayBuffer Stop intercom prompt sound. PCM format, 8000Hz sample rate, 16-bit, mono channel. No

1.2. Methods

1.2.1. start

Description

Start intercom.

Example

  • intercomPlayer.start()

1.2.2. stop

Description

Stop intercom.

Example

  • intercomPlayer.stop()

1.2.3. getStartTime

Description

This method is used to obtain the start time of the intercom session, returning the UTC timestamp to the client in milliseconds.

Example

  • intercomPlayer.getStartTime()

Note: To get the end time, please refer to the afterDestroy hook in HOOKS.

1.2.4. getDuration

Description

This method is used to obtain the duration of the intercom session (in milliseconds).

Example

  • intercomPlayer.getDuration()

1.2.5. disableMic

Description

Turn off the microphone.

Example

  • intercomPlayer.disableMic()

1.2.6. enableMic

Description

Turn on the microphone.

Example

  • intercomPlayer.enableMic()

1.3. Properties

1.3.1. volume: number

Description

This property is used to set the play volume on the client side.

Example

  • intercomPlayer.volume = 0.5

This property is used to set the value range as a number, representing the expected channel volume with a range from 0 to 1.

2. Interface Examples

<script src="./h5-player.js"></script>
<script>
 const H5Player = playerjs;
 H5Player.config = {
     baseURL: 'http://192.168.132.72:21250'
 };
 H5Player.defaultHeaders = {
     _appId: '1',
     _tenantId: '2',
 }
 let intercom = null;
 // Open intercom
 function openIntercom() {
     if (intercom) return;
     intercom = H5Player.createIntercom({
         devId: 'f98dc093bfe74e5e8ff368bb7a04fea9'
     });
     intercom.hooks.afterLoaded.tap('play', () => {
         intercom.start();
     });
     intercom.hooks.onError.tap('auto close', () => {
         console.log('auto close');
     });
 }
 // Close intercom
 function closeIntercom() {
     if (intercom) {
         intercom.stop();
         intercom = null;
     }
 }
</script>