mirror of
https://github.com/nestriness/nestri.git
synced 2025-12-12 16:55:37 +02:00
## Description We are attempting to hookup maitred to the API Maitred duties will be: - [ ] Hookup to the API - [ ] Wait for signal (from the API) to start Steam - [ ] Stop signal to stop the gaming session, clean up Steam... and maybe do the backup ## Summary by CodeRabbit - **New Features** - Introduced Docker-based deployment configurations for both the main and relay applications. - Added new API endpoints enabling real-time machine messaging and enhanced IoT operations. - Expanded database schema and actor types to support improved machine tracking. - **Improvements** - Enhanced real-time communication and relay management with streamlined room handling. - Upgraded dependencies, logging, and error handling for greater stability and performance. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: DatCaptainHorse <DatCaptainHorse@users.noreply.github.com> Co-authored-by: Kristian Ollikainen <14197772+DatCaptainHorse@users.noreply.github.com>
120 lines
2.9 KiB
Go
120 lines
2.9 KiB
Go
package connections
|
|
|
|
import (
|
|
"github.com/pion/webrtc/v4"
|
|
"google.golang.org/protobuf/proto"
|
|
gen "relay/internal/proto"
|
|
)
|
|
|
|
// SendMeshHandshake sends a handshake message to another relay.
|
|
func (ws *SafeWebSocket) SendMeshHandshake(relayID, publicKey string) error {
|
|
msg := &gen.MeshMessage{
|
|
Type: &gen.MeshMessage_Handshake{
|
|
Handshake: &gen.Handshake{
|
|
RelayId: relayID,
|
|
DhPublicKey: publicKey,
|
|
},
|
|
},
|
|
}
|
|
data, err := proto.Marshal(msg)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return ws.SendBinary(data)
|
|
}
|
|
|
|
// SendMeshHandshakeResponse sends a handshake response to a relay.
|
|
func (ws *SafeWebSocket) SendMeshHandshakeResponse(relayID, dhPublicKey string, approvals map[string]string) error {
|
|
msg := &gen.MeshMessage{
|
|
Type: &gen.MeshMessage_HandshakeResponse{
|
|
HandshakeResponse: &gen.HandshakeResponse{
|
|
RelayId: relayID,
|
|
DhPublicKey: dhPublicKey,
|
|
Approvals: approvals,
|
|
},
|
|
},
|
|
}
|
|
data, err := proto.Marshal(msg)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return ws.SendBinary(data)
|
|
}
|
|
|
|
// SendMeshForwardSDP sends a forwarded SDP message to another relay
|
|
func (ws *SafeWebSocket) SendMeshForwardSDP(roomName, participantID string, sdp webrtc.SessionDescription) error {
|
|
msg := &gen.MeshMessage{
|
|
Type: &gen.MeshMessage_ForwardSdp{
|
|
ForwardSdp: &gen.ForwardSDP{
|
|
RoomName: roomName,
|
|
ParticipantId: participantID,
|
|
Sdp: sdp.SDP,
|
|
Type: sdp.Type.String(),
|
|
},
|
|
},
|
|
}
|
|
data, err := proto.Marshal(msg)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return ws.SendBinary(data)
|
|
}
|
|
|
|
// SendMeshForwardICE sends a forwarded ICE candidate to another relay
|
|
func (ws *SafeWebSocket) SendMeshForwardICE(roomName, participantID string, candidate webrtc.ICECandidateInit) error {
|
|
var sdpMLineIndex uint32
|
|
if candidate.SDPMLineIndex != nil {
|
|
sdpMLineIndex = uint32(*candidate.SDPMLineIndex)
|
|
}
|
|
|
|
msg := &gen.MeshMessage{
|
|
Type: &gen.MeshMessage_ForwardIce{
|
|
ForwardIce: &gen.ForwardICE{
|
|
RoomName: roomName,
|
|
ParticipantId: participantID,
|
|
Candidate: &gen.ICECandidateInit{
|
|
Candidate: candidate.Candidate,
|
|
SdpMid: candidate.SDPMid,
|
|
SdpMLineIndex: &sdpMLineIndex,
|
|
UsernameFragment: candidate.UsernameFragment,
|
|
},
|
|
},
|
|
},
|
|
}
|
|
data, err := proto.Marshal(msg)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return ws.SendBinary(data)
|
|
}
|
|
|
|
func (ws *SafeWebSocket) SendMeshForwardIngest(roomName string) error {
|
|
msg := &gen.MeshMessage{
|
|
Type: &gen.MeshMessage_ForwardIngest{
|
|
ForwardIngest: &gen.ForwardIngest{
|
|
RoomName: roomName,
|
|
},
|
|
},
|
|
}
|
|
data, err := proto.Marshal(msg)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return ws.SendBinary(data)
|
|
}
|
|
|
|
func (ws *SafeWebSocket) SendMeshStreamRequest(roomName string) error {
|
|
msg := &gen.MeshMessage{
|
|
Type: &gen.MeshMessage_StreamRequest{
|
|
StreamRequest: &gen.StreamRequest{
|
|
RoomName: roomName,
|
|
},
|
|
},
|
|
}
|
|
data, err := proto.Marshal(msg)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return ws.SendBinary(data)
|
|
}
|