首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在IceLink库中集成XMPP而不是WebSync

在IceLink库中集成XMPP而不是WebSync
EN

Stack Overflow用户
提问于 2014-03-22 22:19:35
回答 1查看 516关注 0票数 3

我正在使用IceLink库进行点对点通信。我们需要部署两个服务器IceLink和WebSync,这里列出了http://docs.frozenmountain.com/icelink2/index.html#class=icelink-getting-started-creating-a-conference-10_ios-macosx,但我想使用XMPP而不是WebSync。下面的代码用于WebSync,现在我只想替换它,以便在此WebSync的情况下可以使用XMPP。

代码语言:javascript
复制
[client addOnStreamFailureWithValueBlock:^(FMWebSyncStreamFailureArgs *e)
         {
             [conference unlinkAll];
         }];

        // Add a couple event handlers to the conference to send
        // generated offers/answers and candidates to a peer.
        // The peer ID is something we define later. In this case,
        // it represents the remote WebSync client ID. WebSync's
        // "notify" method is used to send data to a specific client.
        [conference addOnLinkOfferAnswerWithValueBlock:^(FMIceLinkLinkOfferAnswerArgs *e)
         {
             [client notifyWithNotifyArgs:[FMWebSyncNotifyArgs notifyArgsWithClientId:[FMGuid guidWithG:e.peerId]
                                                                             dataJson:[e.offerAnswer toJson]
                                                                                  tag:@"offeranswer"]];
         }];
        [conference addOnLinkCandidateWithValueBlock:^(FMIceLinkLinkCandidateArgs *e)
         {
             [client notifyWithNotifyArgs:[FMWebSyncNotifyArgs notifyArgsWithClientId:[FMGuid guidWithG:e.peerId]
                                                                             dataJson:[e.candidate toJson]
                                                                                  tag:@"candidate"]];
         }];

        // Add an event handler to the WebSync client to receive
        // incoming offers/answers and candidates from a peer.
        // Call the "receiveOfferAnswer" or "receiveCandidate"
        // method to pass the information to the conference.
        [client addOnNotifyWithValueBlock:^(FMWebSyncNotifyReceiveArgs *e)
         {
             NSString *peerId = [e.notifyingClient.clientId toString];
             NSObject *peerState = e.notifyingClient.boundRecords;
             if ([e.tag isEqualToString:@"offeranswer"])
             {
                 [conference receiveOfferAnswerWithOfferAnswer:[FMIceLinkOfferAnswer fromJsonWithOfferAnswerJson:e.dataJson]
                                                        peerId:peerId
                                                     peerState:peerState];
             }
             else if ([e.tag isEqualToString:@"candidate"])
             {
                 [conference receiveCandidateWithCandidate:[FMIceLinkCandidate fromJsonWithCandidateJson:e.dataJson]
                                                    peerId:peerId];
             }
         }];

        // Subscribe to a WebSync channel. When another client joins the same
        // channel, create a P2P link. When a client leaves, destroy it.
        FMWebSyncSubscribeArgs *subscribeArgs = [FMWebSyncSubscribeArgs subscribeArgsWithChannel:@"/mychat"];
        [subscribeArgs setOnSuccessBlock:^(FMWebSyncSubscribeSuccessArgs *e)
         {
             [self writeLine:@"-- Subscribed to %@.", e.channel];
         }];
        [subscribeArgs setOnFailureBlock:^(FMWebSyncSubscribeFailureArgs *e)
         {
             [self writeLine:@"-- Could not subscribe to %@. %@", e.channel, e.exception.message];
         }];
        [subscribeArgs setOnReceiveBlock:^(FMWebSyncSubscribeReceiveArgs *e) { }];
        [subscribeArgs setOnClientSubscribeWithOnClientSubscribeBlock:^(FMWebSyncSubscribersClientSubscribeArgs *e)
         {
             NSString *peerId = [e.subscribedClient.clientId toString];
             NSObject *peerState = e.subscribedClient.boundRecords;
             [conference linkWithPeerId:peerId peerState:peerState];
         }];
        [subscribeArgs setOnClientUnsubscribeWithOnClientUnsubscribeBlock:^(FMWebSyncSubscribersClientUnsubscribeArgs *e)
         {
             NSString *peerId = [e.unsubscribedClient.clientId toString];
             [conference unlinkWithPeerId:peerId];
         }];
        [client subscribeWithSubscribeArgs:subscribeArgs];
EN

回答 1

Stack Overflow用户

发布于 2015-08-01 05:45:16

这是毫无疑问的。无论如何,作为对未来读者的一般回答,您可以使用客户端之间的任何通信方法。您甚至可以通过电子邮件发送和复制/粘贴通过信令通道发送的信息(我在最早的WebRTC工作中实际上就是这样做的,以避免使用信令服务器的复杂性)。

您只需使用您的信令通道来交换以下信息(我使用的是C#命名,但其他语言应该具有类似的名称,但遵循语言约定):

  1. 一个对等体的offer (在调用Conference.Link时通过回调OnLinkOfferAnswer生成)被发送给另一个对等体。要呼叫Conference.Link,您需要知道您连接到谁的对等方ID,因此可能需要您的信令服务器将此数据发送给我们(在我的使用中,我实际上连接到中间服务器进行记录,因此可以使用硬编码的“服务器”对等方ID)。
  2. 该对等方的答案(在您向Conference.ReceiveOfferAnswer注册offer后通过回调OnLinkOfferAnswer生成)发送给第一个对等方(并以相同的方式注册)。
  3. 两个对等方将通过OnLinkCandidate回调(多次)生成ICE候选。它必须发送给另一个对等体并向Conference.ReceiveCandidate.

注册

请注意,这一切都是异步发生的,因此可以在收到答案之前生成ICE候选。这很好,因为IceLink将在内部管理它们。

您必须跟踪这是针对哪个同级的(提供/回答和候选人是特定于同级的)。这完全取决于您的信令库(这里是XMPP)来生成某种唯一的对等ID,以便您可以识别用户(如果您的信令库没有这样做,您也可以自己做)。

交换的数据是JSON,但是在通常的用法中您不应该修改它。OfferAnswerCandidate对象具有处理转换的FromJsonToJson方法。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22578748

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档