Skip to content

Commit 102b36b

Browse files
committed
changes suggested by louis49 to support namespace
1 parent 65dd00b commit 102b36b

File tree

6 files changed

+25
-49
lines changed

6 files changed

+25
-49
lines changed

SocketIO.m

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ - (void) sendEvent:(NSString *)eventName withData:(id)data andAcknowledge:(Socke
291291
if (function) {
292292
packet.ack = @"data";
293293
}
294+
NSLog(@"%@", packet.data);
294295
[self send:packet];
295296
}
296297

@@ -338,7 +339,7 @@ - (void) send:(SocketIOPacket *)packet
338339
return;
339340
}
340341
DEBUGLOG(@"Prepare to send()");
341-
342+
packet.endpoint = _endpoint;
342343

343344
NSString *req = [packet toString];
344345
if (![_transport isReady]) {
@@ -686,10 +687,10 @@ - (void) onData:(NSString *)data
686687
//??
687688
break;
688689
case 2:
689-
{
690+
690691
//Ping->Pong
691692
[self sendMessage:[NSString stringWithFormat:@"3:%@", data]];
692-
} break;
693+
break;
693694
case 3:
694695
//Pong
695696
if([data isEqualToString:@"probe"])
@@ -708,7 +709,7 @@ - (void) onData:(NSString *)data
708709
//GET ENDPOINT
709710
NSUInteger rendpoint = [packet.data rangeOfString:@"["].location;
710711
if(rendpoint == NSNotFound)
711-
packet.endpoint = @"";
712+
packet.endpoint = packet.data;
712713
else
713714
packet.endpoint = [packet.data substringToIndex:rendpoint];
714715

SocketIOPacket.m

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,19 @@ - (NSString *) toString
8181
NSNumber *typeAsNumber = [self typeAsNumber];
8282
NSMutableArray *encoded = [NSMutableArray arrayWithObject:typeAsNumber];
8383

84+
NSNumber *typeNumber = [self typeAsNumber];
85+
if (!(self.endpoint == nil || [@"/" isEqualToString:self.endpoint]) && [typeNumber intValue] != 6 && [typeNumber intValue] != 2)
86+
{
87+
[encoded addObject:[self.endpoint stringByAppendingString:@","]];
88+
}
89+
8490
NSString *pIdL = self.pId != nil ? self.pId : @"";
8591

8692

8793
if( !([self isKindOfClass:[SocketIOPacketV10x class]]) ){
8894
if ([self.ack isEqualToString:@"data"])
8995
{
90-
pIdL = [pIdL stringByAppendingString:@"+"];
96+
//pIdL = [pIdL stringByAppendingString:@"+"];
9197
}
9298
} else {
9399
// Engine.IO 1.0 expects payload with the ping packet
@@ -97,24 +103,24 @@ - (NSString *) toString
97103
}
98104

99105
// Do not write pid for acknowledgements
100-
if ([type intValue] != 6) {
106+
if ([typeNumber intValue] != 6) {
101107
[encoded addObject:pIdL];
102108
}
103109

104110
// Add the end point for the namespace to be used, as long as it is not
105111
// an ACK, heartbeat, or disconnect packet
106-
if ([type intValue] != 6 && [type intValue] != 2 && [type intValue] != 0) {
112+
/*if ([type intValue] != 6 && [type intValue] != 2 && [type intValue] != 0) {
107113
[encoded addObject:endpoint];
108114
}
109115
else {
110116
[encoded addObject:@""];
111-
}
117+
}*/
112118

113119
if (data != nil)
114120
{
115121
NSString *ackpId = @"";
116122
// This is an acknowledgement packet, so, prepend the ack pid to the data
117-
if ([type intValue] == 6)
123+
if ([typeNumber intValue] == 6)
118124
{
119125
if( !([self isKindOfClass:[SocketIOPacketV10x class]]) )
120126
ackpId = [NSString stringWithFormat:@":%@%@", pIdL, @"+"];

SocketIOTransportWebsocket.m

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@
2929
#define DEBUGLOG(...)
3030
#endif
3131

32-
static NSString* kInsecureSocketURL = @"ws://%@/socket.io/1/websocket/%@%@";
33-
static NSString* kSecureSocketURL = @"wss://%@/socket.io/1/websocket/%@%@";
34-
static NSString* kInsecureSocketPortURL = @"ws://%@:%d/socket.io/1/websocket/%@%@";
35-
static NSString* kSecureSocketPortURL = @"wss://%@:%d/socket.io/1/websocket/%@%@";
32+
static NSString* kInsecureSocketURL = @"ws://%@/socket.io/1/websocket/%@";
33+
static NSString* kSecureSocketURL = @"wss://%@/socket.io/1/websocket/%@";
34+
static NSString* kInsecureSocketPortURL = @"ws://%@:%d/socket.io/1/websocket/%@";
35+
static NSString* kSecureSocketPortURL = @"wss://%@:%d/socket.io/1/websocket/%@";
3636

3737
@implementation SocketIOTransportWebsocket
3838

@@ -62,17 +62,17 @@ - (void) openUsing:(SocketIOVersion)version
6262
{
6363
NSString *urlStr;
6464
NSString *format;
65-
NSString *addOnVersion = @"";
65+
NSString *addOnVersion = delegate.sid;;
6666
if(version == V10x)
67-
addOnVersion = @"?EIO=2&transport=websocket&sid=";
67+
addOnVersion = [NSString stringWithFormat:@"?EIO=2&transport=websocket&sid=%@", delegate.sid];
6868

6969
if (delegate.port) {
7070
format = delegate.useSecure ? kSecureSocketPortURL : kInsecureSocketPortURL;
71-
urlStr = [NSString stringWithFormat:format, delegate.host, delegate.port, addOnVersion, delegate.sid];
71+
urlStr = [NSString stringWithFormat:format, delegate.host, delegate.port, addOnVersion, delegate.sid, addOnVersion];
7272
}
7373
else {
7474
format = delegate.useSecure ? kSecureSocketURL : kInsecureSocketURL;
75-
urlStr = [NSString stringWithFormat:format, delegate.host,addOnVersion, delegate.sid];
75+
urlStr = [NSString stringWithFormat:format, delegate.host,addOnVersion, delegate.sid, addOnVersion];
7676
}
7777
NSURL *url = [NSURL URLWithString:urlStr];
7878

socket.io-objc.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ spec.name = 'socket.io-objc'
33
spec.version = '0.6.4'
44
spec.license = 'MIT'
55
spec.homepage = 'https://github.com/francoisp/socket.IO-objc/'
6-
spec.authors = { 'Francois Payette' => '[email protected]' }
6+
spec.authors = { 'Philipp Kyeck' => '[email protected]' }
77
spec.summary = 'Socket.io 1.x client for Objective-C projects., with backward 0.9 compatibility'
88
spec.description = "Interface to communicate between Objective C and Socket.IO with the help of websockets. Originally based on fpotter's socketio-cocoa and uses square's SocketRocket.\n"
99
spec.source = { :git => 'https://github.com/francoisp/socket.IO-objc.git' }

submodules/.gitignore

Lines changed: 0 additions & 30 deletions
This file was deleted.

submodules/socket-rocket

Submodule socket-rocket deleted from a2dd92a

0 commit comments

Comments
 (0)