sjrmanning / birdsong Goto Github PK
View Code? Open in Web Editor NEW:bird::musical_score: Swift WebSockets client for Phoenix Channels.
License: MIT License
:bird::musical_score: Swift WebSockets client for Phoenix Channels.
License: MIT License
Wanted to get your thoughts on some variations on init, that would allow you to init based on:
let socket = Socket(url: "http://localhost:3000/user_socket/websocket")
public init(url: **String**, params: [String: String]? = nil, selfSignedSSL: Bool = false) {
heartbeatQueue = dispatch_queue_create("com.ecksd.birdsong.hbqueue", nil)
socket = WebSocket(url: buildURL(url, params: params))
socket.delegate = self
socket.selfSignedSSL = selfSignedSSL
}
// MARK: - Private URL helpers
private func buildURL(url_string: **String**, params: [String: String]?) -> NSURL {
**let url = NSURL(string: url_string)!**
guard let components = NSURLComponents(URL: url, resolvingAgainstBaseURL: false),
params = params else {
return url
}
var queryItems = [NSURLQueryItem]()
params.forEach({
queryItems.append(NSURLQueryItem(name: $0, value: $1))
})
components.queryItems = queryItems
return components.URL!
}
"http://localhost:4000/socket/websocket"
):let socket = Socket(port: 4001) // http://localhost:4001/socket/websocket
let socket = Socket()
Add component based initialiser
// MARK: - Component based Initialisation
public init(protocol: String = "http", host: String = "localhost", port: Int = 4000,
path: String = "socket", transport: String = "websocket",
params: [String: String]? = nil, selfSignedSSL: Bool = false) {
string_port = String(port)
url = "\(protocol)://\(host):\(port)/\(path)/\(transport)"
heartbeatQueue = dispatch_queue_create("com.ecksd.birdsong.hbqueue", nil)
socket = WebSocket(url: buildURL(protocol, host, port, path, transport, params: params))
socket.delegate = self
socket.selfSignedSSL = selfSignedSSL
}
And overload buildURL:
func buildURL(protocol: String, host: String, port: Int, path: String,
transport: String, params: [String: String]? = nil) -> NSURL {
full_path = "/\(path)/\(transport)"
let components = NSURLComponents()
components.scheme = "protocol";
components.host = host;
components.path = full_path;
components.port = port;
guard let params = params else {
return components.URL!
}
var queryItems = [NSURLQueryItem]()
params.forEach({
queryItems.append(NSURLQueryItem(name: $0, value: $1))
})
components.queryItems = queryItems
return components.URL!
}
Note: I haven't tried these out, but if it sounds like a good fit for Birdsong, I'd be happy to work through it and pull a PR.
Cheers
Are queued messages re-sent upon reconnect?
Birdsong depends on Starscream 2.0.1 which doesn't compile under Swift 4
Hi,
Would you please add support for installation using Carthage?
$ pod install Analyzing dependencies Fetching podspec for
Birdsongfrom
../`
[!] Unable to satisfy the following requirements:
Starscream (= 1.1.3)
required by Podfile.lock
Starscream (= 1.1.1)
required by Birdsong (0.2.2)
It seems like you've changed the constraints of dependency Starscream
inside your development pod Birdsong
.
You should run pod update Starscream
to apply changes you've made.`
I've recently started seeing this crash in Crashlytics (generated from an app that users have downloaded from the App Store).
Unfortunately, I don't know more information than the crash info below so I cannot recreate the cause.
Crashed: com.apple.main-thread
0 Birdsong 0x102212d40 specialized Dictionary.subscript.getter + 28 (<compiler-generated>:28)
1 Birdsong 0x102214f98 specialized Socket.websocketDidReceiveMessage(socket:text:) + 1232 (<compiler-generated>:1232)
2 Birdsong 0x1022c6a18 closure #1 in WebSocket.processResponse(_:) + 264 (<compiler-generated>:264)
3 Birdsong 0x101e44b8c thunk for @escaping @callee_guaranteed () -> () + 28 (<compiler-generated>:28)
4 libdispatch.dylib 0x1fc960a38 _dispatch_call_block_and_release + 24
5 libdispatch.dylib 0x1fc9617d4 _dispatch_client_callout + 16
6 libdispatch.dylib 0x1fc90f008 _dispatch_main_queue_callback_4CF$VARIANT$mp + 1068
7 CoreFoundation 0x1fceb4b20 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 12
8 CoreFoundation 0x1fceafa58 __CFRunLoopRun + 1924
9 CoreFoundation 0x1fceaefb4 CFRunLoopRunSpecific + 436
10 GraphicsServices 0x1ff0b079c GSEventRunModal + 104
11 UIKitCore 0x229710c38 UIApplicationMain + 212
12 Edmodo 0x100caba6c main + 21 (AppDelegate.swift:21)
13 libdyld.dylib 0x1fc9728e0 start + 4
Environment: Birdsong, 0.6
Can you help to see this? @sjrmanning
I was able to get Birdsong migrated to Swift 3 with relative ease ๐ So whenever you have a chance to put a Swift-3
branch up, I'll fork and send over some PRs with detailed commits on what changed and why.
While the server is turned off intentionally (thus my socket being disconnected), I am running the following block of code:
_ = channel?.send("new:msg", payload: ["body" : body])?
.receive("error", callback: { (payload) in
// This is never called
})
I was expecting the error callback to be executed if trying to send a message while the socket was disconnected. I don't know wether this is the way the library is designed or if it is a bug. Should I be checking before I send messages to the channel wether or not the socket is connected?
I've recently started seeing this crash in Crashlytics (generated from an app that users have downloaded from the App Store).
Unfortunately, I don't know more information than the crash info below so I cannot recreate the cause.
Crashed: NSOperationQueue 0x15130d400 (QOS: UNSPECIFIED)
EXC_BAD_ACCESS KERN_INVALID_ADDRESS 0x0000000adc3d4640
0 libobjc.A.dylib 0x1bfaf0fb0 objc_msgSend + 16
1 WebSocket 0x105f5784c FoundationStream.write(data:) + 241 (WebSocket.swift:241)
2 WebSocket 0x105f586ec protocol witness for WSStream.write(data:) in conformance FoundationStream + 20 (<compiler-generated>:20)
3 WebSocket 0x105f5f650 closure #1 in WebSocket.dequeueWrite(_:code:writeCompletion:) + 1268 (WebSocket.swift:1268)
4 WebSocket 0x105adcb8c thunk for @escaping @callee_guaranteed () -> () + 28 (<compiler-generated>:28)
5 Foundation 0x1c01ac9d4 <redacted> + 24
6 Foundation 0x1c00ae4a8 <redacted> + 104
7 Foundation 0x1c01aed30 <redacted> + 24
8 Foundation 0x1c00ae124 <redacted> + 740
9 Foundation 0x1c01af75c <redacted> + 24
10 Foundation 0x1c01af21c <redacted> + 184
11 libdispatch.dylib 0x1bfa8e39c <redacted> + 144
12 libdispatch.dylib 0x1bfa81fd8 <redacted> + 20
13 libdispatch.dylib 0x1bfa84758 <redacted> + 408
14 libdispatch.dylib 0x1bfa83f74 <redacted> + 784
15 libdispatch.dylib 0x1bfa90bd4 <redacted> + 348
16 libdispatch.dylib 0x1bfa91384 <redacted> + 120
17 libsystem_pthread.dylib 0x1bfae7690 _pthread_wqthread + 216
18 libsystem_pthread.dylib 0x1bfaed9e8 start_wqthread + 8
Environment: Birdsong, 0.6
Can you help to see this? @sjrmanning
Hi Simon,
Your library was such a relief when SwiftPhoenixClient couldn't support presence :)
But, I was wondering why you did not provide delegation for your socket class or your channels instead of setting callbacks in onConnect method.
Thanks for your help,
Soroush
Hi there,
Very nice library, especially with the handling of presence!
Could you please outline what are the differences with this one (beyond the presence)? https://github.com/davidstump/SwiftPhoenixClient
Thanks for your help,
Alex
Following is the XCode error I got when open fresh clone from this github page, could someone shed some light on how to fix it?
Showing All Messages
๐ ../Birdsong/Example/Pods/Target Support Files/Pods-Birdsong_Example/Pods-Birdsong_Example.debug.xcconfig: unable to open file (in target "Birdsong_Example" in project "Birdsong") (in target 'Birdsong_Example')
AFAICT, linux compatibility shouldn't be an issue as starscream works on linux doesn't, but we can also use something like Perfect.org 's socket handlers. Can we start a branch that works on linux?
Hey there, I just played around with the Example App and wanted to send a little PR to let it match the current Phoenix.Channel docs.
I then saw, that the message counter doesn't go up, so I set a breakpoint at ViewController.swift#L86 and it seems this never get's called ๐ค
I'm fairly new to Swift and Xcode, so maybe I just missed something ๐
Thread 2 Crashed:
0 CoreFoundation 0x31f4fc98c __exceptionPreprocess
1 libobjc.A.dylib 0x3410160a0 objc_exception_throw
2 CoreFoundation 0x31f400438 -[NSObject(NSObject) doesNotRecognizeSelector:]
3 CoreFoundation 0x31f500e04 forwarding
4 CoreFoundation 0x31f502be8 _CF_forwarding_prep_0
5 libswiftCore.dylib 0x32f64beac Dictionary._Variant.setValue
6 libswiftCore.dylib 0x32f819778 Dictionary.subscript.setter
7 libswiftCore.dylib 0x32f61c6c8 Dictionary.subscript.setter
8 Birdsong 0x102863cd8 Socket.send
9 Birdsong 0x102854ffc Channel.send
10 Appname 0x200b71624 SocketManager.fetchAllFeedsPosts
11 Appname 0x200ac4d54 @callee_guaranteed
12 libdispatch.dylib 0x197b8960c _dispatch_call_block_and_release
13 libdispatch.dylib 0x197b8a180 _dispatch_client_callout
14 libdispatch.dylib 0x197b70234 _dispatch_root_queue_drain
15 libdispatch.dylib 0x197b708ac _dispatch_worker_thread2
16 libsystem_pthread.dylib 0x3182b3f60 _pthread_wqthread
17 libsystem_pthread.dylib 0x3182b6adc start_wqthread
Thread 0
0 libsystem_kernel.dylib 0x197c935f4 mach_msg_trap
1 libsystem_kernel.dylib 0x197c92a5c mach_msg
2 CoreFoundation 0x31f47a064 __CFRunLoopServiceMachPort
3 CoreFoundation 0x31f475184 __CFRunLoopRun
4 CoreFoundation 0x31f4748b8 CFRunLoopRunSpecific
5 GraphicsServices 0x356e75324 GSEventRunModal
6 UIKitCore 0x3305de6d0 UIApplicationMain
7 Appname 0x201133964 main
8 libdyld.dylib 0x317e7245c start
Thread 1
0 libsystem_kernel.dylib 0x197cb5a74 __workq_kernreturn
1 libsystem_pthread.dylib 0x3182b3fec _pthread_wqthread
Thread 3
0 libsystem_pthread.dylib 0x3182b6ad8 start_wqthread
Thread 4
0 libsystem_pthread.dylib 0x3182b6ad8 start_wqthread
Thread 5
0 libsystem_kernel.dylib 0x197cb5a74 __workq_kernreturn
1 libsystem_pthread.dylib 0x3182b3fec _pthread_wqthread
Thread 6 name: com.apple.uikit.eventfetch-thread
0 libsystem_kernel.dylib 0x197c935f4 mach_msg_trap
1 libsystem_kernel.dylib 0x197c92a5c mach_msg
2 CoreFoundation 0x31f47a064 __CFRunLoopServiceMachPort
3 CoreFoundation 0x31f475184 __CFRunLoopRun
4 CoreFoundation 0x31f4748b8 CFRunLoopRunSpecific
5 Foundation 0x319e07990 -[NSRunLoop(NSRunLoop) runMode:beforeDate:]
6 Foundation 0x319e07870 -[NSRunLoop(NSRunLoop) runUntilDate:]
7 UIKitCore 0x330676498 -[UIEventFetcher threadMain]
8 Foundation 0x319f380ac NSThread__start
9 libsystem_pthread.dylib 0x3182b31e8 _pthread_start
Thread 7
0 libsystem_kernel.dylib 0x197cb5238 __semwait_signal
1 libsystem_c.dylib 0x197b21640 nanosleep
2 libsystem_c.dylib 0x197b21440 sleep
3 Sentry 0x103584504 monitorCachedData
4 libsystem_pthread.dylib 0x3182b31e8 _pthread_start
Thread 8 name: SentryCrash Exception Handler (Secondary)
0 libsystem_kernel.dylib 0x197c935f4 mach_msg_trap
1 libsystem_kernel.dylib 0x197c92a5c mach_msg
2 libsystem_kernel.dylib 0x197caf320 thread_suspend
3 Sentry 0x1035986c4 handleExceptions
4 libsystem_pthread.dylib 0x3182b31e8 _pthread_start
Thread 9 name: SentryCrash Exception Handler (Primary)
0 libsystem_kernel.dylib 0x197c935f4 mach_msg_trap
1 libsystem_kernel.dylib 0x197c92a5c mach_msg
2 Sentry 0x103598704 handleExceptions
3 libsystem_pthread.dylib 0x3182b31e8 _pthread_start
Thread 10
0 libsystem_kernel.dylib 0x197cb5a74 __workq_kernreturn
1 libsystem_pthread.dylib 0x3182b3fec _pthread_wqthread
Thread 11
0 libsystem_pthread.dylib 0x3182b6ad8 start_wqthread
Thread 12
0 libsystem_kernel.dylib 0x197cb5a74 __workq_kernreturn
1 libsystem_pthread.dylib 0x3182b3fec _pthread_wqthread
Thread 13 name: com.twitter.crashlytics.ios.MachExceptionServer
0 libsystem_kernel.dylib 0x197c935f4 mach_msg_trap
1 libsystem_kernel.dylib 0x197c92a5c mach_msg
2 Appname 0x20136b5b8 CLSMachExceptionServer
3 libsystem_pthread.dylib 0x3182b31e8 _pthread_start
Thread 14 name: com.apple.CFStream.LegacyThread
0 libsystem_kernel.dylib 0x197c935f4 mach_msg_trap
1 libsystem_kernel.dylib 0x197c92a5c mach_msg
2 CoreFoundation 0x31f47a064 __CFRunLoopServiceMachPort
3 CoreFoundation 0x31f475184 __CFRunLoopRun
4 CoreFoundation 0x31f4748b8 CFRunLoopRunSpecific
5 CoreFoundation 0x31f492d5c _legacyStreamRunLoop_workThread
6 libsystem_pthread.dylib 0x3182b31e8 _pthread_start
Thread 15 name: com.apple.NSURLConnectionLoader
0 libsystem_kernel.dylib 0x197c935f4 mach_msg_trap
1 libsystem_kernel.dylib 0x197c92a5c mach_msg
2 CoreFoundation 0x31f47a064 __CFRunLoopServiceMachPort
3 CoreFoundation 0x31f475184 __CFRunLoopRun
4 CoreFoundation 0x31f4748b8 CFRunLoopRunSpecific
5 CFNetwork 0x34fe4ae68
6 Foundation 0x319f380ac NSThread__start
7 libsystem_pthread.dylib 0x3182b31e8 _pthread_start
Thread 16 name: com.apple.CFSocket.private
0 libsystem_kernel.dylib 0x197cb5148 select$DARWIN_EXTSN
1 CoreFoundation 0x31f487b38 __CFSocketManager
2 libsystem_pthread.dylib 0x3182b31e8 _pthread_start
Thread 17
0 libsystem_kernel.dylib 0x197cb5a74 __workq_kernreturn
1 libsystem_pthread.dylib 0x3182b3fec _pthread_wqthread
Thread 18 name: com.apple.vectorkit.dispatch.imageLoaderQueue
0 libsystem_kernel.dylib 0x197c93648 semaphore_timedwait_trap
1 libdispatch.dylib 0x197b5bf2c _dispatch_sema4_timedwait$VARIANT$armv81
2 libdispatch.dylib 0x197b5c4b4 _dispatch_semaphore_wait_slow
3 libdispatch.dylib 0x197b6ff40 _dispatch_worker_thread
4 libsystem_pthread.dylib 0x3182b31e8 _pthread_start
Thread 19 name: com.apple.vectorkit.dispatch.imageLoaderQueue
0 libsystem_kernel.dylib 0x197c93648 semaphore_timedwait_trap
1 libdispatch.dylib 0x197b5bf2c _dispatch_sema4_timedwait$VARIANT$armv81
2 libdispatch.dylib 0x197b5c4b4 _dispatch_semaphore_wait_slow
3 libdispatch.dylib 0x197b6ff40 _dispatch_worker_thread
4 libsystem_pthread.dylib 0x3182b31e8 _pthread_start
Hi, maybe could we transform the error object in an Error type in the channel.join() closure to treat errors in a better way ?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.