- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
我对 Pusher 平台中的 presence-channels
有点困惑,因为我正在从头构建聊天应用程序。现在,我知道你们中的一些人已经看到了大量的“实时聊天应用程序”主题,但是,我正在寻找点对点聊天而不是站点范围内的全局性话题。更像是 Facebook 聊天,您可以在那里一对一聊天。
现在,我在 PubNub 的演示中看到了一个例子(名为 Babel),但是,那个东西与我正在寻找的东西相去甚远,因为我已经检查了控制台中的请求,即使它没有显示,发送的其他用户之间的消息也显示在我的网络请求日志中,因为它是在 JS 中过滤的,而不是在服务器端过滤的,这不是我想要的。
所以,回到主题,我知道 channel /私有(private) channel /存在 channel 功能,我决定这样做:
打开应用程序时,每个用户都订阅他的 private-user_id
channel (创建,如果它尚不存在)。
同时(打开应用程序时)user1
订阅了一个 presence-global
channel ,如果 friend 在线,其他人会在该 channel 上进行跟踪。
当其他人想给他发消息时,例如user2
到user1
,他订阅了private-1
,之后javascript会处理事件。
现在,我知道这有问题,因为..如果 user3
会发送消息给 user1
他会订阅 private-user1
所以我猜他在向 user1
发送消息时也会看到 user2
触发的事件,对吗?还是我弄错了?
我在他们的文档中读到presence
channel 实际上是一个private
channel 扩展,所以我现在在想..为什么不再使用 private
channel ,然后,我如何通知我所有的 friend 我在线。
但是随后,他们的文档 中出现了其他内容,告诉我channels
提供了两个重要的东西(除其他外),首先是a过滤数据的方式
,第二种是控制访问的方式
。
我应该如何“过滤数据”,因为他们的文档中没有链接,或者更好的是,您对一对一聊天有什么想法。如果我弄错了他们所有的文档,我很抱歉,我查看了他们的示例应用程序,但没有一个使用我正在寻找的一对一技术。
我是 Pusher 和套接字连接等方面的新手,但我已经学会了如何进行身份验证,如何创建、检测和处理 channel 中的事件,并且我可以与在线成员创建简单的全局聊天,但是,当谈到私有(private) channel ,我对如何为两个用户创建单独的 channel 感到很困惑。
提前致谢!
最佳答案
目的private channels是限制谁可以订阅该 channel 。因此,您可以:
在一对一聊天中,我建议您选择后者(第 2 条)。
考虑到这一点,我打算按如下方式实现一对一聊天:
当用户加入聊天应用程序时,他们都订阅了两个 channel :
private-notifications-<user_id>
其中 user_id
是他们唯一的用户 ID,例如leggetter
就我而言。此 channel 用于特定于用户的通知。presence-forum
对于该论坛中的所有用户。这个问题叫做 presence-global
.实现方式如下:
var notifications = pusher.subscribe( 'private-notifications-user_one' );
var forum = pusher.subscribe( 'presence-forum' );
订阅每个 channel 后 channel authentication过程将发生。
在论坛中,您可以在 presence-forum
上进行一般公开聊天/presence-global
presence channel通过发送和接收消息。
当一个用户 ( user_one
) 想要与另一个用户 ( user_two
) 进行私有(private)聊天时,您显然需要 UI 中的某些内容来触发此操作。说 user_one
单击 user_two
旁边的内容这表明他们想要一对一的聊天。当发生这种情况时,应向服务器(权威机构)发出请求以指示 user_one
想发起与 user_two
的私聊†.
注意:† 如果您为一对一聊天选择 channel 命名约定,则私有(private) channel 身份验证实际上可以用作私有(private)一对一聊天启动
当服务器收到这个请求时,它可以为这个一对一聊天生成一个唯一的私有(private) channel 名称。一个非常简单的方法是连接用户 ID,例如private-chat-<initiating_user>-<receiving_user>
(还有其他考虑因素,例如,您可能想确保两个用户之间的 channel 名称始终相同)。在我们的简单场景中, channel 名称将是 private-chat-user_one-user_two
.
然后服务器可以触发 one-to-one-chat-request
每个用户的私有(private)通知 channel 上的事件在有效负载中传递一对一的私有(private)聊天 channel 名称。
// Trigger event on both user channels with one call
var channels = [ 'private-notifications-user_one', 'private-notifications-user_two' ];
// Additional event data could also be sent
// e.g. more info on the initiating user
var eventData = {
'channel_name': 'private-chat-user_one-user_two',
'initiated_by': 'user_one'
'chat_with' : 'user_two'
};
pusher.trigger( channels, 'one-to-one-chat-request', eventData );
当 user_one
收到 one-to-one-chat-request
他们将订阅 eventData.channel_name
channel 和 auth process将在该 channel 发生。
// A lookup of private chats
// where the key is the user ID of the current user is chatting with
var privateChats = {};
notifications.bind( 'one-to-one-chat-request', function( data ) {
// MY_USER_ID would need to be stored somewhere
// and in this case the value would be 'user_one'.
// expectingChatWith should make sure user_one is waiting for
// a private chat response with the given user
if( data.initiated_by === MY_USER_ID &&
expectingChatWith( data.chat_with ) ) {
startPrivateChat( data.chat_with, data.channel_name );
}
} );
function startPrivateChat( withUserId, channelName ) {
privateChats[ withUserId ] = pusher.subscribe( channelName );
}
当 user_two
收到 one-to-one-chat-request
用户将需要收到有关请求的通知,并接受或拒绝。如果用户接受,则客户端代码只需订阅该 channel 。如果用户拒绝,则应向服务器发送请求并在 private-notifications-user_one
上触发事件。告诉他们他们的一对一聊天请求被拒绝了。这将允许 user_one
取消订阅私有(private)聊天 channel 。
var privateChats = {};
notifications.bind( 'one-to-one-chat-request', function( data ) {
if( ... ) { ... }
// has somebody request to chat with this user?
else if( data.chatWith === MY_USER_ID ) {
// Prompt the user
// Note: more user info required
displayChatPrompt( data );
}
} );
// callback when the user accepts the chat request
function accepted( chatUserId, channelName ) {
startPrivateChat( chatUserId, channelName );
}
// the user doesn't want to chat
function declined( chatUserId ) {
// send info to the server indicating declined request
}
同时user_one
和 user_two
订阅了private-chat-user_one-user_two
他们可以在 channel 上触发事件并参与他们的私有(private)一对一聊天。
关于javascript - Pusher 一对一聊天结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27375125/
我想知道 gmail 聊天如何允许用户连接到 AIM,然后像登录到 AIM 一样聊天。 做起来容易吗?怎么做到的? 有人知道任何类似的开源工具吗? 谢谢! 最佳答案 如果你在谈论编程,这里是源代码示例
大家好,我正在尝试制作一个游戏,两个主持人联系起来,他们将“掷硬币”,并确定谁先出局。我决定从基本代码开始。但是我真的没有主意。 Thread server2 = new Thread(new Ser
我已经创建了一个只有 1 个房间的聊天室、私有(private)消息、审核以及一切,现在一切都很好!当我测试聊天时,我意识到在聊天中输入的所有消息都会被保存,如果有很多人使用聊天,它很快就会占用 Fi
当用户键入内容并出现软键盘时,我必须保持聊天回收器 View 的当前项目可见。目前,它覆盖了聊天,我需要回收器 View 项目与键盘一起显示。 我在 list 中尝试了这些: -android:win
我有一个服务器客户端应用程序集。 (家庭作业) 到目前为止,我已经弄清楚如何让多个客户端连接到服务器并让服务器聚合客户端发送的消息,以及如何让服务器将客户端的消息发送回客户端并将其显示在聊天 Pane
如何从我的应用程序发送/接收 Facebook 聊天消息?它是用 .Net、C# 编写的。 最佳答案 如果你可以使用 C,你就可以使用 libpurple (GPL) 和 pidgin-faceboo
我正在使用启用的 Ajax-Wcf 服务开发 Asp.Net 聊天。这是一个非常简单的聊天引擎,其中消息对话框意味着一对一(单个用户),但是我不知道如何管理(以最佳方式)通知新消息可用性。例如,假设有
我的任务是通过服务器构建一个客户端到客户端的聊天程序。客户端 A 将向服务器发送一条消息,然后服务器将消息转发给客户端 B,反之亦然。所有这一切都将同时发生,直到其中一个将其关闭。我有以下程序。 服务
我创建了一个聊天,用户可以在其中输入文本的输入字段。当他输入文本并按下发送(或输入)时,文本位于输入字段上方。像这样: 我想要的:我希望输入字段位于页面底部。我使用 position: absolut
出于个人兴趣,我尝试定义一个模拟 AI,它基于他学到的信息和互联网搜索,以便提供比系统知道的更多的细节。 我举了一个 child 的例子,当他出生时他需要学习一切,他听到了很多然后提出了一些答案。他的
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 想改进这个问题?将问题更新为 on-topic对于堆栈溢出。 3年前关闭。 Improve this qu
我已经开始聊天了,但我已经将用户的 ID 硬编码到 Chat.php 中。 当他们登录站点时,我的登录名将他们的电子邮件设置为 session ( $_SESSION['email']=$email;
当用户点击像 Start a viber chat with us 这样的链接时,我试图找到一种方法来开始 viber 聊天。但到目前为止我没有找到正确的URI来做到这一点。例如,我知道我可以使用 s
我是 Javascript(纯 javascript)新手,我正在尝试创建一个执行以下操作的聊天 Controller 应用程序。 用户输入内容。 有人对我的知识库进行了后调用。 服务器响应消息。 目
已关闭。这个问题是 not about programming or software development 。目前不接受答案。 这个问题似乎不是关于 a specific programming
如果用户在 x 秒/分钟内处于非事件状态,我想结束聊天,以便我们的代理不必等待聊天自行关闭。我还想在结束聊天之前将标签附加到聊天中,以便我可以看到这是由于不活动造成的。 最佳答案 此内容归功于 j
我正在此网站中构建新网站,客户需要 24/7 实时客户支持。我想在网站上集成 Skype 聊天 聊天界面应该在客户端的网站上。 最佳答案 您可以通过在网站上放置 Skype 按钮来使用它。 http:
事实上,我只是开始积极练习 swing,以便我的理论知识能派上用场:) 我已经为聊天 GUI 实现做了很多工作,但最终遇到了一些问题。所以我决定从头开始重新设计聊天 GUI,但我需要为其选择正确的组件
已关闭。这个问题是 not about programming or software development 。目前不接受答案。 这个问题似乎不是关于 a specific programming
我正在尝试进行简单的聊天,其中连接到服务器的用户发送消息,其他用户接收消息。 这是我的 html: function setupEventSource()
我是一名优秀的程序员,十分优秀!