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

@theoplayer/react-native-connector-template

v0.0.3

Published

React Native template for a quick start with react-native-theoplayer connectors.

Downloads

2

Readme

React Native THEOplayer Connector Template

Overview

This template serves as a starting point for building a connector using react-native-theoplayer.

Included is a basic connector API that interfaces with native components on iOS, Android and web, designed for easy expansion.

Moreover, the template generates a sample application that offers a practical demonstration of how to effectively utilize the connector. To enable compatibility with tvOS, the example employs react-native-tvos. The resulting application can be deployed across multiple platforms:

  • Android, AndroidTV & FireTV
  • iOS & tvOS
  • Web-based platforms

Usage

To begin, initiate a new connector project using this template. Let's name it, for instance, THEODemoConnector:

$ npx react-native init THEODemoConnector --template @theoplayer/react-native-connector-template

This command will also handle the installation of the required dependencies.

Running the Example App

To test the connector, an illustrative project is provided within the template.

Navigate to the example directory:

$ cd THEODemoConnector/example

Install the necessary dependencies:

$ npm i

And run on either Web, Android or iOS:

$ npm run web
$ npm run android
$ (cd ios && pod install) && npm run ios

Connector Bridge

The connector template includes a simple API with initialize and destroy methods that bridge to native iOS and Android.

export class ReactNativeTHEOplayerConnectorAdapter {
    constructor (private player: THEOplayer, config: ReactNativeTHEOplayerConnectorConfiguration) {
        NativeModules.ReactNativeTHEOplayerConnectorModule.initialize(this.player.nativeHandle, config);
    }

    destroy(): void {
        NativeModules.ReactNativeTHEOplayerConnectorModule.destroy(this.player.nativeHandle || -1);
    }
}

The nativeHandle is used to uniquely identify the player instance, as each player can have its own connector instance. On the native iOS and Android side, the handle resolves to the corresponding player instance.

On Android

@ReactMethod
fun initialize(tag: Int, connectorConfig: ReadableMap) {
    viewResolver.resolveViewByTag(tag) { view: ReactTHEOplayerView? ->
        view?.player?.let { player ->
            val config = ReactNativeTHEOplayerConnectorConfiguration(
                connectorConfig.getBoolean(PROP_DEBUG),
            )
            connectors[tag] =
                ReactNativeTHEOplayerConnector(reactApplicationContext, player, config)
        }
    }
}

@ReactMethod
fun destroy(tag: Int) {
    connectors[tag]?.destroy()
    connectors.remove(tag)
}

On iOS

@objc(initialize:config:)
func initialize(_ node: NSNumber, config: NSDictionary) -> Void {
    log("initialize triggered.")

    DispatchQueue.main.async {
        log(config.debugDescription)
        if let view = self.view(for: node), let player = view.player, let sendError = view.mainEventHandler.onNativeError {
            let connector = ReactNativeTHEOplayerConnector()
            self.connectors[node] = connector
        } else {
            log("Cannot find THEOPlayer for node \(node)")
        }
    }
}

@objc(destroy:)
func destroy(_ node: NSNumber) -> Void {
    log("destroy triggered.")
    DispatchQueue.main.async {
        self.connectors.removeValue(forKey: node)
    }
}

The API can be extended with additional bridge methods.

React Hook

For user convenience, a React hook is provided. This hook manages the destruction of the connector when either the player is being destroyed or the connector itself is unmounted.

import { useTHEODemoConnector } from 'THEODemoConnector';

const config: THEODemoConnectorConfiguration = {
  debug: true,
};

const App = () => {
  const [connector, initConnector] = useTHEODemoConnector(config);

  const onPlayerReady = (player: THEOplayer) => {
    // Initialize connector
    initConnector(player);
  }

  return (<THEOplayerView config={playerConfig} onPlayerReady={onPlayerReady}/>);
}