Skip to content

Commit

Permalink
save websocket client-id on dynamodb
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanjoz committed May 26, 2024
1 parent 20351ef commit 276abaf
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
3 changes: 2 additions & 1 deletion backend/core/responses.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ type HandlerArgs struct {
QueryString string
Method string
Route string
ClientID string
ClientID string // websocket
ConnectionID string // websocket
Authorization string
MergedID int32
ResponseBody *string
Expand Down
43 changes: 42 additions & 1 deletion backend/handlers/webrtc.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,49 @@
package handlers

import "app/core"
import (
"app/aws"
"app/core"
"encoding/json"
)

type RtcClientOffer struct {
Offer string `json:"offer"`
Name string `json:"name"`
ClientID string `json:"id"`
ConnectionID string `json:"connID"`
Updated string `json:"updated"` // unix time / 2 in base36
}

func MakeClientTable() aws.DynamoTableRecords[RtcClientOffer] {
return aws.DynamoTableRecords[RtcClientOffer]{
TableName: core.Env.DYNAMO_TABLE,
PK: "client",
UseCompression: true,
GetIndexKeys: func(e RtcClientOffer, idx uint8) string {
switch idx {
case 0: // SK (Sort Key)
return core.Concatn(e.ClientID)
case 1: // ix1
return core.Concatn(e.Updated)
}
return ""
},
}
}

func PostRtcOffer(args *core.HandlerArgs) core.HandlerResponse {

offer := RtcClientOffer{}
err := json.Unmarshal([]byte(*args.Body), &offer)
if err != nil {
core.Log("Error al interpretar el mensaje:", err)
return core.HandlerResponse{}
}

offer.ClientID = args.ClientID

dynamoTable := MakeClientTable()
dynamoTable.PutItem(&offer, 1)

return core.HandlerResponse{}
}

0 comments on commit 276abaf

Please sign in to comment.