Skip to content

Commit

Permalink
renaming android implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
charliesbox committed Jun 13, 2016
1 parent aebd3b4 commit a0492cb
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 26 deletions.
2 changes: 2 additions & 0 deletions GoogleCast.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import { NativeModules } from 'react-native';
module.exports = NativeModules.GoogleCast;
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.reactnativegooglecast.ChromecastManager;
package com.reactnativegooglecast.GoogleCast;

import android.app.Activity;
import android.support.annotation.Nullable;
Expand Down Expand Up @@ -34,7 +34,7 @@
/**
* Created by Charlie on 5/29/16.
*/
public class ChromecastModule extends ReactContextBaseJavaModule implements LifecycleEventListener {
public class GoogleCastModule extends ReactContextBaseJavaModule implements LifecycleEventListener {
private Activity mCurrentActivity;
private VideoCastManager mCastManager;
private VideoCastConsumer mCastConsumer;
Expand All @@ -43,21 +43,21 @@ public class ChromecastModule extends ReactContextBaseJavaModule implements Life


@VisibleForTesting
public static final String REACT_CLASS = "ChromecastModule";
public static final String REACT_CLASS = "GoogleCastModule";

private static final String DEVICE_CHANGED = "GoogleCast:DeviceListChanged";
private static final String DEVICE_AVAILABLE = "GoogleCast:DeviceAvailable";
private static final String DEVICE_CONNECTED = "GoogleCast:DeviceConnected";

public ChromecastModule(ReactApplicationContext reactContext, Activity activity) {
public GoogleCastModule(ReactApplicationContext reactContext, Activity activity) {
super(reactContext);
getReactApplicationContext().addLifecycleEventListener(this);
mCurrentActivity = activity;
}

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

@Override
Expand All @@ -69,12 +69,8 @@ public Map<String, Object> getConstants() {

// RCT_EXTERN_METHOD(startScan)
// RCT_EXTERN_METHOD(stopScan)
//
// RCT_EXTERN_METHOD(connectToDevice: (NSString *) deviceName)
// RCT_EXTERN_METHOD(disconnect)
//
// RCT_EXTERN_METHOD(castVideo: (NSString *) videoUrl title: (NSString *) title description: (NSString *) description imageUrl: (NSString *) imageUrl)
//
// RCT_EXTERN_METHOD(play)
// RCT_EXTERN_METHOD(pause)
//
Expand Down Expand Up @@ -114,8 +110,8 @@ public void getDevices(Promise promise) {
@ReactMethod
public void castMedia(String mediaUrl, String title, String description, String imageUrl) {
Log.e(REACT_CLASS, "Casting media... ");
MediaInfo mediaInfo = ChromecastService.getMediaInfo("http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4", "A video");
//MediaInfo mediaInfo = ChromecastService.getMediaInfo(mediaUrl, title);
MediaInfo mediaInfo = GoogleCastService.getMediaInfo("http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4", "A video");
//MediaInfo mediaInfo = GoogleCastService.getMediaInfo(mediaUrl, title);
try {
mCastManager.loadMedia(mediaInfo, true, 0);
} catch (TransientNetworkDisconnectionException | NoConnectionException e) {
Expand Down Expand Up @@ -145,7 +141,7 @@ public void connectToDevice(String deviceId) {
@ReactMethod
public void startScan() {
Log.e(REACT_CLASS, "start scanning... ");
final CastConfiguration options = ChromecastService.getCastConfig();
final CastConfiguration options = GoogleCastService.getCastConfig();
UiThreadUtil.runOnUiThread(new Runnable() {
public void run() {
VideoCastManager.initialize(getCurrentActivity(), options);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.reactnativegooglecast.ChromecastManager;
package com.reactnativegooglecast.GoogleCast;

import android.app.Activity;

Expand All @@ -15,19 +15,19 @@
/**
* Created by Charlie on 5/29/16.
*/
public class ChromecastManager implements ReactPackage {
public class GoogleCastPackage implements ReactPackage {

private Activity mCurrentActivity;

public ChromecastManager(Activity activity) {
public GoogleCastPackage(Activity activity) {
mCurrentActivity = activity;
}

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

modules.add(new ChromecastModule(reactContext, mCurrentActivity));
modules.add(new GoogleCastModule(reactContext, mCurrentActivity));

return modules;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.reactnativegooglecast.ChromecastManager;
package com.reactnativegooglecast.GoogleCast;

import com.google.android.gms.cast.CastMediaControlIntent;
import com.google.android.gms.cast.MediaInfo;
Expand All @@ -10,10 +10,8 @@
/**
* Created by Charlie on 6/9/16.
*/
public class ChromecastService {
private VideoCastManager mCastManager;
private VideoCastConsumer mCastConsumer;
public static final String REACT_CLASS = "ChromecastModule";
public class GoogleCastService {
public static final String REACT_CLASS = "GoogleCastModule";

public static MediaInfo getMediaInfo(String filmUrl, String filmTitle) {
MediaMetadata mediaMetadata = new MediaMetadata(MediaMetadata.MEDIA_TYPE_MOVIE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.facebook.react.ReactActivity;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
import com.reactnativegooglecast.ChromecastManager.ChromecastManager;
import com.reactnativegooglecast.GoogleCast.GoogleCastPackage;

import java.util.Arrays;
import java.util.List;
Expand Down Expand Up @@ -44,7 +44,7 @@ protected boolean getUseDeveloperSupport() {
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new ChromecastManager(this)
new GoogleCastPackage(this)
);
}
}
4 changes: 1 addition & 3 deletions index.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@ import {
Text,
View,
DeviceEventEmitter,
NativeModules,
TouchableOpacity
} from 'react-native';

var chromecast = NativeModules.ChromecastManager;
import chromecast from "./GoogleCast";

class ReactNativeGoogleCast extends Component {
constructor(props) {
Expand All @@ -27,7 +26,6 @@ class ReactNativeGoogleCast extends Component {

componentDidMount() {
DeviceEventEmitter.addListener("GoogleCast:DeviceAvailable", (existance) => {
console.log("test test ", existance.device_available);
this.setState({chromecastAvailable: existance.device_available});
});
DeviceEventEmitter.addListener("GoogleCast:DeviceConnected", () => {
Expand Down

0 comments on commit a0492cb

Please sign in to comment.