SFSAudioEvent

Represents all the event types related to Audio Streaming System dispatched by the SmartFoxServer Client API.


Constants contained in this object (see Events below) are used to register event listeners; when an event is dispatched, an object containing event-specific parameters is passed to the listener. Parameters are described under each event type; to avoid typing errors, get parameter names from the EventParam class.

Example

This example shows the generic approach to follow to listen to events.

function someMethod()
{
	sfs.addEventListener(SFSAudioEvent.INIT, onAudioInitialized, this);

	// Initialize the Audio Streaming System
	sfs.send(new InitAudioRequest());
}

function onAudioInitialized(evtParams)
{
	console.log("Audio Streaming System initialized successfully");

	// Display the capture and playback devices in list components in the application interface
	...
}

Events

ERROR

Event type dispatched when an error forces the current client's outgoing audio stream to stop.

This event is fired when the Audio Streaming System has to stop the outgoing stream automatically because of an unrecoverable capture error, for example:

  • the audio capture fails to start (no capture device found, device busy or unavailable, etc.);
  • the permission to access the audio capture device is revoked while a stream is in progress (through the browser settings or the operating system);
  • the active capture device is removed (for example unplugged) and no other capture device is available to switch to.

In all these cases the outgoing stream is stopped (the STREAM_STOP event is fired too) and the application is notified of the reason by means of this event. Note that recoverable conditions, like the active capture device being unplugged while another one is available (which causes a seamless switch), do not fire this event.

Properties
NameTypeDescription
errorMessagestringA message describing the error that caused the outgoing audio stream to stop.

INIT

Event type dispatched when the Audio Streaming System is initialized on the client.

This event is fired in response to the InitAudioRequest.

Upon Audio Streaming System initialization, the client receives from the server the audio parametersset in server configuration (for example the audio encoding bitrate value).

STREAM_ADD

Event type dispatched when a new incoming audio stream is received.

This event is fired when another client starts its own audio stream (by means of a StartAudioStreamRequest) in the same Room where the current client is already streaming. The event is also fired (multiple times - one per client) when the current client starts its audio stream in a Room where other clients are already streaming. In all cases the Audio Streaming System starts the audio playback automatically.

Properties
NameTypeDescription
audioStreamAudioStreamInfoThe object representing the audio stream received from another client.

STREAM_REMOVE

Event type dispatched when an incoming audio stream is stopped.

This event is fired when another client stops its own audio stream (by means of a StopAudioStreamRequest) in the same Room where the current client is streaming. The Audio Streaming System stops the audio playback automatically and removes all references to the incoming stream.

Properties
NameTypeDescription
audioStreamAudioStreamInfoThe object representing the audio streams received from another client.

STREAM_START

Event type dispatched when a request to start the outgoing audio stream is sent to the server.

This event is fired in response to the StartAudioStreamRequest. The Audio Streaming System then starts the audio capture and transmission automatically; it also gets ready to receive the incoming audio streams from other clients and send them to the playback device.

Properties
NameTypeDescription
myAudioStreamAudioStreamInfoThe object representing the audio stream of the current client.

STREAM_STOP

Event type dispatched when a request to stop the outgoing audio stream is sent to the server.

This event is fired in response to the StopAudioStreamRequest to signal that the outgoing audio stream of the current client has been stopped.

Properties
NameTypeDescription
myAudioStreamAudioStreamInfoThe object representing the audio stream of the current client.

TOGGLE_MUTE

Event type dispatched when an incoming audio stream is muted or unmuted.

This event is fired when another client toggles the muted state of its own audio stream (by means of a ToggleMuteAudioStreamRequest) in the same Room where the current client is streaming. If the stream is muted, the audo stream is interrupted temporarily. This event can be useful to signal that a client is muted in the application UI.

Properties
NameTypeDescription
audioStreamAudioStreamInfoThe object representing the audio streams received from another client.