API Reference for web - Class: LocalAudioTrack

更新时间: 2023-10-23 16:45:52

# Class: LocalAudioTrack

track/LocalAudioTrack.LocalAudioTrack

# Hierarchy

# Properties

# defaultMaxListeners

Static defaultMaxListeners: number

# Inherited from

LocalTrack.defaultMaxListeners


# errorMonitor

Static Readonly errorMonitor: typeof errorMonitor

This symbol shall be used to install a listener for only monitoring 'error' events. Listeners installed using this symbol are called before the regular 'error' listeners are called.

Installing a listener using this symbol does not change the behavior once an 'error' event is emitted, therefore the process will still crash if no regular 'error' listener is installed.

# Inherited from

LocalTrack.errorMonitor

# Accessors

# enabled

get enabled(): boolean

本地轨道当前的启用状态。

# Returns

boolean

# Inherited from

LocalTrack.enabled


# isPlaying

get isPlaying(): boolean

媒体轨道是否正在页面上播放。

  • true: 媒体轨道正在页面上播放。
  • false: 媒体轨道没有在页面上播放。

# Returns

boolean


# muted

get muted(): boolean

本地媒体轨道当前的静音状态。

# Returns

boolean

# Inherited from

LocalTrack.muted

# Methods

# addListener

addListener(event, listener): LocalAudioTrack

# Parameters

Name Type
event string | symbol
listener (...args: any[]) => void

# Returns

LocalAudioTrack

# Inherited from

LocalTrack.addListener


# close

close(): void

关闭本地轨道,并释放相关采集设备。 一旦本地轨道被关闭,就无法再次使用。如需再次使用本地轨道,需要重新创建。

# Returns

void

# Inherited from

LocalTrack.close


# emit

emit(event, ...args): boolean

# Parameters

Name Type
event string | symbol
...args any[]

# Returns

boolean

# Inherited from

LocalTrack.emit


# eventNames

eventNames(): (string | symbol)[]

# Returns

(string | symbol)[]

# Inherited from

LocalTrack.eventNames


# getListeners

getListeners(event): Function[]

指定一个事件名,获取当前所有监听这个事件的回调函数。

# Parameters

Name Type Description
event string 事件名称。

# Returns

Function[]

# Inherited from

LocalTrack.getListeners


# getMaxListeners

getMaxListeners(): number

# Returns

number

# Inherited from

LocalTrack.getMaxListeners


# getMediaStreamTrack

getMediaStreamTrack(): MediaStreamTrack

获取浏览器原生的 MediaStreamTrack (opens new window) 对象。

# Returns

MediaStreamTrack

# Inherited from

LocalTrack.getMediaStreamTrack


# getTrackId

getTrackId(): string

获取由 SDK 生成的对于媒体轨道来说的唯一 ID。

# Returns

string

媒体轨道 ID。

# Inherited from

LocalTrack.getTrackId


# getTrackLabel

getTrackLabel(): undefined | string

获取本地轨道的来源描述。

# Returns

undefined | string

可能返回以下值:

# Inherited from

LocalTrack.getTrackLabel


# getVolumeLevel

getVolumeLevel(): number

获取本地音频轨道的音量等级。

# Returns

number

音量等级值,范围 [0, 1],1 代表理论最大音量。


# listenerCount

listenerCount(event): number

# Parameters

Name Type
event string | symbol

# Returns

number

# Inherited from

LocalTrack.listenerCount


# listeners

listeners(event): Function[]

# Parameters

Name Type
event string | symbol

# Returns

Function[]

# Inherited from

LocalTrack.listeners


# off

off(event, listener): LocalAudioTrack

# Parameters

Name Type
event string | symbol
listener (...args: any[]) => void

# Returns

LocalAudioTrack

# Inherited from

LocalTrack.off


# once

once(event, listener): LocalAudioTrack

# Parameters

Name Type
event string | symbol
listener (...args: any[]) => void

# Returns

LocalAudioTrack

# Inherited from

LocalTrack.once


# play

play(): void

播放本地音频轨道。

播放音频时 SDK 不会创建任何 DOM 元素,所以无需像视频一样提供 DOM 元素。

# Returns

void


# prependListener

prependListener(event, listener): LocalAudioTrack

# Parameters

Name Type
event string | symbol
listener (...args: any[]) => void

# Returns

LocalAudioTrack

# Inherited from

LocalTrack.prependListener


# prependOnceListener

prependOnceListener(event, listener): LocalAudioTrack

# Parameters

Name Type
event string | symbol
listener (...args: any[]) => void

# Returns

LocalAudioTrack

# Inherited from

LocalTrack.prependOnceListener


# rawListeners

rawListeners(event): Function[]

# Parameters

Name Type
event string | symbol

# Returns

Function[]

# Inherited from

LocalTrack.rawListeners


# removeAllListeners

removeAllListeners(event?): LocalAudioTrack

# Parameters

Name Type
event? string | symbol

# Returns

LocalAudioTrack

# Inherited from

LocalTrack.removeAllListeners


# removeListener

removeListener(event, listener): LocalAudioTrack

# Parameters

Name Type
event string | symbol
listener (...args: any[]) => void

# Returns

LocalAudioTrack

# Inherited from

LocalTrack.removeListener


# safeEmit

safeEmit(event, ...args): boolean

# Parameters

Name Type
event string
...args any[]

# Returns

boolean

# Inherited from

LocalTrack.safeEmit


# safeEmitAsPromise

safeEmitAsPromise(event, ...args): Promise<any>

# Parameters

Name Type
event string
...args any[]

# Returns

Promise<any>

# Inherited from

LocalTrack.safeEmitAsPromise


# setEnabled

setEnabled(enabled): Promise<void>

启用/禁用该轨道。

轨道禁用后,播放和发布都将被停止。

  • 禁用轨道不会触发 LocalTrack.on("track-ended") 事件
  • 如果该轨道已发布,禁用轨道后,远端会触发 user-unpublished 事件。重新启用后,远端会触发 user-published 事件.

# Parameters

Name Type Description
enabled boolean 是否启用该轨道: - true: 启用该轨道。 - false: 禁用该轨道。

# Returns

Promise<void>


# setMaxListeners

setMaxListeners(n): LocalAudioTrack

# Parameters

Name Type
n number

# Returns

LocalAudioTrack

# Inherited from

LocalTrack.setMaxListeners


# setMuted

setMuted(muted): void

发送或暂停发送该轨道的媒体数据。

如果该轨道已发布,调用 setMuted(true) 后,远端会触发 user-unpublished 事件。再调用 [[setMuted(false)]] 后,远端会触发 [[user-published]] 事件。

  • setEnabled 相比,调用该方法响应速度更快且不影响视频采集状态
  • setEnabledsetMuted 不能同时调用。

# Parameters

Name Type Description
muted boolean 是否发送该轨道的媒体数据: - true: 暂停发送该轨道的媒体数据。 - false: 恢复发送该轨道的媒体数据。

# Returns

void


# setVolume

setVolume(volume): void

设置本地音频轨道的音量。

# Parameters

Name Type Description
volume number T音量值,范围 [0, 1000], 0 代表静音,100 代表原始音量。100 以上会使用 WebAudio 进行音量增益。如果本地音频轨道已经发布,修改音量会影响远端听到的音量大小。

# Returns

void


# stop

stop(): void

停止播放。

# Returns

void


# listenerCount

Static listenerCount(emitter, event): number

deprecated since v4.0.0

# Parameters

Name Type
emitter EventEmitter
event string | symbol

# Returns

number

# Inherited from

LocalTrack.listenerCount