过程中XMPP架构的一个扩展对于ejabberd快速重新连接和Push模式

问题描述:

我使用的是为ejabberd由一个XMPPFramework扩展名为ProcessOne有困难。过程中XMPP架构的一个扩展对于ejabberd快速重新连接和Push模式

我想使用ProcessOne扩展对于快速重新连接和Push模式

// Process One Fast Reconnect & Push Standby Mode // 

xmppProcessOne = [[XMPPProcessOne alloc] initWithDispatchQueue:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0)]; 
[xmppProcessOne addDelegate:self delegateQueue:dispatch_get_main_queue()]; 
xmppProcessOne.pushConfiguration = [self setPushconfiguration]; 
[xmppProcessOne activate:_xmppStream]; 

按ejabberd文档,我有流功能确认后发送重新绑定包。 中有正在实施XMPPRebindAuthentication的这个扩展可用的方法。我无法理解如何调用此方法。

+0

我已阅读XMPPFramework代码,我认为,不管是谁写的XMPPFramework ProcessOne扩展没有完成它(或从未公布最终版本)。在阅读代码时,我写了一个工作补丁。我需要清理它才能发布。 –

+0

@MickaëlRémond:谢谢迈克尔,这将是从你身边有很大的帮助。 –

我不认为代码以支持扩展的会话重新绑定/ ProcessOne在XMPPFramework是完整的,可以作为是。

这里有一个补丁,我建议在XMPPFramework应该工作:https://github.com/processone/XMPPFramework/commit/67a20c28b28ca49667ca11012bb2a11373023057

至少我可以从那里使用下面的例子让客户重新绑定工作:

  • AppDelegate.h
// 
// AppDelegate.h 
// 
// Created by Mickaël Rémond on 07/03/16. 
// 

#import <UIKit/UIKit.h> 

#import <XMPPFramework/XMPPRoster.h> 
#import <XMPPFramework/XMPPRosterCoreDataStorage.h> 
#import <XMPPFramework/XMPPProcessOne.h> 

@interface AppDelegate : UIResponder <UIApplicationDelegate, XMPPRosterDelegate, XMPPStreamDelegate> 

@property (strong, nonatomic) UIWindow *window; 

/* XMPP related properties */ 
@property (nonatomic, strong) XMPPStream *xmppStream; 
@property (nonatomic, strong) XMPPRoster *xmppRoster; 
@property (nonatomic, strong) XMPPProcessOne *xmppProcessOne; 
@property (nonatomic, strong) XMPPRosterCoreDataStorage *xmppRosterStorage; 

@end 
  • AppDelegate.m
// 
// AppDelegate.m 
// 
// Created by Mickaël Rémond on 07/03/16. 
// 

#import "AppDelegate.h" 

#import "DDLog.h" 
#import "DDTTYLogger.h" 
#import "XMPPLogging.h" 

@interface AppDelegate() 
- (void)setupStream; 
- (BOOL)connect; 
@end 

@implementation AppDelegate 

static NSString * const kMyJid = @"[email protected]"; 
static NSString * const kMyPass = @"passw0rd"; 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 
    // Log all XMPP traffic for debugging 
    [DDLog addLogger:[DDTTYLogger sharedInstance] withLogLevel:XMPP_LOG_FLAG_SEND_RECV]; 
    [self setupStream]; 

    return YES; 
} 

- (void)applicationWillResignActive:(UIApplication *)application { 
} 

- (void)applicationDidEnterBackground:(UIApplication *)application { 
} 

- (void)applicationWillEnterForeground:(UIApplication *)application { 
} 

- (void)applicationDidBecomeActive:(UIApplication *)application { 
    [self connect]; 
} 

- (void)applicationWillTerminate:(UIApplication *)application { 
} 

#pragma mark == Setup XMPP parameters == 
- (void)setupStream { 
    _xmppStream = [XMPPStream new]; 
    _xmppRosterStorage = [XMPPRosterCoreDataStorage new]; 
    _xmppRoster = [[XMPPRoster alloc] initWithRosterStorage:_xmppRosterStorage]; 

    [_xmppRoster activate:_xmppStream]; 

    [_xmppStream addDelegate:self delegateQueue:dispatch_get_main_queue()]; 
    [_xmppStream addDelegate:self.xmppProcessOne delegateQueue:dispatch_get_main_queue()]; 
    [_xmppRoster addDelegate:self delegateQueue:dispatch_get_main_queue()]; 
    [_xmppStream setMyJID:[XMPPJID jidWithString:kMyJid]]; 

    _xmppProcessOne = [[XMPPProcessOne alloc] initWithDispatchQueue:dispatch_get_main_queue()]; 
    // TODO: Method to generate default push configuration 
    NSXMLElement *pushConfiguration = [XMPPProcessOne pushConfigurationContainer]; 
    [pushConfiguration addChild:[XMPPProcessOne keepaliveWithMax:30]];  // Seconds 
    [pushConfiguration addChild:[XMPPProcessOne sessionWithDuration:300]]; // Seconds 
    _xmppProcessOne.pushConfiguration = pushConfiguration; 

    [_xmppProcessOne addDelegate:self delegateQueue:dispatch_get_main_queue()]; 
    [_xmppProcessOne activate:self.xmppStream]; 
} 

#pragma mark == XMPP DELEGATES == 
- (void)xmppStreamDidConnect:(XMPPStream *)sender { 
    if ([self.xmppStream supportsRebind] && self.xmppProcessOne.savedSessionJID != nil) { 
     NSError *error = nil; 
     _xmppRoster.autoFetchRoster = NO; 
     if (![[self xmppStream] rebindSession:self.xmppProcessOne.savedSessionID forJID:self.xmppProcessOne.savedSessionJID withError:&error]) { 
      NSLog(@"Could not send session rebind successfully: %@", error); 
     } 
    } else { 
     NSError *error = nil; 
     _xmppRoster.autoFetchRoster = YES; 
     if (![[self xmppStream] authenticateWithPassword:kMyPass error:&error]) { 
      NSLog(@"Could not send standard password auth info: %@", error); 
     } 
    } 
} 

// Rebind failed, try standard auth 
- (void)xmppStream:(XMPPStream *)sender runFallbackAuthentication:(NSXMLElement *)error { 
    NSLog(@"Rebind failed: %@", error); 
    NSError *error2 = nil; 
    _xmppRoster.autoFetchRoster = YES; 
    if (![[self xmppStream] authenticateWithPassword:kMyPass error:&error2]) { 
     NSLog(@"did not authenticate %@", error2); 
    } 
} 

- (void)xmppStream:(XMPPStream *)sender didNotAuthenticate:(NSXMLElement *)error { 
    NSLog(@"Authentication failed: %@", error); 
} 

- (void)xmppStreamDidAuthenticate:(XMPPStream *)sender { 
    NSLog(@"Authentication successfull"); 
    [[self xmppStream] sendElement:[XMPPPresence presence]]; 
} 

/* Initiate TCP connection to XMPP server */ 
- (BOOL)connect { 
    if (!self.xmppStream.isConnected) { 
     if (![self.xmppStream isDisconnected]) { 
      return YES; 
     } 

     NSError *error = nil; 
     if (![self.xmppStream connectWithTimeout:XMPPStreamTimeoutNone error:&error]) { 
      NSLog(@"Error connecting to XMPP server"); 
     } else { 
      NSLog(@"Successfully connected"); 
     } 

     return YES; 
    } else { 
     return YES; 
    } 
} 

@end 
+0

我有一个问题,虽然。可以说会话时间设置为10分钟,会话将在10分钟后过期。如果我试图重新绑定与旧的会话ID的会话,然后我们会得到这个错误会话没有发现 此方法的正常身份验证将完成或它在应用程序方面 –

+0

在处理作为展会结束后例如:在runFallbackAuthentication中运行标准认证。无需重新连接。 –

+0

我用你的代码段,在正常情况下正常工作。但是,当使用XMPPStream管理(XEP-0198)平行并以这种方式实现。 if([sender supportsStreamManagement]) {[XmppManager xmppSharedManager] xmppStreamManagement] enableStreamManagementWithResumption:NO maxTimeout:0]; } 由于我们使用快速重新连接,而不是使XEP-0198流恢复。我们推出了从终止状态的应用程序后,没有发现会话和行之有效的,如果应用程序被打开,流丢失了,快速重新连接并行XEP-0198的作品没有找到 –