diff --git a/.gitignore b/.gitignore index e43b0f9..4befed3 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ .DS_Store +.idea diff --git a/package.json b/package.json index b114589..3c1f274 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name":"cdv-socket-plugin", - "version":"0.4.0", + "version":"0.4.1", "description":"cdv-socket-plugin", "cordova":{ "id":"com.tlantic.cdv-socket-plugin", diff --git a/plugin.xml b/plugin.xml index e250613..f617325 100644 --- a/plugin.xml +++ b/plugin.xml @@ -2,7 +2,7 @@ + version="0.4.1"> Socket Tlantic TCP socket plugin GPL diff --git a/src/ios/CDVSocketPlugin.m b/src/ios/CDVSocketPlugin.m index 180a44b..0045367 100644 --- a/src/ios/CDVSocketPlugin.m +++ b/src/ios/CDVSocketPlugin.m @@ -222,6 +222,7 @@ -(void)send: (CDVInvokedUrlCommand *) command { CDVPluginResult* result= nil; Connection* socket = nil; NSString* data = nil; + NSString* format = nil; NSString* key = nil; @try { @@ -243,7 +244,14 @@ -(void)send: (CDVInvokedUrlCommand *) command { } else { // writting on output stream data = [command.arguments objectAtIndex:1]; - [socket write:data]; + if ([command.arguments count] > 2) { + format = [command.arguments objectAtIndex:2]; + } + if ([format isEqual: @"base64"]) { + [socket writeBase64:data]; + } else { + [socket write:data]; + } //formatting success response result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:key]; @@ -277,4 +285,4 @@ -(void) sendMessage :(NSString *)host :(int)port :(NSString *)chunk { [self.commandDelegate evalJs:receiveHook]; } -@end \ No newline at end of file +@end diff --git a/src/ios/Connection.h b/src/ios/Connection.h index 65e07dd..f9c312f 100644 --- a/src/ios/Connection.h +++ b/src/ios/Connection.h @@ -22,6 +22,7 @@ - (void) open; - (void) close; - (void) write : (NSString*) data; +- (void) writeBase64 : (NSString*) data; - (void) stream : (NSStream *) theStream handleEvent : (NSStreamEvent) streamEvent; diff --git a/src/ios/Connection.m b/src/ios/Connection.m index 6a0db26..6a4f251 100644 --- a/src/ios/Connection.m +++ b/src/ios/Connection.m @@ -61,6 +61,11 @@ - (void) write : (NSString *) data { [writer write : [pChunk bytes] maxLength : [pChunk length]]; } +- (void) writeBase64 : (NSString *) data { + NSData *decodedData = [[NSData alloc] initWithBase64EncodedString:data options:0]; + [writer write : [decodedData bytes] maxLength : [decodedData length]]; +} + - (void) stream : (NSStream *) theStream handleEvent : (NSStreamEvent) streamEvent { switch (streamEvent) { case NSStreamEventOpenCompleted: diff --git a/www/socket.js b/www/socket.js index 740db6c..e0b1419 100644 --- a/www/socket.js +++ b/www/socket.js @@ -28,9 +28,9 @@ Socket.prototype.disconnectAll = function (successCallback, errorCallback) { }; // -Socket.prototype.send = function (successCallback, errorCallback, connectionId, data) { +Socket.prototype.send = function (successCallback, errorCallback, connectionId, data, format) { 'use strict'; - exec(successCallback, errorCallback, this.pluginRef, 'send', [connectionId, typeof data == 'string' ? data : JSON.stringify(data)]); + exec(successCallback, errorCallback, this.pluginRef, 'send', [connectionId, typeof data == 'string' ? data : JSON.stringify(data), format]); }; //