-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
save websocket client-id on dynamodb
- Loading branch information
Showing
2 changed files
with
44 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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{} | ||
} |