Skip to content

Commit

Permalink
Merge pull request #19 from prlanzarin/v0.0.8-dev-keyframe
Browse files Browse the repository at this point in the history
#18 (requestKeyframe/keyframeNeeded)
  • Loading branch information
prlanzarin authored Jul 3, 2019
2 parents fe73b18 + 0f6b8d8 commit 98b12dc
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 5 deletions.
1 change: 1 addition & 0 deletions lib/MCSBaseClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ class MCSBaseClient extends MCSBase {
case C.ON_ICE_CANDIDATE:
case C.DTMF_RECEIVED:
case C.SUBSCRIBED_TO:
case C.KEYFRAME_NEEDED:
identifier = mediaId;
}

Expand Down
17 changes: 17 additions & 0 deletions lib/MCSClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const StartRecordingMessage = require('./messages/startRecording');
const StopRecordingMessage = require('./messages/stopRecording');
const SetStrategy = require('./messages/setStrategy');
const GetStrategy = require('./messages/setStrategy');
const RequestKeyframe = require('./messages/requestKeyframe');

/**
* This class handles connection to Media Control Server application
Expand Down Expand Up @@ -630,6 +631,22 @@ class MCSClient extends MCSBaseClient {
return this.deferTransaction(message);
}
}

/**
* @param {String} mediaId The mediaId to which a keyframe is going to be requested.
*/
requestKeyframe (mediaId) {
if (!mediaId || typeof mediaId !== 'string') {
throw new Error('Error: invalid identifier');
}

const message =
new RequestKeyframe(mediaId);

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

/**
Expand Down
32 changes: 32 additions & 0 deletions lib/MCSResponseClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ const CurrentStrategy = require('./messages/currentStrategy');
const DTMFSent = require('./messages/dtmfSent');
const DTMFReceived = require('./messages/dtmfReceived');
const SubscribedTo = require('./messages/subscribedTo');
const KeyframeRequested = require('./messages/keyframeRequested');
const KeyframeNeeded = require('./messages/keyframeNeeded');

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

/**
* @param {String} mediaId The mediaId to listen for keyframe requests
*/
keyframeNeeded (mediaId) {
if (!mediaId || typeof(mediaId) !== 'string') {
throw new Error('Error : invalid mediaId');
}

const message = new KeyframeNeeded(mediaId);

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

/**
* @param {String} mediaId The mediaId to which a keyframe was requested.
*/
keyframeRequested (mediaId) {
if (!mediaId || typeof(mediaId) !== 'string') {
throw new Error('Error : invalid mediaId');
}

const message = new KeyframeRequested(mediaId);

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

/*
* TODO docs
*/
Expand Down
11 changes: 7 additions & 4 deletions lib/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,17 @@ const C = {
DTMF_SENT: "dtmfSent",
DTMF_RECEIVED: "dtmfReceived",
SUBSCRIBED_TO: "subscribedTo",
REQUEST_KEYFRAME: "requestKeyframe",
KEYFRAME_REQUESTED: "keyframeRequested",
KEYFRAME_NEEDED: "keyframeNeeded",
}

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.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]
[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]
}

module.exports = { ...C, EVENT_UNREGISTER_MAP };
13 changes: 13 additions & 0 deletions lib/messages/keyframeNeeded.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 KeyframeNeeded extends MCSMessage {
constructor(mediaId) {
super(C.KEYFRAME_NEEDED);
this.body.mediaId = mediaId;
}
}

module.exports = KeyframeNeeded;
13 changes: 13 additions & 0 deletions lib/messages/keyframeRequested.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 KeyframeRequested extends MCSMessage {
constructor(mediaId, params) {
super(C.KEYFRAME_REQUESTED, null, params);
this.body.mediaId = mediaId;
}
}

module.exports = KeyframeRequested;
13 changes: 13 additions & 0 deletions lib/messages/requestKeyframe.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 RequestKeyframe extends MCSMessage {
constructor(mediaId) {
super(C.REQUEST_KEYFRAME);
this.body.mediaId = mediaId;
}
}

module.exports = RequestKeyframe;
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.7",
"version": "0.0.8-dev.1",
"dependencies": {
"ws": "6.1.2",
"uuid": "3.3.2"
Expand Down

0 comments on commit 98b12dc

Please sign in to comment.