Skip to content
Merged
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
17 changes: 17 additions & 0 deletions Split.podspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require "json"

package = JSON.parse(File.read(File.join(__dir__, "package.json")))

Pod::Spec.new do |s|
s.name = "Split"
s.module_name = "Split"
s.summary = package["description"]
s.version = package["version"]
s.author = package["author"]
s.license = package["license"]
s.homepage = package["homepage"]
s.platform = :ios, "9.0"
s.source = { :git => "https://github.com/splitio/react-native-client.git", :tag => "v#{s.version}" }
s.source_files = "ios/**/*.{h,m}"
s.dependency "React"
end
20 changes: 20 additions & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
def safeExtGet(name, fallback) {
rootProject.ext.has(name) ? rootProject.ext.get(name) : fallback
}

apply plugin: "com.android.library"

android {
compileSdkVersion safeExtGet("compileSdkVersion", 28)

defaultConfig {
minSdkVersion safeExtGet("minSdkVersion", 16)
targetSdkVersion safeExtGet("targetSdkVersion", 28)
versionCode 1
versionName "1.0"
}
}

dependencies {
implementation "com.facebook.react:react-native:+"
}
4 changes: 4 additions & 0 deletions android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.github.jonnybgod.RNEventSource">
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
package com.github.jonnybgod.RNEventSource;

import java.io.IOException;

import com.facebook.common.logging.FLog;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.common.ReactConstants;
import com.facebook.react.modules.core.DeviceEventManagerModule;

import java.net.URI;
import java.net.URL;

import org.kaazing.net.sse.SseEventReader;
import org.kaazing.net.sse.SseEventSource;
import org.kaazing.net.sse.SseEventSourceFactory;
import org.kaazing.net.sse.SseEventType;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;

public class RNEventSourceModule extends ReactContextBaseJavaModule {

private Map<Integer, SseEventSource> mEventSourceConnections = new HashMap<>();
private Map<Integer, Thread> mEventReaderThreads = new HashMap<>();

private SseEventSourceFactory factory = SseEventSourceFactory.createEventSourceFactory();
private ReactContext mReactContext;

public RNEventSourceModule(ReactApplicationContext context) {
super(context);
mReactContext = context;
}

private void sendEvent(String eventName, WritableMap params) {
mReactContext
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
.emit(eventName, params);
}

@Override
public String getName() {
return "RNEventSource";
}

@ReactMethod
public void connect(final String url, final int id) {
try {

final SseEventSource source = factory.createEventSource(new URI(url));

source.connect();

mEventSourceConnections.put(id, source);
WritableMap params = Arguments.createMap();
params.putInt("id", id);
sendEvent("eventsourceOpen", params);

Thread sseEventReaderThread = new Thread() {
public void run() {
try {
SseEventReader reader = source.getEventReader();

SseEventType type = null;
while ((type = reader.next()) != SseEventType.EOS) {
switch (type) {
case DATA:
String name;
String data;
try {
name = reader.getName();
data = reader.getData().toString();
} catch (IOException e) {
notifyEventSourceFailed(id, e.getMessage());
return;
}

WritableMap params = Arguments.createMap();
params.putInt("id", id);
params.putString("type", name != null ? name : "message");
params.putString("data", data);
sendEvent("eventsourceEvent", params);
break;
case EMPTY:
break;
}
}

notifyEventSourceFailed(id, "Connection with the event source was closed.");
close(id);
}
catch (Exception e) {
notifyEventSourceFailed(id, e.getMessage());

Thread.currentThread().interrupt();
mEventReaderThreads.remove(id);
return;
}
}
};

sseEventReaderThread.start();
mEventReaderThreads.put(id, sseEventReaderThread);
}
catch (Exception e) {
notifyEventSourceFailed(id, e.getMessage());
}
}

@ReactMethod
public void close(int id) {
SseEventSource source = mEventSourceConnections.get(id);
Thread thread = mEventReaderThreads.get(id);
if (source == null) {
// EventSource is already closed
// Don't do anything, mirror the behaviour on web
FLog.w(
ReactConstants.TAG,
"Cannot close EventSource. Unknown EventSource id " + id);

return;
}
try {
thread.interrupt();
source.close();
mEventSourceConnections.remove(id);
mEventReaderThreads.remove(id);
} catch (Exception e) {
FLog.e(
ReactConstants.TAG,
"Could not close EventSource connection for id " + id,
e);
}
}

private void notifyEventSourceFailed(int id, String message) {
WritableMap params = Arguments.createMap();
params.putInt("id", id);
params.putString("message", message);
sendEvent("eventsourceFailed", params);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.github.jonnybgod.RNEventSource;

import java.util.Arrays;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import com.facebook.react.ReactPackage;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.uimanager.ViewManager;
import com.facebook.react.bridge.JavaScriptModule;

public class RNEventSourcePackage implements ReactPackage {

public RNEventSourcePackage() {}

@Override
public List<NativeModule> createNativeModules(
ReactApplicationContext reactContext) {
List<NativeModule> modules = new ArrayList<>();

modules.add(new RNEventSourceModule(reactContext));

return modules;
}

public List<Class<? extends JavaScriptModule>> createJSModules() {
return Collections.emptyList();
}

public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
return Collections.emptyList();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* Copyright (c) 2007-2014 Kaazing Corporation. All rights reserved.
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.kaazing.gateway.bridge;

final class ValidateOrigin {

}
64 changes: 64 additions & 0 deletions android/src/main/java/org/kaazing/gateway/client/impl/Channel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/**
* Copyright (c) 2007-2014 Kaazing Corporation. All rights reserved.
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.kaazing.gateway.client.impl;

import java.util.concurrent.atomic.AtomicLong;

import org.kaazing.net.auth.ChallengeResponse;

public class Channel {
public static final String HEADER_SEQUENCE = "X-Sequence-No";

// TODO: This is an abstration violation - authentication should not be exposed on Channel
/** Authentication data */
public ChallengeResponse challengeResponse = new ChallengeResponse(null, null);
public boolean authenticationReceived = false;
public boolean preventFallback = false;

private Channel parent;
private final AtomicLong sequence;

public Channel() {
this(0);
}

public Channel(long sequence) {
this.sequence = new AtomicLong(sequence);
}

public void setParent(Channel parent) {
this.parent = parent;
}

public Channel getParent() {
return parent;
}

public long nextSequence() {
return this.sequence.getAndIncrement();
}

@Override
public String toString() {
return "[" + this.getClass().getSimpleName() + "]";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* Copyright (c) 2007-2014 Kaazing Corporation. All rights reserved.
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.kaazing.gateway.client.impl;

public interface CommandMessage {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* Copyright (c) 2007-2014 Kaazing Corporation. All rights reserved.
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.kaazing.gateway.client.impl;

import org.kaazing.gateway.client.util.WrappedByteBuffer;


public interface DecoderInput<C> {

WrappedByteBuffer read(C channel);

}
Loading