Skip to content
This repository has been archived by the owner on May 13, 2024. It is now read-only.

How to subscribe and listen to events? #131

Open
VikranthKumar05 opened this issue Sep 10, 2018 · 1 comment
Open

How to subscribe and listen to events? #131

VikranthKumar05 opened this issue Sep 10, 2018 · 1 comment

Comments

@VikranthKumar05
Copy link

Can anyone please share the code snippet of subscribing and listening to events?

@iosparesh
Copy link

I am also looking for same
var request = URLRequest(url:url)
request.method = .get
do {
let json = try JSONSerialization.data(withJSONObject: ["topic": "aws/subscribe", "content": ["topics":"aws/chat"]], options: .fragmentsAllowed)
request.httpBody = json
} catch {
print("error")
}
socket = WebSocket(request: request)
socket?.compression.on = true
socket?.eventQueue = .main
socket?.binaryType = .nsData
socket?.delegate = self
socket?.event.open = {
print("opened")
}
socket?.event.error = { error in
print("error (error)")
}
socket?.event.message = {(data) in
print(data as? String ?? "")
}

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

No branches or pull requests

2 participants