commit
c762ba231b
|
@ -205,7 +205,18 @@ UdpSocket.prototype.address = function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
UdpSocket.prototype.setBroadcast = function(flag) {
|
UdpSocket.prototype.setBroadcast = function(flag) {
|
||||||
// nothing yet
|
var self = this
|
||||||
|
|
||||||
|
if (this._state !== STATE.BOUND) {
|
||||||
|
throw new Error('you must bind before setBroadcast()')
|
||||||
|
}
|
||||||
|
|
||||||
|
Sockets.setBroadcast(this._id, flag, function(err) {
|
||||||
|
if (err) {
|
||||||
|
self._debug('failed to set broadcast', err)
|
||||||
|
return self.emit('error', err)
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
UdpSocket.prototype.setTTL = function(ttl) {
|
UdpSocket.prototype.setTTL = function(ttl) {
|
||||||
|
|
|
@ -82,4 +82,9 @@ typedef enum RCTUDPError RCTUDPError;
|
||||||
*/
|
*/
|
||||||
- (void)close;
|
- (void)close;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enable broadcast
|
||||||
|
*/
|
||||||
|
- (BOOL)setBroadcast:(BOOL) flag error:(NSError **) error;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -126,6 +126,12 @@ remoteAddress:(NSString *)address
|
||||||
[_udpSocket close];
|
[_udpSocket close];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (BOOL) setBroadcast:(BOOL)flag
|
||||||
|
error:(NSError **)error
|
||||||
|
{
|
||||||
|
return [_udpSocket enableBroadcast:flag error:error];
|
||||||
|
}
|
||||||
|
|
||||||
- (void)udpSocket:(GCDAsyncUdpSocket *)sock didReceiveData:(NSData *)data
|
- (void)udpSocket:(GCDAsyncUdpSocket *)sock didReceiveData:(NSData *)data
|
||||||
fromAddress:(NSData *)address
|
fromAddress:(NSData *)address
|
||||||
withFilterContext:(id)filterContext
|
withFilterContext:(id)filterContext
|
||||||
|
|
15
UdpSockets.m
15
UdpSockets.m
|
@ -82,6 +82,21 @@ RCT_EXPORT_METHOD(close:(NSString*)cId
|
||||||
if (callback) callback(@[]);
|
if (callback) callback(@[]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RCT_EXPORT_METHOD(setBroadcast:(NSString*)cId
|
||||||
|
flag:(BOOL)flag
|
||||||
|
callback:(RCTResponseSenderBlock)callback) {
|
||||||
|
UdpSocketClient* client = [self findClient:cId callback:callback];
|
||||||
|
if (!client) return;
|
||||||
|
|
||||||
|
NSError *error = nil;
|
||||||
|
if (![client setBroadcast:flag error:&error])
|
||||||
|
{
|
||||||
|
callback(@[error]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
callback(@[[NSNull null]]);
|
||||||
|
}
|
||||||
|
|
||||||
- (void) onData:(UdpSocketClient*) client data:(NSData *)data host:(NSString *)host port:(uint16_t)port
|
- (void) onData:(UdpSocketClient*) client data:(NSData *)data host:(NSString *)host port:(uint16_t)port
|
||||||
{
|
{
|
||||||
NSString *clientID = [[_clients allKeysForObject:client] objectAtIndex:0];
|
NSString *clientID = [[_clients allKeysForObject:client] objectAtIndex:0];
|
||||||
|
|
Loading…
Reference in New Issue