Skip to content

Commit

Permalink
Merge pull request #83 from Tlantic/v0.4.1
Browse files Browse the repository at this point in the history
V0.4.1
  • Loading branch information
joelbraga authored Sep 12, 2017
2 parents 0796feb + 05db806 commit adec425
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.DS_Store
.idea
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android"
id="com.tlantic.plugins.socket"
version="0.4.0">
version="0.4.1">
<name>Socket</name>
<description>Tlantic TCP socket plugin</description>
<license>GPL</license>
Expand Down
12 changes: 10 additions & 2 deletions src/ios/CDVSocketPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ -(void)send: (CDVInvokedUrlCommand *) command {
CDVPluginResult* result= nil;
Connection* socket = nil;
NSString* data = nil;
NSString* format = nil;
NSString* key = nil;

@try {
Expand All @@ -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];
Expand Down Expand Up @@ -277,4 +285,4 @@ -(void) sendMessage :(NSString *)host :(int)port :(NSString *)chunk {
[self.commandDelegate evalJs:receiveHook];

}
@end
@end
1 change: 1 addition & 0 deletions src/ios/Connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
- (void) open;
- (void) close;
- (void) write : (NSString*) data;
- (void) writeBase64 : (NSString*) data;

- (void) stream : (NSStream *) theStream handleEvent : (NSStreamEvent) streamEvent;

Expand Down
5 changes: 5 additions & 0 deletions src/ios/Connection.m
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions www/socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
};

//
Expand Down

0 comments on commit adec425

Please sign in to comment.