drop unimplemented functions
This commit is contained in:
parent
b7a63b8874
commit
31f7d5b9aa
49
TcpSocket.js
49
TcpSocket.js
|
@ -144,34 +144,6 @@ TcpSocket.prototype.setTimeout = function(msecs: number, callback: () => void) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
TcpSocket.prototype.setNoDelay = function(noDelay) {
|
|
||||||
// nothing yet
|
|
||||||
};
|
|
||||||
|
|
||||||
TcpSocket.prototype.setEncoding = function(encoding) {
|
|
||||||
// nothing yet
|
|
||||||
};
|
|
||||||
|
|
||||||
TcpSocket.prototype.setKeepAlive = function(enable, initialDelay) {
|
|
||||||
// nothing yet
|
|
||||||
};
|
|
||||||
|
|
||||||
TcpSocket.prototype.pause = function() {
|
|
||||||
// nothing yet
|
|
||||||
};
|
|
||||||
|
|
||||||
TcpSocket.prototype.resume = function() {
|
|
||||||
// nothing yet
|
|
||||||
};
|
|
||||||
|
|
||||||
TcpSocket.prototype.ref = function() {
|
|
||||||
// nothing yet
|
|
||||||
};
|
|
||||||
|
|
||||||
TcpSocket.prototype.unref = function() {
|
|
||||||
// nothing yet
|
|
||||||
};
|
|
||||||
|
|
||||||
TcpSocket.prototype.address = function() : { port: number, address: string, family: string } {
|
TcpSocket.prototype.address = function() : { port: number, address: string, family: string } {
|
||||||
return { port: this._port,
|
return { port: this._port,
|
||||||
address: this._address,
|
address: this._address,
|
||||||
|
@ -231,9 +203,8 @@ TcpSocket.prototype._onEvent = function(info: { event: string, data: any }) {
|
||||||
this.emit(info.event, info.data);
|
this.emit(info.event, info.data);
|
||||||
};
|
};
|
||||||
|
|
||||||
TcpSocket.prototype.write = function(buffer, encoding, callback) {
|
TcpSocket.prototype.write = function(buffer: any, callback: ?(err: ?Error) => void) : boolean {
|
||||||
var self = this;
|
var self = this;
|
||||||
var encoded = false;
|
|
||||||
|
|
||||||
if (this._state === STATE.DISCONNECTED) {
|
if (this._state === STATE.DISCONNECTED) {
|
||||||
throw new Error('Socket is not connected.');
|
throw new Error('Socket is not connected.');
|
||||||
|
@ -241,26 +212,20 @@ TcpSocket.prototype.write = function(buffer, encoding, callback) {
|
||||||
// we're ok, GCDAsyncSocket handles queueing internally
|
// we're ok, GCDAsyncSocket handles queueing internally
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof encoding === 'function') {
|
var cb = callback || noop;
|
||||||
callback = encoding;
|
|
||||||
encoding = null;
|
|
||||||
}
|
|
||||||
callback = callback || noop;
|
|
||||||
var str;
|
var str;
|
||||||
if (typeof buffer === 'string') {
|
if (typeof buffer === 'string') {
|
||||||
console.warn('socket.WRITE(): encoding as base64');
|
self._debug('socket.WRITE(): encoding as base64');
|
||||||
str = Base64Str.encode(buffer);
|
str = Base64Str.encode(buffer);
|
||||||
} else if (typeof Buffer !== 'undefined' && global.Buffer.isBuffer(buffer)) {
|
} else if (typeof Buffer !== 'undefined' && global.Buffer.isBuffer(buffer)) {
|
||||||
encoded = true;
|
|
||||||
str = buffer.toString('base64');
|
str = buffer.toString('base64');
|
||||||
} else if (buffer instanceof Uint8Array || Array.isArray(buffer)) {
|
} else if (buffer instanceof Uint8Array || Array.isArray(buffer)) {
|
||||||
encoded = true;
|
|
||||||
str = base64.fromByteArray(buffer);
|
str = base64.fromByteArray(buffer);
|
||||||
} else {
|
} else {
|
||||||
throw new Error('invalid message format');
|
throw new Error('invalid message format');
|
||||||
}
|
}
|
||||||
|
|
||||||
Sockets.write(this._id, str, encoded, function(err) {
|
Sockets.write(this._id, str, function(err) {
|
||||||
if (self._timeout) {
|
if (self._timeout) {
|
||||||
clearTimeout(self._timeout);
|
clearTimeout(self._timeout);
|
||||||
self._timeout = null;
|
self._timeout = null;
|
||||||
|
@ -269,11 +234,13 @@ TcpSocket.prototype.write = function(buffer, encoding, callback) {
|
||||||
err = normalizeError(err);
|
err = normalizeError(err);
|
||||||
if (err) {
|
if (err) {
|
||||||
self._debug('write failed', err);
|
self._debug('write failed', err);
|
||||||
return callback(err);
|
return cb(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
callback();
|
cb();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
function normalizeError(err) {
|
function normalizeError(err) {
|
||||||
|
|
|
@ -64,7 +64,6 @@ RCT_EXPORT_METHOD(connect:(nonnull NSNumber*)cId
|
||||||
|
|
||||||
RCT_EXPORT_METHOD(write:(nonnull NSNumber*)cId
|
RCT_EXPORT_METHOD(write:(nonnull NSNumber*)cId
|
||||||
string:(NSString *)base64String
|
string:(NSString *)base64String
|
||||||
encoded:(BOOL)encoded
|
|
||||||
callback:(RCTResponseSenderBlock)callback) {
|
callback:(RCTResponseSenderBlock)callback) {
|
||||||
TcpSocketClient* client = [self findClient:cId callback:callback];
|
TcpSocketClient* client = [self findClient:cId callback:callback];
|
||||||
if (!client) return;
|
if (!client) return;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
Pod::Spec.new do |s|
|
Pod::Spec.new do |s|
|
||||||
s.name = 'react-native-tcp'
|
s.name = 'react-native-tcp'
|
||||||
s.version = '0.1.3'
|
s.version = '0.1.1'
|
||||||
s.summary = 'node\'s net API in React Native.'
|
s.summary = 'node\'s net API in React Native.'
|
||||||
s.description = <<-DESC
|
s.description = <<-DESC
|
||||||
Enables accessing tcp sockets in React Native.
|
Enables accessing tcp sockets in React Native.
|
||||||
|
|
Loading…
Reference in New Issue