limit data channel name for chat
This commit is contained in:
parent
91e7055bf6
commit
cac896ff1d
@ -42,6 +42,8 @@ var (
|
||||
StyleError = lipgloss.NewStyle().Foreground(lipgloss.Color("red"))
|
||||
StylePeer = lipgloss.NewStyle()
|
||||
StylePeerSelected = lipgloss.NewStyle().Background(lipgloss.Color("gray"))
|
||||
|
||||
dataChannelName = "chat"
|
||||
)
|
||||
|
||||
type SignalClient struct {
|
||||
@ -270,7 +272,7 @@ func (client *SignalClient) OnDiscoverResponse(ctx context.Context, stream proto
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
dataChannel, err := peerConnection.CreateDataChannel("chan", nil)
|
||||
dataChannel, err := peerConnection.CreateDataChannel(dataChannelName, nil)
|
||||
if err != nil {
|
||||
client.Program.Send(systemMsg(fmt.Sprint("failed to create answer: ", err)))
|
||||
return
|
||||
@ -407,6 +409,9 @@ func (client SignalClient) GetOrCreatePeerConnection(sender string) (*webrtc.Pee
|
||||
|
||||
peerConnection.OnDataChannel(func(dc *webrtc.DataChannel) {
|
||||
client.Program.Send(systemMsg(fmt.Sprint("Connected to client " + sender + ": " + dc.Label())))
|
||||
if dc.Label() != dataChannelName {
|
||||
client.Program.Send(fmt.Sprintf("ignored data channel: %v", dc.Label()))
|
||||
}
|
||||
client.Channels[sender] = dc
|
||||
|
||||
client.SetupDataChannel(peerConnection, dc, sender)
|
||||
@ -428,6 +433,10 @@ func (client *SignalClient) SetupDataChannel(pc *webrtc.PeerConnection, dc *webr
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
dc.OnError(func(err error) {
|
||||
dc.Close()
|
||||
})
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user