-
Notifications
You must be signed in to change notification settings - Fork 20
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
Add presence #18
Add presence #18
Conversation
Adds onPresenceChange callback to Phoenix.Channel module.
that's really cool! |
Thanks for this @jur0! I'll most likely review tomorrow. |
@jur0 it would be great to see this running, could you add something to the example app? |
Having something in the example app would be sufficient but some unit test coverage on https://github.com/saschatimme/elm-phoenix/pull/18/files#diff-58ad5ceac6b844a5376bf0b35cb0cc68R45 would also be very helpful. The testing situation is far from ideal at the moment (Tasks make it tricky) but this seems like a good spot for some tests. I did get as far as setting them up in https://github.com/saschatimme/elm-phoenix/pull/19/files but it's probably easiest to just run elm-test in the root and go from there. No worries if that's too much work though, I'm not too familiar with Presence so it would be a good exercise to add the coverage myself later. |
I will update the example app with the Presence so you can check how that's supposed to work. It might be done tomorrow. |
Thanks @jur0! |
Hey @opsb. I created a new repo with the example: https://github.com/jur0/elm_phoenix_example There is no I didn't change the example in this repo as it is an old version of Phoenix and it'd be too much work to update it I think. |
Thanks @jur0, I'm a bit short in time tomorrow but I'll try to take a look. If not it'll be thursday for sure. I've started putting some elm-test coverage together so I'm already up to speed with Presence. |
Hey @jur0, this is looking really good! One thought I had though, I think the state should be decoded before it's passed to the
What do you think? |
Yes, it'd be better to have something like:
and a decoder for all of that. Would you like to add it or shall I do it (might take a couple of days though)? |
Also, I had to change https://github.com/jur0/elm_phoenix_example/blob/master/assets/elm/src/Chat.elm#L171 in the example app |
@jur0 I'm taking a long weekend so I won't be able to look at it until next week. Happy to pick it up sometime next week if you haven't had a chance though. |
Ok, in case I start working on it, I will post a message here so both of us won't work on the same thing. |
@jur0 I've been giving some thought to the API and it's not really clear what the best approach is (mainly because I haven't actually used Phoenix Presence yet). I think we should perhaps merge this in as is and see what patterns emerge. @jur0, @saschatimme let me know if this seems like a reasonable approach and I'll go ahead and merge it in. |
I think any refinements will build on this API so I'm just going to go ahead and merge. |
This adds support for Phoenix presence.
There is a new callback
onPresenceChange
inPhoenix.Channel
module. The callback is called each time there is apresence_state
orpresence_diff
event. The callback exposes the current presence state asDict String (List Value)
. It is a dictionary where the key is presence key (such as user id) and the value is a list of payload data such as[{ phx_ref = "y6aMeMQNuR8=", online_at = "1490470085" },{ phx_ref = "LGFol1M18BM=", online_at = "1490470085" }]
(each user can be connected more than once so we track that).The presence state is updated internally on
presence_state
andpresence_diff
events.