Fix of close method for wp and android platforms.
This commit is contained in:
parent
b35a04b159
commit
c99ea1cf48
@ -45,6 +45,7 @@ public class SocketAdapterImpl implements SocketAdapter {
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
this.invokeCloseEventHandler(false);
|
||||
this.socket.close();
|
||||
}
|
||||
|
||||
|
@ -63,6 +63,7 @@ namespace Blocshop.ScoketsForCordova
|
||||
|
||||
public void Close()
|
||||
{
|
||||
this.CloseEventHandler(false);
|
||||
this.socket.Close();
|
||||
}
|
||||
|
||||
|
@ -21,56 +21,36 @@ namespace Blocshop.ScoketsForCordova
|
||||
this.socketStorage = SocketStorage.CreateSocketStorage();
|
||||
}
|
||||
|
||||
public void create(string parameters)
|
||||
{
|
||||
string socketKey = JsonHelper.Deserialize<string[]>(parameters)[0];
|
||||
|
||||
ISocketAdapter socketAdapter = new SocketAdapter();
|
||||
socketAdapter.CloseEventHandler = (hasError) => this.CloseEventHandler(socketKey, hasError);
|
||||
socketAdapter.DataConsumer = (data) => this.DataConsumer(socketKey, data);
|
||||
socketAdapter.ErrorHandler = (ex) => this.ErrorHandler(socketKey, ex);
|
||||
|
||||
this.socketStorage.Add(socketKey, socketAdapter);
|
||||
|
||||
this.DispatchCommandResult(new PluginResult(PluginResult.Status.OK));
|
||||
}
|
||||
|
||||
public void registerWPEventDispatcher(string parameters)
|
||||
{
|
||||
this.eventDispatcherCallbackId = this.CurrentCommandCallbackId;
|
||||
PluginResult result = new PluginResult(PluginResult.Status.OK);
|
||||
result.KeepCallback = true;
|
||||
DispatchCommandResult(result, this.eventDispatcherCallbackId);
|
||||
}
|
||||
|
||||
public void connect(string parameters)
|
||||
{
|
||||
string socketKey = JsonHelper.Deserialize<string[]>(parameters)[0];
|
||||
string host = JsonHelper.Deserialize<string[]>(parameters)[1];
|
||||
int port = int.Parse(JsonHelper.Deserialize<string[]>(parameters)[2]);
|
||||
|
||||
ISocketAdapter socket = this.socketStorage.Get(socketKey);
|
||||
ISocketAdapter socketAdapter = new SocketAdapter();
|
||||
socketAdapter.CloseEventHandler = (hasError) => this.CloseEventHandler(socketKey, hasError);
|
||||
socketAdapter.DataConsumer = (data) => this.DataConsumer(socketKey, data);
|
||||
socketAdapter.ErrorHandler = (ex) => this.ErrorHandler(socketKey, ex);
|
||||
|
||||
try
|
||||
{
|
||||
socket.Connect(host, port).Wait();
|
||||
socketAdapter.Connect(host, port).Wait();
|
||||
|
||||
this.socketStorage.Add(socketKey, socketAdapter);
|
||||
|
||||
this.DispatchCommandResult(new PluginResult(PluginResult.Status.OK));
|
||||
}
|
||||
catch (SocketException ex)
|
||||
{
|
||||
this.ErrorHandler(socketKey, ex);
|
||||
this.DispatchCommandResult(new PluginResult(PluginResult.Status.IO_EXCEPTION, ex.Message));
|
||||
socketStorage.Remove(socketKey);
|
||||
}
|
||||
catch (AggregateException ex)
|
||||
{
|
||||
this.ErrorHandler(socketKey, ex.InnerException);
|
||||
this.DispatchCommandResult(new PluginResult(PluginResult.Status.IO_EXCEPTION, ex.InnerException.Message));
|
||||
socketStorage.Remove(socketKey);
|
||||
}
|
||||
}
|
||||
|
||||
public void write(string parameters/*, string socketKey, byte[] data*/)
|
||||
public void write(string parameters)
|
||||
{
|
||||
string socketKey = JsonHelper.Deserialize<string[]>(parameters)[0];
|
||||
string dataJsonArray = JsonHelper.Deserialize<string[]>(parameters)[1];
|
||||
@ -107,6 +87,14 @@ namespace Blocshop.ScoketsForCordova
|
||||
socket.Close();
|
||||
}
|
||||
|
||||
public void registerWPEventDispatcher(string parameters)
|
||||
{
|
||||
this.eventDispatcherCallbackId = this.CurrentCommandCallbackId;
|
||||
PluginResult result = new PluginResult(PluginResult.Status.OK);
|
||||
result.KeepCallback = true;
|
||||
DispatchCommandResult(result, this.eventDispatcherCallbackId);
|
||||
}
|
||||
|
||||
//private void setOptions(CordovaArgs args, CallbackContext callbackContext) throws JSONException {
|
||||
|
||||
// String socketKey = args.getString(0);
|
||||
|
Loading…
Reference in New Issue
Block a user