使用Pusher.com API进行客户端到客户端事件

I have setup an account and app in the pusher.com API dashboard and have experimented with both private and public channels and client->client events - I have no trouble doing this.

My project is using CodeIgniter (latest) PHP framework (+ jQuery latest + pusher latest) and I have access to edit everything - nothing is out of bounds in terms of solutions, this is a non commercial project.

My aim is to have client/socket A send an event/message to client/socket B within 'channelX'.

I would like many people/sockets to be possible within 'channelX' - so for example we could have 10 clients connected to this channel, but within it I would like 2 parties to be able to communicate directly with each other (can be via server or just via pusher api).

At the moment, and where my understanding and research leads me: is that any event triggered in my 'channelX' private channel is sent to all clients - now I have used the 'exclude socket' parameter to make sure the event doesn't trigger on 'socketA' (the person doing the initiating of the event) - and this works when there is only 2 clients/sockets connected to a channel - but add more parties and it gets messy.

The question: Should a channel ONLY have 2 clients/sockets if the events are only to be shared between two?

Ideally what I would like to do: Have one master channel which holds all users - then each user should be able to send a 'ping' or 'poke' to one of the other users - without all of the other clients receiving this pusher event/trigger.

I do have code but my question is really theory based and so I'm not expecting bundles of code to come from this question - but the docs on the pusher.com website kind of miss this point (or perhaps I did!)

Thanks for any input

1个回答



如何实施1对1聊天,可以提供适合您需求的策略。</ p> \ n </ div>

展开原文

原文

There is an old FAQ article on how to implement 1-to-1 chat that may provide a strategy that suits your needs.

dongwei8729
dongwei8729 谢谢@leggetter我得出了类似的结论,我将让服务器生成一个私有通道名称,并通过ajax将其发送到客户端,以便客户端动态绑定到新的私有通道,然后可能从旧的启动用户 channel / unbind以防止任何交叉
6 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问