Added network error codes support
This commit is contained in:
parent
961a68ed13
commit
3de2552705
@ -164,4 +164,5 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
- 1.5.2 - fixed iOS open timeout [iOS]
|
||||
- 1.5.3 - added Android open and write timeouts [Android]
|
||||
- 1.5.4 - fixed iOS closing sockets on open timeout [iOS]
|
||||
- 1.6.0 - close old existing sockets on reopen by destination ports. Removed iOS trash sources [iOS, Android]
|
||||
- 1.6.0 - close old existing sockets on reopen by destination ports. Removed iOS trash sources [iOS, Android]
|
||||
- 1.7.0 - added codes to error handlers [iOS, Android]
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "cordova-plugin-socket-tcp",
|
||||
"version": "1.6.1",
|
||||
"version": "1.7.0",
|
||||
"description": "This Cordova plugin provides JavaScript API, that allows you to communicate with server through TCP protocol. Currently we support these platforms: iOS, Android, WP8.",
|
||||
"cordova": {
|
||||
"platforms": [
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android" id="cordova-plugin-socket-tcp" version="1.6.0">
|
||||
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android" id="cordova-plugin-socket-tcp" version="1.7.0">
|
||||
<name>SocketsForCordova</name>
|
||||
<description>
|
||||
This Cordova plugin provides JavaScript API, that allows you to communicate with server through TCP protocol.
|
||||
|
@ -259,6 +259,7 @@ public class SocketPlugin extends CordovaPlugin {
|
||||
JSONObject event = new JSONObject();
|
||||
event.put("type", "Error");
|
||||
event.put("errorMessage", errorMessage);
|
||||
event.put("code", 0);
|
||||
event.put("socketKey", socketKey);
|
||||
|
||||
dispatchEvent(event);
|
||||
@ -277,7 +278,11 @@ public class SocketPlugin extends CordovaPlugin {
|
||||
|
||||
@Override
|
||||
public void accept(String errorMessage) {
|
||||
this.openCallbackContext.error(errorMessage);
|
||||
JSONObject event = new JSONObject();
|
||||
event.put("errorMessage", errorMessage);
|
||||
event.put("socketKey", "key");
|
||||
event.put("code", 0);
|
||||
this.openCallbackContext.error(event);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -36,9 +36,9 @@
|
||||
- (void)stream:(NSStream *)stream handleEvent:(NSStreamEvent)event;
|
||||
|
||||
@property (copy) void (^openEventHandler)();
|
||||
@property (copy) void (^openErrorEventHandler)(NSString*);
|
||||
@property (copy) void (^openErrorEventHandler)(NSString*, NSInteger);
|
||||
@property (copy) void (^dataConsumer)(NSArray*);
|
||||
@property (copy) void (^closeEventHandler)(BOOL);
|
||||
@property (copy) void (^errorEventHandler)(NSString*, NSString *);
|
||||
@property (copy) void (^errorEventHandler)(NSString*, NSString *, NSInteger);
|
||||
|
||||
@end
|
||||
@end
|
||||
|
@ -78,14 +78,14 @@ int writeTimeoutSeconds = 5.0;
|
||||
-(void)onOpenTimeout:(NSTimer *)timer {
|
||||
NSLog(@"[NATIVE] Open timeout: %d", openTimeoutSeconds);
|
||||
//self.errorEventHandler(@"Socket open timeout", @"openTimeout");
|
||||
self.openErrorEventHandler(@"Socket open timeout");
|
||||
self.openErrorEventHandler(@"Socket open timeout", 0);
|
||||
openTimer = nil;
|
||||
[self close];
|
||||
}
|
||||
|
||||
-(void)onWriteTimeout:(NSTimer *)timer {
|
||||
NSLog(@"[NATIVE] Write timeout: %d", writeTimeoutSeconds);
|
||||
self.errorEventHandler(@"Socket write timeout", @"writeTimeout");
|
||||
self.errorEventHandler(@"Socket write timeout", @"writeTimeout", 0);
|
||||
writeTimer = nil;
|
||||
}
|
||||
|
||||
@ -208,13 +208,23 @@ int writeTimeoutSeconds = 5.0;
|
||||
{
|
||||
NSLog(@"[NATIVE] Stream event error: %@", [[stream streamError] localizedDescription]);
|
||||
|
||||
NSInteger code = [[stream streamError] code];
|
||||
|
||||
if (wasOpenned) {
|
||||
self.errorEventHandler([[stream streamError] localizedDescription], @"general");
|
||||
self.errorEventHandler([[stream streamError] localizedDescription], @"general", code);
|
||||
self.openErrorEventHandler([[stream streamError] localizedDescription],
|
||||
code);
|
||||
if(openTimer != nil){
|
||||
NSLog(@"[NATIVE] openTimer invalidate on open event");
|
||||
[openTimer invalidate];
|
||||
openTimer = nil;
|
||||
}
|
||||
self.closeEventHandler(TRUE);
|
||||
}
|
||||
else {
|
||||
self.errorEventHandler([[stream streamError] localizedDescription], @"general");
|
||||
self.openErrorEventHandler([[stream streamError] localizedDescription]);
|
||||
self.errorEventHandler([[stream streamError] localizedDescription], @"general", code);
|
||||
self.openErrorEventHandler([[stream streamError] localizedDescription],
|
||||
code);
|
||||
}
|
||||
//[self closeStreams];
|
||||
break;
|
||||
@ -277,4 +287,4 @@ int writeTimeoutSeconds = 5.0;
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
@end
|
||||
|
@ -26,7 +26,7 @@
|
||||
|
||||
NSString *socketKey = [command.arguments objectAtIndex:0];
|
||||
NSString *host = [command.arguments objectAtIndex:1];
|
||||
NSNumber *port = [NSNumber numberWithInteger:[[command.arguments objectAtIndex:2] integerValue]];
|
||||
NSNumber *port = [command.arguments objectAtIndex:2];
|
||||
|
||||
NSLog(@"[NATIVE] OPEN socket for port: %@", port);
|
||||
|
||||
@ -53,18 +53,25 @@
|
||||
|
||||
socketAdapter = nil;
|
||||
};
|
||||
socketAdapter.openErrorEventHandler = ^ void (NSString *error){
|
||||
NSLog(@"[NATIVE] openErrorEventHandler");
|
||||
socketAdapter.openErrorEventHandler = ^ void (NSString *error, NSInteger code){
|
||||
NSLog(@"[NATIVE] openErrorEventHandler. Code %ld", code);
|
||||
|
||||
NSMutableDictionary *errorDictionaryData = [[NSMutableDictionary alloc] init];
|
||||
[errorDictionaryData setObject:error forKey:@"message"];
|
||||
[errorDictionaryData setObject:socketKey forKey:@"socketKey"];
|
||||
[errorDictionaryData setObject:[NSString stringWithFormat: @"%ld", (long)code] forKey:@"code"];
|
||||
|
||||
[self.commandDelegate
|
||||
sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:error]
|
||||
sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:errorDictionaryData]
|
||||
callbackId:command.callbackId];
|
||||
};
|
||||
socketAdapter.errorEventHandler = ^ void (NSString *error, NSString *errorType){
|
||||
socketAdapter.errorEventHandler = ^ void (NSString *error, NSString *errorType, NSInteger code){
|
||||
NSMutableDictionary *errorDictionaryData = [[NSMutableDictionary alloc] init];
|
||||
[errorDictionaryData setObject:@"Error" forKey:@"type"];
|
||||
[errorDictionaryData setObject:errorType forKey:@"errorType"];
|
||||
[errorDictionaryData setObject:error forKey:@"errorMessage"];
|
||||
[errorDictionaryData setObject:socketKey forKey:@"socketKey"];
|
||||
[errorDictionaryData setObject:[NSString stringWithFormat: @"%ld", (long)code] forKey:@"code"];
|
||||
|
||||
[self dispatchEventWithDictionary:errorDictionaryData];
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user