Skip to content

Commit

Permalink
feat(websockets): update to match starscream 4.X protocols
Browse files Browse the repository at this point in the history
  • Loading branch information
jeff-arn committed Feb 2, 2021
1 parent 14fee78 commit 1afba98
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions Sources/SpeechToTextV1/WebSockets/SpeechToTextSocket.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,32 @@ import Starscream
import IBMSwiftSDKCore

internal class SpeechToTextSocket: WebSocketDelegate {
// TODO: need to figure out what this does
func didReceive(event: WebSocketEvent, client: WebSocket) {
switch event {
case .connected(let headers):
self.websocketDidConnect(socket: client)
case .disconnected(let reason, let code):
self.websocketDidDisconnect(socket: client, error: nil)
case .text(let string):
self.websocketDidReceiveMessage(socket: client, text: string)
case .binary(let data):
self.websocketDidReceiveData(socket: client, data: data)
case .ping:
break
case .pong:
break
case .viabilityChanged:
break
case .reconnectSuggested:
break
case .cancelled:
break
case .error(let error):
self.websocketDidDisconnect(socket: client, error: error)
break
}
}

private(set) internal var results = SpeechRecognitionResults()
private(set) internal var state: SpeechToTextState = .disconnected
Expand Down Expand Up @@ -154,7 +180,7 @@ internal class SpeechToTextSocket: WebSocketDelegate {
queue.addOperation {
self.queue.isSuspended = true
self.queue.cancelAllOperations()
self.socket.disconnect(forceTimeout: forceTimeout)
self.socket.disconnect()
}
}

Expand Down Expand Up @@ -225,7 +251,8 @@ internal class SpeechToTextSocket: WebSocketDelegate {
private func isAuthenticationFailure(error: Error) -> Bool {
if let error = error as? WSError {
let matchesCode = (error.code == 400)
let matchesType = (error.type == .upgradeError)
// TODO: what error type is thrown when there is an authentication error
let matchesType = (error.type == .securityError)
return matchesCode && matchesType
}
return false
Expand Down

0 comments on commit 1afba98

Please sign in to comment.