67 lines
1.5 KiB
GDScript
67 lines
1.5 KiB
GDScript
class_name ConnectionRoute
|
|
extends RefCounted
|
|
|
|
enum Kind {
|
|
DIRECT,
|
|
DISCOVERY_DIRECT,
|
|
DISCOVERY_RELAY,
|
|
}
|
|
|
|
var kind: Kind = Kind.DIRECT
|
|
var direct_endpoint: ConnectionEndpoint
|
|
var display_description: String = ""
|
|
var discovery_room_id: String = ""
|
|
|
|
|
|
static func direct(endpoint: ConnectionEndpoint) -> ConnectionRoute:
|
|
var route := ConnectionRoute.new()
|
|
route.kind = Kind.DIRECT
|
|
route.direct_endpoint = endpoint
|
|
route.display_description = "direct server" if endpoint != null else ""
|
|
return route
|
|
|
|
|
|
static func discovery_direct(
|
|
endpoint: ConnectionEndpoint,
|
|
room_id: String,
|
|
room_name: String,
|
|
) -> ConnectionRoute:
|
|
var route := ConnectionRoute.new()
|
|
route.kind = Kind.DISCOVERY_DIRECT
|
|
route.direct_endpoint = endpoint
|
|
route.discovery_room_id = room_id
|
|
var cleaned_name := room_name.strip_edges()
|
|
route.display_description = (
|
|
cleaned_name if not cleaned_name.is_empty() else "public room"
|
|
)
|
|
return route
|
|
|
|
|
|
static func discovery_relay(
|
|
endpoint: ConnectionEndpoint,
|
|
room_id: String,
|
|
room_name: String,
|
|
) -> ConnectionRoute:
|
|
var route := discovery_direct(endpoint, room_id, room_name)
|
|
route.kind = Kind.DISCOVERY_RELAY
|
|
return route
|
|
|
|
|
|
func is_valid() -> bool:
|
|
return (
|
|
kind in [Kind.DIRECT, Kind.DISCOVERY_DIRECT, Kind.DISCOVERY_RELAY]
|
|
and direct_endpoint != null
|
|
and direct_endpoint.is_valid()
|
|
and (
|
|
kind == Kind.DIRECT
|
|
or not discovery_room_id.is_empty()
|
|
)
|
|
)
|
|
|
|
|
|
func is_discovery_join() -> bool:
|
|
return kind in [Kind.DISCOVERY_DIRECT, Kind.DISCOVERY_RELAY]
|
|
|
|
|
|
func is_relay() -> bool:
|
|
return kind == Kind.DISCOVERY_RELAY
|