Added chat support

This commit is contained in:
Håvar Aambø Fosstveit
2018-03-01 16:19:37 +01:00
parent 9a7e149c35
commit 494250153e
18 changed files with 617 additions and 7 deletions
+34
View File
@@ -26,6 +26,8 @@ class Room extends EventEmitter
// Closed flag.
this._closed = false;
this._chatHistory = [];
try
{
// Protoo Room instance.
@@ -226,6 +228,38 @@ class Room extends EventEmitter
break;
}
case 'chat-message':
{
accept();
const { chatMessage } = request.data;
this._chatHistory.push(chatMessage);
// Spread to others via protoo.
this._protooRoom.spread(
'chat-message-receive',
{
peerName : protooPeer.id,
chatMessage : chatMessage
},
[ protooPeer ]);
break;
}
case 'chat-history':
{
accept();
protooPeer.send(
'chat-history-receive',
{ chatHistory : this._chatHistory }
);
break;
}
default:
{
logger.error('unknown request.method "%s"', request.method);