Skip to content

Added unknown source frame handler #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions serverhandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,16 @@ type ServerHandlerOnFrameCtx struct {
type ServerHandlerOnFrame interface {
OnFrame(*ServerHandlerOnFrameCtx)
}

// ServerHandlerOnUnknownClientCtx is the context of an UDP frame coming from an unknown source.
type ServerHandlerOnUnknownClientCtx struct {
StreamType StreamType
Payload []byte
Clients map[clientAddr]*clientData
ClientAddr clientAddr
}

// ServerHandlerOnUnknownClient can be implemented by a ServerHandler.
type ServerHandlerOnUnknownClient interface {
OnUnknownClient(*ServerHandlerOnUnknownClientCtx) error
}
17 changes: 16 additions & 1 deletion serverudpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,22 @@ func (u *serverUDPListener) run() {
clientAddr.fill(addr.IP, addr.Port)
clientData, ok := u.clients[clientAddr]
if !ok {
return
//Call handler to allow user to handle frame from unknown source (NAT hole punch)
if h, ok := u.s.Handler.(ServerHandlerOnUnknownClient); ok {
err = h.OnUnknownClient(&ServerHandlerOnUnknownClientCtx{
StreamType: u.streamType,
Payload: buf[:n],
Clients: u.clients,
ClientAddr: clientAddr,
})
//Check if clientData exists in possibly modified clients list
clientData, ok = u.clients[clientAddr]
if err != nil || !ok {
return
}
} else {
return
}
}

if clientData.isPublishing {
Expand Down