yapingcat / gomedia

golang library for rtmp, mpeg-ts,mpeg-ps,flv,mp4,ogg,rtsp
MIT License
407 stars 70 forks source link

RTMP publish reject stream #149

Open kbats183 opened 2 months ago

kbats183 commented 2 months ago

Hello.

I am working on rtmp restreamer. Some rtmp servers can reject connection if user sends incorrect stream key. In this case, OBS shows a message like this image

I took code from example and their method OnPublish returns only rtmp.NETSTREAM_PUBLISH_START.

How can I reject connection with incorrect stream name here?

Thank you for your answer!

yapingcat commented 2 months ago

please refer to this code

sess.handle.OnPublish(func(app, streamName string) rtmp.StatusCode {
        if streamName == "stream_reject" {
            return rtmp.NETCONNECT_CONNECT_REJECTED
        }
        return rtmp.NETSTREAM_PUBLISH_START
    })
sess.handle.OnStateChange(func(newState rtmp.RtmpState) {
        if newState == rtmp.STATE_RTMP_PLAY_START {

        } else if newState == rtmp.STATE_RTMP_PUBLISH_START {

        } else if newState == rtmp.STATE_RTMP_PUBLISH_FAILED {
            fmt.Println("publish failed")
            sess.stop()
        }
    })