Enhancing My Julia RPC Chat Application with New Features
Written on
Introduction to My Chat Application
I’m thrilled to share that I have completed the final touches on my JLChat application, which utilizes the Julia programming language.
Toolips Framework Updates
I’m excited to announce the release of a major update to my extensible web-development framework for Julia, known as Toolips. This latest version has replaced traditional servers with modules, resulting in a significant boost in performance. It has also integrated advanced parallel computing capabilities and has evolved further in its design philosophy, making it the ideal web-development framework I envisioned. For those interested, you can find more details on the GitHub page for the project.
The extensibility of Toolips has grown to the point where I now refer to it as a server-development framework. With just a few additional features, its application can vary significantly. Currently, I am working on two projects, ChiProxy and ChiNS, which serve as a proxy server and a UDP name server, respectively. These projects highlight the flexibility of Toolips, with ChiProxy acting as a substitute for the Toolips router, allowing for host-based routing.
While the core Toolips package stands strong on its own, the main goal of Toolips is to modify functionalities through diverse extensions. One of the key extensions is ToolipsSession, which provides full-stack callbacks, RPC, input mapping, and authentication features in its latest iteration, version 0.4. This extension is crucial for the overall Toolips ecosystem and will be essential for the documentation website I plan to develop.
With the release of Toolips, I am also looking forward to quickly launching ToolipsSession 0.4, as it is vital for creating comprehensive websites using Toolips.
Exploring the RPC Feature
As part of my ongoing development, I am creating additional packages to test and showcase the functionalities of Toolips. One feature that has undergone significant enhancement is the RPC (Remote Procedure Call) capability. Initially developed in ToolipsSession 0.3, I created a simple chat application called JLChat to demonstrate its potential. This application allowed users to join a large chatroom seamlessly.
With the improvements to the RPC feature in the new ToolipsSession, I decided to build a similar chat application to test these updates. For those seeking more context, you can refer to my previous article that provides a detailed explanation of RPC.
Before we proceed with the final steps of connecting RPC and getting our chat application operational, let’s briefly review the RPC implementation within ToolipsSession. RPC enables Toolips to execute the same calls among clients engaged in a shared RPC session.
To initiate this process, each client must use either open_rpc! or join_rpc!. These functions can be executed on a Connection or a Connection combined with a ComponentModifier. It's essential to utilize the correct function based on the required response type.
open_rpc!(c::AbstractConnection; tickrate::Int64 = 500)
open_rpc!(c::AbstractConnection, cm::ComponentModifier; tickrate::Int64 = 500)
join_rpc!(c::AbstractConnection, host::String; tickrate::Int64 = 500)
join_rpc!(c::AbstractConnection, cm::ComponentModifier, host::String; tickrate::Int64 = 500)
When using join_rpc!, you must specify the host, which is the IP address of the client you are connecting to. This information should be stored for future reference and can be retrieved using get_ip.
If a user refreshes the page, we can reconnect them using the function reconnect_rpc!(c::Connection; tickrate::Int64 = 500).
Building the Chat Interface
To enhance user experience, we need to create a dynamic menu that displays existing chats. The build_main function constructs this menu, which includes buttons for both active and inactive chats, along with an option to create new chats:
function build_main(c::AbstractConnection, cm::ComponentModifier)
chatnav = div("chatnav")
style!(chatnav, "position" => "absolute", "width" => 10percent)
active_box = div("active-chats")
style!(active_box, "width" => 100percent)
inactive_box = div("inactive-chats")
style!(inactive_box, "width" => 100percent)
create_chat = button("create-chat", text = "create chat")
on(c, create_chat, "click") do cm::ComponentModifier
append!(cm, "jlchatbod", chat_builder(c))
focus!(cm, "makerchat")
end
style!(create_chat, "color" => "white", "background-color" => "#AA336A", "width" => 100percent,
"padding" => 5px, "font-size" => 16pt, "font-weight" => "bold")
push!(chatnav, create_chat, active_box, inactive_box)
...
end
This function iterates through active chats and generates corresponding menu options. The build_chatmenu function is called to create individual chat elements, which are then added to either the active or inactive sections based on membership.
Final Thoughts
This concludes the basic outline of creating a multi-chatroom application using Julia and Toolips. While this project is relatively straightforward, it serves to showcase the new functionalities within Toolips and the significant improvements made in version 0.3. I am eager to continue enhancing this application with additional Toolips features, including advanced multi-threading capabilities and potentially developing a mobile version.
Thank you for following along on this journey!