This commit is contained in:
parent
17c991f442
commit
c284b15788
55
client/helpers/call.go
Normal file
55
client/helpers/call.go
Normal file
@ -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() {
|
||||
|
||||
}
|
@ -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) {
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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 {
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user