commit
c762ba231b
|
@ -205,7 +205,18 @@ UdpSocket.prototype.address = function() {
|
|||
}
|
||||
|
||||
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) {
|
||||
|
|
|
@ -82,4 +82,9 @@ typedef enum RCTUDPError RCTUDPError;
|
|||
*/
|
||||
- (void)close;
|
||||
|
||||
/**
|
||||
* Enable broadcast
|
||||
*/
|
||||
- (BOOL)setBroadcast:(BOOL) flag error:(NSError **) error;
|
||||
|
||||
@end
|
||||
|
|
|
@ -126,6 +126,12 @@ remoteAddress:(NSString *)address
|
|||
[_udpSocket close];
|
||||
}
|
||||
|
||||
- (BOOL) setBroadcast:(BOOL)flag
|
||||
error:(NSError **)error
|
||||
{
|
||||
return [_udpSocket enableBroadcast:flag error:error];
|
||||
}
|
||||
|
||||
- (void)udpSocket:(GCDAsyncUdpSocket *)sock didReceiveData:(NSData *)data
|
||||
fromAddress:(NSData *)address
|
||||
withFilterContext:(id)filterContext
|
||||
|
|
15
UdpSockets.m
15
UdpSockets.m
|
@ -82,6 +82,21 @@ RCT_EXPORT_METHOD(close:(NSString*)cId
|
|||
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
|
||||
{
|
||||
NSString *clientID = [[_clients allKeysForObject:client] objectAtIndex:0];
|
||||
|
|
Loading…
Reference in New Issue