Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package chat.rocket.reactnative;

import android.os.Build;

import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;

import java.io.IOException;

public class CustomInterceptor implements Interceptor {

public CustomInterceptor() {}

@Override
public Response intercept(Interceptor.Chain chain) throws IOException {
Request originalRequest = chain.request();
Request requestWithUserAgent = originalRequest.newBuilder()
.removeHeader("User-Agent")
.addHeader("User-Agent", "RC-RN Mobile/" + BuildConfig.VERSION_NAME + " (build: " + BuildConfig.VERSION_CODE + "; OS: Android " + Build.VERSION.RELEASE + ")")
.build();

return chain.proceed(requestWithUserAgent);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package chat.rocket.reactnative;

import okhttp3.OkHttpClient;

import com.facebook.react.ReactActivityDelegate;
import com.facebook.react.ReactRootView;
import com.facebook.react.modules.network.OkHttpClientProvider;
import com.swmansion.gesturehandler.react.RNGestureHandlerEnabledRootView;
import android.os.Bundle;
import com.facebook.react.ReactFragmentActivity;
Expand All @@ -15,6 +18,8 @@ public class MainActivity extends ReactFragmentActivity {
protected void onCreate(Bundle savedInstanceState) {
SplashScreen.show(this);
super.onCreate(null);

OkHttpClientProvider.setOkHttpClientFactory(new UserAgentClientFactory());
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package chat.rocket.reactnative;

import android.os.Build;
import com.facebook.react.modules.network.OkHttpClientFactory;
import com.facebook.react.modules.network.ReactCookieJarContainer;

import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
import okhttp3.Response;

public class UserAgentClientFactory implements OkHttpClientFactory {
@Override
public OkHttpClient createNewNetworkModuleClient() {
return new OkHttpClient.Builder().cookieJar(new ReactCookieJarContainer()).addNetworkInterceptor(new CustomInterceptor()).build();
}
}
52 changes: 52 additions & 0 deletions patches/react-native+0.61.1.patch
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,22 @@ index e72e943..ec0a0ba 100644
+}
+
@end
diff --git a/node_modules/react-native/Libraries/Network/RCTNetworking.mm b/node_modules/react-native/Libraries/Network/RCTNetworking.mm
index 193e3c5..e4e57e6 100644
--- a/node_modules/react-native/Libraries/Network/RCTNetworking.mm
+++ b/node_modules/react-native/Libraries/Network/RCTNetworking.mm
@@ -287,6 +287,11 @@ - (RCTURLRequestCancellationBlock)buildRequest:(NSDictionary<NSString *, id> *)q
}
}];

+ NSString *osVersion = [[UIDevice currentDevice] systemVersion];
+ NSString *version = [[NSBundle mainBundle] objectForInfoDictionaryKey: @"CFBundleShortVersionString"];
+ NSString *code = [[NSBundle mainBundle] objectForInfoDictionaryKey: (NSString *)kCFBundleVersionKey];
+ [request addValue:[NSString stringWithFormat:@"RC-RN Mobile/%@ (build: %@; OS: iOS %@)", version, code, osVersion] forHTTPHeaderField:@"User-Agent"];
+
request.timeoutInterval = [RCTConvert NSTimeInterval:query[@"timeout"]];
NSDictionary<NSString *, id> *data = [RCTConvert NSDictionary:RCTNilIfNull(query[@"data"])];
NSString *trackingName = data[@"trackingName"];
diff --git a/node_modules/react-native/Libraries/WebSocket/RCTSRWebSocket.m b/node_modules/react-native/Libraries/WebSocket/RCTSRWebSocket.m
index a134d2e..a88c099 100644
--- a/node_modules/react-native/Libraries/WebSocket/RCTSRWebSocket.m
Expand Down Expand Up @@ -141,6 +157,22 @@ index a134d2e..a88c099 100644
[self _sendFrameWithOpcode:RCTSROpCodeConnectionClose data:payload];
});
}
diff --git a/node_modules/react-native/Libraries/WebSocket/RCTWebSocketModule.m b/node_modules/react-native/Libraries/WebSocket/RCTWebSocketModule.m
index d9387c4..3995989 100644
--- a/node_modules/react-native/Libraries/WebSocket/RCTWebSocketModule.m
+++ b/node_modules/react-native/Libraries/WebSocket/RCTWebSocketModule.m
@@ -81,6 +81,11 @@ - (void)invalidate
[request addValue:[RCTConvert NSString:value] forHTTPHeaderField:key];
}];

+ NSString *osVersion = [[UIDevice currentDevice] systemVersion];
+ NSString *version = [[NSBundle mainBundle] objectForInfoDictionaryKey: @"CFBundleShortVersionString"];
+ NSString *code = [[NSBundle mainBundle] objectForInfoDictionaryKey: (NSString *)kCFBundleVersionKey];
+ [request addValue:[NSString stringWithFormat:@"RC-RN Mobile/%@ (build: %@; OS: iOS %@)", version, code, osVersion] forHTTPHeaderField:@"User-Agent"];
+
RCTSRWebSocket *webSocket = [[RCTSRWebSocket alloc] initWithURLRequest:request protocols:protocols];
[webSocket setDelegateDispatchQueue:_methodQueue];
webSocket.delegate = self;
diff --git a/node_modules/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/systeminfo/AndroidInfoModule.java b/node_modules/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/systeminfo/AndroidInfoModule.java
index ef2ae93..2795802 100644
--- a/node_modules/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/systeminfo/AndroidInfoModule.java
Expand All @@ -154,3 +186,23 @@ index ef2ae93..2795802 100644
return true;
} catch (ClassNotFoundException ignored) {
return false;
diff --git a/node_modules/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/websocket/WebSocketModule.java b/node_modules/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/websocket/WebSocketModule.java
index bfc83f6..4507ccf 100644
--- a/node_modules/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/websocket/WebSocketModule.java
+++ b/node_modules/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/websocket/WebSocketModule.java
@@ -6,6 +6,7 @@
*/
package com.facebook.react.modules.websocket;

+import android.os.Build;
import androidx.annotation.Nullable;
import com.facebook.common.logging.FLog;
import com.facebook.react.bridge.Arguments;
@@ -86,6 +87,7 @@ public final class WebSocketModule extends ReactContextBaseJavaModule {
final int id) {
OkHttpClient client =
new OkHttpClient.Builder()
+ .header("User-Agent", "RC-RN Mobile/" + BuildConfig.VERSION_NAME + " (build: " + BuildConfig.VERSION_CODE + "; OS: Android " + Build.VERSION.RELEASE + ")")
.connectTimeout(10, TimeUnit.SECONDS)
.writeTimeout(10, TimeUnit.SECONDS)
.readTimeout(0, TimeUnit.MINUTES) // Disable timeouts for read