Skip to content

Commit

Permalink
Merge pull request #23 from Alwinator/next
Browse files Browse the repository at this point in the history
Fixes Android build issues
  • Loading branch information
Alwinator committed Aug 31, 2023
2 parents 2f534ad + 72f1806 commit 0d57ebf
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 65 deletions.
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
16 changes: 9 additions & 7 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
buildscript {
repositories {
jcenter()
mavenCentral()
}

dependencies {
classpath 'com.android.tools.build:gradle:2.2.0'
classpath 'com.android.tools.build:gradle:2.3.0'
}
}

allprojects {
repositories {
jcenter()
mavenCentral()
}
}

apply plugin: 'com.android.library'

android {
compileSdkVersion 26
buildToolsVersion "26.0.2"
compileSdkVersion 33
buildToolsVersion "33.0.2"
namespace "at.alwinschuster.HttpServer"

defaultConfig {
minSdkVersion 16
targetSdkVersion 22
minSdkVersion 21
targetSdkVersion 33
versionCode 2
versionName "1.1"
ndk {
Expand Down
5 changes: 1 addition & 4 deletions android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="at.alwinschuster.HttpServer">

<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.INTERNET"/>

</manifest>
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
package at.alwinschuster.HttpServer;

import fi.iki.elonen.NanoHTTPD;
import fi.iki.elonen.NanoHTTPD.Response;
import fi.iki.elonen.NanoHTTPD.Response.Status;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.modules.core.DeviceEventManagerModule;

import java.util.Map;
import java.util.Set;
import java.util.HashMap;
import java.util.Random;

Expand Down
7 changes: 4 additions & 3 deletions httpServer.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
'use strict';

import {DeviceEventEmitter, NativeModules} from 'react-native';
import {NativeEventEmitter, NativeModules} from 'react-native';
const Server = NativeModules.HttpServer;
const ServerEventEmitter = new NativeEventEmitter(Server);

module.exports = {
start: function (port, serviceName, callback) {
Expand All @@ -10,12 +11,12 @@ module.exports = {
}

Server.start(port, serviceName);
DeviceEventEmitter.addListener('httpServerResponseReceived', callback);
ServerEventEmitter.addListener('httpServerResponseReceived', callback);
},

stop: () => {
Server.stop();
DeviceEventEmitter.removeAllListeners('httpServerResponseReceived');
ServerEventEmitter.removeAllListeners('httpServerResponseReceived');
},

respond: (requestId, code, type, body) => Server.respond(requestId, code, type, body)
Expand Down
26 changes: 18 additions & 8 deletions ios/RCTHttpServer.m
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@

#import "RCTHttpServer.h"
#import "React/RCTBridge.h"
#import "React/RCTLog.h"
#import "React/RCTEventDispatcher.h"
#import <React/RCTBridge.h>
#import <React/RCTLog.h>
#import <React/RCTEventEmitter.h>

#import "GCDWebServer.h"
#import "GCDWebServerDataResponse.h"
#import "GCDWebServerDataRequest.h"
#import "GCDWebServerPrivate.h"
#include <stdlib.h>

@interface RCTHttpServer : NSObject <RCTBridgeModule> {
@interface RCTHttpServer : RCTEventEmitter <RCTBridgeModule> {
GCDWebServer* _webServer;
NSMutableDictionary* _completionBlocks;
}
Expand All @@ -24,6 +24,16 @@ @implementation RCTHttpServer

RCT_EXPORT_MODULE();

- (void)invalidate {
[self stop];
[super invalidate];
}

- (NSArray<NSString *> *)supportedEvents {
return @[
@"httpServerResponseReceived"
];
}

- (void)initResponseReceivedFor:(GCDWebServer *)server forType:(NSString*)type {
[server addDefaultHandlerForMethod:type
Expand All @@ -35,25 +45,25 @@ - (void)initResponseReceivedFor:(GCDWebServer *)server forType:(NSString*)type {
NSString *requestId = [NSString stringWithFormat:@"%lld:%d", milliseconds, r];

@synchronized (self) {
[_completionBlocks setObject:completionBlock forKey:requestId];
[self->_completionBlocks setObject:completionBlock forKey:requestId];
}

@try {
if ([GCDWebServerTruncateHeaderValue(request.contentType) isEqualToString:@"application/json"]) {
GCDWebServerDataRequest* dataRequest = (GCDWebServerDataRequest*)request;
[self.bridge.eventDispatcher sendAppEventWithName:@"httpServerResponseReceived"
[self sendEventWithName:@"httpServerResponseReceived"
body:@{@"requestId": requestId,
@"postData": dataRequest.jsonObject,
@"type": type,
@"url": request.URL.relativeString}];
} else {
[self.bridge.eventDispatcher sendAppEventWithName:@"httpServerResponseReceived"
[self sendEventWithName:@"httpServerResponseReceived"
body:@{@"requestId": requestId,
@"type": type,
@"url": request.URL.relativeString}];
}
} @catch (NSException *exception) {
[self.bridge.eventDispatcher sendAppEventWithName:@"httpServerResponseReceived"
[self sendEventWithName:@"httpServerResponseReceived"
body:@{@"requestId": requestId,
@"type": type,
@"url": request.URL.relativeString}];
Expand Down
82 changes: 42 additions & 40 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,41 +1,43 @@
{
"name": "react-native-http-bridge-refurbished",
"version": "0.0.0-development",
"description": "A simple HTTP debug server for React Native apps",
"main": "index.js",
"types": "index.d.ts",
"repository": {
"type": "git",
"url": "https://github.com/Alwinator/react-native-http-bridge-refurbished.git"
},
"keywords": [
"react-component",
"react-native",
"nanohttpd",
"gcdhttpserver",
"http",
"server",
"bridge"
],
"author": "Alwin Schuster",
"license": "MIT",
"bugs": {
"url": "https://github.com/Alwinator/react-native-http-bridge-refurbished/issues"
},
"homepage": "https://github.com/Alwinator/react-native-http-bridge-refurbished#readme",
"scripts": {
"semantic-release": "semantic-release"
},
"dependencies": {
"react-native": "^0.72.3"
},
"devDependencies": {
"semantic-release": "^21.0.1"
},
"release": {
"branches": [
"main",
"next"
]
}
}
"name": "react-native-http-bridge-refurbished",
"version": "0.0.0-development",
"description": "A simple HTTP debug server for React Native apps",
"main": "index.js",
"types": "index.d.ts",
"repository": {
"type": "git",
"url": "https://github.com/Alwinator/react-native-http-bridge-refurbished.git",
"directory": "packages/react-native-http-bridge-refurbished"
},
"keywords": [
"react-component",
"react-native",
"nanohttpd",
"gcdhttpserver",
"http",
"server",
"bridge",
"webserver"
],
"author": "Alwin Schuster",
"license": "MIT",
"bugs": {
"url": "https://github.com/Alwinator/react-native-http-bridge-refurbished/issues"
},
"homepage": "https://github.com/Alwinator/react-native-http-bridge-refurbished#readme",
"scripts": {
"semantic-release": "semantic-release"
},
"dependencies": {
"react-native": "^0.71.3"
},
"devDependencies": {
"semantic-release": "^21.0.1"
},
"release": {
"branches": [
"main",
"next"
]
}
}

0 comments on commit 0d57ebf

Please sign in to comment.