@@ -66,7 +66,6 @@ public String getName() {
66
66
67
67
@ ReactMethod
68
68
public void connect (final String url , @ Nullable final ReadableArray protocols , @ Nullable final ReadableMap headers , final int id ) {
69
- // ignoring protocols, since OKHttp overrides them.
70
69
OkHttpClient client = new OkHttpClient ();
71
70
72
71
client .setConnectTimeout (10 , TimeUnit .SECONDS );
@@ -99,6 +98,21 @@ public void connect(final String url, @Nullable final ReadableArray protocols, @
99
98
builder .addHeader ("origin" , setDefaultOrigin (url ));
100
99
}
101
100
101
+ if (protocols != null && protocols .size () > 0 ) {
102
+ StringBuilder protocolsValue = new StringBuilder ("" );
103
+ for (int i = 0 ; i < protocols .size (); i ++) {
104
+ String v = protocols .getString (i ).trim ();
105
+ if (!v .isEmpty () && !v .contains ("," )) {
106
+ protocolsValue .append (v );
107
+ protocolsValue .append ("," );
108
+ }
109
+ }
110
+ if (protocolsValue .length () > 0 ) {
111
+ protocolsValue .replace (protocolsValue .length () - 1 , protocolsValue .length (), "" );
112
+ builder .addHeader ("Sec-WebSocket-Protocol" , protocolsValue .toString ());
113
+ }
114
+ }
115
+
102
116
WebSocketCall .create (client , builder .build ()).enqueue (new WebSocketListener () {
103
117
104
118
@ Override
0 commit comments