mirror of
https://github.com/owncast/owncast.git
synced 2025-11-03 21:08:36 +08:00
Add test to verify websocket events come through for changing message visibility
This commit is contained in:
@ -29,5 +29,27 @@ function sendChatMessage(message, accessToken, done) {
|
||||
ws.on('open', onOpen);
|
||||
}
|
||||
|
||||
async function listenForEvent(name, accessToken, done) {
|
||||
const ws = new WebSocket(
|
||||
`ws://localhost:8080/ws?accessToken=${accessToken}`,
|
||||
{
|
||||
origin: 'http://localhost:8080',
|
||||
}
|
||||
);
|
||||
|
||||
ws.on('message', function incoming(message) {
|
||||
const messages = message.split('\n');
|
||||
messages.forEach(function (message) {
|
||||
const event = JSON.parse(message);
|
||||
|
||||
if (event.type === name) {
|
||||
done();
|
||||
ws.close();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
module.exports.sendChatMessage = sendChatMessage;
|
||||
module.exports.registerChat = registerChat;
|
||||
module.exports.registerChat = registerChat;
|
||||
module.exports.listenForEvent = listenForEvent;
|
||||
|
||||
Reference in New Issue
Block a user