All Projects → alfredbaudisch → Godotphoenixchannels

alfredbaudisch / Godotphoenixchannels

Licence: mit
GDScript and Godot client for real-time Phoenix Framework Channels

Programming Languages

elixir
2628 projects

Projects that are alternatives of or similar to Godotphoenixchannels

Butterfly Server
The Everything is Real-Time C# Backend for Single Page Applications
Stars: ✭ 247 (+97.6%)
Mutual labels:  websocket, realtime
Deepstream.io
deepstream.io server
Stars: ✭ 6,947 (+5457.6%)
Mutual labels:  websocket, realtime
Eureca.io
eureca.io : a nodejs bidirectional RPC that can use WebSocket, WebRTC or XHR fallback as transport layers
Stars: ✭ 341 (+172.8%)
Mutual labels:  websocket, realtime
Glass Isc Dhcp
Glass - ISC DHCP Server Interface
Stars: ✭ 486 (+288.8%)
Mutual labels:  websocket, realtime
Socketcluster Server
Minimal server module for SocketCluster
Stars: ✭ 70 (-44%)
Mutual labels:  websocket, realtime
Mercure
Server-sent live updates: protocol and reference implementation
Stars: ✭ 2,608 (+1986.4%)
Mutual labels:  websocket, realtime
Clusterws
💥 Lightweight, fast and powerful framework for building scalable WebSocket applications in Node.js
Stars: ✭ 868 (+594.4%)
Mutual labels:  websocket, realtime
Firecamp
The world's first Multi-protocol API Platform. Run, Test, Collaborate to build Any Kind Of APIs.
Stars: ✭ 195 (+56%)
Mutual labels:  websocket, realtime
Clusterws Client Js
🔥 JavaScript Client for ClusterWS - lightweight, fast and powerful framework for building scalable WebSocket applications in Node.js.
Stars: ✭ 120 (-4%)
Mutual labels:  websocket, realtime
Beaver
💨 A real time messaging system to build a scalable in-app notifications, multiplayer games, chat apps in web and mobile apps.
Stars: ✭ 1,056 (+744.8%)
Mutual labels:  websocket, realtime
Rtb
Benchmarking tool to stress real-time protocols
Stars: ✭ 35 (-72%)
Mutual labels:  websocket, realtime
Sandstone
PHP microframework designed to build a RestApi working together with a websocket server. Build a real time RestApi!
Stars: ✭ 98 (-21.6%)
Mutual labels:  websocket, realtime
Nodefony Starter
Nodefony Starter Node.js Framework
Stars: ✭ 95 (-24%)
Mutual labels:  websocket, realtime
Webchat
A realtime chat for web
Stars: ✭ 106 (-15.2%)
Mutual labels:  websocket, realtime
Inkgd
Implementation of inkle's Ink in pure GDScript for Godot, with editor support.
Stars: ✭ 118 (-5.6%)
Mutual labels:  godot
Eon Map
Realtime maps with PubNub and MapBox.
Stars: ✭ 121 (-3.2%)
Mutual labels:  realtime
Nassh Relay
Relay Server for the Secure Shell Chromium plugin
Stars: ✭ 118 (-5.6%)
Mutual labels:  websocket
Node Multiple Rooms Chat
node socket.io multiple room chat demo
Stars: ✭ 118 (-5.6%)
Mutual labels:  websocket
Tap Tap Adventure
Tap Tap Adventure is a massively online 2D MMORPG set in the medieval times with twists.
Stars: ✭ 123 (-1.6%)
Mutual labels:  websocket
Harmonic
A high performance and scalable RTMP live streaming application framework
Stars: ✭ 121 (-3.2%)
Mutual labels:  websocket

Phoenix Channels Client for Godot and GDScript Godot 3.2

GodotPhoenixChannels is a GDScript and Godot Engine implementation for the Channels API of the Phoenix Framework. It enables Godot projects and games to connect to Phoenix Channels to leverage the connected massive real-time capabilities of Elixir and Phoenix backends. Compatible with Godot 3.* (including 3.2.*).

Before diving in, if you want to see some crazy numbers about the scalability of Phoenix, check The Road to 2 Million Websocket Connections in Phoenix and How Discord Scaled Elixir to 5,000,000 Concurrent Users.

What is Elixir?

Elixir is a dynamic, functional language designed for building scalable and maintainable applications.

Elixir leverages the Erlang VM, known for running low-latency, distributed and fault-tolerant systems, while also being successfully used in web development and the embedded software domain.

What is Phoenix?

Phoenix is a web and real-time framework built with Elixir. Phoenix leverages the Erlang VM ability to handle millions of connections alongside Elixir's beautiful syntax and productive tooling for building fault-tolerant systems.

What are Phoenix Channels?

Channels are an exciting part of Phoenix that enable soft real-time communication with and between millions of connected clients. Some possible use cases include:

  • Chat rooms and APIs for messaging apps
  • Breaking news, like "a goal was scored" or "an earthquake is coming"
  • Tracking trains, trucks, or race participants on a map
  • Events in multiplayer games
  • Monitoring sensors and controlling lights

Implementation

This library tries to follow the same design patterns of the official Phoenix JavaScript client, but important changes had to be made regarding events, in order to accommodate to GDScript. Godot's WebSocketClient is used as the transport.

Features

Almost every feature from the JS official client are implemented:

  • Main features of Phoenix Socket (connect, heartbeats, reconnect timers, errors)
  • Main features of Phoenix Channel (join, leave, push, receive, rejoin timers, errors)
  • All features of Presence
  • Automatic disconnection and channel leaving on Node freeing

Examples

Example Godot Project

  • For usage examples see the Demo project.
  • Godello is a complex project made with Godot, GDScript and Elixir, and uses this library.

Example Elixir Project

A simple Elixir server is available in Demo/Server.

To run it, have Elixir installed, then:

cd Demo/server
mix deps.get
iex -S mix phx.server

After the server is running, you can run the Godot demo and in the Host field put: ws://localhost:4000/socket.

Example Usage

var socket : PhoenixSocket
var channel : PhoenixChannel
var presence : PhoenixPresence

socket = PhoenixSocket.new("ws://localhost:4000/socket", {
  params = {user_id = 10, token = "some_token"}
})

# Subscribe to Socket events
socket.connect("on_open", self, "_on_Socket_open")
socket.connect("on_close", self, "_on_Socket_close")
socket.connect("on_error", self, "_on_Socket_error")
socket.connect("on_connecting", self, "_on_Socket_connecting")

# If you want to track Presence
presence = PhoenixPresence.new()

# Subscribe to Presence events (sync_diff and sync_state are also implemented)
presence.connect("on_join", self, "_on_Presence_join")
presence.connect("on_leave", self, "_on_Presence_leave")

# Create a Channel
channel = socket.channel("game:abc", {}, presence)

# Subscribe to Channel events
channel.connect("on_event", self, "_on_Channel_event")
channel.connect("on_join_result", self, "_on_Channel_join_result")
channel.connect("on_error", self, "_on_Channel_error")
channel.connect("on_close", self, "_on_Channel_close")

call_deferred("add_child", socket, true)

# Connect!
socket.connect_socket()

Then you implement the listeners:

#
# Socket events
#

func _on_Socket_open(payload):
	channel.join()
	print("_on_Socket_open: ", " ", payload)

func _on_Socket_close(payload):
	print("_on_Socket_close: ", " ", payload)

func _on_Socket_error(payload):
	print("_on_Socket_error: ", " ", payload)

func _on_Socket_connecting(is_connecting):
	print("_on_Socket_connecting: ", " ", is_connecting)

#
# Channel events
#

func _on_Channel_event(event, payload, status):
	print("_on_Channel_event:  ", event, ", ", status, ", ", payload)

func _on_Channel_join_result(status, result):
	print("_on_Channel_join_result:  ", status, result)

func _on_Channel_error(error):
	print("_on_Channel_error: " + str(error))

func _on_Channel_close(closed):
	print("_on_Channel_close: " + str(closed))

#
# Presence events
#

func _on_Presence_join(joins):
	print("_on_Presence_join: " + str(joins))

func _on_Presence_leave(leaves):
	print("_on_Presence_leave: " + str(leaves))

Push messages to the server:

channel.push("event_name", {some: "param"})

Broadcasts and push replies are received in the event PhoenixChannel.on_event:

channel.connect("on_event", self, "_on_Channel_event")

func _on_Channel_event(event, payload, status):
	print("_on_channel_event:  ", event, ", ", status, ", ", payload)

TODO

See the issues, but mostly:

  • [ ] Game example
  • [ ] Channel push buffer
  • [ ] Socket push buffer

Additional Facts about Elixir

As it was shown above, Elixir leverages the Erlang VM, which itself is a programming language used to build massively scalable soft real-time systems with requirements on high availability. Some of its uses are in telecoms, banking, e-commerce, computer telephony and instant messaging. Erlang's runtime system has built-in support for concurrency, distribution and fault tolerance.

Erlang is some 30 years old, built by Ericsson. To give you some context: Ericsson has 45% of the mobile satellite infrastructure in the world. If you are using data in your mobile phone you are certainly in some stage of the day using an equipment that uses Erlang (Source).

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].