Skip to content

Commit

Permalink
feat(ts) TypeScript version of rtcevents
Browse files Browse the repository at this point in the history
  • Loading branch information
garyhuntddn authored Feb 28, 2022
1 parent 0399d6e commit c9f1dbb
Show file tree
Hide file tree
Showing 4 changed files with 299 additions and 144 deletions.
116 changes: 0 additions & 116 deletions service/RTC/RTCEvents.js

This file was deleted.

33 changes: 32 additions & 1 deletion service/RTC/RTCEvents.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ describe( "/service/RTC/RTCEvents members", () => {
LOCAL_UFRAG_CHANGED,
REMOTE_UFRAG_CHANGED,
RTCEvents,
default: RTCEventsDefault,
...others
} = exported as any; // TODO: remove cast after typescript conversion
} = exported;

it( "known members", () => {
expect( CREATE_ANSWER_FAILED ).toBe( 'rtc.create_answer_failed' );
Expand Down Expand Up @@ -63,6 +64,7 @@ describe( "/service/RTC/RTCEvents members", () => {
expect( ENDPOINT_STATS_RECEIVED ).toBe( 'rtc.endpoint_stats_received' );
expect( LOCAL_UFRAG_CHANGED ).toBe( 'rtc.local_ufrag_changed' );
expect( REMOTE_UFRAG_CHANGED ).toBe( 'rtc.remote_ufrag_changed' );

if ( RTCEvents ) {
expect( RTCEvents.CREATE_ANSWER_FAILED ).toBe( 'rtc.create_answer_failed' );
expect( RTCEvents.CREATE_OFFER_FAILED ).toBe( 'rtc.create_offer_failed' );
Expand Down Expand Up @@ -91,6 +93,35 @@ describe( "/service/RTC/RTCEvents members", () => {
expect( RTCEvents.LOCAL_UFRAG_CHANGED ).toBe( 'rtc.local_ufrag_changed' );
expect( RTCEvents.REMOTE_UFRAG_CHANGED ).toBe( 'rtc.remote_ufrag_changed' );
}

if ( RTCEventsDefault ) {
expect( RTCEventsDefault.CREATE_ANSWER_FAILED ).toBe( 'rtc.create_answer_failed' );
expect( RTCEventsDefault.CREATE_OFFER_FAILED ).toBe( 'rtc.create_offer_failed' );
expect( RTCEventsDefault.DATA_CHANNEL_OPEN ).toBe( 'rtc.data_channel_open' );
expect( RTCEventsDefault.ENDPOINT_CONN_STATUS_CHANGED ).toBe( 'rtc.endpoint_conn_status_changed' );
expect( RTCEventsDefault.DOMINANT_SPEAKER_CHANGED ).toBe( 'rtc.dominant_speaker_changed' );
expect( RTCEventsDefault.LASTN_ENDPOINT_CHANGED ).toBe( 'rtc.lastn_endpoint_changed' );
expect( RTCEventsDefault.PERMISSIONS_CHANGED ).toBe( 'rtc.permissions_changed' );
expect( RTCEventsDefault.SENDER_VIDEO_CONSTRAINTS_CHANGED ).toBe( 'rtc.sender_video_constraints_changed' );
expect( RTCEventsDefault.LASTN_VALUE_CHANGED ).toBe( 'rtc.lastn_value_changed' );
expect( RTCEventsDefault.LOCAL_TRACK_SSRC_UPDATED ).toBe( 'rtc.local_track_ssrc_updated' );
expect( RTCEventsDefault.LOCAL_TRACK_MAX_ENABLED_RESOLUTION_CHANGED ).toBe( 'rtc.local_track_max_enabled_resolution_changed' );
expect( RTCEventsDefault.TRACK_ATTACHED ).toBe( 'rtc.track_attached' );
expect( RTCEventsDefault.REMOTE_TRACK_ADDED ).toBe( 'rtc.remote_track_added' );
expect( RTCEventsDefault.REMOTE_TRACK_MUTE ).toBe( 'rtc.remote_track_mute' );
expect( RTCEventsDefault.REMOTE_TRACK_REMOVED ).toBe( 'rtc.remote_track_removed' );
expect( RTCEventsDefault.REMOTE_TRACK_UNMUTE ).toBe( 'rtc.remote_track_unmute' );
expect( RTCEventsDefault.SET_LOCAL_DESCRIPTION_FAILED ).toBe( 'rtc.set_local_description_failed' );
expect( RTCEventsDefault.SET_REMOTE_DESCRIPTION_FAILED ).toBe( 'rtc.set_remote_description_failed' );
expect( RTCEventsDefault.AUDIO_OUTPUT_DEVICE_CHANGED ).toBe( 'rtc.audio_output_device_changed' );
expect( RTCEventsDefault.DEVICE_LIST_CHANGED ).toBe( 'rtc.device_list_changed' );
expect( RTCEventsDefault.DEVICE_LIST_WILL_CHANGE ).toBe( 'rtc.device_list_will_change' );
expect( RTCEventsDefault.DEVICE_LIST_AVAILABLE ).toBe( 'rtc.device_list_available' );
expect( RTCEventsDefault.ENDPOINT_MESSAGE_RECEIVED ).toBe( 'rtc.endpoint_message_received' );
expect( RTCEventsDefault.ENDPOINT_STATS_RECEIVED ).toBe( 'rtc.endpoint_stats_received' );
expect( RTCEventsDefault.LOCAL_UFRAG_CHANGED ).toBe( 'rtc.local_ufrag_changed' );
expect( RTCEventsDefault.REMOTE_UFRAG_CHANGED ).toBe( 'rtc.remote_ufrag_changed' );
}
} );

it( "unknown members", () => {
Expand Down
147 changes: 147 additions & 0 deletions service/RTC/RTCEvents.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
export enum RTCEvents {
/**
* Indicates error while create answer call.
*/
CREATE_ANSWER_FAILED = 'rtc.create_answer_failed',

/**
* Indicates error while create offer call.
*/
CREATE_OFFER_FAILED = 'rtc.create_offer_failed',
DATA_CHANNEL_OPEN = 'rtc.data_channel_open',
ENDPOINT_CONN_STATUS_CHANGED = 'rtc.endpoint_conn_status_changed',
DOMINANT_SPEAKER_CHANGED = 'rtc.dominant_speaker_changed',
LASTN_ENDPOINT_CHANGED = 'rtc.lastn_endpoint_changed',
FORWARDED_SOURCES_CHANGED = 'rtc.forwarded_sources_changed',

/**
* Event emitted when the user granted/blocked a permission for the camera / mic.
* Used to keep track of the granted permissions on browsers which don't
* support the Permissions API.
*/
PERMISSIONS_CHANGED = 'rtc.permissions_changed',

SENDER_VIDEO_CONSTRAINTS_CHANGED = 'rtc.sender_video_constraints_changed',

/**
* Event emitted when {@link RTC.setLastN} method is called to update with
* the new value set.
* The first argument is the value passed to {@link RTC.setLastN}.
*/
LASTN_VALUE_CHANGED = 'rtc.lastn_value_changed',

/**
* Event emitted when ssrc for a local track is extracted and stored
* in {@link TraceablePeerConnection}.
* @param {JitsiLocalTrack} track which ssrc was updated
* @param {string} ssrc that was stored
*/
LOCAL_TRACK_SSRC_UPDATED = 'rtc.local_track_ssrc_updated',

/**
* The max enabled resolution of a local video track was changed.
*/
LOCAL_TRACK_MAX_ENABLED_RESOLUTION_CHANGED = 'rtc.local_track_max_enabled_resolution_changed',

TRACK_ATTACHED = 'rtc.track_attached',

/**
* Event fired when we remote track is added to the conference.
* 1st event argument is the added <tt>JitsiRemoteTrack</tt> instance.
**/
REMOTE_TRACK_ADDED = 'rtc.remote_track_added',

// FIXME get rid of this event in favour of NO_DATA_FROM_SOURCE event
// (currently implemented for local tracks only)
REMOTE_TRACK_MUTE = 'rtc.remote_track_mute',

/**
* Indicates that the remote track has been removed from the conference.
* 1st event argument is the removed {@link JitsiRemoteTrack} instance.
*/
REMOTE_TRACK_REMOVED = 'rtc.remote_track_removed',

// FIXME get rid of this event in favour of NO_DATA_FROM_SOURCE event
// (currently implemented for local tracks only)
REMOTE_TRACK_UNMUTE = 'rtc.remote_track_unmute',

/**
* Indicates error while set local description.
*/
SET_LOCAL_DESCRIPTION_FAILED = 'rtc.set_local_description_failed',

/**
* Indicates error while set remote description.
*/
SET_REMOTE_DESCRIPTION_FAILED = 'rtc.set_remote_description_failed',
AUDIO_OUTPUT_DEVICE_CHANGED = 'rtc.audio_output_device_changed',
DEVICE_LIST_CHANGED = 'rtc.device_list_changed',

/**
* Indicates that the list with available devices will change.
*/
DEVICE_LIST_WILL_CHANGE = 'rtc.device_list_will_change',
DEVICE_LIST_AVAILABLE = 'rtc.device_list_available',

/**
* Indicates that a message from another participant is received on
* data channel.
*/
ENDPOINT_MESSAGE_RECEIVED = 'rtc.endpoint_message_received',

/**
* Indicates that the remote endpoint stats have been received on data channel.
*/
ENDPOINT_STATS_RECEIVED = 'rtc.endpoint_stats_received',

/**
* Designates an event indicating that the local ICE username fragment of
* the jingle session has changed.
* The first argument of the vent is <tt>TraceablePeerConnection</tt> which
* is the source of the event.
* The second argument is the actual "ufrag" string.
*/
LOCAL_UFRAG_CHANGED = 'rtc.local_ufrag_changed',

/**
* Designates an event indicating that the local ICE username fragment of
* the jingle session has changed.
* The first argument of the vent is <tt>TraceablePeerConnection</tt> which
* is the source of the event.
* The second argument is the actual "ufrag" string.
*/
REMOTE_UFRAG_CHANGED = 'rtc.remote_ufrag_changed'
};

export const CREATE_ANSWER_FAILED = RTCEvents.CREATE_ANSWER_FAILED;
export const CREATE_OFFER_FAILED = RTCEvents.CREATE_OFFER_FAILED;
export const DATA_CHANNEL_OPEN = RTCEvents.DATA_CHANNEL_OPEN;
export const ENDPOINT_CONN_STATUS_CHANGED = RTCEvents.ENDPOINT_CONN_STATUS_CHANGED;
export const DOMINANT_SPEAKER_CHANGED = RTCEvents.DOMINANT_SPEAKER_CHANGED;
export const LASTN_ENDPOINT_CHANGED = RTCEvents.LASTN_ENDPOINT_CHANGED;
export const FORWARDED_SOURCES_CHANGED = RTCEvents.FORWARDED_SOURCES_CHANGED;
export const PERMISSIONS_CHANGED = RTCEvents.PERMISSIONS_CHANGED;
export const SENDER_VIDEO_CONSTRAINTS_CHANGED = RTCEvents.SENDER_VIDEO_CONSTRAINTS_CHANGED;
export const LASTN_VALUE_CHANGED = RTCEvents.LASTN_VALUE_CHANGED;
export const LOCAL_TRACK_SSRC_UPDATED = RTCEvents.LOCAL_TRACK_SSRC_UPDATED;
export const LOCAL_TRACK_MAX_ENABLED_RESOLUTION_CHANGED = RTCEvents.LOCAL_TRACK_MAX_ENABLED_RESOLUTION_CHANGED;
export const TRACK_ATTACHED = RTCEvents.TRACK_ATTACHED;
export const REMOTE_TRACK_ADDED = RTCEvents.REMOTE_TRACK_ADDED;
export const REMOTE_TRACK_MUTE = RTCEvents.REMOTE_TRACK_MUTE;
export const REMOTE_TRACK_REMOVED = RTCEvents.REMOTE_TRACK_REMOVED;
export const REMOTE_TRACK_UNMUTE = RTCEvents.REMOTE_TRACK_UNMUTE;
export const SET_LOCAL_DESCRIPTION_FAILED = RTCEvents.SET_LOCAL_DESCRIPTION_FAILED;
export const SET_REMOTE_DESCRIPTION_FAILED = RTCEvents.SET_REMOTE_DESCRIPTION_FAILED;
export const AUDIO_OUTPUT_DEVICE_CHANGED = RTCEvents.AUDIO_OUTPUT_DEVICE_CHANGED;
export const DEVICE_LIST_CHANGED = RTCEvents.DEVICE_LIST_CHANGED;
export const DEVICE_LIST_WILL_CHANGE = RTCEvents.DEVICE_LIST_WILL_CHANGE;
export const DEVICE_LIST_AVAILABLE = RTCEvents.DEVICE_LIST_AVAILABLE;
export const ENDPOINT_MESSAGE_RECEIVED = RTCEvents.ENDPOINT_MESSAGE_RECEIVED;
export const ENDPOINT_STATS_RECEIVED = RTCEvents.ENDPOINT_STATS_RECEIVED;
export const LOCAL_UFRAG_CHANGED = RTCEvents.LOCAL_UFRAG_CHANGED;
export const REMOTE_UFRAG_CHANGED = RTCEvents.REMOTE_UFRAG_CHANGED;

// TODO: this was a pre-ES6 module using module.exports = RTCEvents which doesn't translate well
// it is used in a number of places and should be updated to use the named export

export default RTCEvents;
Loading

0 comments on commit c9f1dbb

Please sign in to comment.