Skip to content

Commit

Permalink
Merge pull request #21 from mconf/0.x-release
Browse files Browse the repository at this point in the history
v0.0.9
  • Loading branch information
prlanzarin authored Dec 12, 2019
2 parents 06a1e27 + d578283 commit 94292a2
Show file tree
Hide file tree
Showing 9 changed files with 131 additions and 11 deletions.
6 changes: 5 additions & 1 deletion lib/MCSBaseClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class MCSBaseClient extends MCSBase {
}

_getValidIdentifier(eventName, payload) {
const { roomId, userId, mediaId } = payload;
const { roomId, userId, mediaSessionId, mediaId } = payload;
let identifier;
switch (eventName) {
case C.ROOM_CREATED:
Expand All @@ -162,6 +162,10 @@ class MCSBaseClient extends MCSBase {
case C.SUBSCRIBED_TO:
case C.KEYFRAME_NEEDED:
identifier = mediaId;
break;
case C.BITRATE_CHANGE:
identifier = mediaSessionId;
break;
}

return identifier;
Expand Down
25 changes: 23 additions & 2 deletions lib/MCSClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const StopRecordingMessage = require('./messages/stopRecording');
const SetStrategy = require('./messages/setStrategy');
const GetStrategy = require('./messages/setStrategy');
const RequestKeyframe = require('./messages/requestKeyframe');
const GetMedias = require('./messages/getMedias');

/**
* This class handles connection to Media Control Server application
Expand Down Expand Up @@ -555,7 +556,7 @@ class MCSClient extends MCSBaseClient {
/**
* TODO docs
*/
startRecording (userId, mediaId, recordingPath) {
startRecording (userId, mediaId, recordingPath, options) {
if (!userId || typeof userId !== 'string') {
throw new Error('Error: invalid userId');
}
Expand All @@ -569,7 +570,7 @@ class MCSClient extends MCSBaseClient {
}

const message =
new StartRecordingMessage(userId, mediaId, recordingPath);
new StartRecordingMessage(userId, mediaId, recordingPath, options);

if (message) {
return this.deferTransaction(message);
Expand Down Expand Up @@ -647,6 +648,26 @@ class MCSClient extends MCSBaseClient {
return this.deferTransaction(message);
}
}

/**
* TODO docs
*/
getMedias (memberType, identifier, options) {
if (!memberType || typeof memberType !== 'string') {
throw new Error('Error: invalid memberType');
}

if (!identifier || typeof identifier !== 'string') {
throw new Error('Error: invalid identifier');
}

const message =
new GetMedias(memberType, identifier, options);

if (message) {
return this.deferTransaction(message);
}
}
}

/**
Expand Down
31 changes: 31 additions & 0 deletions lib/MCSResponseClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ const DTMFReceived = require('./messages/dtmfReceived');
const SubscribedTo = require('./messages/subscribedTo');
const KeyframeRequested = require('./messages/keyframeRequested');
const KeyframeNeeded = require('./messages/keyframeNeeded');
const BitrateChange = require('./messages/bitrateChange');
const GetMediasResponse = require('./messages/getMediasResponse');

/**
* This class represents a client in server's context. It is used to
Expand Down Expand Up @@ -766,6 +768,35 @@ class MCSResponseClient extends MCSBaseClient {
}
}

/**
* TODO docs
*/
bitrateChange (mediaSessionId, suggestedBitrates, descriptor) {
if (!mediaSessionId || typeof(mediaSessionId) !== 'string') {
throw new Error('Error : invalid mediaSessionId');
}

const message = new BitrateChange(mediaSessionId, suggestedBitrates, descriptor);

if (message) {
return this.send(message);
}
}

/**
* TODO docs
*/
getMediasResponse (medias, options) {
if (!medias || typeof medias !== 'object') {
throw new Error('Error: Invalid user medias object');
}

const message = new GetMediasResponse(medias, options);
if (message) {
this.send(message);
}
}

/*
* TODO docs
*/
Expand Down
32 changes: 27 additions & 5 deletions lib/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,36 @@ const C = {
REQUEST_KEYFRAME: "requestKeyframe",
KEYFRAME_REQUESTED: "keyframeRequested",
KEYFRAME_NEEDED: "keyframeNeeded",
BITRATE_CHANGE: "bitrateChange",
GET_MEDIAS: "getMedias",
GET_MEDIAS_RESPONSE: "getMediasResponse",
}

const MEDIA_TYPES = {
RTP: "RTP",
WebRTC: "WebRTC",
URI: "URI",
RECORDING: "RECORDING",
}

const MEMBER_TYPES = {
ROOM: "room",
USER: "user",
MEDIA_SESSION: "mediaSession",
MEDIA: "media",
}

const EVENT_UNREGISTER_MAP = {
[C.ROOM_DESTROYED]: [C.USER_JOINED, C.USER_LEFT, C.MEDIA_CONNECTED, C.CONFERENCE_FLOOR_CHANGED, C.CONTENT_FLOOR_CHANGED, C.ROOM_DESTROYED],
[C.MEDIA_DISCONNECTED]: [C.MEDIA_STATE, C.MUTED, C.UNMUTED, C.VOLUME_CHANGED, C.ON_ICE_CANDIDATE, C.MEDIA_DISCONNECTED, C.START_TALKING, C.STOP_TALKING, C.DTMF_RECEIVED, C.SUBSCRIBED_TO, C.KEYFRAME_NEEDED],
[C.UNPUBLISHED]: [C.MEDIA_STATE, C.MUTED, C.UNMUTED, C.VOLUME_CHANGED, C.ON_ICE_CANDIDATE, C.MEDIA_DISCONNECTED, C.START_TALKING, C.STOP_TALKING, C.DTMF_RECEIVED, C.SUBSCRIBED_TO, C.KEYFRAME_NEEDED],
[C.UNSUBSCRIBED]: [C.MEDIA_STATE, C.MUTED, C.UNMUTED, C.VOLUME_CHANGED, C.ON_ICE_CANDIDATE, C.MEDIA_DISCONNECTED, C.START_TALKING, C.STOP_TALKING, C.DTMF_RECEIVED, C.SUBSCRIBED_TO, C.KEYFRAME_NEEDED],
[C.UNPUBLISHED_AND_UNSUBSCRIBED]: [C.MEDIA_STATE, C.MUTED, C.UNMUTED, C.VOLUME_CHANGED, C.ON_ICE_CANDIDATE, C.MEDIA_DISCONNECTED, C.START_TALKING, C.STOP_TALKING, C.DTMF_RECEIVED, C.SUBSCRIBED_TO, C.KEYFRAME_NEEDED]
[C.MEDIA_DISCONNECTED]: [C.MEDIA_STATE, C.MUTED, C.UNMUTED, C.VOLUME_CHANGED, C.ON_ICE_CANDIDATE, C.MEDIA_DISCONNECTED, C.START_TALKING, C.STOP_TALKING, C.DTMF_RECEIVED, C.SUBSCRIBED_TO, C.KEYFRAME_NEEDED, C.BITRATE_CHANGE],
[C.UNPUBLISHED]: [C.MEDIA_STATE, C.MUTED, C.UNMUTED, C.VOLUME_CHANGED, C.ON_ICE_CANDIDATE, C.MEDIA_DISCONNECTED, C.START_TALKING, C.STOP_TALKING, C.DTMF_RECEIVED, C.SUBSCRIBED_TO, C.KEYFRAME_NEEDED, C.BITRATE_CHANGE],
[C.UNSUBSCRIBED]: [C.MEDIA_STATE, C.MUTED, C.UNMUTED, C.VOLUME_CHANGED, C.ON_ICE_CANDIDATE, C.MEDIA_DISCONNECTED, C.START_TALKING, C.STOP_TALKING, C.DTMF_RECEIVED, C.SUBSCRIBED_TO, C.KEYFRAME_NEEDED, C.BITRATE_CHANGE],
[C.UNPUBLISHED_AND_UNSUBSCRIBED]: [C.MEDIA_STATE, C.MUTED, C.UNMUTED, C.VOLUME_CHANGED, C.ON_ICE_CANDIDATE, C.MEDIA_DISCONNECTED, C.START_TALKING, C.STOP_TALKING, C.DTMF_RECEIVED, C.SUBSCRIBED_TO, C.KEYFRAME_NEEDED, C.BITRATE_CHANGE]
}

module.exports = { ...C, EVENT_UNREGISTER_MAP };
module.exports = {
...C,
EVENT_UNREGISTER_MAP,
MEMBER_TYPES,
MEDIA_TYPES,
};
15 changes: 15 additions & 0 deletions lib/messages/bitrateChange.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'use strict';

const MCSMessage = require('./MCSMessage');
const C = require('../constants');

class BitrateChange extends MCSMessage {
constructor(mediaSessionId, suggestedBitrates, descriptor = '') {
super(C.BITRATE_CHANGE);
this.body.mediaSessionId = mediaSessionId;
this.body.suggestedBitrates = suggestedBitrates;
this.body.descriptor = descriptor;
}
}

module.exports = BitrateChange;
15 changes: 15 additions & 0 deletions lib/messages/getMedias.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'use strict';

const MCSMessage = require('./MCSMessage');
const C = require('../constants');

class getMedias extends MCSMessage {
constructor(memberType, identifier, options = {}) {
super(C.GET_MEDIAS);
this.body.memberType = memberType;
this.body.identifier = identifier;
this.body.options = options
}
}

module.exports = getMedias;
13 changes: 13 additions & 0 deletions lib/messages/getMediasResponse.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use strict';

const MCSMessage = require('./MCSMessage');
const C = require('../constants');

class GetMediasResponse extends MCSMessage {
constructor(medias, options) {
super(C.GET_MEDIAS_RESPONSE, null, options);
this.body.medias = medias;
}
}

module.exports = GetMediasResponse;
3 changes: 1 addition & 2 deletions lib/messages/userMedias.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ const C = require('../constants');

class UserMedias extends MCSMessage {
constructor(medias, params) {
super(null, null, params);
super(C.USER_MEDIAS);
super(C.USER_MEDIAS, null, params);
this.body.medias = medias;
}
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mcs-js",
"version": "0.0.8",
"version": "0.0.9",
"dependencies": {
"ws": "6.1.2",
"uuid": "3.3.2"
Expand Down

0 comments on commit 94292a2

Please sign in to comment.