diff --git a/client/helpers/call.go b/client/helpers/call.go new file mode 100644 index 0000000..89838e4 --- /dev/null +++ b/client/helpers/call.go @@ -0,0 +1,55 @@ +package helpers + +import ( + "forge.redroom.link/yves/meowlib" + "forge.redroom.link/yves/meowlib/client" +) + +func BuildCallRequestMessage(users []string, expiry uint64, srvuid string) ([]byte, string, error) { + // Server: get the invitation server + server, err := client.GetConfig().GetIdentity().MessageServers.LoadServer(srvuid) + if err != nil { + return nil, "BuildCallRequestMessage: LoadServer", err + } + + toSrvMsg, err := server.BuildVideoRoomRequestMessage(users, expiry) + if err != nil { + return nil, "BuildCallRequestMessage: BuildVideoRoomRequestMessage", err + } + msg, err := server.ProcessOutboundMessage(toSrvMsg) + if err != nil { + return nil, "BuildCallRequestMessage: ProcessOutboundMessage", err + } + return msg, "", nil +} + +func ReadCallRequestResponseMessage(data []byte, srvuid string) (*meowlib.VideoData, string, error) { + server, err := client.GetConfig().GetIdentity().MessageServers.LoadServer(srvuid) + if err != nil { + return nil, "ReadCallRequestResponseMessage: LoadServer", err + } + // Server inbound processing : get the invitation server + serverMsg, err := server.ProcessInboundServerResponse(data) + if err != nil { + return nil, "ReadCallRequestResponseMessage: ProcessInboundServerResponse", err + } + return serverMsg.VideoData, "", nil +} + +func BuildCallMessage(videodata *meowlib.VideoData, srvuid string, peer_idx int, replyToUid string, filelist []string) ([]byte, string, error) { + peer := client.GetConfig().GetIdentity().Peers[peer_idx] + + // Creating User message + usermessage, err := peer.BuildSimpleUserMessage(nil) + if err != nil { + return nil, "BuildCallMessage : BuildSimpleUserMessage", err + } + + usermessage.Status.AnswerToUuid = replyToUid + + return messageBuildPostprocess(usermessage, srvuid, peer) +} + +func BuildCancelCallMessage() { + +} diff --git a/client/helpers/messageHelper.go b/client/helpers/messageHelper.go index d8a2dc1..a20af61 100644 --- a/client/helpers/messageHelper.go +++ b/client/helpers/messageHelper.go @@ -1,16 +1,39 @@ package helpers import ( + "forge.redroom.link/yves/meowlib" "forge.redroom.link/yves/meowlib/client" ) +func messageBuildPostprocess(msg *meowlib.UserMessage, srvuid string, peer *client.Peer) ([]byte, string, error) { + // Get the message server + srv, err := client.GetConfig().GetIdentity().MessageServers.LoadServer(srvuid) + if err != nil { + return nil, "messageBuildPostprocess : LoadServer", err + } + // Prepare cyphered + packed user message + packedMsg, err := peer.ProcessOutboundUserMessage(msg) + if err != nil { + return nil, "messageBuildPostprocess : ProcessOutboundUserMessage", err + } + // Creating Server message for transporting the user message + toServerMessage := srv.BuildToServerMessageFromUserMessage(packedMsg) + data, err := srv.ProcessOutboundMessage(toServerMessage) + if err != nil { + return nil, "messageBuildPostprocess : ProcessOutboundMessage", err + } + // Store message + err = peer.StoreMessage(msg, nil) + if err != nil { + return nil, "messageBuildPostprocess : StoreMessage", err + } + return data, "", nil +} + func PrepareUserMessage(message string, srvuid string, peer_idx int, replyToUid string, filelist []string) ([]byte, string, error) { peer := client.GetConfig().GetIdentity().Peers[peer_idx] - srv, err := client.GetConfig().GetIdentity().MessageServers.LoadServer(srvuid) - if err != nil { - return nil, "PrepareServerMessage : LoadServer", err - } + // Creating User message usermessage, err := peer.BuildSimpleUserMessage([]byte(message)) if err != nil { @@ -23,23 +46,9 @@ func PrepareUserMessage(message string, srvuid string, peer_idx int, replyToUid } } usermessage.Status.AnswerToUuid = replyToUid - // Prepare cyphered + packed user message - packedMsg, err := peer.ProcessOutboundUserMessage(usermessage) - if err != nil { - return nil, "PrepareServerMessage : ProcessOutboundUserMessage", err - } - // Creating Server message for transporting the user message - toServerMessage := srv.BuildToServerMessageFromUserMessage(packedMsg) - data, err := srv.ProcessOutboundMessage(toServerMessage) - if err != nil { - return nil, "PrepareServerMessage : ProcessOutboundMessage", err - } - // Store message - err = peer.StoreMessage(usermessage, filelist) - if err != nil { - return nil, "PrepareServerMessage : StoreMessage", err - } - return data, "", nil + + return messageBuildPostprocess(usermessage, srvuid, peer) + } func SendAck(messageUid string, srvuid string, peer_idx int, received int64, processed int64) ([]byte, string, error) { diff --git a/client/peerstorage.go b/client/peerstorage.go index 2a9a918..aa7cd42 100644 --- a/client/peerstorage.go +++ b/client/peerstorage.go @@ -15,6 +15,7 @@ import ( type PeerStorage struct { DbFile string `json:"db_file,omitempty"` db *badger.DB + cache map[string]*Peer } // Open a badger database from struct PeerStorage diff --git a/client/server.go b/client/server.go index d6ebdbc..152bb6f 100644 --- a/client/server.go +++ b/client/server.go @@ -168,7 +168,7 @@ func (ints *Server) BuildMessageRequestMessage(lookupKeys []string) ([]byte, err } // BuildVideoRoomRequestMessage creates a video room request to server and returns it as protobuf serialized byte array -func (ints *Server) BuildVideoRoomRequestMessage(users []string, expiry uint64) ([]byte, error) { +func (ints *Server) BuildVideoRoomRequestMessage(users []string, expiry uint64) (*meowlib.ToServerMessage, error) { var msg meowlib.ToServerMessage msg.Uuid = uuid.New().String() msg.Type = "1" @@ -181,11 +181,7 @@ func (ints *Server) BuildVideoRoomRequestMessage(users []string, expiry uint64) } } msg.VideoData.Credentials = videocreds - out, err := proto.Marshal(&msg) - if err != nil { - return nil, err - } - return out, nil + return &msg, nil } // BuildToServerMessageInvitation creates an invitation message to server and returns it as a meowlib.ToServerMessage diff --git a/pb/messages.proto b/pb/messages.proto index 834bc13..13b73f3 100644 --- a/pb/messages.proto +++ b/pb/messages.proto @@ -33,7 +33,6 @@ message Invitation { string from=9; // used in step 3 the answer public key to check the signature in user message } - // structure for requesting incoming messages message ConversationRequest { string lookup_key = 1; // lookup key for a conversation @@ -91,6 +90,8 @@ message FromServerMessage { repeated PackedUserMessage device_messages = 9; // messages from other devices belonging to the same user VideoData video_data = 10; // video call data + + repeated ContactCard contactCard = 11; // contact list for a personae } message MatriochkaServer { diff --git a/server/videoserver.go b/server/videoserver.go index bd2ec6b..b9db8cf 100644 --- a/server/videoserver.go +++ b/server/videoserver.go @@ -10,7 +10,7 @@ import ( type VideoServer struct { Url string `json:"url,omitempty"` ApiKey string `json:"api_key,omitempty"` - ApiSecret string `json:"secret,omitempty"` + ApiSecret string `json:"api_secret,omitempty"` } func (s *VideoServer) GetJoinToken(room, username string, validity time.Duration) (string, error) {