Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix wrong connectionIds when using multiple erizoJS processes #1439

Merged
merged 4 commits into from
Jul 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions erizo_controller/erizoJS/erizoJS.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ const controller = require('./erizoJSController');
// Logger
const log = logger.getLogger('ErizoJS');

const rpcID = process.argv[2];

process.on('unhandledRejection', (error) => {
log.error('unhandledRejection', error);
});
Expand All @@ -110,7 +112,7 @@ if (global.config.erizo.useNicer) {
ioThreadPool.start();
}

const ejsController = controller.ErizoJSController(threadPool, ioThreadPool);
const ejsController = controller.ErizoJSController(rpcID, threadPool, ioThreadPool);

ejsController.keepAlive = (callback) => {
callback('callback', true);
Expand All @@ -123,8 +125,6 @@ amqper.connect(() => {
try {
amqper.setPublicRPC(ejsController);

const rpcID = process.argv[2];

log.info(`message: Started, erizoId: ${rpcID}, isDebugMode: ${isDebugMode}`);

amqper.bindBroadcast('ErizoJS');
Expand Down
5 changes: 3 additions & 2 deletions erizo_controller/erizoJS/erizoJSController.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const ExternalInput = require('./models/Publisher').ExternalInput;
// Logger
const log = logger.getLogger('ErizoJSController');

exports.ErizoJSController = (threadPool, ioThreadPool) => {
exports.ErizoJSController = (erizoJSId, threadPool, ioThreadPool) => {
const that = {};
// {streamId1: Publisher, streamId2: Publisher}
const publishers = {};
Expand Down Expand Up @@ -86,7 +86,8 @@ exports.ErizoJSController = (threadPool, ioThreadPool) => {
const getOrCreateClient = (erizoControllerId, clientId, singlePC = false) => {
let client = clients.get(clientId);
if (client === undefined) {
client = new Client(erizoControllerId, clientId, threadPool, ioThreadPool, !!singlePC);
client = new Client(erizoControllerId, erizoJSId, clientId,
threadPool, ioThreadPool, !!singlePC);
client.on('status_event', onConnectionStatusEvent.bind(this));
clients.set(clientId, client);
}
Expand Down
7 changes: 4 additions & 3 deletions erizo_controller/erizoJS/models/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ const log = logger.getLogger('Client');

class Client extends EventEmitter {

constructor(erizoControllerId, id, threadPool, ioThreadPool, singlePc = false) {
constructor(erizoControllerId, erizoJSId, id, threadPool, ioThreadPool, singlePc = false) {
super();
log.info(`Constructor Client ${id}`);
this.id = id;
this.erizoJSId = erizoJSId;
this.erizoControllerId = erizoControllerId;
this.connections = new Map();
this.threadPool = threadPool;
Expand All @@ -21,9 +22,9 @@ class Client extends EventEmitter {

_getNewConnectionClientId() {
this.connectionClientId += 1;
let id = `${this.id}_${this.connectionClientId}`;
let id = `${this.id}_${this.erizoJSId}_${this.connectionClientId}`;
while (this.connections.get(id)) {
id = `${this.id}_${this.connectionClientId}`;
id = `${this.id}_${this.erizoJSId}_${this.connectionClientId}`;
this.connectionClientId += 1;
}
return id;
Expand Down
41 changes: 21 additions & 20 deletions erizo_controller/test/erizoJS/erizoJSController.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ describe('Erizo JS Controller', () => {
const kActiveUptimeLimit = 1; // in days
const kMaxTimeSinceLastOperation = 1; // in hours
const kCheckUptimeInterval = 1; // in seconds
const kArbitraryErizoJSId = 'erizoJSId1';

beforeEach('Mock Process', () => {
this.originalExit = process.exit;
Expand All @@ -40,7 +41,7 @@ describe('Erizo JS Controller', () => {
amqperMock = mocks.start(mocks.amqper);
erizoApiMock = mocks.start(mocks.erizoAPI);
// eslint-disable-next-line global-require
controller = require('../../erizoJS/erizoJSController').ErizoJSController();
controller = require('../../erizoJS/erizoJSController').ErizoJSController(kArbitraryErizoJSId);
});

afterEach(() => {
Expand Down Expand Up @@ -238,7 +239,7 @@ describe('Erizo JS Controller', () => {
.equal(mocks.MediaStream);
expect(callback.callCount).to.equal(1);
expect(callback.args[0]).to.deep.equal(['callback',
{ type: 'initializing', connectionId: `${kArbitraryClientId}_1` }]);
{ type: 'initializing', connectionId: `${kArbitraryClientId}_${kArbitraryErizoJSId}_1` }]);
done();
}, 0);
});
Expand Down Expand Up @@ -280,7 +281,7 @@ describe('Erizo JS Controller', () => {
setTimeout(() => {
expect(callback.callCount).to.equal(1);
expect(callback.args[0]).to.deep.equal(['callback',
{ type: 'initializing', connectionId: `${kArbitraryClientId}_1` }]);
{ type: 'initializing', connectionId: `${kArbitraryClientId}_${kArbitraryErizoJSId}_1` }]);
expect(amqperMock.callRpc.withArgs(`erizoController_${kArbitraryErizoControllerId}`,
'connectionStatusEvent').callCount).to.equal(1);
const call = amqperMock.callRpc.withArgs(`erizoController_${kArbitraryErizoControllerId}`,
Expand All @@ -296,7 +297,7 @@ describe('Erizo JS Controller', () => {
setTimeout(() => {
expect(callback.callCount).to.equal(1);
expect(callback.args[0]).to.deep.equal(['callback',
{ type: 'initializing', connectionId: `${kArbitraryClientId}_1` }]);
{ type: 'initializing', connectionId: `${kArbitraryClientId}_${kArbitraryErizoJSId}_1` }]);
expect(amqperMock.callRpc.withArgs(`erizoController_${kArbitraryErizoControllerId}`,
'connectionStatusEvent').callCount).to.equal(1);
const call = amqperMock.callRpc.withArgs(`erizoController_${kArbitraryErizoControllerId}`,
Expand All @@ -311,11 +312,11 @@ describe('Erizo JS Controller', () => {
controller.addPublisher(kArbitraryErizoControllerId, kArbitraryClientId,
kArbitraryStreamId, {}, callback);
controller.processConnectionMessage(kArbitraryErizoControllerId, kArbitraryClientId,
`${kArbitraryClientId}_1`, { type: 'offer', sdp: '' });
`${kArbitraryClientId}_${kArbitraryErizoJSId}_1`, { type: 'offer', sdp: '' });
setTimeout(() => {
expect(callback.callCount).to.equal(1);
expect(callback.args[0]).to.deep.equal(['callback',
{ type: 'initializing', connectionId: `${kArbitraryClientId}_1` }]);
{ type: 'initializing', connectionId: `${kArbitraryClientId}_${kArbitraryErizoJSId}_1` }]);
expect(amqperMock.callRpc.withArgs(`erizoController_${kArbitraryErizoControllerId}`,
'connectionStatusEvent').callCount).to.equal(1);
const call = amqperMock.callRpc.withArgs(`erizoController_${kArbitraryErizoControllerId}`,
Expand All @@ -329,11 +330,11 @@ describe('Erizo JS Controller', () => {
controller.addPublisher(kArbitraryErizoControllerId, kArbitraryClientId,
kArbitraryStreamId, { trickleIce: true }, callback);
controller.processConnectionMessage(kArbitraryErizoControllerId, kArbitraryClientId,
`${kArbitraryClientId}_1`, { type: 'offer', sdp: '' });
`${kArbitraryClientId}_${kArbitraryErizoJSId}_1`, { type: 'offer', sdp: '' });
setTimeout(() => {
expect(callback.callCount).to.equal(1);
expect(callback.args[0]).to.deep.equal(['callback', { type: 'initializing',
connectionId: `${kArbitraryClientId}_1` }]);
connectionId: `${kArbitraryClientId}_${kArbitraryErizoJSId}_1` }]);
expect(amqperMock.callRpc.withArgs(`erizoController_${kArbitraryErizoControllerId}`,
'connectionStatusEvent').callCount).to.equal(1);
const call = amqperMock.callRpc.withArgs(`erizoController_${kArbitraryErizoControllerId}`,
Expand All @@ -350,7 +351,7 @@ describe('Erizo JS Controller', () => {
setTimeout(() => {
expect(callback.callCount).to.equal(1);
expect(callback.args[0]).to.deep.equal(['callback',
{ type: 'initializing', connectionId: `${kArbitraryClientId}_1` }]);
{ type: 'initializing', connectionId: `${kArbitraryClientId}_${kArbitraryErizoJSId}_1` }]);
expect(amqperMock.callRpc.withArgs(`erizoController_${kArbitraryErizoControllerId}`,
'connectionStatusEvent').callCount).to.equal(1);
const call = amqperMock.callRpc.withArgs(`erizoController_${kArbitraryErizoControllerId}`,
Expand All @@ -367,7 +368,7 @@ describe('Erizo JS Controller', () => {
setTimeout(() => {
expect(callback.callCount).to.equal(1);
expect(callback.args[0]).to.deep.equal(['callback',
{ type: 'initializing', connectionId: `${kArbitraryClientId}_1` }]);
{ type: 'initializing', connectionId: `${kArbitraryClientId}_${kArbitraryErizoJSId}_1` }]);
expect(amqperMock.callRpc.withArgs(`erizoController_${kArbitraryErizoControllerId}`,
'connectionStatusEvent').callCount).to.equal(1);
const call = amqperMock.callRpc.withArgs(`erizoController_${kArbitraryErizoControllerId}`,
Expand All @@ -391,11 +392,11 @@ describe('Erizo JS Controller', () => {
initCallback(104, ''); // CONN_READY
}).then(() =>
controller.processConnectionMessage(kArbitraryErizoControllerId, kArbitraryClientId,
`${kArbitraryClientId}_1`, { type: 'offer', sdp: '' }))
`${kArbitraryClientId}_${kArbitraryErizoJSId}_1`, { type: 'offer', sdp: '' }))
.then(() => {
expect(callback.callCount).to.equal(2);
expect(callback.args[0]).to.deep.equal(['callback',
{ type: 'initializing', connectionId: `${kArbitraryClientId}_1` }]);
{ type: 'initializing', connectionId: `${kArbitraryClientId}_${kArbitraryErizoJSId}_1` }]);
expect(amqperMock.callRpc.withArgs(`erizoController_${kArbitraryErizoControllerId}`,
'connectionStatusEvent').callCount).to.equal(2);
const call = amqperMock.callRpc.withArgs(`erizoController_${kArbitraryErizoControllerId}`,
Expand All @@ -413,7 +414,7 @@ describe('Erizo JS Controller', () => {
return Promise.resolve().then(() => {}).then(() => {
expect(callback.callCount).to.equal(2);
expect(callback.args[1]).to.deep.equal(['callback', { type: 'initializing',
connectionId: `${kArbitraryClientId}_1` }]);
connectionId: `${kArbitraryClientId}_${kArbitraryErizoJSId}_1` }]);
expect(callback.args[0]).to.deep.equal(['callback', { type: 'started' }]);
});
});
Expand All @@ -430,15 +431,15 @@ describe('Erizo JS Controller', () => {

it('should set remote sdp when received', () => {
controller.processConnectionMessage(kArbitraryErizoControllerId, kArbitraryClientId,
`${kArbitraryClientId}_1`,
`${kArbitraryClientId}_${kArbitraryErizoJSId}_1`,
{ type: 'offer', sdp: '', config: {} });

expect(mocks.WebRtcConnection.setRemoteDescription.callCount).to.equal(1);
});

it('should set candidate when received', () => {
controller.processConnectionMessage(kArbitraryErizoControllerId, kArbitraryClientId,
`${kArbitraryClientId}_1`, {
`${kArbitraryClientId}_${kArbitraryErizoJSId}_1`, {
type: 'candidate',
candidate: {} });

Expand All @@ -447,7 +448,7 @@ describe('Erizo JS Controller', () => {

it('should update sdp', () => {
controller.processConnectionMessage(kArbitraryErizoControllerId, kArbitraryClientId,
`${kArbitraryClientId}_1`, {
`${kArbitraryClientId}_${kArbitraryErizoJSId}_1`, {
type: 'updatestream',
sdp: 'sdp' });

Expand Down Expand Up @@ -505,7 +506,7 @@ describe('Erizo JS Controller', () => {
expect(subCallback.callCount).to.equal(2);
expect(subCallback.args[0]).to.deep.equal(['callback', { type: 'ready' }]);
expect(subCallback.args[1]).to.deep.equal(['callback', { type: 'initializing',
connectionId: `${kArbitrarySubClientId}_1` }]);
connectionId: `${kArbitrarySubClientId}_${kArbitraryErizoJSId}_1` }]);
expect(mocks.MediaStream.setSlideShowMode.callCount).to.equal(1);
});
});
Expand All @@ -519,7 +520,7 @@ describe('Erizo JS Controller', () => {

it('should set remote sdp when received', () => {
controller.processConnectionMessage(kArbitraryErizoControllerId, kArbitrarySubClientId,
`${kArbitrarySubClientId}_1`, {
`${kArbitrarySubClientId}_${kArbitraryErizoJSId}_1`, {
type: 'offer',
sdp: '',
config: {} });
Expand All @@ -529,7 +530,7 @@ describe('Erizo JS Controller', () => {

it('should set candidate when received', () => {
controller.processConnectionMessage(kArbitraryErizoControllerId, kArbitrarySubClientId,
`${kArbitrarySubClientId}_1`, {
`${kArbitrarySubClientId}_${kArbitraryErizoJSId}_1`, {
type: 'candidate',
candidate: {} });

Expand All @@ -538,7 +539,7 @@ describe('Erizo JS Controller', () => {

it('should update sdp', () => {
controller.processConnectionMessage(kArbitraryErizoControllerId, kArbitrarySubClientId,
`${kArbitrarySubClientId}_1`, {
`${kArbitrarySubClientId}_${kArbitraryErizoJSId}_1`, {
type: 'updatestream',
sdp: 'aaa' });

Expand Down