shahryarjb

shahryarjb

Hello, I have read this page, and some video which wanted to create a real time chat in a web page with Phoenix channel help. But I never realized some things that are very basic and important.

question one:

when I just need to create a api for mobile developer, do I need to know js and write js for my project ? because I want to create a api, not html render?

question two:

if I don’t need js please tell me how to test my api which is created by websocket like postman app for json api.

question three:

I just found a lib for Mac Terminal that it’s name is wscat, but after some second it is terminated, and I cant test more than it.

I found heartbeats or there was something, that Kept my connection a live, but I didn’t find something more than it

at last, I think Phoenix channel is like elixir GenServer, but I can’t start and test a api to learn it, and this is a problem I have no easy sampel code to create a api just this not more.

if you have a code that Handles easy task like a registration user Api and how to test with some soft in mac or terminal not a mobile app, please give me and help me

Thanks

Showing Posts 1 to 5

hauleth

hauleth

No, if there is no web UI then you do not need to care.

Write tests. There are also CLI tools for connecting to WS.

You need not only to connect to WS, but you also need to talk proper protocol, in this case Phoenix protocol defined in Phoenix.Socket.V2.JSONSerializer.

For testing channels you can use Phoenix.ChannelTest helpers.

shahryarjb

shahryarjb OP

Thanks, I have a question about keeping a live a connection for user.

  • server should keep alive user with pinging user after some second?
  • or the user should ping server after some second?

imagine you have a chat application like Whatsapp or the better sample Telegram, how could you keep user connection?

Would you mind explaining me simple? please.

I read about heartbeat but I didn’t understand anything :cold_face:

The question is about Phoenix channel for mobile app without js

LostKobrakai

LostKobrakai

Using channels without js simply means you need an implementation of phoenix.js for your mobile app. Phoenix channels are not just raw websockets, but a communication protocol on top of many transports – websockets being one of them. Therefore your app needs to be able to communicate using that protocol. In detail this means being able to negotiate a serialization protocol for messages. Being able to serialize/deserialize messages according to said protocol, understanding a handful of channel specific messages as well as dealing with all the app specific messages. Then you’ll need facilities for handling channel joins/connection, dealing with replys and such. And if you need it (and it sounds like you do) you also need to deal with presence messages and the diffing mechanism.

As for tracking connectivity. Websocket connections will terminate once disconnected, but especially for flaky network this can be unrelyable for detecting disconnects. Therefore there are heartbeats as part of phoenix channels. I’m not sure currently if there’re initiated by the client or by the server though, but it’s likely the client.

shahryarjb

shahryarjb OP

Now this became clearer for me, Thank you, I think based on what I need, my user needs to use heartbeat, because if there is a problem server can’t create a new connection, but the mobile client how to use heartbeat?

I have read this page:

and I didn’t find anything about heartbeat in order to figure out how does they send me a heartbeat if the connection is online or not!! if not create a new!!! that I understand whether I need to create a function or not , or the phoenix handles it?

if you have sample code in swift please show me to know how it works!

thanks for explaining
https://github.com/phoenixframework/phoenix/blob/master/lib/phoenix/socket.ex#L97-L102

outlog

outlog

if you search for heartbeat in that repo it’s there Repository search results · GitHub
I assume it’s handled automatically..

I haven’t done anything in swift but there is an example project there https://github.com/davidstump/SwiftPhoenixClient/tree/master/Example/ChatExample with specific code here:

https://github.com/davidstump/SwiftPhoenixClient/blob/master/Example/ChatExample/ViewController.swift

— All posts loaded —

Where Next? Top

Trending in Discussions Top

AstonJ
As the title says, please share what you’ve been up to with Elixir. Whether that’s been learning it, looking into it, making stuff with i...
2977 92995 915
New
caslu
I want to open this thread for you all to discuss and help those who really like Ash but are still hesitant to use it in a real project. ...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
GES233
I’m posting this in response to Jose’s recent tweet (Cr. link) : People are sleeping on Elixir for a coding harness: Hot-code swappi...
New
marciol
It would be helpful to have a list of companies worldwide that hire engineers without prior experience in Elixir. Often, it can be quite ...
New
durvia
Anyone running long-lived stateful processes on BEAM? We’re building an AI agent runtime and would love to compare notes. We’re a small ...
New
AstonJ
This might be a bit disturbing for some but it’s happening - computers running on living human neurons. They’ve made them smart enough t...
New

Other Trending Topics Top

marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
webofbits
Aludel - LLM Evaluation Workbench Aludel is an embeddable Phoenix LiveView dashboard for evaluating and comparing LLM prompts across mult...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews