54 lines
1.8 KiB
GDScript
54 lines
1.8 KiB
GDScript
extends Reference
|
|
class_name PolyServiceBuilder
|
|
|
|
## https://xmpp.org/extensions/xep-0030.html
|
|
|
|
func request(connection: Connections.Connection) -> Sums.Promise:
|
|
return connection.promise_iq(connection.domain, "get",
|
|
Stanza.disco_items_queury,
|
|
_service_discovery(connection))
|
|
|
|
func _service_discovery(connection: Connections.Connection) -> Sums.Result:
|
|
var response = yield()
|
|
if not response.is_ok:
|
|
return response
|
|
|
|
var query := Stanza.unwrap_query_result(response.value)
|
|
if not query.is_ok:
|
|
return query.value
|
|
|
|
var poly_services := Array()
|
|
for item in query.value.children:
|
|
if not item.is_element() or item.name != "item":
|
|
continue
|
|
|
|
var poly_service = load("res://scenes/PolyService.gd").new()
|
|
poly_service.jid = item.attributes["jid"]
|
|
if "name" in item.attributes:
|
|
poly_service.name = item.attributes["name"]
|
|
|
|
poly_services.push_back(poly_service)
|
|
|
|
var feature_promise = connection.promise_iq(
|
|
item.attributes["jid"], "get",
|
|
Stanza.disco_info_queury,
|
|
Stanza.yield_as_is())
|
|
|
|
if not feature_promise.is_done:
|
|
yield(feature_promise, "done")
|
|
|
|
# todo: Propagate error if it's unrelated to service discovery itself.
|
|
if feature_promise.is_ok:
|
|
# If features arrived, - populate services.
|
|
var jid = feature_promise.value.attributes["from"]
|
|
|
|
var features := Stanza.unwrap_query_result(feature_promise.value)
|
|
if not features.is_ok:
|
|
# todo: Propagate the error.
|
|
continue
|
|
|
|
poly_service.muc = load("res://scenes/MucService.gd").new().try_init(
|
|
connection, jid, features.value)
|
|
|
|
return Sums.Result.make_value(poly_services)
|