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

More stuff

上级 ec715ee3
......@@ -395,6 +395,67 @@ class Peer extends EventEmitter
return producer;
}
receiveRequest(request)
{
if (this._closed)
return Promise.reject(new errors.InvalidStateError('Room closed'));
else if (typeof request !== 'object')
return Promise.reject(new TypeError('wrong request Object'));
else if (request.notification)
return Promise.reject(new TypeError('not a request'));
else if (typeof request.method !== 'string')
return Promise.reject(new TypeError('wrong/missing request method'));
const { method } = request;
logger.debug('receiveRequest() [method:%s]', method);
switch (method)
{
default:
return Promise.reject(new Error(`unknown request method "${method}"`));
}
}
receiveNotification(notification)
{
try
{
if (this.closed)
throw new errors.InvalidStateError('Room closed');
else if (typeof notification !== 'object')
throw new TypeError('wrong notification Object');
else if (notification.notification !== true)
throw new TypeError('not a notification');
else if (typeof notification.method !== 'string')
throw new TypeError('wrong/missing notification method');
const { method } = notification;
logger.debug('receiveNotification() [method:%s]', method);
switch (method)
{
// TODO: Handle appData.
case 'leave':
{
this.close();
break;
}
default:
return Promise.reject(new Error(`unknown request method "${method}"`));
}
}
catch (error)
{
logger.error(
'receiveNotification() failed [notification:%o]: %s',
notification, error.toString());
}
}
}
module.exports = Peer;
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论