npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

vp-google-cast

v1.0.0

Published

Google Cast SDK v3 support for React-Native

Downloads

4

Readme

Google Cast SDK v3 support for React-Native

CAVEATS!

  • Only Android at the moment, iOS to come.
  • Only supports talking to your custom receiver thru a custom channel at the moment, so the default use-case of playing some media is currently NOT supported. Sorry, but this is what I needed today.

Installation

npm install --save vp-google-cast
react-native link

Or, you know, the same in yarn if that's what we are all using this week...

Configuration for Android

Add required dependencies to ./android/app/build.gradle:

dependencies {
  implementation project(':vp-google-cast')
  implementation "com.android.support:appcompat-v7:23.0.1"
  implementation 'com.android.support:mediarouter-v7:23.0.1'
  implementation "com.google.android.gms:play-services-cast-framework:11.8.0"
  ... // And so on
}

Make sure the version of the appcompat and mediarouter dependencies matches your compileSdkVersion.

Add the following inside the <application>-element in ./android/app/src/main/AndroidManifest.xml:

<meta-data
  android:name="com.google.android.gms.cast.framework.OPTIONS_PROVIDER_CLASS_NAME"
  android:value="com.reactnativegooglecastv3.CastOptionsProvider" />
<meta-data
  android:name="com.reactnativegooglecastv3.castAppId"
  android:value="YOUR_APP_ID" />
<meta-data
  android:name="com.reactnativegooglecastv3.castNamespace"
  android:value="urn:x-cast:your.own.namespace" />

Update your ./android/app/src/main/java/your.package/MainApplication.java, override onCreate, and add CastManager initialization:

  @Override
  public void onCreate() {
    super.onCreate();
    com.reactnativegooglecastv3.CastManager.init(this);
  }

Usage

Import

import CastButton, { GoogleCastV3 } from 'vp-google-cast'

GoogleCastV3.appId // is your castAppId
GoogleCastV3.namespace // is your castNamespace

Render the Cast button

The CastButton will appear and disappear depending on cast device availability, and show the current connection status:

<View>
  <CastButton color="#f00 (optional)" />
</View>

To trigger showing the device modal from another component, save a reference to the CastButton, and call click() on it:

// render:
<CastButton ref={c => this.myCastButton = c } ... />

// elsewhere in your component
this.myCastButton.click()

Get information about the currently connected device

 GoogleCastV3.getCurrentDevice().then(device => {
    // device: null || { id, model, name, version }
 })

Send messages to a connected Cast device

Using the namespace declared in you AndroidManifest.xml:

GoogleCastV3.send('WHADDUP')

Using some other namespace:

GoogleCastV3.send('urn:x-cast:some.other.namespace', 'WHADDUP')

Listen to things

GoogleCastV3.addCastStateListener(state => {
  // state is one of: GoogleCastV3.{NO_DEVICES_AVAILABLE, NOT_CONNECTED, CONNECTING or CONNECTED}
})

GoogleCastV3.addCastMessageListener(message => {
  // message is: { namespace: 'urn:x-cast:your.own.namespace', message: String }
})

Load media

GoogleCastV3.load({
        url:      PropType.string,
        title:    PropType.string,
        subtitle: PropType.string,
        image:    PropType.string,
        duration: PropType.number
      })
        .then(result => {
          console.log("LOAD_RESULT", result);
        })
        .catch(error => {
          console.log("LOAD_ERROR", error);
        })