const $ = require('jquery');
const video = require('../../utils/video');
module.exports = function(data, websocket) {
if (data.target === "all") {
if (data.type === "watchroom-open") {
$("#watchrooms").prepend($(
`<div class="watchroom-item">
Join ${data.host.display_name}'s Watchroom
</div>`
).attr("video_id", data.video_id).on("click", function() {
websocket.send({
command: "start-watching",
data: data.video_id
});
}));
} else if (data.type === "watchroom-closed") {
$("#watchrooms").find(`[video_id='${data.video_id}']`).remove();
}
} else if (data.target === "watchroom") {
//logger.log(data);
if (data.type === "viewer-update") {
video.update_viewer(data.viewer);
} else if (data.type === "user-left") {
$(".video-sidebar").find(`#${data.user_id}`).remove();
}
}
};