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

The resource part of the websocket-url not set correctly #169

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions SocketIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ typedef enum {
}

@property (nonatomic, readonly) NSString *host;
@property (nonatomic, readonly) NSString *resourceName;
@property (nonatomic, readonly) NSInteger port;
@property (nonatomic, readonly) NSString *sid;
@property (nonatomic, readonly) NSTimeInterval heartbeatTimeout;
Expand Down
7 changes: 3 additions & 4 deletions SocketIO.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
#define DEBUGLOG(...)
#endif

static NSString* kResourceName = @"socket.io";
static NSString* kHandshakeURL = @"%@://%@%@/%@/1/?t=%.0f%@";
static NSString* kForceDisconnectURL = @"%@://%@%@/%@/1/xhr-polling/%@?disconnect";

Expand Down Expand Up @@ -136,7 +135,7 @@ - (void) connectToHost:(NSString *)host
NSString *protocol = _useSecure ? @"https" : @"http";
NSString *port = _port ? [NSString stringWithFormat:@":%d", _port] : @"";
NSTimeInterval time = [[NSDate date] timeIntervalSince1970] * 1000;
NSString *handshakeUrl = [NSString stringWithFormat:kHandshakeURL, protocol, _host, port, kResourceName, time, query];
NSString *handshakeUrl = [NSString stringWithFormat:kHandshakeURL, protocol, _host, port, _resourceName, time, query];

DEBUGLOG(@"Connecting to socket with URL: %@", handshakeUrl);
query = nil;
Expand Down Expand Up @@ -183,7 +182,7 @@ - (void) disconnectForced
{
NSString *protocol = [self useSecure] ? @"https" : @"http";
NSString *port = _port ? [NSString stringWithFormat:@":%d", _port] : @"";
NSString *urlString = [NSString stringWithFormat:kForceDisconnectURL, protocol, _host, port, kResourceName, _sid];
NSString *urlString = [NSString stringWithFormat:kForceDisconnectURL, protocol, _host, port, _resourceName, _sid];
NSURL *url = [NSURL URLWithString:urlString];
DEBUGLOG(@"Force disconnect at: %@", urlString);

Expand Down Expand Up @@ -261,7 +260,7 @@ - (void) sendAcknowledgement:(NSString *)pId withArgs:(NSArray *)data

- (void) setResourceName:(NSString *)name
{
kResourceName = [name copy];
_resourceName = [name copy];
}

# pragma mark -
Expand Down
1 change: 1 addition & 0 deletions SocketIOTransport.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

@property (nonatomic, readonly) NSString *host;
@property (nonatomic, readonly) NSInteger port;
@property (nonatomic, readonly) NSString *resourceName;
@property (nonatomic, readonly) NSString *sid;
@property (nonatomic, readonly) NSTimeInterval heartbeatTimeout;
@property (nonatomic) BOOL useSecure;
Expand Down
12 changes: 6 additions & 6 deletions SocketIOTransportWebsocket.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
#define DEBUGLOG(...)
#endif

static NSString* kInsecureSocketURL = @"ws://%@/socket.io/1/websocket/%@";
static NSString* kSecureSocketURL = @"wss://%@/socket.io/1/websocket/%@";
static NSString* kInsecureSocketPortURL = @"ws://%@:%d/socket.io/1/websocket/%@";
static NSString* kSecureSocketPortURL = @"wss://%@:%d/socket.io/1/websocket/%@";
static NSString* kInsecureSocketURL = @"ws://%@/%@/1/websocket/%@";
static NSString* kSecureSocketURL = @"wss://%@/%@/1/websocket/%@";
static NSString* kInsecureSocketPortURL = @"ws://%@:%d/%@/1/websocket/%@";
static NSString* kSecureSocketPortURL = @"wss://%@:%d/%@/1/websocket/%@";

@implementation SocketIOTransportWebsocket

Expand All @@ -58,11 +58,11 @@ - (void) open
NSString *format;
if (delegate.port) {
format = delegate.useSecure ? kSecureSocketPortURL : kInsecureSocketPortURL;
urlStr = [NSString stringWithFormat:format, delegate.host, delegate.port, delegate.sid];
urlStr = [NSString stringWithFormat:format, delegate.host, delegate.port, delegate.resourceName, delegate.sid];
}
else {
format = delegate.useSecure ? kSecureSocketURL : kInsecureSocketURL;
urlStr = [NSString stringWithFormat:format, delegate.host, delegate.sid];
urlStr = [NSString stringWithFormat:format, delegate.host, delegate.resourceName, delegate.sid];
}
NSURL *url = [NSURL URLWithString:urlStr];

Expand Down