Skip to content
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

Presence enter error coming #664

Closed
gouravgupta72 opened this issue Dec 21, 2017 · 11 comments
Closed

Presence enter error coming #664

gouravgupta72 opened this issue Dec 21, 2017 · 11 comments

Comments

@gouravgupta72
Copy link

Hi Folks,

When i'm calling enter presence then it is giving an error

presence.enter(nil) { error in
guard error == nil else {
self.signalError(error!)
return
}
}

ARTErrorInfo with code 13, message: attempted to publish presence message without clientId, reason: (null)

@ricardopereira
Copy link
Contributor

Hello @gouravgupta72. You need to provide a cliendId.

In order to be present on a channel, a client must be identified by having a client ID, have permission to be present, and be attached to the channel. Ably Docs

@gouravgupta72
Copy link
Author

Hi I tried subscribe channel and then enter presence still getting the same error, we are using token authentication.

guard let channel = self.channel else { return }
let presence = channel.presence

    channel.attach(){ error in
    }
    presence.subscribe(self.membersChanged)
    channel.subscribe(self.receiveMessage)
    delay(1.0) {
        presence.enter("") { error in
            guard error == nil else {
                self.signalError(error!)
                return
            }
        }
    }

@funkyboy
Copy link
Contributor

funkyboy commented Aug 2, 2018

@gouravgupta72 Thanks for getting in touch. A few questions.

Enable logging

Can you please enable a more verbose logging to see what's going on?

options.logLevel = .verbose
let client = ARTRealtime(options: options)

Log errors (if any)

Can you please check if there's any error along the way? E.g.

channel.attach(){ error in
  // print error here if not nil
}

Provide a clientId

Does your instance of ARTRealtime have a clientId set? E.g.

options.clientId = "myClientId"

@gouravgupta72
Copy link
Author

hey,
i got the error and now it working.
Thanks for the help.

@gouravgupta72
Copy link
Author

Hi Folks,

When i'm trying to update user presence from my code no action is having, when doing the same from ably consol it's working fine.

let channel = realtime.channels.get("ate-dad-fly")
channel.presence.subscribe(.Enter) { member in
print("Member (member.clientId) entered")
}
channel.presence.enter(nil)

Can you please help me in getting update user presence?

@funkyboy
Copy link
Contributor

funkyboy commented Aug 6, 2018

@gouravgupta72 your code looks fine. For sake of completeness it should be something like

let options = ARTClientOptions(key: "YOUR_API_KEY")
options.clientId = "bob"
let realtime = ARTRealtime(options: options)
let channel = realtime.channels.get("dot-jaw-bye")
channel.presence.subscribe(.Enter) { member in
    print("Member \(member.clientId) entered")
}
channel.presence.enter(nil)

Are you using the same api key both in your code and in the Ably console?

@gouravgupta72
Copy link
Author

We are doing authentication using JWT token, so in app i can't assign clientId, when i'm trying to do so it is not getting connected to chat.

@funkyboy
Copy link
Contributor

funkyboy commented Aug 6, 2018

@gouravgupta72 With JWT you can use a clientId. See the documentation here: https://www.ably.io/tutorials/jwt-authentication

UPDATE: The key for the clientId in the JWT claim is x-ably-clientId

@gouravgupta72
Copy link
Author

Hey @funkyboy ,

this is the debug log we are getting

"token":{"token":"key_name-S3bidW4uF8zqqm_AwKRXPNQdvR7QCOoryx9ocl62tXhTiRWRqwkSUpqSDmCjAMoqOhA9HezDHtRN2kTqlbGfghpNjolzb4WYwWolSMAL4FlJ749thea6d4BtVAjxyfAXf559_DA---SrFNgUSoyUA","keyName":"key_name.P__eEQ","issued":1533624962493,"expires":1533628562493,"capability":"{"*":["publish","subscribe"]}","clientId":"Bob"}}

It is showing that client id is assign to my token, but when i'm trying to enter my presence i'm still not able to see it in dev consol.

Only 1 member is showing for which i added presence from dev consol.

@funkyboy
Copy link
Contributor

funkyboy commented Aug 7, 2018

@gouravgupta72 I think that's because you don't have capabilities for presence. See docs here: https://www.ably.io/documentation/general/authentication#capabilities-explained
So you should have something like:

"capability":"{"*":["publish","subscribe","presence"]}"

@gouravgupta72
Copy link
Author

Thanks for the help.

It worked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants