From ad436b196dbbf2aaf13aa2ca4bede5c8bd584424 Mon Sep 17 00:00:00 2001 From: Glenn Engel Date: Wed, 16 Jan 2019 18:39:56 -0800 Subject: [PATCH 1/8] Issue-63: Update hostname regex to allow modern hostnames (#77) --- UdpSocket.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UdpSocket.js b/UdpSocket.js index 9d609c92..400acdda 100644 --- a/UdpSocket.js +++ b/UdpSocket.js @@ -23,7 +23,7 @@ var Sockets = NativeModules.UdpSockets var base64 = require('base64-js') var ipRegex = require('ip-regex') // RFC 952 hostname format -var hostnameRegex = /^(([a-zA-Z]|[a-zA-Z][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z]|[A-Za-z][A-Za-z0-9\-]*[A-Za-z0-9])$/; +var hostnameRegex = /^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$/; var noop = function () {} var instances = 0 var STATE = { From 39cb2e47af771461ae6f01a838be0faa38fa3866 Mon Sep 17 00:00:00 2001 From: Mark Vayngrib Date: Fri, 1 Feb 2019 13:16:31 -0500 Subject: [PATCH 2/8] fix: #79 --- android/build.gradle | 17 ++++++++++++----- .../java/com/tradle/react/UdpSocketsModule.java | 6 ------ 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/android/build.gradle b/android/build.gradle index 447d6751..1a8d75f9 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -1,12 +1,17 @@ apply plugin: 'com.android.library' +def DEFAULT_COMPILE_SDK_VERSION = 28 +def DEFAULT_BUILD_TOOLS_VERSION = "28.0.3" +def DEFAULT_TARGET_SDK_VERSION = 27 +def DEFAULT_SUPPORT_LIB_VERSION = "28.0.0" + android { - compileSdkVersion 23 - buildToolsVersion "23.0.1" + compileSdkVersion rootProject.hasProperty('compileSdkVersion') ? rootProject.compileSdkVersion : DEFAULT_COMPILE_SDK_VERSION + buildToolsVersion rootProject.hasProperty('buildToolsVersion') ? rootProject.buildToolsVersion : DEFAULT_BUILD_TOOLS_VERSION defaultConfig { minSdkVersion 16 - targetSdkVersion 22 + targetSdkVersion rootProject.hasProperty('targetSdkVersion') ? rootProject.targetSdkVersion : DEFAULT_TARGET_SDK_VERSION versionCode 1 versionName "0.2.0" } @@ -25,7 +30,9 @@ android { } dependencies { + def supportLibVersion = project.hasProperty('supportLibVersion') ? project.supportLibVersion : DEFAULT_SUPPORT_LIB_VERSION + compile fileTree(dir: 'libs', include: ['*.jar']) - compile 'com.android.support:appcompat-v7:23.0.1' - compile 'com.facebook.react:react-native:0.11.+' + compile "com.android.support:appcompat-v7:$supportLibVersion" + compile 'com.facebook.react:react-native:+' } diff --git a/android/src/main/java/com/tradle/react/UdpSocketsModule.java b/android/src/main/java/com/tradle/react/UdpSocketsModule.java index d6f42be3..d323b479 100644 --- a/android/src/main/java/com/tradle/react/UdpSocketsModule.java +++ b/android/src/main/java/com/tradle/react/UdpSocketsModule.java @@ -8,7 +8,6 @@ package com.tradle.react; import com.facebook.react.ReactPackage; -import com.facebook.react.bridge.JavaScriptModule; import com.facebook.react.bridge.NativeModule; import com.facebook.react.bridge.ReactApplicationContext; import com.facebook.react.uimanager.ViewManager; @@ -30,11 +29,6 @@ public List createNativeModules( return modules; } - @Override - public List> createJSModules() { - return Collections.emptyList(); - } - @Override public List createViewManagers( ReactApplicationContext reactContext) { From 45dbdaeddaa5e1e2b70ad7cca9091cb0b04ff8de Mon Sep 17 00:00:00 2001 From: Mark Vayngrib Date: Fri, 1 Feb 2019 14:48:17 -0500 Subject: [PATCH 3/8] 2.4.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 3c5dbae8..d3b73e60 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-udp", - "version": "2.3.1", + "version": "2.4.0", "description": "node's dgram API for react-native", "main": "UdpSockets.js", "scripts": { From 789e81ecc439cf3faf610d0825dbb330431db6e7 Mon Sep 17 00:00:00 2001 From: Damnjan Lukovic Date: Fri, 22 Feb 2019 14:58:19 +0100 Subject: [PATCH 4/8] Allow callback to be passed as the only prop to bind (#80) * add normalizeBindOptions, test --- UdpSocket.js | 8 +++----- normalizeBindOptions.js | 21 +++++++++++++++++++++ package.json | 6 +++++- test/normalizeBindOptions.test.js | 29 +++++++++++++++++++++++++++++ 4 files changed, 58 insertions(+), 6 deletions(-) create mode 100644 normalizeBindOptions.js create mode 100644 test/normalizeBindOptions.test.js diff --git a/UdpSocket.js b/UdpSocket.js index 400acdda..f21116a8 100644 --- a/UdpSocket.js +++ b/UdpSocket.js @@ -22,6 +22,7 @@ var { var Sockets = NativeModules.UdpSockets var base64 = require('base64-js') var ipRegex = require('ip-regex') +var normalizeBindOptions = require('./normalizeBindOptions') // RFC 952 hostname format var hostnameRegex = /^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$/; var noop = function () {} @@ -73,15 +74,12 @@ UdpSocket.prototype._debug = function() { } } -UdpSocket.prototype.bind = function(port, address, callback) { +UdpSocket.prototype.bind = function(...args) { var self = this if (this._state !== STATE.UNBOUND) throw new Error('Socket is already bound') - if (typeof address === 'function') { - callback = address - address = undefined - } + let { port, address, callback } = normalizeBindOptions(...args) if (!address) address = '0.0.0.0' diff --git a/normalizeBindOptions.js b/normalizeBindOptions.js new file mode 100644 index 00000000..33e67787 --- /dev/null +++ b/normalizeBindOptions.js @@ -0,0 +1,21 @@ +module.exports = function normalizeBindOptions(...args) { + const [arg1, arg2] = args + const lastArg = args[args.length - 1] + let options = {} + + if (typeof arg1 === 'object') { + options = arg1 + } else if (typeof arg1 === 'number') { + options.port = arg1 + } else if (typeof arg1 === 'string') { + options.address = arg1 + } + if (typeof arg2 === 'string') { + options.address = arg2 + } + if (typeof lastArg === 'function') { + options.callback = lastArg + } + + return options +} diff --git a/package.json b/package.json index d3b73e60..401a74ba 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,8 @@ "description": "node's dgram API for react-native", "main": "UdpSockets.js", "scripts": { - "start": "exit 1" + "start": "exit 1", + "test": "mocha" }, "browser": { "dgram": "./UdpSockets.js" @@ -38,5 +39,8 @@ "inherits": "^2.0.1", "ip-regex": "^1.0.3", "util": "^0.10.3" + }, + "devDependencies": { + "mocha": "^6.0.1" } } diff --git a/test/normalizeBindOptions.test.js b/test/normalizeBindOptions.test.js new file mode 100644 index 00000000..1c68022c --- /dev/null +++ b/test/normalizeBindOptions.test.js @@ -0,0 +1,29 @@ +const assert = require('assert') +const normalizeBindOptions = require('../normalizeBindOptions') +const prettify = obj => JSON.stringify(obj, null, 2) + +describe('normalizeBindOptions', () => { + const args = [ + { name: 'port', value: 1234 }, + { name: 'address', value: '1.2.3.4' }, + { name: 'callback', value: () => {} }, + ] + + it('should support all combinations of arguments', () => { + // check every combination of arguments (retaining order) + // use a bit mask to decide whether to keep an argument + for (let i = 0, numCombinations = Math.pow(2, args.length); i < numCombinations; i++) { + const usedArgs = args.filter((arg, bit) => (i + 1) & 1 << bit) + const expected = {} + usedArgs.forEach(arg => expected[arg.name] = arg.value) + const usedArgsValues = usedArgs.map(arg => arg.value) + + const result = normalizeBindOptions(...usedArgsValues) + try { + assert.deepEqual(result, expected) + } catch (err) { + throw new Error(`for args: ${prettify(usedArgsValues)}\nexpected: ${prettify(expected)}\ngot ${prettify(result)}`) + } + } + }) +}) From 02c31de453249de6c276c11bfe3a2ff67e3df042 Mon Sep 17 00:00:00 2001 From: Mark Vayngrib Date: Fri, 22 Feb 2019 08:58:55 -0500 Subject: [PATCH 5/8] test: alt opts to bind() --- test/normalizeBindOptions.test.js | 38 ++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/test/normalizeBindOptions.test.js b/test/normalizeBindOptions.test.js index 1c68022c..2053d9f1 100644 --- a/test/normalizeBindOptions.test.js +++ b/test/normalizeBindOptions.test.js @@ -3,13 +3,14 @@ const normalizeBindOptions = require('../normalizeBindOptions') const prettify = obj => JSON.stringify(obj, null, 2) describe('normalizeBindOptions', () => { - const args = [ - { name: 'port', value: 1234 }, - { name: 'address', value: '1.2.3.4' }, - { name: 'callback', value: () => {} }, - ] - it('should support all combinations of arguments', () => { + it('should support all combinations of arguments for [port], [address], [callback]', () => { + const args = [ + { name: 'port', value: 1234 }, + { name: 'address', value: '1.2.3.4' }, + { name: 'callback', value: () => {} }, + ] + // check every combination of arguments (retaining order) // use a bit mask to decide whether to keep an argument for (let i = 0, numCombinations = Math.pow(2, args.length); i < numCombinations; i++) { @@ -26,4 +27,29 @@ describe('normalizeBindOptions', () => { } } }) + + it('should support all combinations of arguments for [options], [callback]', () => { + const callback = () => {} + const inOut = [ + [ + [{ port: 123 }, callback], { port: 123, callback } + ], + [ + [{ port: 123 }], { port: 123 } + ], + [ + [callback], { callback } + ], + ] + + for (const [args, expected] of inOut) { + let result + try { + result = normalizeBindOptions(...args) + assert.deepEqual(result, expected) + } catch (err) { + throw new Error(`for args: ${prettify(args)}\nexpected: ${prettify(expected)}\ngot ${prettify(result)}`) + } + } + }) }) From 5216ecea7ad03ca66bdbaf00fba82b9cae71de1f Mon Sep 17 00:00:00 2001 From: Mark Vayngrib Date: Fri, 22 Feb 2019 09:00:31 -0500 Subject: [PATCH 6/8] 2.5.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 401a74ba..a28d0b89 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-udp", - "version": "2.4.0", + "version": "2.5.0", "description": "node's dgram API for react-native", "main": "UdpSockets.js", "scripts": { From ef81627c8d5efcdbdb1440c14432dfac0ae273d4 Mon Sep 17 00:00:00 2001 From: Mark Aron Szulyovszky Date: Wed, 20 Dec 2017 19:45:43 +0000 Subject: [PATCH 7/8] Added podspec --- react-native-udp.podspec | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 react-native-udp.podspec diff --git a/react-native-udp.podspec b/react-native-udp.podspec new file mode 100644 index 00000000..85004bdf --- /dev/null +++ b/react-native-udp.podspec @@ -0,0 +1,16 @@ +require 'json' +package_json = JSON.parse(File.read('package.json')) + +Pod::Spec.new do |s| + + s.name = package_json["name"] + s.version = package_json["version"] + s.summary = package_json["description"] + s.homepage = package_json["homepage"] + s.license = package_json["license"] + s.author = { package_json["author"] => package_json["author"] } + s.platform = :ios, "7.0" + s.source = { :git => package_json["repository"]["url"].gsub(/(http.*)/).first, :tag => "v#{s.version}" } + s.source_files = 'ios/**/*.{h,m}' + +end From 9970884d6eee4a10609b1b47731204f801dfca85 Mon Sep 17 00:00:00 2001 From: Mark Vayngrib Date: Tue, 26 Mar 2019 08:00:08 -0400 Subject: [PATCH 8/8] 2.5.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a28d0b89..57999eab 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-udp", - "version": "2.5.0", + "version": "2.5.1", "description": "node's dgram API for react-native", "main": "UdpSockets.js", "scripts": {