42 lines
1.1 KiB
Go
Executable File
42 lines
1.1 KiB
Go
Executable File
package websocket
|
|
|
|
import (
|
|
"fmt"
|
|
participanthandler "legatus-rme/backend/participantHandler"
|
|
partydata "legatus-rme/backend/partyData"
|
|
serviceportsinformation "legatus-rme/backend/servicePortsInformation"
|
|
typedata "legatus-rme/backend/typeData"
|
|
"log"
|
|
"net/url"
|
|
|
|
"github.com/gorilla/websocket"
|
|
)
|
|
|
|
func OpenWebsocket(websocketType string, port []int) interface{} {
|
|
var sockets []*websocket.Conn
|
|
for _, port := range port {
|
|
u := url.URL{Scheme: "ws", Host: fmt.Sprintf("localhost:%d", port)}
|
|
|
|
socket, _, err := websocket.DefaultDialer.Dial(u.String(), nil)
|
|
if err != nil {
|
|
log.Fatal("Error connecting to websocket:", err)
|
|
}
|
|
|
|
sockets = append(sockets, socket)
|
|
}
|
|
|
|
switch websocketType {
|
|
case "servicePortsInformation":
|
|
return serviceportsinformation.ServicePortsInformation{Websocket: sockets[0]}
|
|
case "typeBaseData":
|
|
return typedata.TypeData{Websocket: sockets[0]}
|
|
case "partyBaseData":
|
|
return partydata.PartyData{Websocket: sockets[0]}
|
|
case "participantHandler":
|
|
return participanthandler.ParticipantHandler{ParticipantManagement: sockets[0], MariusSocket: sockets[1]}
|
|
default:
|
|
log.Fatal("Invalid websocket type")
|
|
return nil
|
|
}
|
|
}
|