我正在使用 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。
[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];