Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Message of type unrecognized is treated as normal message in deserialize then fails as channelName does not exist #66

Open
Clabybite opened this issue Feb 29, 2024 · 0 comments

Comments

@Clabybite
Copy link

Clabybite commented Feb 29, 2024

In JSONSerializer.deserialize, unrecognized message is grouped with message, but ultimately fails since message may be malformed eg does not contain channelName

case .welcome, .ping, .unrecognized:
                return Message(channelName: nil,
                               actionName: nil,
                               messageType: messageType,
                               data: nil,
                               error: nil)
            case .message:
                var messageActionName : String?
                var messageValue      : AnyObject?
                var messageError      : Swift.Error?
                
                do {
                    // No channel name was extracted from identifier
                    guard let _ = channelName
                        else { throw SerializationError.protocolViolation }
                    
                    // No message was extracted from identifier
                    guard let messageObj = JSONObj["message"]
                        else { throw SerializationError.protocolViolation }
                    
                    if let actionObj = messageObj["action"], let actionStr = actionObj as? String {
                        messageActionName = actionStr
                    }
                    
                    messageValue = messageObj
                } catch {
                  messageError = error
                }
                
                return Message(channelName: channelName!,
                               actionName: messageActionName,
                               messageType: MessageType.message,
                               data: messageValue,
                               error: messageError)

In onMessage, unrecognized message is not further processed.

fileprivate func onMessage(_ message: Message) {
            switch(message.messageType) {
            case .unrecognized:
                break
            case .welcome:
                break
            case .ping:
                if let callback = onPing {
                    DispatchQueue.main.async(execute: callback)
                }
            case .message:
                if let channel = channels[message.channelName!] {
                    // Notify Channel
                    channel.onMessage(message)

I suggest unrecognized be grouped with welcome and ping message types.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant