pusher / chatkit-server-php

PHP SDK for Pusher Chatkit
https://pusher.com/chatkit
MIT License
35 stars 20 forks source link

Join users to a room #25

Closed mludi closed 6 years ago

mludi commented 6 years ago

Hi, is it planned that I can join users to a room through the server sdk?

That would be very nice, I connected my app with a local database and it doesn't feel good that the iOS app has to make the join and the subscribe.

Thanks

hamchapman commented 6 years ago

That's definitely something that could be added to this SDK. If you'd like to make a PR for it then we'd be more than happy to merge it in.

It should be quite easy to take one of the existing method calls and adapt it to make a call to join a user to a room by following the API docs here: https://docs.pusher.com/chatkit/reference/api#join-a-room

mludi commented 6 years ago

Hi @hamchapman yeah I'll have a look :)

Just one question:

I tried to pass the token from $token = $this->getServerToken();

and my request looks

     $ch = $this->createCurl(
            $this->api_settings,
            '/rooms/' . $roomId . '/users/add',
            $token,
            'PUT',
             $body
        );

so the curl give me

Missing token subject as an exception.

With a token generated by

        $token = $this->generateToken([
            'user_id' => '67B62939-C44B-4A79-A823-C0C2A94C3910',
            'su' => true
        ]);

It's working fine.

Otherwise the sdk needs a user to handle that, something like an API user from the dashboard.

Any better idea?

hamchapman commented 6 years ago

Ah so I think that's something we should make possible on our side. Right now the API requires a token with a subject of the user ID of the user making the request. However, it should be possible for a user with a server (su / sudo) token to make the request, without providing a user ID to use as a token subject.

I'll work on allowing that tomorrow morning 👍

mludi commented 6 years ago

Hi, awesome :) Thanks. Let me know, if you've done that and I'll make a PR with the changes in the php sdk.

hamchapman commented 6 years ago

@mludi sorry it took a bit longer than I'd expected to get it done. It's all live now though, so you should be able to make join requests with a su token that doesn't have a user ID 👍

mludi commented 6 years ago

No problem dude! Thanks for that 💙. I‘ll check at monday, so no worry 😊

mludi commented 6 years ago

Hi @hamchapman, I've still the same issue.

I tried to request a token with

        $token = $this->generateToken([
            'su' => true
        ]);

that worked.

But on the /users/add API I got

{
    "message": "Missing token subject", 
    "exception": "Chatkit\\Exceptions\\ChatkitException",
}
hamchapman commented 6 years ago

Ah okay so just to confirm, the join endpoint is now working?

The add and remove endpoints may well have the same restriction currently. Were you trying to add that functionality too? If so I can make the same change to those endpoints today 👍

mludi commented 6 years ago

Hi @hamchapman, oh yeah, I tested with the add API instead the join. The join is now working fine! 👍 Thanks for that.

hamchapman commented 6 years ago

@mludi I've just deployed some changes that allow add and remove member requests with su tokens (i.e. the same change as we did for join / leave).

mludi commented 6 years ago

@hamchapman very nice! I'll make the changes to your sdk this week 👍