Updated error handling & error messages
This commit is contained in:
+20
-8
@@ -261,6 +261,7 @@ func peerInit(id *uuid.UUID, p2p **webrtc.PeerConnection, offer *webrtc.SessionD
|
|||||||
(*p2p).OnICECandidate(func(candidate *webrtc.ICECandidate) {
|
(*p2p).OnICECandidate(func(candidate *webrtc.ICECandidate) {
|
||||||
// Checking if ICE gathering has finished
|
// Checking if ICE gathering has finished
|
||||||
if candidate != nil {
|
if candidate != nil {
|
||||||
|
fmt.Print(config_t.Messages.WEBRTC.ON_CANDIDATE)
|
||||||
// Constructing candidate, encoding to JSON and sending to websocket
|
// Constructing candidate, encoding to JSON and sending to websocket
|
||||||
candidate_t := Candidate{
|
candidate_t := Candidate{
|
||||||
Type: "candidate",
|
Type: "candidate",
|
||||||
@@ -395,11 +396,22 @@ func answer(id *uuid.UUID, p2p **webrtc.PeerConnection, offer *webrtc.SessionDes
|
|||||||
func candidate(id *uuid.UUID, p2p **webrtc.PeerConnection, raw []byte) {
|
func candidate(id *uuid.UUID, p2p **webrtc.PeerConnection, raw []byte) {
|
||||||
// Decoding JSON with candidate in it
|
// Decoding JSON with candidate in it
|
||||||
var candidate_t Candidate
|
var candidate_t Candidate
|
||||||
json.Unmarshal(raw, &candidate_t)
|
message_unmarshal_error := json.Unmarshal(raw, &candidate_t)
|
||||||
|
if message_unmarshal_error != nil {
|
||||||
|
fmt.Fprintf(os.Stderr, config_t.Messages.JSON.UNMARSHAL.ERROR, message_unmarshal_error)
|
||||||
|
os.Exit(-1)
|
||||||
|
} else {
|
||||||
|
fmt.Print(config_t.Messages.JSON.UNMARSHAL.SUCCESS)
|
||||||
|
}
|
||||||
|
|
||||||
// Checking if id matches and adding candidate
|
// Checking if id matches and adding candidate
|
||||||
if *id == candidate_t.Id {
|
if *id == candidate_t.Id {
|
||||||
(*p2p).AddICECandidate(candidate_t.Candidate)
|
add_ice_error := (*p2p).AddICECandidate(candidate_t.Candidate)
|
||||||
|
if add_ice_error != nil {
|
||||||
|
fmt.Fprint(os.Stderr, config_t.Messages.WEBRTC.ADD_CANDIDATE.ERROR, add_ice_error)
|
||||||
|
} else {
|
||||||
|
fmt.Print(config_t.Messages.WEBRTC.ADD_CANDIDATE.SUCCESS)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -408,14 +420,14 @@ func main() {
|
|||||||
raw_config, config_error := os.ReadFile("config.yml")
|
raw_config, config_error := os.ReadFile("config.yml")
|
||||||
if config_error != nil {
|
if config_error != nil {
|
||||||
fmt.Fprintf(os.Stderr, "Could not read config file.\n%v\n", config_error)
|
fmt.Fprintf(os.Stderr, "Could not read config file.\n%v\n", config_error)
|
||||||
return
|
os.Exit(-1)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Loading config file to config struct
|
// Loading config file to config struct
|
||||||
config_error = yaml.Unmarshal(raw_config, &config_t)
|
config_error = yaml.Unmarshal(raw_config, &config_t)
|
||||||
if config_error != nil {
|
if config_error != nil {
|
||||||
fmt.Fprintf(os.Stderr, "Could not load config file.\n%v\n", config_error)
|
fmt.Fprintf(os.Stderr, "Could not load config file.\n%v\n", config_error)
|
||||||
return
|
os.Exit(-1)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Starting program
|
// Starting program
|
||||||
@@ -428,7 +440,7 @@ func main() {
|
|||||||
|
|
||||||
if len(os.Args) != 2 {
|
if len(os.Args) != 2 {
|
||||||
fmt.Fprint(os.Stderr, config_t.Messages.MISSING_PORT)
|
fmt.Fprint(os.Stderr, config_t.Messages.MISSING_PORT)
|
||||||
return
|
os.Exit(-1)
|
||||||
} else {
|
} else {
|
||||||
http_port = os.Args[1]
|
http_port = os.Args[1]
|
||||||
}
|
}
|
||||||
@@ -437,7 +449,7 @@ func main() {
|
|||||||
conn, _, dial_error := websocket.DefaultDialer.Dial(config_t.Config.SIGNALING_SERVER, nil)
|
conn, _, dial_error := websocket.DefaultDialer.Dial(config_t.Config.SIGNALING_SERVER, nil)
|
||||||
if dial_error != nil {
|
if dial_error != nil {
|
||||||
fmt.Fprintf(os.Stderr, config_t.Messages.WS.CONNECT.ERROR, dial_error)
|
fmt.Fprintf(os.Stderr, config_t.Messages.WS.CONNECT.ERROR, dial_error)
|
||||||
return
|
os.Exit(-1)
|
||||||
} else {
|
} else {
|
||||||
fmt.Print(config_t.Messages.WS.CONNECT.SUCCESS)
|
fmt.Print(config_t.Messages.WS.CONNECT.SUCCESS)
|
||||||
}
|
}
|
||||||
@@ -483,10 +495,10 @@ func main() {
|
|||||||
// Registering to the signaling server as normal user
|
// Registering to the signaling server as normal user
|
||||||
ws_write_error := conn.WriteMessage(websocket.TextMessage, register_msg)
|
ws_write_error := conn.WriteMessage(websocket.TextMessage, register_msg)
|
||||||
if ws_write_error != nil {
|
if ws_write_error != nil {
|
||||||
fmt.Fprintf(os.Stderr, config_t.Messages.WS.WRITE.ERROR, ws_write_error)
|
fmt.Fprintf(os.Stderr, config_t.Messages.WS.REGISTER.ERROR, ws_write_error)
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
fmt.Print(config_t.Messages.WS.WRITE.SUCCESS)
|
fmt.Print(config_t.Messages.WS.REGISTER.SUCCESS)
|
||||||
}
|
}
|
||||||
|
|
||||||
// WebSocket loop for incomming messages
|
// WebSocket loop for incomming messages
|
||||||
|
|||||||
@@ -115,7 +115,5 @@ type Config struct {
|
|||||||
ENCODE Message `yaml:"ENCODE"`
|
ENCODE Message `yaml:"ENCODE"`
|
||||||
DECODE Message `yaml:"DECODE"`
|
DECODE Message `yaml:"DECODE"`
|
||||||
} `yaml:"GOB"`
|
} `yaml:"GOB"`
|
||||||
WS_CONNECT_ERROR string `yaml:"WS_CONNECT_ERROR"`
|
|
||||||
WS_CLOSE_ERROR string `yaml:"WS_CLOSE_ERROR"`
|
|
||||||
} `yaml:"messages"`
|
} `yaml:"messages"`
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user