You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have tried to use the example provided by you. I send a message Hello World1 from my account, then subscribe to myself and read it back. However when I send a Hello World2, Hello World3... messages I get back only the first one Hello World1. I assume I am either not subscribing correctly or I am doing something wrong. Can you please guide me how to send and receive all messages from a specific user, not only the first one? Below is an example I have used.
func read(){
do{
let keyPair = try KeyPair(privateKey: "df9aae2ac8233ffa210a086c54059d02ba3247dab1130dad968f28f036326a83")
let subscription = Subscription(filters: [.init(authors: [keyPair.publicKey],eventKinds: [.textNote])])
let message = ClientMessage.subscribe(subscription)
let relayUrl = URL(string: "wss://jiggytom.ddns.net")!
let webSocketTask = URLSession(configuration: .default).webSocketTask(with: relayUrl)
webSocketTask.resume()
webSocketTask.send(.string(try! message.string())) { error in
if let error = error {
fatalError("Error: \(error)")
}
}
webSocketTask.receive { result in
switch result {
case .success(let message):
switch message {
case .string(let text):
let message = try! RelayMessage(text: text)
self.text = text
print(message)
default:
fatalError("Error: Received unknown message type")
}
case .failure(let error):
fatalError("Error: \(error)")
}
}
}catch{
}
}
func write(){
do{
let keyPair = try KeyPair(privateKey: "df9aae2ac8233ffa210a086c54059d02ba3247dab1130dad968f28f036326a83")
let event = try Event(keyPair: keyPair, kind: EventKind.textNote, tags: [], content: "Hello World1")
print(event.id)
let message = ClientMessage.event(event)
let relayUrl = URL(string: "wss://jiggytom.ddns.net")!
let webSocketTask = URLSession(configuration: .default).webSocketTask(with: relayUrl)
webSocketTask.resume()
webSocketTask.send(.string(try! message.string())) { error in
if let error = error {
fatalError("Error: \(error)")
}
}
}catch{
}
}
The text was updated successfully, but these errors were encountered:
I don't know if this is the right way to handle this but you need to listen again every time you receive a new message. Just add task.receive at the end of your listening function.
I have tried to use the example provided by you. I send a message Hello World1 from my account, then subscribe to myself and read it back. However when I send a Hello World2, Hello World3... messages I get back only the first one Hello World1. I assume I am either not subscribing correctly or I am doing something wrong. Can you please guide me how to send and receive all messages from a specific user, not only the first one? Below is an example I have used.
func read(){
The text was updated successfully, but these errors were encountered: