2525import Foundation
2626
2727public final class SocketIOClient : NSObject , SocketEngineClient , SocketParsable {
28- public let socketURL : String
28+ public let socketURL : NSURL
2929
3030 public private( set) var engine : SocketEngineSpec ?
3131 public private( set) var status = SocketIOClientStatus . NotConnected
@@ -55,25 +55,18 @@ public final class SocketIOClient: NSObject, SocketEngineClient, SocketParsable
5555 private( set) var reconnectAttempts = - 1
5656
5757 var waitingData = [ SocketPacket] ( )
58-
58+
5959 /**
6060 Type safe way to create a new SocketIOClient. opts can be omitted
6161 */
62- public init ( socketURL: String , options: Set < SocketIOClientOption > = [ ] ) {
62+ public init ( socketURL: NSURL , options: Set < SocketIOClientOption > = [ ] ) {
6363 self . options = options
64-
65- if socketURL. hasPrefix ( " https:// " ) {
64+ self . socketURL = socketURL
65+
66+ if socketURL. absoluteString. hasPrefix ( " https:// " ) {
6667 self . options. insertIgnore ( . Secure( true ) )
6768 }
6869
69- var cleanedURL = socketURL [ " https?:// " ] <~ " "
70-
71- if cleanedURL. hasSuffix ( " / " ) {
72- cleanedURL = String ( cleanedURL. characters. dropLast ( ) )
73- }
74-
75- self . socketURL = cleanedURL
76-
7770 for option in options {
7871 switch option {
7972 case let . ConnectParams( params) :
@@ -98,19 +91,32 @@ public final class SocketIOClient: NSObject, SocketEngineClient, SocketParsable
9891 continue
9992 }
10093 }
101-
94+
10295 self . options. insertIgnore ( . Path( " /socket.io " ) )
103-
96+
10497 super. init ( )
10598 }
106-
99+
107100 /**
108101 Not so type safe way to create a SocketIOClient, meant for Objective-C compatiblity.
109- If using Swift it's recommended to use `init(var socketURL: String , options: Set<SocketIOClientOption>)`
102+ If using Swift it's recommended to use `init(var socketURL: NSURL , options: Set<SocketIOClientOption>)`
110103 */
111- public convenience init ( socketURL: String , options: NSDictionary ? ) {
112- self . init ( socketURL: socketURL,
113- options: options? . toSocketOptionsSet ( ) ?? [ ] )
104+ public convenience init ( socketURL: NSURL , options: NSDictionary ? ) {
105+ self . init ( socketURL: socketURL, options: options? . toSocketOptionsSet ( ) ?? [ ] )
106+ }
107+
108+ /// Please use the NSURL based init
109+ @available ( * , deprecated= 5.3 )
110+ public convenience init ( socketURLString: String , options: Set < SocketIOClientOption > = [ ] ) {
111+ guard let url = NSURL ( string: socketURLString) else { fatalError ( " Incorrect url " ) }
112+ self . init ( socketURL: url, options: options)
113+ }
114+
115+ /// Please use the NSURL based init
116+ @available ( * , deprecated= 5.3 )
117+ public convenience init ( socketURLString: String , options: NSDictionary ? ) {
118+ guard let url = NSURL ( string: socketURLString) else { fatalError ( " Incorrect url " ) }
119+ self . init ( socketURL: url, options: options? . toSocketOptionsSet ( ) ?? [ ] )
114120 }
115121
116122 deinit {
0 commit comments