Skip to content

Commit

Permalink
fix(MeetingsSdkAdapter): use getMeeting for audio and video controls
Browse files Browse the repository at this point in the history
  • Loading branch information
CernaianuMihai authored and cipak committed Jul 19, 2021
1 parent bb7bd93 commit b1bf081
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 56 deletions.
59 changes: 11 additions & 48 deletions src/MeetingsSDKAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
import {
catchError,
concatMap,
distinctUntilChanged,
flatMap,
filter,
last,
Expand Down Expand Up @@ -685,7 +686,6 @@ export default class MeetingsSDKAdapter extends MeetingsAdapter {
* @returns {Observable.<MeetingControlDisplay>} Observable stream that emits display data of the audio control
*/
audioControl(ID) {
const sdkMeeting = this.fetchMeeting(ID);
const muted = {
ID: AUDIO_CONTROL,
icon: 'microphone-muted_28',
Expand All @@ -707,31 +707,13 @@ export default class MeetingsSDKAdapter extends MeetingsAdapter {
state: MeetingControlState.DISABLED,
text: null,
};
const states = {
[MeetingControlState.ACTIVE]: unmuted,
[MeetingControlState.INACTIVE]: muted,
[MeetingControlState.DISABLED]: disabled,
};

const initialState$ = Observable.create((observer) => {
if (sdkMeeting) {
const meeting = this.meetings[ID];
const noAudio = !meeting.disabledLocalAudio && !meeting.localAudio.stream;

observer.next(noAudio ? disabled : unmuted);
} else {
observer.error(new Error(`Could not find meeting with ID "${ID}" to add audio control`));
}

observer.complete();
});

const localMediaUpdateEvent$ = fromEvent(sdkMeeting, EVENT_MEDIA_LOCAL_UPDATE).pipe(
filter((event) => event.control === AUDIO_CONTROL),
map(({state}) => states[state]),
return this.getMeeting(ID).pipe(
map(({localAudio: {stream}, disabledLocalAudio}) => (
(stream && unmuted) || (disabledLocalAudio && muted) || disabled
)),
distinctUntilChanged(),
);

return concat(initialState$, localMediaUpdateEvent$);
}

/**
Expand Down Expand Up @@ -794,7 +776,6 @@ export default class MeetingsSDKAdapter extends MeetingsAdapter {
* @returns {Observable.<MeetingControlDisplay>} Observable stream that emits display data of the video control
*/
videoControl(ID) {
const sdkMeeting = this.fetchMeeting(ID);
const muted = {
ID: VIDEO_CONTROL,
icon: 'camera-muted_28',
Expand All @@ -816,31 +797,13 @@ export default class MeetingsSDKAdapter extends MeetingsAdapter {
state: MeetingControlState.DISABLED,
text: null,
};
const states = {
[MeetingControlState.ACTIVE]: unmuted,
[MeetingControlState.INACTIVE]: muted,
[MeetingControlState.DISABLED]: disabled,
};

const initialState$ = Observable.create((observer) => {
if (sdkMeeting) {
const meeting = this.meetings[ID];
const noVideo = !meeting.disabledLocalVideo && !meeting.localVideo.stream;

observer.next(noVideo ? disabled : unmuted);
} else {
observer.error(new Error(`Could not find meeting with ID "${ID}" to add video control`));
}

observer.complete();
});

const localMediaUpdateEvent$ = fromEvent(sdkMeeting, EVENT_MEDIA_LOCAL_UPDATE).pipe(
filter((event) => event.control === VIDEO_CONTROL),
map(({state}) => states[state]),
return this.getMeeting(ID).pipe(
map(({localVideo: {stream}, disabledLocalVideo}) => (
(stream && unmuted) || (disabledLocalVideo && muted) || disabled
)),
distinctUntilChanged(),
);

return concat(initialState$, localMediaUpdateEvent$);
}

/**
Expand Down
12 changes: 4 additions & 8 deletions src/MeetingsSDKAdapter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -554,12 +554,10 @@ describe('Meetings SDK Adapter', () => {
});

test('throws errors if sdk meeting object is not defined', (done) => {
meetingSDKAdapter.fetchMeeting = jest.fn();

meetingSDKAdapter.audioControl(meetingID).subscribe(
meetingSDKAdapter.audioControl('inexistent').subscribe(
() => {},
(error) => {
expect(error.message).toBe('Could not find meeting with ID "meetingID" to add audio control');
expect(error.message).toBe('Could not find meeting with ID "inexistent"');
done();
},
);
Expand Down Expand Up @@ -667,12 +665,10 @@ describe('Meetings SDK Adapter', () => {
});

test('throws errors if sdk meeting object is not defined', (done) => {
meetingSDKAdapter.fetchMeeting = jest.fn();

meetingSDKAdapter.videoControl(meetingID).subscribe(
meetingSDKAdapter.videoControl('inexistent').subscribe(
() => {},
(error) => {
expect(error.message).toBe('Could not find meeting with ID "meetingID" to add video control');
expect(error.message).toBe('Could not find meeting with ID "inexistent"');
done();
},
);
Expand Down

0 comments on commit b1bf081

Please sign in to comment.