这是indexloc提供的服务,不要输入任何密码
Skip to content

Dev #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 8, 2021
Merged

Dev #23

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions addons/supabase/Auth/auth.gd
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const _invite_endpoint : String = _auth_endpoint+"/invite"
const _reset_password_endpoint : String = _auth_endpoint+"/recover"

var tcp_server : TCP_Server = TCP_Server.new()
var tcp_timer : Timer = Timer.new()

var _config : Dictionary = {}
var _header : PoolStringArray = []
Expand Down Expand Up @@ -77,15 +78,11 @@ func sign_in(email : String, password : String = "") -> AuthTask:

# Sign in with a Provider
# @provider = Providers.PROVIDER
func sign_in_with_provider(provider : String) -> AuthTask:
var payload : Dictionary = {}
var auth_task : AuthTask = AuthTask.new(
AuthTask.Task.SIGNIN,
_config.supabaseUrl + _provider_endpoint + "?provider=" + provider,
_header,
payload)
_process_task(auth_task)
return auth_task
func sign_in_with_provider(provider : String, grab_from_browser : bool = true, port : int = 3000) -> void:
OS.shell_open(_config.supabaseUrl + _provider_endpoint + "?provider="+provider)
# ! to be implemented
pass


# If a user is logged in, this will log it out
func sign_out() -> AuthTask:
Expand Down Expand Up @@ -177,6 +174,7 @@ func _get_link_response(delta : float) -> void:
var peer : StreamPeer = tcp_server.take_connection()
if peer != null:
var raw_result : String = peer.get_utf8_string(peer.get_available_bytes())
return raw_result
else:
_get_link_response(delta)

Expand Down Expand Up @@ -210,8 +208,6 @@ func _on_task_completed(task : AuthTask) -> void:
elif task.data == null:
match task._code:
AuthTask.Task.MAGICLINK:
tcp_server.listen(3000)
_get_link_response(0.5)
emit_signal("magic_link_sent")
AuthTask.Task.RECOVER:
emit_signal("reset_email_sent")
Expand All @@ -227,3 +223,8 @@ func _on_task_completed(task : AuthTask) -> void:
emit_signal("error", task.error)


# A timer used to listen through TCP on the redirect uri of the request
func _tcp_stream_timer() -> void:
var peer : StreamPeer = tcp_server.take_connection()
# ! to be implemented
pass
9 changes: 4 additions & 5 deletions addons/supabase/Database/query.gd
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ func _init():
# Build the query from the scrut
func build_query() -> String:
for key in query_struct:
if query_struct[key].empty(): continue
match key:
"table":
query += query_struct[key]
Expand Down Expand Up @@ -210,17 +211,15 @@ func Or(column : String, value : String) -> SupabaseQuery:
return self

# Text Search
func text_seach(column : String, query : String, _named_properties : Dictionary = {}) -> SupabaseQuery:
var type : String = _named_properties.get("type", "")
func text_seach(column : String, query : String, type : String = "", config : String = "") -> SupabaseQuery:
var filter : int
match type:
"plain": filter = Filters.PLFTS
"phrase": filter = Filters.PHFLTS
"websearch": filter = Filters.WFTS
_: filter = Filters.FTS
_named_properties.erase("type")
query = query.replacen(" ", "%20")
filter(column, filter, query, _named_properties)
filter(column, filter, query, {config = config})
return self

func clean() -> void:
Expand Down Expand Up @@ -249,4 +248,4 @@ func clean() -> void:


func _to_string() -> String:
return "QUERY: " + query
return build_query()
21 changes: 13 additions & 8 deletions addons/supabase/Realtime/realtime_channel.gd
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func _init(topic : String, client) -> void:
self.topic = topic
_client = client

func publish(message : Dictionary):
func _publish(message : Dictionary) -> void:
if not subscribed: return
match message.event:
_client.SupabaseEvents.DELETE:
Expand All @@ -24,32 +24,37 @@ func publish(message : Dictionary):
_client.SupabaseEvents.INSERT:
emit_signal("insert", message.payload.record, self)
emit_signal("all", message.payload.get("old_record", {}), message.payload.get("new_record", {}), self)


func on(event : String, to : Object, function : String) -> RealtimeChannel:
connect(event, to, function)
return self

func subscribe():
func subscribe() -> RealtimeChannel:
if subscribed:
_client._error("Already subscribed to topic: %s" % topic)
return
return self
_client.send_message({
"topic": topic,
"event": _client.PhxEvents.JOIN,
"payload": {},
"ref": null
})
subscribed = true
return self


func unsubscribe():
func unsubscribe() -> RealtimeChannel:
if not subscribed:
_client._error("Already unsubscribed from topic: %s" % topic)
return
return self
_client.send_message({
"topic": topic,
"event": _client.PhxEvents.LEAVE,
"payload": {},
"ref": null
})
subscribed = false
return self

func remove() -> void:
_client.erase(self)
func close() -> void:
_client._remove_channel(self)
32 changes: 23 additions & 9 deletions addons/supabase/Realtime/realtime_client.gd
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ func _init(url : String, apikey : String, timeout : float) -> void:
_db_url = url.replace("http","ws")+"/realtime/v1/websocket"
_apikey = apikey
_heartbeat_timer.set_wait_time(timeout)
_heartbeat_timer.name = "PhxHeartbeat"
name = "RealtimeClient"

func _ready() -> void:
add_child(_heartbeat_timer)
Expand All @@ -44,7 +46,7 @@ func _connect_signals() -> void:

func _disconnect_signals() -> void:
_ws_client.disconnect("connection_closed", self, "_closed")
_ws_client.disconnect("connection_error", self, "_closed")
_ws_client.disconnect("connection_error", self, "_error")
_ws_client.disconnect("connection_established", self, "_connected")
_ws_client.disconnect("data_received", self, "_on_data")
_heartbeat_timer.disconnect("timeout", self, "_on_timeout")
Expand All @@ -62,6 +64,9 @@ func connect_client() -> int:
func disconnect_client() -> void:
_ws_client.disconnect_from_host(1000, "Disconnection requested from client.")

func remove_client() -> void:
queue_free()

func channel(schema : String, table : String = "", col_value : String = "") -> RealtimeChannel:
var topic : String = _build_topic(schema, table, col_value)
var channel : RealtimeChannel = get_channel(topic)
Expand All @@ -81,39 +86,48 @@ func _build_topic(schema : String, table : String = "", col_value : String = "")
func _add_channel(channel : RealtimeChannel) -> void:
channels.append(channel)

func _remove_channel(channel : RealtimeChannel) -> void:
channels.erase(channel)

func _connected(proto = ""):
emit_signal("connected")
set_process(true)

func _closed(was_clean : bool = false):
emit_signal("disconnected")
channels = []
_disconnect_signals()
emit_signal("disconnected")
set_process(false)

func _error(msg : String = "") :
func _error(msg : String = "") -> void:
emit_signal("error", msg)

func _on_data() -> void:
var data : Dictionary = get_message(_ws_client.get_peer(1).get_packet())
print(data)
match data.event:
PhxEvents.REPLY:
if _check_response(data) == 0:
print("Received reply = "+to_json(data))
pass
# print("Received reply = "+to_json(data))
PhxEvents.JOIN:
if _check_response(data) == 0:
print("Joined topic '%s'" % data.topic)
pass
# print("Joined topic '%s'" % data.topic)
PhxEvents.LEAVE:
if _check_response(data) == 0:
print("Left topic '%s'" % data.topic)
pass
# print("Left topic '%s'" % data.topic)
PhxEvents.CLOSE:
print("Channel closed.")
pass
# print("Channel closed.")
PhxEvents.ERROR:
emit_signal("error", data.payload)
SupabaseEvents.DELETE, SupabaseEvents.INSERT, SupabaseEvents.UPDATE:
print("Received %s event..." % data.event)
# print("Received %s event..." % data.event)
var channel : RealtimeChannel = get_channel(data.topic)
if channel != null:
channel.publish(data)
channel._publish(data)

func get_channel(topic : String) -> RealtimeChannel:
for channel in channels:
Expand Down