Intercom Access

1. APIs

1.1. createIntercom

Description

Create an intercom instance

Example

  • intercomPlayer = playjs.createIntercom(options: Object)

Parameters

Field Type Description Default Value Required
devId String Device unique identifier Yes
audioChan Number Number of audio channels 1 No
mediaProtocol String Media Protocol: WS WS No
audioType String Audio format: G711A (WS), AAC (RTMP) G711A No
audioSample Number Audio sample rate: 8000 (WS), 48000 (RTMP) 8000 No
audioBits Number Number of audio sample bits 16 No
audioRate Number Audio bit rate 0 No
optId String Business operation ID, which can be used for operation trace records "" No
expireTime Number Address expiration time in seconds 20 No
addrType number Address type: 1: External network address; 2: Intranet address 1 No
startPrompt buffer Start prompt tone, PCM format, 16-bit, 8000Hz sample rate, mono channel No
stopPrompt buffer End prompt sound, PCM format, 16-bit, 8000Hz sample rate, 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

Get the start time of the intercom and return the client UTC timestamp in milliseconds.

Example

  • intercomPlayer.getStartTime()

Note: If you want to get the end time, please refer to afterDestroy in HOOKS

1.2.4. getDuration

Description

Get the duration of the intercom, in milliseconds.

Example

  • intercomPlayer.getDuration()

1.2.5. 【1.3.10-P7】enableMic

Description

Enable microphone, resume microphone collection

Example

  • intercomPlayer.enableMic()

1.2.6. 【1.3.10-P7】disableMic

Description

Disable microphone, send mute command to device

Example

  • intercomPlayer.disableMic()

1.3. Properties

1.3.1. volume: number

Description

Set client playback volume

Example

  • intercomPlayer.volume = 0.5

Set value range: Number, expected channel volume, range 0 - 1

2. Interface Examples

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