fix im p0 backend issues

This commit is contained in:
richjohnrambo
2026-09-07 15:12:14 +08:00
parent b92154bece
commit 7e8fc8237b
7 changed files with 371 additions and 13 deletions
+60
View File
@@ -493,6 +493,66 @@ func TestHandleBroadcastCall(t *testing.T) {
}
}
func TestHandleBroadcastDraftyCallInvite(t *testing.T) {
numUsers := 2
helper := TopicTestHelper{}
helper.setUp(t, numUsers, types.TopicCatP2P, "p2p-test" /*attach=*/, true)
oldThirdParty := store.ThirdPartyConfig
globals.iceServers = []iceServer{{Username: "dummy"}}
store.ThirdPartyConfig = testThirdPartyConfigStore{
"audio_call_enabled": "1",
"video_call_enabled": "1",
}
helper.topic.lastID = 5
defer func() {
globals.iceServers = nil
store.ThirdPartyConfig = oldThirdParty
helper.tearDown()
}()
helper.mm.EXPECT().Save(types.TenantID(1), gomock.Any(), gomock.Any(), gomock.Any()).
Return(&types.MessageSaveResult{SeqId: 1, MarkedReadBySender: true}, nil)
from := helper.uids[0].UserId()
msg := &ClientComMessage{
AsUser: from,
Original: from,
Pub: &MsgClientPub{
Topic: "p2p",
Head: map[string]any{"webrtc": "started", "mime": "text/x-drafty"},
Content: map[string]any{
"txt": " ",
"ent": []any{map[string]any{
"tp": "VC",
"data": map[string]any{
"call_id": "call-drafty-1",
"aonly": true,
"state": "started",
},
}},
},
NoEcho: true,
},
sess: helper.sessions[0],
}
helper.topic.handleClientMsg(msg)
helper.finish()
if errorMsgs, hasError := helper.hubMessages["__ERROR__"]; hasError {
t.Fatal(errorMsgs[0].Ctrl.Text)
}
if len(helper.results[1].messages) != 1 {
t.Fatalf("callee: expected 1 message, got %d", len(helper.results[1].messages))
}
data := helper.results[1].messages[0].(*ServerComMessage).Data
content := data.Content.(map[string]any)
if content["callId"] != "call-drafty-1" || content["callType"] != "audio" || content["video"] != false {
t.Fatalf("unexpected normalized Drafty call content: %#v", content)
}
if data.Head["x-im-type"] != "call" || data.Head["mime"] != "text/x-drafty" {
t.Fatalf("unexpected normalized Drafty call head: %#v", data.Head)
}
}
func TestHandleBroadcastCallRequiresStructuredInvite(t *testing.T) {
numUsers := 2
helper := TopicTestHelper{}