提交 c2c3efdf authored 作者: Iñaki Baz Castillo's avatar Iñaki Baz Castillo

"backup" before removing Peer in worker

上级 1ae26d1c
# BUGS
* `CREATE_PEER` is emitting `newconsumer` but does not emit `newpeer`. Who must do that?
* `then()` of Promises is async so if we create an instance (Peer, Producer, Transport, etc) within the `channel.request().then(....)` and an event happens for that instance immediately, such an event may be lost.
- The solution is creating the instance before calling `channel.request()`.
- DOC: https://stackoverflow.com/questions/36726890/why-are-javascript-promises-asynchronous-when-calling-only-synchronous-functions
+ I must avoid unnecesary `Promise.resolve()`.
- "The callback passed to a Promise constructor is always called synchronously, but the callbacks passed into then are always called asynchronously"
# TODO in mediasoup v2 (server-side) # TODO in mediasoup v2 (server-side)
* If the Producer is paused, should we pass the packet to the BWE? * It's hard that `join` returns an array of `Peers` since, upon creation of the new `Peer`, it will receive `newconsumer` events which will try to send a `newPeer` mediasoup notification to the client.
* Use "@xxxxx" for private events and `safeEmit("xxxx")` for public events (already done except for Producer and Consumer). * worker: If a `Producer` is paused and a new `Peer` joins (so a new `Consumer` is generated) such a new `Consumer` does not know that its associated `Producer` is paused. When creating a `Consumer` the `Room` should check `producer->IsPaused()` and call `consumer->setSourcePaused(true)` or similar.
* If the transport of a consumer is closed, and the consumer was "enabled", it should become "disabled" and emit event? I think yes. Enabled should mean "it has a transport". Period. * If the transport of a consumer is closed, and the consumer was "enabled", it should become "disabled" and emit event (and send `consumerDisabled` notification? I think yes. Enabled should mean "it has a transport and RTP parameters.
- NOTE: We don't need `consumerDisabled` since we already receive `transportClosed` which fires `unhandled` in the client's `Consumer`.
* May have to react on DTLS ALERT CLOSE in the server and make it "really" close the Transport and notify the client. Bufff... I don't like this... * May have to react on DTLS ALERT CLOSE in the server and make it "really" close the Transport and notify the client. Bufff... I don't like this...
......
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
const Logger = require('./Logger'); const Logger = require('./Logger');
const EnhancedEventEmitter = require('./EnhancedEventEmitter'); const EnhancedEventEmitter = require('./EnhancedEventEmitter');
const errors = require('./errors'); const errors = require('./errors');
const Transport = require('./Transport');
const logger = new Logger('Consumer'); const logger = new Logger('Consumer');
...@@ -30,28 +29,25 @@ class Consumer extends EnhancedEventEmitter ...@@ -30,28 +29,25 @@ class Consumer extends EnhancedEventEmitter
// - .peer // - .peer
// - .transport // - .transport
// - .rtpParameters // - .rtpParameters
// - .associatedProducer // - .source
this._data = data; this._data = data;
// Channel instance. // Channel instance.
this._channel = channel; this._channel = channel;
// Subscribe to notifications. // Locally paused flag.
this._channel.on(this._internal.consumerId, (event) => // @type {Boolean}
{ this._locallyPaused = false;
switch (event)
{
case 'close':
{
this.close(); // TODO
break; // Remotely paused flag.
} // @type {Boolean}
this._remotelyPaused = false;
default: // Source paused flag.
logger.error('ignoring unknown event "%s"', event); // @type {Boolean}
} this._sourcePaused = false;
});
this._handleNotifications();
} }
get id() get id()
...@@ -84,24 +80,66 @@ class Consumer extends EnhancedEventEmitter ...@@ -84,24 +80,66 @@ class Consumer extends EnhancedEventEmitter
return this._data.rtpParameters; return this._data.rtpParameters;
} }
get associatedProducer() get source()
{
return this._data.source;
}
/**
* Whether the Consumer is locally paused.
*
* @return {Boolean}
*/
get locallyPaused()
{
return this._locallyPaused;
}
/**
* Whether the Consumer is remotely paused.
*
* @return {Boolean}
*/
get remotelyPaused()
{
return this._remotelyPaused;
}
/**
* Whether the source (Producer) is paused.
*
* @return {Boolean}
*/
get sourcePaused()
{
return this._sourcePaused;
}
/**
* Whether the Consumer is paused.
*
* @return {Boolean}
*/
get paused()
{ {
return this._data.associatedProducer; return this._locallyPaused || this._remotelyPaused || this._sourcePaused;
} }
/** /**
* Close the Consumer. * Close the Consumer.
* The app is not supposed to call this method. *
* @private * @private
*/ */
close() close()
{ {
logger.debug('close()');
if (this._closed) if (this._closed)
return; return;
this._closed = true; this._closed = true;
logger.debug('close()'); this.emit('@notify', 'consumerClosed', { id: this.id });
// Remove notification subscriptions. // Remove notification subscriptions.
this._channel.removeAllListeners(this._internal.consumerId); this._channel.removeAllListeners(this._internal.consumerId);
...@@ -137,125 +175,229 @@ class Consumer extends EnhancedEventEmitter ...@@ -137,125 +175,229 @@ class Consumer extends EnhancedEventEmitter
} }
/** /**
* Assign Transport. * Start sending media to the remote Consumer.
* *
* @param {Transport} transport - Transport instance. * @param {Transport} transport - Transport instance.
* @param {RTCRtpParameters} rtpParameters - Sending RTP parameters.
* *
* @return {Promise} Resolves to this. * @return {Promise} Resolves to this.
*/ */
setTransport(transport) enable(transport, rtpParameters)
{ {
logger.debug('setTransport()'); logger.debug('enable()');
if (this._closed) if (this._closed)
return Promise.reject(new errors.InvalidStateError('Consumer closed')); return Promise.reject(new errors.InvalidStateError('Consumer closed'));
else if (this.transport)
return Promise.reject(new errors.InvalidStateError('Consumer already enabled'));
// Ensure `transport` is given. this._internal.transportId = transport.id;
if (!transport)
return Promise.reject(new TypeError('transport not given'));
// Ensure `transport` is a Transport. const data =
if (!(transport instanceof Transport))
{ {
return Promise.reject( rtpParameters
new TypeError('transport must be a instance of Transport')); };
}
// Ensure `transport` is not closed. return this._channel.request('consumer.enable', this._internal, data)
if (transport.closed)
return Promise.reject(new errors.InvalidStateError('transport is closed'));
const previousTransportId = this._internal.transportId;
this._internal.transportId = transport._internal.transportId;
return this._channel.request('consumer.setTransport', this._internal)
.then(() => .then(() =>
{ {
logger.debug('"consumer.setTransport" request succeeded'); logger.debug('"consumer.enable" request succeeded');
this._data.transport = transport; this._data.transport = transport;
this._data.rtpParameters = rtpParameters;
this.emit('transport', transport); // On Transport closure reset the Consumer.
transport.on('@close', () =>
{
this._internal.transportId = undefined;
});
return this; return this;
}) })
.catch((error) => .catch((error) =>
{ {
logger.error('"consumer.setTransport" request failed: %s', String(error)); logger.error('"consumer.enable" request failed: %s', String(error));
this._internal.transportId = previousTransportId; this._internal.transportId = undefined;
throw error; throw error;
}); });
} }
/** /**
* Enable. * Pauses sending media.
* *
* @return {Promise} Resolves to this. * @param {Any} [appData] - App custom data.
*
* @return {Boolean} true if paused.
*/ */
enable(options) pause(appData)
{ {
logger.debug('enable() [options:%o]', options); logger.debug('pause()');
if (this._closed) if (this._closed)
return Promise.reject(new errors.InvalidStateError('Consumer closed')); {
logger.error('pause() | Consumer closed');
options = options || {}; return false;
}
else if (this._locallyPaused)
{
return true;
}
if (!this._sourcePaused)
this.emit('@notify', 'consumerPaused', { id: this.id, appData });
this._locallyPaused = true;
// Send Channel request. // Send Channel request.
return this._channel.request('consumer.disable', this._internal, this._channel.request('consumer.pause', this._internal)
{
disabled : false,
emit : Boolean(options.emit)
})
.then(() => .then(() =>
{ {
logger.debug('"consumer.disable" request succeeded'); logger.debug('"consumer.pause" request succeeded');
return this;
}) })
.catch((error) => .catch((error) =>
{ {
logger.error('"consumer.disable" request failed: %s', String(error)); logger.error('"consumer.pause" request failed: %s', String(error));
throw error;
}); });
this.safeEmit('pause', 'local', appData);
// Return true if really paused.
return this.paused;
} }
/** /**
* Disable. * The remote Consumer was paused.
* Invoked via remote notification.
* *
* @return {Promise} Resolves to this. * @private
*
* @param {Any} [appData] - App custom data.
*/ */
disable(options) remotePause(appData)
{ {
logger.debug('disable() [options:%o]', options); logger.debug('remotePause()');
if (this._closed) if (this._closed || this._remotelyPaused)
return Promise.reject(new errors.InvalidStateError('Consumer closed')); return;
options = options || {}; this._remotelyPaused = true;
// Send Channel request. // Send Channel request.
return this._channel.request('consumer.disable', this._internal, this._channel.request('consumer.pause', this._internal)
{
disabled : true,
emit : Boolean(options.emit)
})
.then(() => .then(() =>
{ {
logger.debug('"consumer.disable" request succeeded'); logger.debug('"consumer.pause" request succeeded');
return this;
}) })
.catch((error) => .catch((error) =>
{ {
logger.error('"consumer.disable" request failed: %s', String(error)); logger.error('"consumer.pause" request failed: %s', String(error));
throw error;
}); });
this.safeEmit('pause', 'remote', appData);
}
/**
* Resumes sending media.
*
* @param {Any} [appData] - App custom data.
*
* @return {Boolean} true if not paused.
*/
resume(appData)
{
logger.debug('resume()');
if (this._closed)
{
logger.error('resume() | Consumer closed');
return false;
}
else if (!this._locallyPaused)
{
return true;
}
if (!this._sourcePaused)
this.emit('@notify', 'consumerResumed', { id: this.id, appData });
this._locallyPaused = false;
if (!this._remotelyPaused)
{
// Send Channel request.
this._channel.request('consumer.resume', this._internal)
.then(() =>
{
logger.debug('"consumer.resume" request succeeded');
})
.catch((error) =>
{
logger.error('"consumer.resume" request failed: %s', String(error));
});
}
this.safeEmit('resume', 'local', appData);
// Return true if not paused.
return !this.paused;
}
/**
* The remote Consumer was resumed.
* Invoked via remote notification.
*
* @private
*
* @param {Any} [appData] - App custom data.
*/
remoteResume(appData)
{
logger.debug('remoteResume()');
if (this._closed || !this._remotelyPaused)
return;
this._remotelyPaused = false;
if (!this._locallyPaused)
{
// Send Channel request.
this._channel.request('consumer.resume', this._internal)
.then(() =>
{
logger.debug('"consumer.resume" request succeeded');
})
.catch((error) =>
{
logger.error('"consumer.resume" request failed: %s', String(error));
});
}
this.safeEmit('resume', 'remote', appData);
}
_handleNotifications()
{
// Subscribe to notifications.
this._channel.on(this._internal.consumerId, (event) =>
{
switch (event)
{
case 'close':
{
this.close();
break;
}
default:
logger.error('ignoring unknown event "%s"', event);
}
});
} }
} }
......
...@@ -14,7 +14,7 @@ const logger = new Logger('Peer'); ...@@ -14,7 +14,7 @@ const logger = new Logger('Peer');
class Peer extends EnhancedEventEmitter class Peer extends EnhancedEventEmitter
{ {
constructor(internal, channel, sandbox) constructor(internal, data, channel, sandbox)
{ {
super(logger); super(logger);
...@@ -31,7 +31,7 @@ class Peer extends EnhancedEventEmitter ...@@ -31,7 +31,7 @@ class Peer extends EnhancedEventEmitter
// Peer data. // Peer data.
// - .rtpCapabilities // - .rtpCapabilities
this._data = {}; this._data = data;
// Channel instance. // Channel instance.
this._channel = channel; this._channel = channel;
...@@ -43,6 +43,9 @@ class Peer extends EnhancedEventEmitter ...@@ -43,6 +43,9 @@ class Peer extends EnhancedEventEmitter
// App data. // App data.
this._appData = undefined; this._appData = undefined;
// Whether we are joined so can emit '@notify' events.
this._joined = false;
// Map of Transports indexed by id. // Map of Transports indexed by id.
this._transports = new Map(); this._transports = new Map();
...@@ -52,55 +55,7 @@ class Peer extends EnhancedEventEmitter ...@@ -52,55 +55,7 @@ class Peer extends EnhancedEventEmitter
// Map of Consumers indexed by id. // Map of Consumers indexed by id.
this._consumers = new Map(); this._consumers = new Map();
// Subscribe to notifications. this._handleNotifications();
this._channel.on(this._internal.peerId, (event, data) =>
{
switch (event)
{
case 'close':
{
this.close(undefined, false);
break;
}
case 'newconsumer':
{
const associatedProducer = this._sandbox.getProducerById(
data.associatedProducerId);
const internal2 =
{
roomId : this._internal.roomId,
peerId : this._internal.peerId,
consumerId : data.consumerId,
transportId : null
};
const data2 =
{
kind : data.kind,
peer : this,
rtpParameters : data.rtpParameters,
associatedProducer : associatedProducer
};
// Create a Consumer instance.
const consumer = new Consumer(internal2, data2, this._channel);
// Store the Consumer instance and remove it when closed.
this._consumers.set(consumer.id, consumer);
consumer.on('@close', () => this._consumers.delete(consumer.id));
this.safeEmit('newconsumer', consumer);
break;
}
default:
logger.error('ignoring unknown event "%s"', event);
}
});
} }
get id() get id()
...@@ -128,6 +83,11 @@ class Peer extends EnhancedEventEmitter ...@@ -128,6 +83,11 @@ class Peer extends EnhancedEventEmitter
this._appData = appData; this._appData = appData;
} }
set joined(flag)
{
this._joined = Boolean(joined);
}
get rtpCapabilities() get rtpCapabilities()
{ {
return this._data.rtpCapabilities; return this._data.rtpCapabilities;
...@@ -332,21 +292,6 @@ class Peer extends EnhancedEventEmitter ...@@ -332,21 +292,6 @@ class Peer extends EnhancedEventEmitter
}); });
} }
/**
* Set peer RTP capabilities.
*
* @param {RTCRtpCapabilities} [rtpCapabilities]
*/
setRtpCapabilities(rtpCapabilities)
{
logger.debug('setRtpCapabilities()');
if (this._closed)
return Promise.reject(new errors.InvalidStateError('Peer closed'));
this._data.rtpCapabilities = rtpCapabilities;
}
receiveRequest(request) receiveRequest(request)
{ {
if (this._closed) if (this._closed)
...@@ -384,7 +329,7 @@ class Peer extends EnhancedEventEmitter ...@@ -384,7 +329,7 @@ class Peer extends EnhancedEventEmitter
.then(() => transport) .then(() => transport)
.catch((error) => .catch((error) =>
{ {
transport.close(); transport.remoteClose();
throw error; throw error;
}); });
...@@ -449,7 +394,7 @@ class Peer extends EnhancedEventEmitter ...@@ -449,7 +394,7 @@ class Peer extends EnhancedEventEmitter
return producer.receive(rtpParameters, rtpMapping) return producer.receive(rtpParameters, rtpMapping)
.catch((error) => .catch((error) =>
{ {
producer.close(); producer.remoteClose();
throw error; throw error;
}); });
...@@ -531,20 +476,6 @@ class Peer extends EnhancedEventEmitter ...@@ -531,20 +476,6 @@ class Peer extends EnhancedEventEmitter
break; break;
} }
case 'closeProducer':
{
const { id, appData } = notification;
const producer = this._producers.get(id);
// Just ignore it.
if (!producer)
break;
producer.remoteClose(appData);
break;
}
// TODO: Do it. // TODO: Do it.
case 'updateProducer': case 'updateProducer':
{ {
...@@ -577,6 +508,20 @@ class Peer extends EnhancedEventEmitter ...@@ -577,6 +508,20 @@ class Peer extends EnhancedEventEmitter
break; break;
} }
case 'closeProducer':
{
const { id, appData } = notification;
const producer = this._producers.get(id);
// Just ignore it.
if (!producer)
break;
producer.remoteClose(appData);
break;
}
default: default:
throw new Error(`unknown notification method "${method}"`); throw new Error(`unknown notification method "${method}"`);
} }
...@@ -618,7 +563,7 @@ class Peer extends EnhancedEventEmitter ...@@ -618,7 +563,7 @@ class Peer extends EnhancedEventEmitter
{ {
logger.debug('"peer.createTransport" request succeeded'); logger.debug('"peer.createTransport" request succeeded');
// Create a Transport instance. // Create a Transport.
const transport = new Transport(internal, data, this._channel); const transport = new Transport(internal, data, this._channel);
// Store the Transport and remove it when closed. // Store the Transport and remove it when closed.
...@@ -666,8 +611,9 @@ class Peer extends EnhancedEventEmitter ...@@ -666,8 +611,9 @@ class Peer extends EnhancedEventEmitter
const data = const data =
{ {
kind, kind : kind,
transport peer : this,
transport : transport
}; };
const options = const options =
...@@ -693,7 +639,7 @@ class Peer extends EnhancedEventEmitter ...@@ -693,7 +639,7 @@ class Peer extends EnhancedEventEmitter
}); });
// On Transport closure close the Producer. // On Transport closure close the Producer.
transport.on('close', () => transport.on('@close', () =>
{ {
if (!producer.closed) if (!producer.closed)
producer.close(); producer.close();
...@@ -711,6 +657,86 @@ class Peer extends EnhancedEventEmitter ...@@ -711,6 +657,86 @@ class Peer extends EnhancedEventEmitter
throw error; throw error;
}); });
} }
_handleNotifications()
{
// Subscribe to notifications.
this._channel.on(this._internal.peerId, (event, data) =>
{
switch (event)
{
case 'close':
{
this.close(undefined, false);
break;
}
// TODO: yes? or get it from data.peerName in 'newconsumer' and retreive
// peers via JS? Then what about `peerClosed`?
case 'newpeer':
{
// TODO
break;
}
case 'newconsumer':
{
// TODO
console.warn('----------------- newconsumer | peer.consumers:%s', this._consumers.size + 1);
// TODO
const source = this._sandbox.getProducerById(data.sourceId);
const consumerInternal =
{
roomId : this._internal.roomId,
peerId : this._internal.peerId,
consumerId : data.consumerId,
transportId : undefined
};
// TODO
const consumerData =
{
kind : data.kind,
peer : this,
rtpParameters : data.rtpParameters,
source : source
};
// Create a Consumer instance.
const consumer =
new Consumer(consumerInternal, consumerData, this._channel);
// Store the Consumer instance and remove it when closed.
this._consumers.set(consumer.id, consumer);
consumer.on('@close', () => this._consumers.delete(consumer.id));
// TODO: Get the Consumer Peer?
if (this._joined)
{
// TODO: Let's see.
// TODO: appData? of the associated Producer/source?
// const foo = consumer.toJson();
const foo = { id: consumer.id, kind: consumer.kind };
// Send a notification.
this._sendNotification('newConsumer', foo);
}
this.safeEmit('newconsumer', consumer);
break;
}
default:
logger.error('ignoring unknown event "%s"', event);
}
});
}
} }
module.exports = Peer; module.exports = Peer;
...@@ -26,9 +26,9 @@ class Producer extends EnhancedEventEmitter ...@@ -26,9 +26,9 @@ class Producer extends EnhancedEventEmitter
// Producer data. // Producer data.
// - .kind // - .kind
// - .peer
// - .transport // - .transport
// - .rtpParameters // - .rtpParameters
// - .rtpMapping
this._data = data; this._data = data;
// Channel instance. // Channel instance.
...@@ -42,133 +42,7 @@ class Producer extends EnhancedEventEmitter ...@@ -42,133 +42,7 @@ class Producer extends EnhancedEventEmitter
// @type {Boolean} // @type {Boolean}
this._remotelyPaused = false; this._remotelyPaused = false;
// Subscribe to notifications. this._handleNotifications();
this._channel.on(this._internal.producerId, (event, data2, buffer) =>
{
switch (event)
{
case 'close':
{
this.close(undefined, false);
break;
}
case 'rtpraw':
{
this.emit('rtpraw', buffer);
break;
}
case 'rtpobject':
{
// Append the binary buffer into `object.payload`.
data2.object.payload = buffer;
this.emit('rtpobject', data2.object);
break;
}
default:
logger.error('ignoring unknown event "%s"', event);
}
});
// Subscribe to new events.
this.on('newListener', (event) =>
{
switch (event)
{
case 'rtpraw':
{
// Send Channel request.
this._channel.request(
'producer.setRtpRawEvent', this._internal, { enabled: true })
.then(() =>
{
logger.debug('"producer.setRtpRawEvent" request succeeded');
})
.catch((error) =>
{
logger.error(
'"producer.setRtpRawEvent" request failed: %s', String(error));
});
break;
}
case 'rtpobject':
{
// Send Channel request.
this._channel.request(
'producer.setRtpObjectEvent', this._internal, { enabled: true })
.then(() =>
{
logger.debug('"producer.setRtpObjectEvent" request succeeded');
})
.catch((error) =>
{
logger.error(
'"producer.setRtpObjectEvent" request failed: %s', String(error));
});
break;
}
}
});
// Subscribe to events removal.
this.on('removeListener', (event) =>
{
switch (event)
{
case 'rtpraw':
{
// Ignore if there are other remaining listeners.
if (this.listenerCount('rtpraw'))
return;
// Send Channel request.
this._channel.request(
'producer.setRtpRawEvent', this._internal, { enabled: false })
.then(() =>
{
logger.debug('"producer.setRtpRawEvent" request succeeded');
})
.catch((error) =>
{
logger.error(
'"producer.setRtpRawEvent" request failed: %s', String(error));
});
break;
}
case 'rtpobject':
{
// Ignore if there are other remaining listeners.
if (this.listenerCount('rtpobject'))
return;
// Send Channel request.
this._channel.request(
'producer.setRtpObjectEvent', this._internal, { enabled: false })
.then(() =>
{
logger.debug('"producer.setRtpObjectEvent" request succeeded');
})
.catch((error) =>
{
logger.error(
'"producer.setRtpObjectEvent" request failed: %s', String(error));
});
break;
}
}
});
} }
get id() get id()
...@@ -186,6 +60,11 @@ class Producer extends EnhancedEventEmitter ...@@ -186,6 +60,11 @@ class Producer extends EnhancedEventEmitter
return this._data.kind; return this._data.kind;
} }
get peer()
{
return this._data.peer;
}
get transport() get transport()
{ {
return this._data.transport; return this._data.transport;
...@@ -196,11 +75,6 @@ class Producer extends EnhancedEventEmitter ...@@ -196,11 +75,6 @@ class Producer extends EnhancedEventEmitter
return this._data.rtpParameters; return this._data.rtpParameters;
} }
get rtpMapping()
{
return this._data.rtpMapping;
}
/** /**
* Whether the Producer is locally paused. * Whether the Producer is locally paused.
* *
...@@ -246,8 +120,7 @@ class Producer extends EnhancedEventEmitter ...@@ -246,8 +120,7 @@ class Producer extends EnhancedEventEmitter
this._closed = true; this._closed = true;
this.emit( this.emit('@notify', 'producerClosed', { id: this.id, appData });
'@notify', 'producerClosed', { id: this.id, appData });
this.emit('@close'); this.emit('@close');
this.safeEmit('close', 'local', appData); this.safeEmit('close', 'local', appData);
...@@ -354,7 +227,6 @@ class Producer extends EnhancedEventEmitter ...@@ -354,7 +227,6 @@ class Producer extends EnhancedEventEmitter
logger.debug('"producer.receive" request succeeded'); logger.debug('"producer.receive" request succeeded');
this._data.rtpParameters = rtpParameters; this._data.rtpParameters = rtpParameters;
this._data.rtpMapping = rtpMapping;
return this; return this;
}) })
...@@ -388,8 +260,7 @@ class Producer extends EnhancedEventEmitter ...@@ -388,8 +260,7 @@ class Producer extends EnhancedEventEmitter
return true; return true;
} }
this.emit( this.emit('@notify', 'producerPaused', { id: this.id, appData });
'@notify', 'producerPaused', { id: this.id, appData });
this._locallyPaused = true; this._locallyPaused = true;
...@@ -463,8 +334,7 @@ class Producer extends EnhancedEventEmitter ...@@ -463,8 +334,7 @@ class Producer extends EnhancedEventEmitter
return true; return true;
} }
this.emit( this.emit('@notify', 'producerResumed', { id: this.id, appData });
'@notify', 'producerResumed', { id: this.id, appData });
this._locallyPaused = false; this._locallyPaused = false;
...@@ -521,6 +391,137 @@ class Producer extends EnhancedEventEmitter ...@@ -521,6 +391,137 @@ class Producer extends EnhancedEventEmitter
this.safeEmit('resume', 'remote', appData); this.safeEmit('resume', 'remote', appData);
} }
_handleNotifications()
{
// Subscribe to notifications.
this._channel.on(this._internal.producerId, (event, data, buffer) =>
{
switch (event)
{
case 'close':
{
this.close(undefined, false);
break;
}
case 'rtpraw':
{
this.emit('rtpraw', buffer);
break;
}
case 'rtpobject':
{
// Append the binary buffer into `object.payload`.
data.object.payload = buffer;
this.emit('rtpobject', data.object);
break;
}
default:
logger.error('ignoring unknown event "%s"', event);
}
});
// Subscribe to new events.
this.on('newListener', (event) =>
{
switch (event)
{
case 'rtpraw':
{
// Send Channel request.
this._channel.request(
'producer.setRtpRawEvent', this._internal, { enabled: true })
.then(() =>
{
logger.debug('"producer.setRtpRawEvent" request succeeded');
})
.catch((error) =>
{
logger.error(
'"producer.setRtpRawEvent" request failed: %s', String(error));
});
break;
}
case 'rtpobject':
{
// Send Channel request.
this._channel.request(
'producer.setRtpObjectEvent', this._internal, { enabled: true })
.then(() =>
{
logger.debug('"producer.setRtpObjectEvent" request succeeded');
})
.catch((error) =>
{
logger.error(
'"producer.setRtpObjectEvent" request failed: %s', String(error));
});
break;
}
}
});
// Subscribe to events removal.
this.on('removeListener', (event) =>
{
switch (event)
{
case 'rtpraw':
{
// Ignore if there are other remaining listeners.
if (this.listenerCount('rtpraw'))
return;
// Send Channel request.
this._channel.request(
'producer.setRtpRawEvent', this._internal, { enabled: false })
.then(() =>
{
logger.debug('"producer.setRtpRawEvent" request succeeded');
})
.catch((error) =>
{
logger.error(
'"producer.setRtpRawEvent" request failed: %s', String(error));
});
break;
}
case 'rtpobject':
{
// Ignore if there are other remaining listeners.
if (this.listenerCount('rtpobject'))
return;
// Send Channel request.
this._channel.request(
'producer.setRtpObjectEvent', this._internal, { enabled: false })
.then(() =>
{
logger.debug('"producer.setRtpObjectEvent" request succeeded');
})
.catch((error) =>
{
logger.error(
'"producer.setRtpObjectEvent" request failed: %s', String(error));
});
break;
}
}
});
}
} }
module.exports = Producer; module.exports = Producer;
...@@ -38,117 +38,7 @@ class Room extends EnhancedEventEmitter ...@@ -38,117 +38,7 @@ class Room extends EnhancedEventEmitter
// Map of Producer instances indexed by `producerId`. // Map of Producer instances indexed by `producerId`.
this._producers = new Map(); this._producers = new Map();
// Subscribe to notifications. this._handleNotifications();
this._channel.on(this._internal.roomId, (event, data2) =>
{
switch (event)
{
case 'close':
{
this.close(undefined, false);
break;
}
case 'audiolevels':
{
const entries = data2.entries;
const data3 = [];
for (const entry of entries)
{
const producerId = entry[0];
const audioLevel = entry[1];
const producer = this._producers.get(producerId);
if (!producer)
continue;
const peer = producer.peer;
if (!peer)
continue;
data3.push({ peer, producer, audioLevel });
}
const orderedEntries = data3.sort((a, b) =>
{
if (a.audioLevel > b.audioLevel)
return -1;
else if (a.audioLevel < b.audioLevel)
return 1;
else
return 0;
});
this.safeEmit('audiolevels', orderedEntries);
break;
}
default:
logger.error('ignoring unknown event "%s"', event);
}
});
// Subscribe to new events.
this.on('newListener', (event) =>
{
switch (event)
{
case 'audiolevels':
{
// Ignore if there are listeners already.
if (this.listenerCount('audiolevels'))
return;
// Send Channel request.
this._channel.request(
'room.setAudioLevelsEvent', this._internal, { enabled: true })
.then(() =>
{
logger.debug('"room.setAudioLevelsEvent" request succeeded');
})
.catch((error) =>
{
logger.error(
'"room.setAudioLevelsEvent" request failed: %s', String(error));
});
break;
}
}
});
// Subscribe to events removal.
this.on('removeListener', (event) =>
{
switch (event)
{
case 'audiolevels':
{
// Ignore if there are other remaining listeners.
if (this.listenerCount('audiolevels'))
return;
// Send Channel request.
this._channel.request(
'room.setAudioLevelsEvent', this._internal, { enabled: false })
.then(() =>
{
logger.debug('"room.setAudioLevelsEvent" request succeeded');
})
.catch((error) =>
{
logger.error(
'"room.setAudioLevelsEvent" request failed: %s', String(error));
});
break;
}
}
});
} }
get id() get id()
...@@ -292,39 +182,20 @@ class Room extends EnhancedEventEmitter ...@@ -292,39 +182,20 @@ class Room extends EnhancedEventEmitter
{ {
const { peerName, rtpCapabilities, appData } = request; const { peerName, rtpCapabilities, appData } = request;
return Promise.resolve() // Ensure that the given capabilties are a subset of the Room
.then(() => // capabilities.
{ // NOTE: This may throw.
const peer = this._createPeer(peerName); ortc.assertCapabilitiesSubset(
rtpCapabilities, this.rtpCapabilities);
peer.appData = appData;
const peer = this._createPeer(peerName, rtpCapabilities, appData);
try
{ const response =
// Ensure that the given capabilties are a subset of the room {
// capabilities. peers : [] // TODO: remove...
// NOTE: This may throw. };
ortc.assertCapabilitiesSubset(
rtpCapabilities, this.rtpCapabilities); return response;
peer.setRtpCapabilities(rtpCapabilities);
}
catch (error)
{
peer.close(undefined, false);
throw error;
}
})
.then(() =>
{
const response =
{
peers : [] // TODO
};
return response;
});
} }
default: default:
...@@ -339,21 +210,14 @@ class Room extends EnhancedEventEmitter ...@@ -339,21 +210,14 @@ class Room extends EnhancedEventEmitter
}); });
} }
/** _createPeer(peerName, rtpCapabilities, appData)
* Create a Peer instance.
*
* @param {String} peerName - Peer identificator.
*
* @return {Peer}
*/
_createPeer(peerName)
{ {
logger.debug('_createPeer() [peerName:"%s]', peerName); logger.debug('_createPeer() [peerName:"%s]', peerName);
if (!peerName || typeof peerName !== 'string') if (!peerName || typeof peerName !== 'string')
throw new TypeError('peerName must be a string'); return Promise.reject(new TypeError('peerName must be a string'));
else if (this._peers.has(peerName)) else if (this._peers.has(peerName))
throw new Error(`Peer already exists [peerName:"${peerName}"]`); return Promise.reject(new Error(`duplicated Peer [peerName:"${peerName}"]`));
const internal = const internal =
{ {
...@@ -362,7 +226,11 @@ class Room extends EnhancedEventEmitter ...@@ -362,7 +226,11 @@ class Room extends EnhancedEventEmitter
peerName : peerName peerName : peerName
}; };
// TODO: yes? const data =
{
rtpCapabilities
};
const sandbox = const sandbox =
{ {
getProducerById : (producerId) => getProducerById : (producerId) =>
...@@ -379,18 +247,20 @@ class Room extends EnhancedEventEmitter ...@@ -379,18 +247,20 @@ class Room extends EnhancedEventEmitter
}; };
// Create a Peer. // Create a Peer.
const peer = new Peer(internal, this._channel, sandbox); const peer = new Peer(internal, data, this._channel, sandbox);
peer.appData = appData;
// Store the Peer and remove it when closed. // Store the Peer and remove it when closed.
this._peers.set(peer.name, peer); this._peers.set(peer.name, peer);
peer.on('close', () => this._peers.delete(peer.name)); peer.on('@close', () => this._peers.delete(peer.name));
// Listen for new Producers so we can associate new Consumers. // Listen for new Producers so we can associate new Consumers.
peer.on('@newproducer', (producer) => peer.on('@newproducer', (producer) =>
{ {
// Store the Producer and remove it when closed. // Store the Producer and remove it when closed.
this._producers.set(producer.id, producer); this._producers.set(producer.id, producer);
producer.on('close', () => this._producers.delete(producer.id)); producer.on('@close', () => this._producers.delete(producer.id));
}); });
this._channel.request('room.createPeer', internal) this._channel.request('room.createPeer', internal)
...@@ -398,17 +268,131 @@ class Room extends EnhancedEventEmitter ...@@ -398,17 +268,131 @@ class Room extends EnhancedEventEmitter
{ {
logger.debug('"room.createPeer" request succeeded'); logger.debug('"room.createPeer" request succeeded');
this.safeEmit('newpeer', peer); peer.joined = true;
}) })
.catch((error) => .catch((error) =>
{ {
logger.error('"room.createPeer" request failed: %s', String(error)); logger.error('"room.createPeer" request failed: %s', String(error));
peer.close(undefined, false); peer.close();
}); });
this.safeEmit('newpeer', peer);
return peer; return peer;
} }
_handleNotifications()
{
// Subscribe to notifications.
this._channel.on(this._internal.roomId, (event, data) =>
{
switch (event)
{
case 'close':
{
this.close(undefined, false);
break;
}
case 'audiolevels':
{
const entries = data.entries;
const entries2 = [];
for (const entry of entries)
{
const producerId = entry[0];
const audioLevel = entry[1];
const producer = this._producers.get(producerId);
if (!producer)
continue;
const peer = producer.peer;
entries2.push({ peer, producer, audioLevel });
}
const orderedEntries = entries2.sort((a, b) =>
{
if (a.audioLevel > b.audioLevel)
return -1;
else if (a.audioLevel < b.audioLevel)
return 1;
else
return 0;
});
this.safeEmit('audiolevels', orderedEntries);
break;
}
default:
logger.error('ignoring unknown event "%s"', event);
}
});
// Subscribe to new events.
this.on('newListener', (event) =>
{
switch (event)
{
case 'audiolevels':
{
// Ignore if there are listeners already.
if (this.listenerCount('audiolevels'))
return;
// Send Channel request.
this._channel.request(
'room.setAudioLevelsEvent', this._internal, { enabled: true })
.then(() =>
{
logger.debug('"room.setAudioLevelsEvent" request succeeded');
})
.catch((error) =>
{
logger.error(
'"room.setAudioLevelsEvent" request failed: %s', String(error));
});
break;
}
}
});
// Subscribe to events removal.
this.on('removeListener', (event) =>
{
switch (event)
{
case 'audiolevels':
{
// Ignore if there are other remaining listeners.
if (this.listenerCount('audiolevels'))
return;
// Send Channel request.
this._channel.request(
'room.setAudioLevelsEvent', this._internal, { enabled: false })
.then(() =>
{
logger.debug('"room.setAudioLevelsEvent" request succeeded');
})
.catch((error) =>
{
logger.error(
'"room.setAudioLevelsEvent" request failed: %s', String(error));
});
break;
}
}
});
}
} }
module.exports = Room; module.exports = Room;
...@@ -65,55 +65,7 @@ class Transport extends EnhancedEventEmitter ...@@ -65,55 +65,7 @@ class Transport extends EnhancedEventEmitter
// App data. // App data.
this._appData = undefined; this._appData = undefined;
// Subscribe to notifications. this._handleNotifications();
this._channel.on(this._internal.transportId, (event, data2) =>
{
switch (event)
{
case 'close':
{
this.close(undefined, false);
break;
}
case 'iceselectedtuplechange':
{
this._data.iceSelectedTuple = data2.iceSelectedTuple;
// Emit it to the app.
this.safeEmit('iceselectedtuplechange', data2.iceSelectedTuple);
break;
}
case 'icestatechange':
{
this._data.iceState = data2.iceState;
// Emit it to the app.
this.safeEmit('icestatechange', data2.iceState);
break;
}
case 'dtlsstatechange':
{
this._data.dtlsState = data2.dtlsState;
if (data2.dtlsState === 'connected')
this._data.dtlsRemoteCert = data2.dtlsRemoteCert;
// Emit it to the app.
this.safeEmit('dtlsstatechange', data2.dtlsState);
break;
}
default:
logger.error('ignoring unknown event "%s"', event);
}
});
} }
get id() get id()
...@@ -377,6 +329,59 @@ class Transport extends EnhancedEventEmitter ...@@ -377,6 +329,59 @@ class Transport extends EnhancedEventEmitter
throw error; throw error;
}); });
} }
_handleNotifications()
{
// Subscribe to notifications.
this._channel.on(this._internal.transportId, (event, data) =>
{
switch (event)
{
case 'close':
{
this.close(undefined, false);
break;
}
case 'iceselectedtuplechange':
{
this._data.iceSelectedTuple = data.iceSelectedTuple;
// Emit it to the app.
this.safeEmit('iceselectedtuplechange', data.iceSelectedTuple);
break;
}
case 'icestatechange':
{
this._data.iceState = data.iceState;
// Emit it to the app.
this.safeEmit('icestatechange', data.iceState);
break;
}
case 'dtlsstatechange':
{
this._data.dtlsState = data.dtlsState;
if (data.dtlsState === 'connected')
this._data.dtlsRemoteCert = data.dtlsRemoteCert;
// Emit it to the app.
this.safeEmit('dtlsstatechange', data.dtlsState);
break;
}
default:
logger.error('ignoring unknown event "%s"', event);
}
});
}
} }
module.exports = Transport; module.exports = Transport;
...@@ -18,9 +18,14 @@ namespace Channel ...@@ -18,9 +18,14 @@ namespace Channel
void EmitWithBinary( void EmitWithBinary(
uint32_t targetId, uint32_t targetId,
const std::string& event, const std::string& event,
Json::Value& data,
const uint8_t* binaryData, const uint8_t* binaryData,
size_t binaryLen); size_t binaryLen);
void EmitWithBinary(
uint32_t targetId,
const std::string& event,
const uint8_t* binaryData,
size_t binaryLen,
Json::Value& data);
public: public:
// Passed by argument. // Passed by argument.
......
...@@ -42,8 +42,9 @@ namespace Channel ...@@ -42,8 +42,9 @@ namespace Channel
PRODUCER_SET_RTP_RAW_EVENT, PRODUCER_SET_RTP_RAW_EVENT,
PRODUCER_SET_RTP_OBJECT_EVENT, PRODUCER_SET_RTP_OBJECT_EVENT,
CONSUMER_DUMP, CONSUMER_DUMP,
CONSUMER_SET_TRANSPORT, CONSUMER_ENABLE,
CONSUMER_DISABLE CONSUMER_PAUSE,
CONSUMER_RESUME
}; };
private: private:
......
...@@ -71,7 +71,8 @@ namespace RTC ...@@ -71,7 +71,8 @@ namespace RTC
RTC::RtpParameters* rtpParameters{ nullptr }; RTC::RtpParameters* rtpParameters{ nullptr };
RTC::RtpStreamSend* rtpStream{ nullptr }; RTC::RtpStreamSend* rtpStream{ nullptr };
// Others. // Others.
std::unordered_set<uint8_t> supportedPayloadTypes; bool paused{ false };
std::unordered_set<uint8_t> supportedPayloadTypes; // TODO: NO
// Timestamp when last RTCP was sent. // Timestamp when last RTCP was sent.
uint64_t lastRtcpSentTime{ 0 }; uint64_t lastRtcpSentTime{ 0 };
uint16_t maxRtcpInterval{ 0 }; uint16_t maxRtcpInterval{ 0 };
...@@ -96,8 +97,11 @@ namespace RTC ...@@ -96,8 +97,11 @@ namespace RTC
{ {
if (this->transport == transport) if (this->transport == transport)
this->transport = nullptr; this->transport = nullptr;
// TODO: More. Remove rtpParameters.
} }
// TODO: What for?
inline RTC::RtpParameters* Consumer::GetParameters() const inline RTC::RtpParameters* Consumer::GetParameters() const
{ {
return this->rtpParameters; return this->rtpParameters;
......
...@@ -64,6 +64,7 @@ namespace RTC ...@@ -64,6 +64,7 @@ namespace RTC
RTC::Transport* GetTransport() const; RTC::Transport* GetTransport() const;
void RemoveTransport(RTC::Transport* transport); void RemoveTransport(RTC::Transport* transport);
RTC::RtpParameters* GetParameters() const; RTC::RtpParameters* GetParameters() const;
bool IsPaused() const;
void ReceiveRtpPacket(RTC::RtpPacket* packet); void ReceiveRtpPacket(RTC::RtpPacket* packet);
void ReceiveRtcpSenderReport(RTC::RTCP::SenderReport* report); void ReceiveRtcpSenderReport(RTC::RTCP::SenderReport* report);
void GetRtcp(RTC::RTCP::CompoundPacket* packet, uint64_t now); void GetRtcp(RTC::RTCP::CompoundPacket* packet, uint64_t now);
...@@ -95,11 +96,11 @@ namespace RTC ...@@ -95,11 +96,11 @@ namespace RTC
// Allocated by this. // Allocated by this.
RTC::RtpParameters* rtpParameters{ nullptr }; RTC::RtpParameters* rtpParameters{ nullptr };
std::map<uint32_t, RTC::RtpStreamRecv*> rtpStreams; std::map<uint32_t, RTC::RtpStreamRecv*> rtpStreams;
std::map<uint32_t, RTC::RtpStreamRecv*> rtxStreamMap; std::map<uint32_t, RTC::RtpStreamRecv*> mapRtxStreams;
bool paused{ false };
// Others. // Others.
struct RtpMapping rtpMapping; struct RtpMapping rtpMapping;
struct KnownHeaderExtensions knownHeaderExtensions; struct KnownHeaderExtensions knownHeaderExtensions;
bool paused{ false };
bool rtpRawEventEnabled{ false }; bool rtpRawEventEnabled{ false };
bool rtpObjectEventEnabled{ false }; bool rtpObjectEventEnabled{ false };
// Timestamp when last RTCP was sent. // Timestamp when last RTCP was sent.
...@@ -130,6 +131,11 @@ namespace RTC ...@@ -130,6 +131,11 @@ namespace RTC
return this->rtpParameters; return this->rtpParameters;
} }
inline bool Producer::IsPaused() const
{
return this->paused;
}
inline void Producer::ReceiveRtcpSenderReport(RTC::RTCP::SenderReport* report) inline void Producer::ReceiveRtcpSenderReport(RTC::RTCP::SenderReport* report)
{ {
auto it = this->rtpStreams.find(report->GetSsrc()); auto it = this->rtpStreams.find(report->GetSsrc());
......
...@@ -43,6 +43,7 @@ namespace RTC ...@@ -43,6 +43,7 @@ namespace RTC
private: private:
RTC::Peer* GetPeerFromRequest(Channel::Request* request, uint32_t* peerId = nullptr) const; RTC::Peer* GetPeerFromRequest(Channel::Request* request, uint32_t* peerId = nullptr) const;
void AddConsumerForProducer(RTC::Peer* consumerPeer, const RTC::Producer* producer);
/* Pure virtual methods inherited from RTC::Peer::Listener. */ /* Pure virtual methods inherited from RTC::Peer::Listener. */
public: public:
......
...@@ -48,12 +48,34 @@ namespace Channel ...@@ -48,12 +48,34 @@ namespace Channel
void Notifier::EmitWithBinary( void Notifier::EmitWithBinary(
uint32_t targetId, uint32_t targetId,
const std::string& event, const std::string& event,
Json::Value& data,
const uint8_t* binaryData, const uint8_t* binaryData,
size_t binaryLen) size_t binaryLen)
{ {
MS_TRACE(); MS_TRACE();
static const Json::StaticString JsonStringTargetId{ "targetId" };
static const Json::StaticString JsonStringEvent{ "event" };
static const Json::StaticString JsonStringBinary{ "binary" };
Json::Value json(Json::objectValue);
json[JsonStringTargetId] = Json::UInt{ targetId };
json[JsonStringEvent] = event;
json[JsonStringBinary] = true;
this->channel->Send(json);
this->channel->SendBinary(binaryData, binaryLen);
}
void Notifier::EmitWithBinary(
uint32_t targetId,
const std::string& event,
const uint8_t* binaryData,
size_t binaryLen,
Json::Value& data)
{
MS_TRACE();
static const Json::StaticString JsonStringTargetId{ "targetId" }; static const Json::StaticString JsonStringTargetId{ "targetId" };
static const Json::StaticString JsonStringEvent{ "event" }; static const Json::StaticString JsonStringEvent{ "event" };
static const Json::StaticString JsonStringData{ "data" }; static const Json::StaticString JsonStringData{ "data" };
...@@ -63,8 +85,8 @@ namespace Channel ...@@ -63,8 +85,8 @@ namespace Channel
json[JsonStringTargetId] = Json::UInt{ targetId }; json[JsonStringTargetId] = Json::UInt{ targetId };
json[JsonStringEvent] = event; json[JsonStringEvent] = event;
json[JsonStringData] = data;
json[JsonStringBinary] = true; json[JsonStringBinary] = true;
json[JsonStringData] = data;
this->channel->Send(json); this->channel->Send(json);
this->channel->SendBinary(binaryData, binaryLen); this->channel->SendBinary(binaryData, binaryLen);
......
...@@ -37,8 +37,9 @@ namespace Channel ...@@ -37,8 +37,9 @@ namespace Channel
{ "producer.setRtpRawEvent", Request::MethodId::PRODUCER_SET_RTP_RAW_EVENT }, { "producer.setRtpRawEvent", Request::MethodId::PRODUCER_SET_RTP_RAW_EVENT },
{ "producer.setRtpObjectEvent", Request::MethodId::PRODUCER_SET_RTP_OBJECT_EVENT }, { "producer.setRtpObjectEvent", Request::MethodId::PRODUCER_SET_RTP_OBJECT_EVENT },
{ "consumer.dump", Request::MethodId::CONSUMER_DUMP }, { "consumer.dump", Request::MethodId::CONSUMER_DUMP },
{ "consumer.setTransport", Request::MethodId::CONSUMER_SET_TRANSPORT }, { "consumer.enable", Request::MethodId::CONSUMER_ENABLE },
{ "consumer.disable", Request::MethodId::CONSUMER_DISABLE } { "consumer.pause", Request::MethodId::CONSUMER_PAUSE },
{ "consumer.resume", Request::MethodId::CONSUMER_RESUME }
}; };
// clang-format on // clang-format on
......
...@@ -230,8 +230,9 @@ void Loop::OnChannelRequest(Channel::UnixStreamSocket* /*channel*/, Channel::Req ...@@ -230,8 +230,9 @@ void Loop::OnChannelRequest(Channel::UnixStreamSocket* /*channel*/, Channel::Req
case Channel::Request::MethodId::PRODUCER_SET_RTP_RAW_EVENT: case Channel::Request::MethodId::PRODUCER_SET_RTP_RAW_EVENT:
case Channel::Request::MethodId::PRODUCER_SET_RTP_OBJECT_EVENT: case Channel::Request::MethodId::PRODUCER_SET_RTP_OBJECT_EVENT:
case Channel::Request::MethodId::CONSUMER_DUMP: case Channel::Request::MethodId::CONSUMER_DUMP:
case Channel::Request::MethodId::CONSUMER_SET_TRANSPORT: case Channel::Request::MethodId::CONSUMER_ENABLE:
case Channel::Request::MethodId::CONSUMER_DISABLE: case Channel::Request::MethodId::CONSUMER_PAUSE:
case Channel::Request::MethodId::CONSUMER_RESUME:
{ {
RTC::Room* room; RTC::Room* room;
......
...@@ -41,12 +41,7 @@ namespace RTC ...@@ -41,12 +41,7 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
static const Json::StaticString JsonStringClass{ "class" }; this->notifier->Emit(this->consumerId, "close");
Json::Value eventData(Json::objectValue);
eventData[JsonStringClass] = "Consumer";
this->notifier->Emit(this->consumerId, "close", eventData);
// Notify the listener. // Notify the listener.
this->listener->OnConsumerClosed(this); this->listener->OnConsumerClosed(this);
...@@ -109,6 +104,29 @@ namespace RTC ...@@ -109,6 +104,29 @@ namespace RTC
break; break;
} }
case Channel::Request::MethodId::CONSUMER_PAUSE:
{
this->paused = true;
request->Accept();
break;
}
case Channel::Request::MethodId::CONSUMER_RESUME:
{
bool wasPaused = this->paused;
this->paused = false;
request->Accept();
if (wasPaused)
this->listener->OnConsumerFullFrameRequired(this);
break;
}
default: default:
{ {
MS_ERROR("unknown method"); MS_ERROR("unknown method");
...@@ -122,10 +140,6 @@ namespace RTC ...@@ -122,10 +140,6 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
static const Json::StaticString JsonStringClass{ "class" };
static const Json::StaticString JsonStringRtpParameters{ "rtpParameters" };
static const Json::StaticString JsonStringEnabled{ "enabled" };
MS_ASSERT(rtpParameters, "no RTP parameters given"); MS_ASSERT(rtpParameters, "no RTP parameters given");
// Free the previous RTP parameters. // Free the previous RTP parameters.
......
...@@ -38,10 +38,6 @@ namespace RTC ...@@ -38,10 +38,6 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
static const Json::StaticString JsonStringClass{ "class" };
Json::Value eventData(Json::objectValue);
// Close all the Producers. // Close all the Producers.
for (auto it = this->producers.begin(); it != this->producers.end();) for (auto it = this->producers.begin(); it != this->producers.end();)
{ {
...@@ -72,8 +68,7 @@ namespace RTC ...@@ -72,8 +68,7 @@ namespace RTC
} }
// Notify. // Notify.
eventData[JsonStringClass] = "Peer"; this->notifier->Emit(this->peerId, "close");
this->notifier->Emit(this->peerId, "close", eventData);
// Notify the listener. // Notify the listener.
this->listener->OnPeerClosed(this); this->listener->OnPeerClosed(this);
...@@ -346,83 +341,58 @@ namespace RTC ...@@ -346,83 +341,58 @@ namespace RTC
break; break;
} }
case Channel::Request::MethodId::CONSUMER_DUMP: case Channel::Request::MethodId::CONSUMER_ENABLE:
{
RTC::Consumer* consumer;
try
{
consumer = GetConsumerFromRequest(request);
}
catch (const MediaSoupError& error)
{
request->Reject(error.what());
return;
}
if (consumer == nullptr)
{
request->Reject("Consumer does not exist");
return;
}
consumer->HandleRequest(request);
break;
}
case Channel::Request::MethodId::CONSUMER_SET_TRANSPORT:
{ {
RTC::Consumer* consumer; // RTC::Consumer* consumer;
try // try
{ // {
consumer = GetConsumerFromRequest(request); // consumer = GetConsumerFromRequest(request);
} // }
catch (const MediaSoupError& error) // catch (const MediaSoupError& error)
{ // {
request->Reject(error.what()); // request->Reject(error.what());
return; // return;
} // }
if (consumer == nullptr) // if (consumer == nullptr)
{ // {
request->Reject("Consumer does not exist"); // request->Reject("Consumer does not exist");
return; // return;
} // }
RTC::Transport* transport; // RTC::Transport* transport;
try // try
{ // {
transport = GetTransportFromRequest(request); // transport = GetTransportFromRequest(request);
} // }
catch (const MediaSoupError& error) // catch (const MediaSoupError& error)
{ // {
request->Reject(error.what()); // request->Reject(error.what());
return; // return;
} // }
if (transport == nullptr) // if (transport == nullptr)
{ // {
request->Reject("Transport does not exist"); // request->Reject("Transport does not exist");
return; // return;
} // }
consumer->SetTransport(transport); // consumer->SetTransport(transport);
request->Accept(); request->Accept();
break; break;
} }
case Channel::Request::MethodId::CONSUMER_DISABLE: case Channel::Request::MethodId::CONSUMER_DUMP:
case Channel::Request::MethodId::CONSUMER_PAUSE:
case Channel::Request::MethodId::CONSUMER_RESUME:
{ {
RTC::Consumer* consumer; RTC::Consumer* consumer;
...@@ -463,7 +433,6 @@ namespace RTC ...@@ -463,7 +433,6 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
static const Json::StaticString JsonStringClass{ "class" };
static const Json::StaticString JsonStringConsumerId{ "consumerId" }; static const Json::StaticString JsonStringConsumerId{ "consumerId" };
static const Json::StaticString JsonStringKind{ "kind" }; static const Json::StaticString JsonStringKind{ "kind" };
static const Json::StaticString JsonStringRtpParameters{ "rtpParameters" }; static const Json::StaticString JsonStringRtpParameters{ "rtpParameters" };
...@@ -483,7 +452,6 @@ namespace RTC ...@@ -483,7 +452,6 @@ namespace RTC
// Notify. // Notify.
Json::Value eventData = consumer->ToJson(); Json::Value eventData = consumer->ToJson();
eventData[JsonStringClass] = "Peer";
eventData[JsonStringConsumerId] = Json::UInt{ consumer->consumerId }; eventData[JsonStringConsumerId] = Json::UInt{ consumer->consumerId };
eventData[JsonStringKind] = RTC::Media::GetJsonString(consumer->kind); eventData[JsonStringKind] = RTC::Media::GetJsonString(consumer->kind);
eventData[JsonStringRtpParameters] = consumer->GetParameters()->ToJson(); eventData[JsonStringRtpParameters] = consumer->GetParameters()->ToJson();
......
...@@ -38,13 +38,8 @@ namespace RTC ...@@ -38,13 +38,8 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
static const Json::StaticString JsonStringClass{ "class" };
Json::Value eventData(Json::objectValue);
// Notify. // Notify.
eventData[JsonStringClass] = "Producer"; this->notifier->Emit(this->producerId, "close");
this->notifier->Emit(this->producerId, "close", eventData);
// Notify the listener. // Notify the listener.
this->listener->OnProducerClosed(this); this->listener->OnProducerClosed(this);
...@@ -286,7 +281,6 @@ namespace RTC ...@@ -286,7 +281,6 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
static const Json::StaticString JsonStringClass{ "class" };
static const Json::StaticString JsonStringObject{ "object" }; static const Json::StaticString JsonStringObject{ "object" };
static const Json::StaticString JsonStringPayloadType{ "payloadType" }; static const Json::StaticString JsonStringPayloadType{ "payloadType" };
static const Json::StaticString JsonStringMarker{ "marker" }; static const Json::StaticString JsonStringMarker{ "marker" };
...@@ -307,9 +301,9 @@ namespace RTC ...@@ -307,9 +301,9 @@ namespace RTC
if (!rtpStream->ReceivePacket(packet)) if (!rtpStream->ReceivePacket(packet))
return; return;
} }
else if (this->rtxStreamMap.find(ssrc) != this->rtxStreamMap.end()) else if (this->mapRtxStreams.find(ssrc) != this->mapRtxStreams.end())
{ {
rtpStream = this->rtxStreamMap[ssrc]; rtpStream = this->mapRtxStreams[ssrc];
// Process the packet. // Process the packet.
if (!rtpStream->ReceiveRtxPacket(packet)) if (!rtpStream->ReceiveRtxPacket(packet))
...@@ -329,12 +323,8 @@ namespace RTC ...@@ -329,12 +323,8 @@ namespace RTC
// Emit "rtpraw" if enabled. // Emit "rtpraw" if enabled.
if (this->rtpRawEventEnabled) if (this->rtpRawEventEnabled)
{ {
Json::Value eventData(Json::objectValue);
eventData[JsonStringClass] = "Producer";
this->notifier->EmitWithBinary( this->notifier->EmitWithBinary(
this->producerId, "rtpraw", eventData, packet->GetData(), packet->GetSize()); this->producerId, "rtpraw", packet->GetData(), packet->GetSize());
} }
// Emit "rtpobject" is enabled. // Emit "rtpobject" is enabled.
...@@ -343,8 +333,6 @@ namespace RTC ...@@ -343,8 +333,6 @@ namespace RTC
Json::Value eventData(Json::objectValue); Json::Value eventData(Json::objectValue);
Json::Value jsonObject(Json::objectValue); Json::Value jsonObject(Json::objectValue);
eventData[JsonStringClass] = "Producer";
jsonObject[JsonStringPayloadType] = Json::UInt{ packet->GetPayloadType() }; jsonObject[JsonStringPayloadType] = Json::UInt{ packet->GetPayloadType() };
jsonObject[JsonStringMarker] = packet->HasMarker(); jsonObject[JsonStringMarker] = packet->HasMarker();
jsonObject[JsonStringSequenceNumber] = Json::UInt{ packet->GetSequenceNumber() }; jsonObject[JsonStringSequenceNumber] = Json::UInt{ packet->GetSequenceNumber() };
...@@ -354,7 +342,7 @@ namespace RTC ...@@ -354,7 +342,7 @@ namespace RTC
eventData[JsonStringObject] = jsonObject; eventData[JsonStringObject] = jsonObject;
this->notifier->EmitWithBinary( this->notifier->EmitWithBinary(
this->producerId, "rtpobject", eventData, packet->GetPayload(), packet->GetPayloadLength()); this->producerId, "rtpobject", packet->GetPayload(), packet->GetPayloadLength(), eventData);
} }
// Apply the Producer RTP mapping before dispatching the packet to the Room. // Apply the Producer RTP mapping before dispatching the packet to the Room.
...@@ -562,14 +550,14 @@ namespace RTC ...@@ -562,14 +550,14 @@ namespace RTC
// Check rtx capabilities. // Check rtx capabilities.
if (encoding.hasRtx && encoding.rtx.ssrc != 0u) if (encoding.hasRtx && encoding.rtx.ssrc != 0u)
{ {
if (this->rtxStreamMap.find(encoding.rtx.ssrc) != this->rtxStreamMap.end()) if (this->mapRtxStreams.find(encoding.rtx.ssrc) != this->mapRtxStreams.end())
return; return;
auto& codec = this->rtpParameters->GetRtxCodecForEncoding(encoding); auto& codec = this->rtpParameters->GetRtxCodecForEncoding(encoding);
auto rtpStream = this->rtpStreams[ssrc]; auto rtpStream = this->rtpStreams[ssrc];
rtpStream->SetRtx(codec.payloadType, encoding.rtx.ssrc); rtpStream->SetRtx(codec.payloadType, encoding.rtx.ssrc);
this->rtxStreamMap[encoding.rtx.ssrc] = rtpStream; this->mapRtxStreams[encoding.rtx.ssrc] = rtpStream;
} }
} }
......
...@@ -36,10 +36,6 @@ namespace RTC ...@@ -36,10 +36,6 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
static const Json::StaticString JsonStringClass{ "class" };
Json::Value eventData(Json::objectValue);
// Close all the Peers. // Close all the Peers.
// NOTE: Upon Peer closure the onPeerClosed() method is called which // NOTE: Upon Peer closure the onPeerClosed() method is called which
// removes it from the map, so this is the safe way to iterate the map // removes it from the map, so this is the safe way to iterate the map
...@@ -56,8 +52,7 @@ namespace RTC ...@@ -56,8 +52,7 @@ namespace RTC
this->audioLevelsTimer->Destroy(); this->audioLevelsTimer->Destroy();
// Notify. // Notify.
eventData[JsonStringClass] = "Room"; this->notifier->Emit(this->roomId, "close");
this->notifier->Emit(this->roomId, "close", eventData);
// Notify the listener. // Notify the listener.
this->listener->OnRoomClosed(this); this->listener->OnRoomClosed(this);
...@@ -207,6 +202,27 @@ namespace RTC ...@@ -207,6 +202,27 @@ namespace RTC
request->Accept(); request->Accept();
for (auto& kv : this->peers)
{
auto* otherPeer = kv.second;
// Skip new Peer.
if (otherPeer == peer)
continue;
// Get all the ready Producers of the others Peers in the Room and create
// Consumers for this new Peer.
for (auto producer : otherPeer->GetProducers())
{
// Skip if the Producer has not RTP parameters.
if (producer->GetParameters() == nullptr)
continue;
AddConsumerForProducer(peer, producer);
}
}
break; break;
} }
...@@ -259,8 +275,9 @@ namespace RTC ...@@ -259,8 +275,9 @@ namespace RTC
case Channel::Request::MethodId::PRODUCER_SET_RTP_RAW_EVENT: case Channel::Request::MethodId::PRODUCER_SET_RTP_RAW_EVENT:
case Channel::Request::MethodId::PRODUCER_SET_RTP_OBJECT_EVENT: case Channel::Request::MethodId::PRODUCER_SET_RTP_OBJECT_EVENT:
case Channel::Request::MethodId::CONSUMER_DUMP: case Channel::Request::MethodId::CONSUMER_DUMP:
case Channel::Request::MethodId::CONSUMER_SET_TRANSPORT: case Channel::Request::MethodId::CONSUMER_ENABLE:
case Channel::Request::MethodId::CONSUMER_DISABLE: case Channel::Request::MethodId::CONSUMER_PAUSE:
case Channel::Request::MethodId::CONSUMER_RESUME:
{ {
RTC::Peer* peer; RTC::Peer* peer;
...@@ -323,6 +340,30 @@ namespace RTC ...@@ -323,6 +340,30 @@ namespace RTC
return nullptr; return nullptr;
} }
inline void Room::AddConsumerForProducer(RTC::Peer* consumerPeer, const RTC::Producer* producer)
{
MS_TRACE();
MS_ASSERT(producer->GetParameters(), "Producer has no parameters");
uint32_t consumerId = Utils::Crypto::GetRandomUInt(10000000, 99999999);
auto consumer = new RTC::Consumer(consumerPeer, this->notifier, consumerId, producer->kind);
// Store into the maps.
this->mapProducerConsumers[producer].insert(consumer);
this->mapConsumerProducer[consumer] = producer;
// TODO: NO
auto rtpParameters = producer->GetParameters();
// TODO: Maybe, not sure
auto associatedProducerId = producer->producerId;
// TODO: Check producer->IsPaused() and, if so, set consumer->SetSourcePaused(true).
// Attach the Consumer to the peer.
consumerPeer->AddConsumer(consumer, rtpParameters, associatedProducerId);
}
void Room::OnPeerClosed(const RTC::Peer* peer) void Room::OnPeerClosed(const RTC::Peer* peer)
{ {
MS_TRACE(); MS_TRACE();
...@@ -358,14 +399,14 @@ namespace RTC ...@@ -358,14 +399,14 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
// Iterate all the peers but this one and create a Consumer associated to this
// Producer for each Peer.
MS_ASSERT(producer->GetParameters(), "Producer has no parameters"); MS_ASSERT(producer->GetParameters(), "Producer has no parameters");
MS_ASSERT( MS_ASSERT(
this->mapProducerConsumers.find(producer) == this->mapProducerConsumers.end(), this->mapProducerConsumers.find(producer) == this->mapProducerConsumers.end(),
"Producer already in mapProducerConsumers"); "Producer already in mapProducerConsumers");
// Iterate all the peers but this one and create a Consumer associated to this
// Producer for each Peer.
// Ensure the entry will exist even with an empty array. // Ensure the entry will exist even with an empty array.
this->mapProducerConsumers[producer]; this->mapProducerConsumers[producer];
...@@ -377,18 +418,7 @@ namespace RTC ...@@ -377,18 +418,7 @@ namespace RTC
if (consumerPeer == peer) if (consumerPeer == peer)
continue; continue;
uint32_t consumerId = Utils::Crypto::GetRandomUInt(10000000, 99999999); AddConsumerForProducer(consumerPeer, producer);
auto consumer = new RTC::Consumer(consumerPeer, this->notifier, consumerId, producer->kind);
// Store into the maps.
this->mapProducerConsumers[producer].insert(consumer);
this->mapConsumerProducer[consumer] = producer;
auto rtpParameters = producer->GetParameters();
auto associatedProducerId = producer->producerId;
// Attach the Consumer to the peer.
consumerPeer->AddConsumer(consumer, rtpParameters, associatedProducerId);
} }
} }
...@@ -523,7 +553,6 @@ namespace RTC ...@@ -523,7 +553,6 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
static const Json::StaticString JsonStringClass{ "class" };
static const Json::StaticString JsonStringEntries{ "entries" }; static const Json::StaticString JsonStringEntries{ "entries" };
// Audio levels timer. // Audio levels timer.
...@@ -558,7 +587,6 @@ namespace RTC ...@@ -558,7 +587,6 @@ namespace RTC
// Emit event. // Emit event.
Json::Value eventData(Json::objectValue); Json::Value eventData(Json::objectValue);
eventData[JsonStringClass] = "Room";
eventData[JsonStringEntries] = Json::arrayValue; eventData[JsonStringEntries] = Json::arrayValue;
for (auto& kv : mapProducerAudioLevel) for (auto& kv : mapProducerAudioLevel)
......
...@@ -211,10 +211,6 @@ namespace RTC ...@@ -211,10 +211,6 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
static const Json::StaticString JsonStringClass{ "class" };
Json::Value eventData(Json::objectValue);
if (this->srtpRecvSession != nullptr) if (this->srtpRecvSession != nullptr)
this->srtpRecvSession->Destroy(); this->srtpRecvSession->Destroy();
...@@ -238,8 +234,7 @@ namespace RTC ...@@ -238,8 +234,7 @@ namespace RTC
this->selectedTuple = nullptr; this->selectedTuple = nullptr;
// Notify. // Notify.
eventData[JsonStringClass] = "Transport"; this->notifier->Emit(this->transportId, "close");
this->notifier->Emit(this->transportId, "close", eventData);
// If this was allocated (it did not throw in the constructor) notify the // If this was allocated (it did not throw in the constructor) notify the
// listener and delete it. // listener and delete it.
...@@ -999,7 +994,6 @@ namespace RTC ...@@ -999,7 +994,6 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
static const Json::StaticString JsonStringClass{ "class" };
static const Json::StaticString JsonStringIceSelectedTuple{ "iceSelectedTuple" }; static const Json::StaticString JsonStringIceSelectedTuple{ "iceSelectedTuple" };
Json::Value eventData(Json::objectValue); Json::Value eventData(Json::objectValue);
...@@ -1015,7 +1009,6 @@ namespace RTC ...@@ -1015,7 +1009,6 @@ namespace RTC
this->selectedTuple = tuple; this->selectedTuple = tuple;
// Notify. // Notify.
eventData[JsonStringClass] = "Transport";
eventData[JsonStringIceSelectedTuple] = tuple->ToJson(); eventData[JsonStringIceSelectedTuple] = tuple->ToJson();
this->notifier->Emit(this->transportId, "iceselectedtuplechange", eventData); this->notifier->Emit(this->transportId, "iceselectedtuplechange", eventData);
} }
...@@ -1024,7 +1017,6 @@ namespace RTC ...@@ -1024,7 +1017,6 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
static const Json::StaticString JsonStringClass{ "class" };
static const Json::StaticString JsonStringIceState{ "iceState" }; static const Json::StaticString JsonStringIceState{ "iceState" };
static const Json::StaticString JsonStringConnected{ "connected" }; static const Json::StaticString JsonStringConnected{ "connected" };
...@@ -1033,7 +1025,6 @@ namespace RTC ...@@ -1033,7 +1025,6 @@ namespace RTC
MS_DEBUG_TAG(ice, "ICE connected"); MS_DEBUG_TAG(ice, "ICE connected");
// Notify. // Notify.
eventData[JsonStringClass] = "Transport";
eventData[JsonStringIceState] = JsonStringConnected; eventData[JsonStringIceState] = JsonStringConnected;
this->notifier->Emit(this->transportId, "icestatechange", eventData); this->notifier->Emit(this->transportId, "icestatechange", eventData);
...@@ -1045,7 +1036,6 @@ namespace RTC ...@@ -1045,7 +1036,6 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
static const Json::StaticString JsonStringClass{ "class" };
static const Json::StaticString JsonStringIceState{ "iceState" }; static const Json::StaticString JsonStringIceState{ "iceState" };
static const Json::StaticString JsonStringCompleted{ "completed" }; static const Json::StaticString JsonStringCompleted{ "completed" };
...@@ -1054,7 +1044,6 @@ namespace RTC ...@@ -1054,7 +1044,6 @@ namespace RTC
MS_DEBUG_TAG(ice, "ICE completed"); MS_DEBUG_TAG(ice, "ICE completed");
// Notify. // Notify.
eventData[JsonStringClass] = "Transport";
eventData[JsonStringIceState] = JsonStringCompleted; eventData[JsonStringIceState] = JsonStringCompleted;
this->notifier->Emit(this->transportId, "icestatechange", eventData); this->notifier->Emit(this->transportId, "icestatechange", eventData);
...@@ -1066,7 +1055,6 @@ namespace RTC ...@@ -1066,7 +1055,6 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
static const Json::StaticString JsonStringClass{ "class" };
static const Json::StaticString JsonStringIceState{ "iceState" }; static const Json::StaticString JsonStringIceState{ "iceState" };
static const Json::StaticString JsonStringDisconnected{ "disconnected" }; static const Json::StaticString JsonStringDisconnected{ "disconnected" };
...@@ -1078,7 +1066,6 @@ namespace RTC ...@@ -1078,7 +1066,6 @@ namespace RTC
this->selectedTuple = nullptr; this->selectedTuple = nullptr;
// Notify. // Notify.
eventData[JsonStringClass] = "Transport";
eventData[JsonStringIceState] = JsonStringDisconnected; eventData[JsonStringIceState] = JsonStringDisconnected;
this->notifier->Emit(this->transportId, "icestatechange", eventData); this->notifier->Emit(this->transportId, "icestatechange", eventData);
...@@ -1090,7 +1077,6 @@ namespace RTC ...@@ -1090,7 +1077,6 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
static const Json::StaticString JsonStringClass{ "class" };
static const Json::StaticString JsonStringDtlsState{ "dtlsState" }; static const Json::StaticString JsonStringDtlsState{ "dtlsState" };
static const Json::StaticString JsonStringConnecting{ "connecting" }; static const Json::StaticString JsonStringConnecting{ "connecting" };
...@@ -1099,7 +1085,6 @@ namespace RTC ...@@ -1099,7 +1085,6 @@ namespace RTC
MS_DEBUG_TAG(dtls, "DTLS connecting"); MS_DEBUG_TAG(dtls, "DTLS connecting");
// Notify. // Notify.
eventData[JsonStringClass] = "Transport";
eventData[JsonStringDtlsState] = JsonStringConnecting; eventData[JsonStringDtlsState] = JsonStringConnecting;
this->notifier->Emit(this->transportId, "dtlsstatechange", eventData); this->notifier->Emit(this->transportId, "dtlsstatechange", eventData);
} }
...@@ -1115,7 +1100,6 @@ namespace RTC ...@@ -1115,7 +1100,6 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
static const Json::StaticString JsonStringClass{ "class" };
static const Json::StaticString JsonStringDtlsState{ "dtlsState" }; static const Json::StaticString JsonStringDtlsState{ "dtlsState" };
static const Json::StaticString JsonStringConnected{ "connected" }; static const Json::StaticString JsonStringConnected{ "connected" };
static const Json::StaticString JsonStringDtlsRemoteCert{ "dtlsRemoteCert" }; static const Json::StaticString JsonStringDtlsRemoteCert{ "dtlsRemoteCert" };
...@@ -1160,7 +1144,6 @@ namespace RTC ...@@ -1160,7 +1144,6 @@ namespace RTC
} }
// Notify. // Notify.
eventData[JsonStringClass] = "Transport";
eventData[JsonStringDtlsState] = JsonStringConnected; eventData[JsonStringDtlsState] = JsonStringConnected;
eventData[JsonStringDtlsRemoteCert] = remoteCert; eventData[JsonStringDtlsRemoteCert] = remoteCert;
this->notifier->Emit(this->transportId, "dtlsstatechange", eventData); this->notifier->Emit(this->transportId, "dtlsstatechange", eventData);
...@@ -1172,7 +1155,6 @@ namespace RTC ...@@ -1172,7 +1155,6 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
static const Json::StaticString JsonStringClass{ "class" };
static const Json::StaticString JsonStringDtlsState{ "dtlsState" }; static const Json::StaticString JsonStringDtlsState{ "dtlsState" };
static const Json::StaticString JsonStringFailed{ "failed" }; static const Json::StaticString JsonStringFailed{ "failed" };
...@@ -1181,7 +1163,6 @@ namespace RTC ...@@ -1181,7 +1163,6 @@ namespace RTC
MS_WARN_TAG(dtls, "DTLS failed"); MS_WARN_TAG(dtls, "DTLS failed");
// Notify. // Notify.
eventData[JsonStringClass] = "Transport";
eventData[JsonStringDtlsState] = JsonStringFailed; eventData[JsonStringDtlsState] = JsonStringFailed;
this->notifier->Emit(this->transportId, "dtlsstatechange", eventData); this->notifier->Emit(this->transportId, "dtlsstatechange", eventData);
...@@ -1193,7 +1174,6 @@ namespace RTC ...@@ -1193,7 +1174,6 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
static const Json::StaticString JsonStringClass{ "class" };
static const Json::StaticString JsonStringDtlsState{ "dtlsState" }; static const Json::StaticString JsonStringDtlsState{ "dtlsState" };
static const Json::StaticString JsonStringClosed{ "closed" }; static const Json::StaticString JsonStringClosed{ "closed" };
...@@ -1202,7 +1182,6 @@ namespace RTC ...@@ -1202,7 +1182,6 @@ namespace RTC
MS_DEBUG_TAG(dtls, "DTLS remotely closed"); MS_DEBUG_TAG(dtls, "DTLS remotely closed");
// Notify. // Notify.
eventData[JsonStringClass] = "Transport";
eventData[JsonStringDtlsState] = JsonStringClosed; eventData[JsonStringDtlsState] = JsonStringClosed;
this->notifier->Emit(this->transportId, "dtlsstatechange", eventData); this->notifier->Emit(this->transportId, "dtlsstatechange", eventData);
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论