simonb
April 30, 2021, 12:31am
1
Hi,
We are experiencing some occasional connection issues. When a login hasn’t happened for some time the first login fails and the retry logic doesn’t recover from the broken state. Reopening the App fixes the issue. Could this be caused by some warmup of a container or serverless functions?
Any help or tips here is appreciated.
Thanks
/Simon
Tyler
April 30, 2021, 3:10pm
2
Hi @simonb ,
Could you share with us your reconnect logic, and additionally any errors you’re receiving?
Thanks!
Yes, I’ll see if I cannot dig this up.
Thanks,
@Tyler Finally got this from our iOS dev. When the connection fails we just call connectSendBird again. We have validated the userid and token.
import SendBirdUIKit
import SendBirdDesk
import KollektivSports_Data
class SendBirdManager {
public static func connectSendBird(for user: User,
completion: ((_ success: Bool) -> Void)? = nil) {
SBUGlobals.CurrentUser = SBUUser(userId: user.sendBirdUserId)
SBUGlobals.AccessToken = user.sendBirdAccessToken
SBUMain.connectionCheck { sbUser, error in
if let usr = sbUser {
print("🐤 Sendbird User connected: \(usr.nickname ?? "")")
if let pendingPushToken = SBDMain.getPendingPushToken() {
SendBirdManager.registerPushToken(pendingPushToken) { (success) in
SendBirdManager.connectSendBirdDesk(user, completion: completion)
}
} else {
SendBirdManager.connectSendBirdDesk(user, completion: completion)
}
} else {
//If error is a cancelled connection, is because a new connection was started, we dont want to handle this as an error
if error?.code == 800102 {
return
}
completion?(false)
}
}
}
public static func registerPushToken(_ token: Data,
completion: ((_ success: Bool) -> Void)? = nil) {
// Register a device token to SendBird server.
SBDMain.registerDevicePushToken(token, unique: true, completionHandler: { (status, error) in
print("🐤 Sendbird Push Token status changed: \(status.rawValue)")
completion?(status != .error)
})
}
public static func connectSendBirdDesk(_ user: User,
completion: ((_ success: Bool) -> Void)? = nil) {
SBDSKMain.authenticate(withUserId: user.sendBirdUserId,
accessToken: user.sendBirdAccessToken) { (error) in
print(error == nil ? "🐤 Sendbird Desk connected" : "🐤 Sendbird Desk connection failed")
completion?(error == nil)
}
}
public static func createSendBirdTicket(for user: User,
channelViewModel: SendBirdChannelViewModel,
completion: ((_ ticket: SBDSKTicket?, _ error: SBDError?) -> Void)? = nil) {
guard let name = user.givenName else {
fatalError("User should have id & name")
}
guard SBUGlobals.CurrentUser != nil else {
fatalError("Should have SendBird User")
}
SBDSKTicket.createTicket(withTitle: channelViewModel.title,
userName: name) { (ticket, error) in
print(error == nil ? "🐤 Sendbird Desk Ticket created: \(channelViewModel.title)" : "🐤 Sendbird ticket creation failed")
if let channel = ticket?.channel {
channel.update(withName: nil,
isDistinct: false,
coverImage: channelViewModel.channelIcon.jpegData(compressionQuality: 0.2),
coverImageName: channelViewModel.title,
data: nil, customType: nil,
progressHandler: nil) { (_, _) in
completion?(ticket, error)
}
}
}
}
public static func getOpenTickets(completion: ((_ tickets: [SBDSKTicket], _ error: SBDError?) -> Void)? = nil) {
SBDSKTicket.getOpenedList(withOffset: 0) { (tickets, hasNext, error) in
print(tickets)
completion?(tickets, error)
}
}
}
@Tyler Any idea here? This issue is hurting us a lot…
Tyler
May 12, 2021, 1:42pm
6
Hey @simonb , my apologies. I’ve not had a chance to look at this yet. I’ll carve out some time to look at it today.
Hi @Tyler ,
We seem to have resolved the issue by changing the following line.
SBUMain.connectionCheck {
With this one. Same parameter schema.
SBUMain.connection {
You might want the team to look into why this would be failling for one function and not for the other.
Best,
Simon