wip: 0.2.7

实现了 rtc 握手和打开数据通道
This commit is contained in:
loveuer
2025-05-26 17:40:06 +08:00
parent 5bc695bde3
commit 21287e0874
7 changed files with 194 additions and 97 deletions

View File

@ -224,16 +224,19 @@ func (rc *roomController) Unregister(client *roomClient) {
rc.Broadcast(map[string]any{"type": RoomMessageTypeLeave, "time": time.Now().UnixMilli(), "body": client})
}
func (rc *roomController) Offer(id string, offer *RoomOffer, candidate *RoomCandidate) {
func (rc *roomController) Offer(id, from string, offer *RoomOffer) {
if _, ok := rc.clients[id]; !ok {
return
}
rc.clients[id].msgChan <- map[string]any{
"type": "offer",
"id": id,
"offer": offer,
"candidate": candidate,
"type": "offer",
"time": time.Now().UnixMilli(),
"data": map[string]any{
"id": id,
"from": from,
"offer": offer,
},
}
}
@ -243,8 +246,32 @@ func (rc *roomController) Answer(id string, answer *RoomOffer) {
}
rc.clients[id].msgChan <- map[string]any{
"type": "answer",
"id": id,
"answer": answer,
"type": "answer",
"time": time.Now().UnixMilli(),
"data": map[string]any{
"id": id,
"answer": answer,
},
}
}
func (rc *roomController) Candidate(id string, candidate *RoomCandidate) {
if _, ok := rc.clients[id]; !ok {
return
}
for _, client := range rc.clients {
if client.Id == id {
continue
}
client.msgChan <- map[string]any{
"type": "candidate",
"time": time.Now().UnixMilli(),
"data": map[string]any{
"id": client.Id,
"candidate": candidate,
},
}
}
}