Skip to content

Commit

Permalink
Merge pull request #17 from mconf/v0.0.7-dev
Browse files Browse the repository at this point in the history
Version 0.0.7
  • Loading branch information
prlanzarin authored Jun 26, 2019
2 parents e1fef94 + 0a9c2ea commit fe73b18
Show file tree
Hide file tree
Showing 14 changed files with 305 additions and 14 deletions.
4 changes: 4 additions & 0 deletions lib/MCSBaseClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,11 @@ class MCSBaseClient extends MCSBase {
case C.MUTED:
case C.UNMUTED:
case C.VOLUME_CHANGED:
case C.START_TALKING:
case C.STOP_TALKING:
case C.ON_ICE_CANDIDATE:
case C.DTMF_RECEIVED:
case C.SUBSCRIBED_TO:
identifier = mediaId;
}

Expand Down
51 changes: 44 additions & 7 deletions lib/MCSClient.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
'use strict';

const MCSBaseClient = require('./MCSBaseClient');
const MCSTransactionManager = require('./MCSTransactionManager');

Expand Down Expand Up @@ -29,8 +28,9 @@ const ReleaseContentFloorMessage = require('./messages/releaseContentFloor')
const GetConferenceFloorMessage = require('./messages/getConferenceFloor')
const GetContentFloorMessage = require('./messages/getContentFloor')
const StartRecordingMessage = require('./messages/startRecording');

const StopRecordingMessage = require('./messages/stopRecording');
const SetStrategy = require('./messages/setStrategy');
const GetStrategy = require('./messages/setStrategy');

/**
* This class handles connection to Media Control Server application
Expand Down Expand Up @@ -531,19 +531,20 @@ class MCSClient extends MCSBaseClient {
}

/**
* TODO docs
* @param {String} mediaId The mediaId of the object to which the DTMF tone is directed
* @param {Number} tone DTMF tone to be sent to mediaId
*/
dtmf (mediaId, digit) {
dtmf (mediaId, tone) {
if (!mediaId || typeof(mediaId) !== 'string') {
throw new Error('Error : invalid mediaId');
}

if (!digit || typeof digit !== 'number') {
throw new Error('Error: invalid digit');
if (!tone || (typeof tone !== 'number' && typeof tone !== 'string')) {
throw new Error('Error: invalid tone');
}

const message =
new DTMF(mediaId, digit);
new DTMF(mediaId, tone);

if (message) {
return this.deferTransaction(message);
Expand Down Expand Up @@ -593,6 +594,42 @@ class MCSClient extends MCSBaseClient {
return this.deferTransaction(message);
}
}

/**
* TODO docs
*/
setStrategy (identifier, strategy, params) {
if (!identifier || typeof identifier !== 'string') {
throw new Error('Error: invalid identifier');
}

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

const message =
new SetStrategy(identifier, strategy, params);

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

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

const message =
new GetStrategy(identifier);

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

/**
Expand Down
128 changes: 128 additions & 0 deletions lib/MCSResponseClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ const UserJoined = require('./messages/userJoined');
const UserLeft = require('./messages/userLeft');
const Muted = require('./messages/muted');
const Unmuted = require('./messages/unmuted');
const StartTalkingMessage = require('./messages/startTalking');
const StopTalkingMessage = require('./messages/stopTalking');
const MediaConnected = require('./messages/mediaConnected');
const MediaDisconnected = require('./messages/mediaDisconnected');
const VolumeChanged = require('./messages/volumeChanged');
Expand All @@ -34,6 +36,10 @@ const ContentFloor = require('./messages/contentFloor');
const RecordingStarted = require('./messages/recordingStarted');
const RecordingStopped = require('./messages/recordingStopped');
const ErrorMessage = require('./messages/error');
const CurrentStrategy = require('./messages/currentStrategy');
const DTMFSent = require('./messages/dtmfSent');
const DTMFReceived = require('./messages/dtmfReceived');
const SubscribedTo = require('./messages/subscribedTo');

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

startTalking (room, user, mediaId) {
if (!room || typeof(room) !== 'string') {
throw new Error('Error : invalid room');
}

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

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

const message =
new StartTalkingMessage(room, user, mediaId);

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

stopTalking (room, user, mediaId) {
if (!room || typeof(room) !== 'string') {
throw new Error('Error : invalid room');
}

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

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

const message =
new StopTalkingMessage(room, user, mediaId);

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

/**
* @param {String} mediaId The id of the media connected
* @param {String} userId The id of the user that has the media
Expand Down Expand Up @@ -606,6 +654,86 @@ class MCSResponseClient extends MCSBaseClient {
}
}

/**
* @param {String} identifier The id of the object to which the strategy relates to
* @param {String} strategy Active strategy for the identifier object
*/
currentStrategy (identifier, strategy, params) {
if (!identifier || typeof (identifier) !== 'string') {
throw (new Error('invalid identifier'));
}

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

const message = new CurrentStrategy(identifier, strategy);

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

/**
* @param {String} mediaId The mediaId of the object to which the DTMF tone was sent
* @param {Number} tone DTMF tone sent to mediaId
*/
dtmfSent (mediaId, tone, params) {
if (!mediaId || typeof(mediaId) !== 'string') {
throw new Error('Error : invalid mediaId');
}

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

const message = new DTMFSent(mediaId, tone, params);

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

/**
* @param {String} mediaId The mediaId of the object which received a DTMF tone
* @param {Number} tone DTMF tone received by mediaId
*/
dtmfReceived (mediaId, tone, params) {
if (!mediaId || typeof(mediaId) !== 'string') {
throw new Error('Error : invalid mediaId');
}

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

const message = new DTMFReceived(mediaId, tone, params);

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

/**
* @param {String} mediaId The mediaId to listen for source media changes
* @param {Object} sourceMediaInfo A media info object of the new source media
*/
subscribedTo (mediaId, sourceMediaInfo) {
if (!mediaId || typeof(mediaId) !== 'string') {
throw new Error('Error : invalid mediaId');
}

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

const message = new SubscribedTo(mediaId, sourceMediaInfo);

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

/*
* TODO docs
*/
Expand Down
16 changes: 12 additions & 4 deletions lib/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ const C = {
SET_CONFERENCE_FLOOR: "setConferenceFloor",
SET_CONTENT_FLOOR: "setContentFloor",
SET_VOLUME: "setVolume",
START_TALKING: "startTalking",
STOP_TALKING: "stopTalking",
SUBSCRIBE: "subscribe",
SUBSCRIBED: "subscribed",
UNMUTE: "unmute",
Expand All @@ -58,14 +60,20 @@ const C = {
STOP_RECORDING: "stopRecording",
RECORDING_STARTED: "recordingStarted",
RECORDING_STOPPED: "recordingStopped",
SET_STRATEGY: "setStrategy",
GET_STRATEGY: "getStrategy",
CURRENT_STRATEGY: "currentStrategy",
DTMF_SENT: "dtmfSent",
DTMF_RECEIVED: "dtmfReceived",
SUBSCRIBED_TO: "subscribedTo",
}

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.UNPUBLISHED]: [C.MEDIA_STATE, C.MUTED, C.UNMUTED, C.VOLUME_CHANGED, C.ON_ICE_CANDIDATE, C.MEDIA_DISCONNECTED],
[C.UNSUBSCRIBED]: [C.MEDIA_STATE, C.MUTED, C.UNMUTED, C.VOLUME_CHANGED, C.ON_ICE_CANDIDATE, C.MEDIA_DISCONNECTED],
[C.UNPUBLISHED_AND_UNSUBSCRIBED]: [C.MEDIA_STATE, C.MUTED, C.UNMUTED, C.VOLUME_CHANGED, C.ON_ICE_CANDIDATE, C.MEDIA_DISCONNECTED]
[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.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.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.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]
}

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

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

class CurrentStrategy extends MCSMessage {
constructor(identifier, strategy, params) {
super(C.CURRENT_STRATEGY, null, params);
this.body.identifier = identifier;
this.body.strategy = strategy;
}
}

module.exports = CurrentStrategy;
4 changes: 2 additions & 2 deletions lib/messages/dtmf.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ const MCSMessage = require('./MCSMessage');
const C = require('../constants');

class DTMF extends MCSMessage {
constructor(mediaId, digit) {
constructor(mediaId, tone) {
super(C.DTMF);
this.body.mediaId = mediaId;
this.body.digit = digit;
this.body.tone = tone;
}
}

Expand Down
14 changes: 14 additions & 0 deletions lib/messages/dtmfReceived.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'use strict';

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

class DTMFReceived extends MCSMessage {
constructor(mediaId, tone, params) {
super(C.DTMF_RECEIVED, null, params);
this.body.mediaId = mediaId;
this.body.tone = tone;
}
}

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

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

class DTMFSent extends MCSMessage {
constructor(mediaId, tone, params) {
super(C.DTMF_SENT, null, params);
this.body.mediaId = mediaId;
this.body.tone = tone;
}
}

module.exports = DTMFSent;
13 changes: 13 additions & 0 deletions lib/messages/getStrategy.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 GetStrategy extends MCSMessage {
constructor(identifier) {
super(C.GET_STRATEGY);
this.body.identifier = identifier;
}
}

module.exports = GetStrategy;
15 changes: 15 additions & 0 deletions lib/messages/setStrategy.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 SetStrategy extends MCSMessage {
constructor(identifier, strategy, params) {
super(C.SET_STRATEGY);
this.body.identifier = identifier;
this.body.strategy = strategy;
this.body.params = params;
}
}

module.exports = SetStrategy;
15 changes: 15 additions & 0 deletions lib/messages/startTalking.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 StartTalking extends MCSMessage {
constructor(room, user, mediaId) {
super(C.START_TALKING);
this.body.roomId = room;
this.body.userId = user;
this.body.mediaId = mediaId;
}
}

module.exports = StartTalking;
Loading

0 comments on commit fe73b18

Please sign in to comment.