Skip to content

Commit

Permalink
fix(MeetingAdapter): sdk addMedia logic is inside join meeting logic
Browse files Browse the repository at this point in the history
  • Loading branch information
akoushke committed Jan 15, 2020
1 parent 087597e commit 32c0c51
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 26 deletions.
50 changes: 26 additions & 24 deletions src/MeetingsSDKAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ const MEDIA_TYPE_LOCAL = 'local';
const MEDIA_TYPE_REMOTE_AUDIO = 'remoteAudio';
const MEDIA_TYPE_REMOTE_VIDEO = 'remoteVideo';
const MEDIA_EVENT_TYPES = [MEDIA_TYPE_LOCAL, MEDIA_TYPE_REMOTE_AUDIO, MEDIA_TYPE_REMOTE_VIDEO];
const DEFAULT_MEDIA_SETTINGS = {
receiveVideo: true,
receiveAudio: true,
receiveShare: false,
sendVideo: true,
sendAudio: true,
sendShare: false,
};

/**
* The `MeetingsSDKAdapter` is an implementation of the `MeetingsAdapter` interface.
Expand Down Expand Up @@ -69,27 +77,14 @@ export default class MeetingsSDKAdapter extends MeetingsAdapter {
async addLocalMedia(ID) {
const sdkMeeting = this.fetchMeeting(ID);

// default media setting
const mediaSettings = {
receiveVideo: true,
receiveAudio: true,
receiveShare: false,
sendVideo: true,
sendAudio: true,
sendShare: false,
};

try {
const [localStream, localShare] = await sdkMeeting.getMediaStreams(mediaSettings);
const [localStream] = await sdkMeeting.getMediaStreams(DEFAULT_MEDIA_SETTINGS);

await sdkMeeting.addMedia({
localShare,
localStream,
mediaSettings,
});
// We need to emit a media ready event for retrieving local stream media
sdkMeeting.emit(EVENT_MEDIA_READY, {type: MEDIA_TYPE_LOCAL, stream: localStream});
} catch (error) {
// eslint-disable-next-line no-console
console.error(`Unable to add local media to meeting "${ID}"`, error);
console.error(`Unable to retrieve local stream media "${ID}"`, error);
}
}

Expand Down Expand Up @@ -174,13 +169,20 @@ export default class MeetingsSDKAdapter extends MeetingsAdapter {
* @param {string} ID ID of the meeting to join
* @memberof MeetingsSDKAdapter
*/
joinMeeting(ID) {
this.fetchMeeting(ID)
.join()
.catch((error) => {
// eslint-disable-next-line no-console
console.error(`Unable to join meeting "${ID}"`, error);
});
async joinMeeting(ID) {
try {
const sdkMeeting = this.fetchMeeting(ID);
const {localAudio, localVideo} = this.meetings[ID];
const localStream = new MediaStream([localAudio.getAudioTracks()[0], localVideo.getVideoTracks()[0]]);

await sdkMeeting.join();

// SDK requires to join the meeting before adding the local stream media to the meeting
await sdkMeeting.addMedia({localStream, DEFAULT_MEDIA_SETTINGS});
} catch (error) {
// eslint-disable-next-line no-console
console.error(`Unable to join meeting "${ID}"`, error);
}
}

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

describe('addLocalMedia()', () => {
test('throws errors if the local media is not added to the meeting successfully', async () => {
test('throws errors if the local media is not retrieved successfully', async () => {
mockSDKMeeting.getMediaStreams = jest.fn(() => Promise.reject());
global.console.error = jest.fn();
await meetingSDKAdapter.addLocalMedia(meetingID);

expect(global.console.error).toHaveBeenCalledWith('Unable to add local media to meeting "meetingID"', undefined);
expect(global.console.error).toHaveBeenCalledWith('Unable to retrieve local stream media "meetingID"', undefined);
});
});

Expand Down

0 comments on commit 32c0c51

Please sign in to comment.