ant-media / Ant-Media-Server

Ant Media Server is a live streaming engine software that provides adaptive, ultra low latency streaming by using WebRTC technology with ~0.5 seconds latency. Ant Media Server is auto-scalable and it can run on-premise or on-cloud.
https://antmedia.io
Other
4.28k stars 631 forks source link

Data channel moderation? #4647

Open tomsharratt opened 1 year ago

tomsharratt commented 1 year ago

Looking into using the data channel feature for livestream chat messages but I need the ability to moderate what is being sent.

SelimEmre commented 1 year ago

Hi @tomsharratt,

Thank you for the great questions. Let me explain it:

Can I moderate/intercept messages before delivery? (e.g remove swearwords from messages)

You can directly check messages before the sending process. Here is part of the code snippets: https://github.com/ant-media/StreamApp/blob/master/src/main/webapp/index.html#L446

For example you can change:

function sendData() {
    try {
        var iceState = webRTCAdaptor.iceConnectionState(streamId);
        if (iceState != null && iceState != "failed" && iceState != "disconnected") {
            var cleanedMessage = checkSwearKeywords($("#dataTextbox").val()); 
            webRTCAdaptor.sendData($("#streamId").val(), cleanedMessage);
            $("#all-messages").append("Sent: " + cleanedMessage + "<br>");
            $("#dataTextbox").val("");
        }
        else {
            alert("WebRTC publishing is not active. Please click Start Publishing first")
        }
    }
    catch (exception) {
        console.error(exception);
        alert("Message cannot be sent. Make sure you've enabled data channel on server web panel");
    }
}

How could I handle roles (e.g moderators who can delete messages, or ban people from chat)

It can handle this kind of requirement from the frontend side. You can send deleteMessage event to viewers and publishers and after that, you can remove it directly from the chatbox.

var eventDetails = { streamId: publishStreamId, eventType:"deleteMessage" };
webRTCAdaptor.sendData(publishStreamId, JSON.stringify(eventDetails));

Please check it for the usage of the MIC_MUTE event. It's similar type development that I suggested you.

From clients and publishers: You can check event types and remove them from chatbox as below:

https://github.com/ant-media/StreamApp/blob/master/src/main/webapp/conference.html#L396 https://github.com/ant-media/StreamApp/blob/master/src/main/webapp/conference.html#L684

Along the lines of question two, can you ban people from sending messages in chat but still read messages of others (also solved if question one is possible)

You can create roles for publishers/viewers. After sending the message, it can be controlled directly.

How would I authorize who can send what kind of events?

It can be also handled from the frontend section.

I hope, it's clear to you. Please let me know if some parts are not clear.

Best Regards, Selim

SelimEmre commented 1 year ago

Hi @tomsharratt,

Have a good day. Did you see my message? Just wanted to know if it's clear or not.

Best Regards, Selim

tomsharratt commented 1 year ago

Thanks for your response.

It sounds like I have to do a lot of work client side which isn't secure. Doesn't really meet my requirements unfortunately.

mekya commented 1 year ago

Thank you @tomsharratt,

Let's have a solution on the backend side @SelimEmre . Front-end solution is not secure as @tomsharratt mentions.