Giter Site home page Giter Site logo

raphamorim / react-tv Goto Github PK

View Code? Open in Web Editor NEW
2.0K 86.0 149.0 8.22 MB

[ Unmaintained due to raphamorim/react-ape ] React Renderer for low memory applications

Home Page: https://www.npmjs.com/package/react-tv

License: MIT License

JavaScript 94.18% HTML 1.46% CSS 4.36%
react tv rendering react-renderer react-tv webos samsung smarttv tvs lg-webos

react-tv's Introduction

react-tv: React Renderer for low memory applications.

react-tv-cli: React Packager for TVs.

Currently under development.

React-TV Logo

import React from 'react'
import ReactTV, { Platform } from 'react-tv'

class Clock extends React.Component {
  state = { date: new Date() }

  componentDidMount() {
    setInterval(() => this.setState({date: new Date()}), 1000)
  }

  render() {
    if (Platform('webos')) {
      return (
        <h1>Time is {this.state.date.toLocaleTimeString()}</h1>
      )
    }

    return <h2>This App is available only at LG webOS</h2>
  }
}

ReactTV.render(<Clock/>, document.getElementById('root'))

Summary

About React-TV

React-TV is an ecosystem for TV based React applications (from the renderer to CLI for pack/build applications).
At the moment we're focusing on webOS and SmartTV.
React-TV's aims to be a better tool for building and developing fast for TVs.

Understanding the Problem

tl;dr: Crafting a high-performance TV user interface using React

Crafting a high-performance TV user interface using React is a real challenge, because of some reasons:

  • Limited graphics acceleration
  • Single core CPUs
  • High Memory Usage for a common TV App

These restrictions make super responsive 60fps experiences especially tricky. The strategy is step in the renderer: Applying reactive concepts to unblock the processing on the renderer layer, plug the TV's keyListener, avoid React.createElement.

In addition: Unify the build for multiple TV platforms.

Articles

Friendly list of tutorials and articles:

To install react-tv-cli (CLI Packager):

$ yarn global add react-tv-cli
Support for React-TV-CLI
Target Platform Status Available Version
LG webOS stable 0.3.1
Samsung Tizen ongoing x
Samsung Orsay not started yet x
Sony PS4 not started yet x
Nintendo Switch not started yet x

Developing for webOS

Short Description: webOS, also known as Open webOS or LG webOS, (previously known as HP webOS and Palm webOS, stylized as webOS) is a Linux kernel-based multitasking operating system for smart devices such as Smart TVs and it has been used as a mobile operating system.


First of all, setup your webOS Environment:

Then, init your react-tv project:

$ react-tv-cli init <my-app-name>

From the project directory, install the dependencies to enable building:

$ yarn install

You will need to keep the list of files related to your app on the React-TV entry up to date in package.json. The init command will already add index.html, bundle.js and style.css to the package.

{
  "name": "my-app-name",
  "react-tv": {
    "files": [
      "index.html",
      "bundle.js",
      "style.css"
    ]
  }
}

To build your project:

$ yarn build

Once the project is built, you can run it on a specific device or emulator:

$ react-tv-cli run-webos <device>
  • When you not specify the device, it runs on VirtualBox webOS Simulator

To install react-tv (React Renderer):

$ yarn add react-tv

Platform

When building a cross-platform TV app, you'll want to re-use as much code as possible. You'll probably have different scenarios where different code might be necessary.
For instance, you may want to implement separated visual components for LG-webOS and Samsung-Tizen.

React-TV provides the Platform module to easily organize your code and separate it by platform:

import { Platform } from 'react-tv'

console.log(Platform('webos')) // true
console.log(Platform('tizen')) // false
console.log(Platform('orsay')) // false

renderOnAppLoaded

Takes a component and returns a higher-order component version of that component, which renders only after application was launched, allows to not write diffent logics for many devices.

import { renderOnAppLoaded } from 'react-tv'

const Component = () => (<div></div>)
const App = renderOnAppLoaded(Component)

findDOMNode

Similar to react-dom findDOMNode

Navigation

If you want to start with Navigation for TVs. React-TV provides a package for spatial navigation with declarative support based on Netflix navigation system.

React-TV Navigation exports withFocusable and withNavigation which act as helpers for Navigation.

import React from 'react'
import ReactTV from 'react-tv'
import { withFocusable, withNavigation } from 'react-tv-navigation'

const Item = ({focused, setFocus, focusPath}) => {
  focused = (focused) ? 'focused' : 'unfocused'
  return (
    <div onClick={() => { setFocus() }} >
      It's {focused} Item
    </div>
  )
}

const Button = ({setFocus}) => {
  return (
    <div onClick={() => { setFocus('item-1') }}>
      Back To First Item!
    </div>
  )
}

const FocusableItem = withFocusable(Item)
const FocusableButton = withFocusable(Button)

function App({currentFocusPath}) {
  return (
    <div>
      <h1>Current FocusPath: '{currentFocusPath}'</h1>,
      <FocusableItem focusPath='item-1'/>
      <FocusableItem focusPath='item-2'/>
      <FocusableButton
        focusPath='button'
        onEnterPress={() => console.log('Pressed enter on Button!')}/>
    </div>
  )
}

const NavigableApp = withNavigation(App)

ReactTV.render(<NavigableApp/>, document.querySelector('#app'))

See examples/navigation for more details about usage.

Examples

Clock App Example

Youtube App Example

References:

webOS

Videos

Windows
OSX

Essentials to beginner

Developing for SmartTV Guidelines

React Basics and Renderer Architecture

Roadmap

Stage 1

Initial proof-of-concept. [DONE]

  • CLI Build Abstraction of LG webOS (run-webos, run-webos-dev)
  • Create a guide or script to Install all LG webOS environment
  • Renderer ReactElements to simple DOM
    • Support HOF and HOC
    • Support State and Lifecycle
    • Keyboard Navigation
  • Check webos Platform
  • Migrate to React-Reconciler

Stage 2 [IN PROGRESS]

Implement essential functionality needed for daily use by early adopters.

  • Support render to Canvas instead DOM using React.CanvasComponent
  • run-webos support TV device as param
  • Optmizate DOMRenderer for TV
  • Start CLI for Tizen
  • Develop helpers for webOS debbug (e.g: Log System).
  • Support Cross Platform
    • Check executable bin path for Windows, OSX and Linux
  • Bind all TV key listeners on React.Element
  • Improve documentation
  • Benchmark it

Stage 3

Add additional features users expect from a Renderer. Then fix bugs and stabilize through continuous daily use. At this point we can start to experiment with innovative ideas and paradigms.

  • Start CLI for Orsay
  • Update Benchmarks
  • Handle common errors
  • Reactive Renderer
  • Testing and stability

See ReactTV's Changelog.

Currently ReactTV is licensed by MIT License

Credits

Thanks react-dom for be example and a inspiration code :)

react-tv's People

Contributors

antonybudianto avatar aspect26 avatar celiolatorraca avatar dead avatar lambertkevin avatar lionralfs avatar marcelometal avatar matheusml avatar nickyzero avatar ntmedina avatar raphamorim avatar roydejong avatar thgmhz avatar wojciech-bilicki avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-tv's Issues

Improvements on Renderer

Some works to do on Renderer:

  • Implements React-ID to help diffCalc
  • Do not appendChild if next Children is string
  • Support DevTools ( #36 )
  • Do propagating of WebOS keyboard for ReactElements ( rel: #40 )
  • AppStart Event ( Still To Discuss)
    • draft1:<MyApp onAppLoaded={() => true}/>
    • draft2:<TVContainer/> which render children only when WebOS, Tizen dispatch loaded

Support canvas based components

What do you think of something on the lines of:

class MyComponent extends ReactTV.CanvasComponent {
  ...
}

Or:

const MyComponent = canvasComponent(() => (
  <Rect .... />
))

draft: navigation interface

Working in Progress in #58 #40

const MyListComponent = (
   <div class="container">
   <div class="list"> 
         <div class="item" focusable onBlur={() => console.log('blur') } >
                Vertical Item with Blur Handler
          </div>
          <div class="horizontal-list">
               <div class="item" focusable onPress={() => console.log('pressed') } >
                     Horizontal Item 1 with Press Handler
               </div>
               <div class="item" focusable focused>
                     Horizontal Item 2 which started focused
                </div>
          </div>
          <div class="item" focusable onFocus={() => console.log('focused') } >
               Vertical Item with Focus Handler
          </div>
          <div class="item">
               Item which can't be focused or selected
           </div>
       </div>
       <div class='button' focusable>
           Enter
       </div>
   </div>
)

References:

simple DOM renderer

  • render reactElement children
  • deliver a simple DOM
  • platform
  • pass TV keyhandlers to reactElement

Support HOF (React.Element)

Current Renderer support (0.2.0)

React.TV(React.createElement('h2', null, 'This App is available only at LG WebOS');

Next Renderer support:

React.TV(
   React.createElement(
      'div', 
      null, 
      React.createElement('h1', null, 'This App is available only at LG WebOS')
   )
);

Roadmap: 0.4.x

0.4.x

Evolutions on Renderer:

  • Device keys
    • Propagate handler for keyboard on React.Elements.
    • <myComponent onPress={(fn) => null} />
  • Canvas Component Based ( #24, #49 )
  • New Focus System ( #40 #85 )
  • Think about AppIsReady for TVS. It's about done/loaded events which WebOS and Tizen dispatch, start mapping it in a HOC?

Evolutions on CLI:

  • migrate to node-webos
  • initial support to Tizen (#54)

virtualize WebOS environment

cc @pantuza

We are required to have the SDK running which connects to an independent virtualbox. The idea of ReactTVCLI is not to depend on VirtualBox. It would be awesome to run apps/tests with docker.

How to install application on LG TV?

# Create a tv2 device

ares-setup-device --add tv2 -i "username=root" -i "host=172.28.75.74" -i "port=22"

 

# Check which devices are listed with ares tools

ares-setup-device --list

<DEVICE NAME>    <PLATFORM>       <FILE STREAM>    <DESCRIPTION>            <SSH ADDRESS>

tv2              starfish         stream           new device description   (ssh://[email protected]:22)

emulator         starfish         sftp             LG webOS TV Emulator     (ssh://[email protected]:6622)

 

# Try to install the app on the TV

ares-install --device tv2 com.rn.app.remotekeyssample_1.0.0_all.ipk

 

# Gettings this error.

ares-install ERR! ares-install: Error: Connection time out. please check the device IP address or port.

https://www.lgwebos.com/topic/1517-how-to-install-application-on-lg-tv/

Tips, issues, ideas, possible future platforms.

Hi raphamorim,

I'm building/have build multiple Smart TV apps with React and TVOS with react-native. I didn't want to comment in every issue, but I have a couple of things to share which could be helpful. I love you're trying to unify building react apps for Smart tvs.

Samsung Toast

Have you looked at Samsung Toast? It's a builder (based on Cordova) and sets up a unified API for Samsung Orsay, Samsung Tizen and LG WebOS. To be honest I think it's pretty terrible to setup, but having tons of legacy stuff unified is great.

I think, if you just rip out the actual toast library, and possibly rip out the build system (creating config.xml, etc) you could have Orsay and Tizen support very fast.

Vewd/Opera TV

Opera TV, since 3 months known as Vewd, is another Smart TV app supply platform. They work (imho) with/on the lower-end spectrum of smart tvs (HiSense, some Sony tvs, Panasonic, Vestel, TP Vision, etc.). It's pretty easy to build apps since their API is pretty much the same as web (window.close, etc, but use a specific keycode set you have to get from the global window (;()). They don't use 'hosted' apps like lg and Samsung, but use urls. What I think is plausible is to use react-tv to build a Vewd app, and let the creator/user host it themselves.

Amazon Firestick

Same as Vewd, not hosted but application urls. Very, very close to web API. Could work with a almost identical build as Vewd, but some different keycodes, eventlisteners.

Chromecast

Chromecast, besides streaming, can run complete JS applications. Also works with application urls. It has very basic HDMI-CEC support (although afaik they're working on it, it doesn't have navigational support). It's very doable to setup a virtual remote control (in web/app) to publish keyevents to the chromecast app. Maybe it's not really the target of this library, but it could be very cool.

Metrological

I don't think it's doable, but it could be researched. They have their own Metrological SDK, which is very limiting. They run on tons of set-top-boxes, e.g. Comcast, Liberty Global with KPN and Ziggo (Dutch), ooredoo (Qatar).

React Native tvOS

I'm/we're using an almost completely sharable codebase between React native for tvOS and web. It's very doable to write a cross platform abstraction layer for views and device/web api.

React Native Samsung

Samsung and Microsoft promised to team up with Facebook to deliver support for React Native on Tizen. This was more than a year ago but only Microsoft delivered. I haven't read any news coming from Samsung since then, but... drumsounds... I've just noticed this repo was created 10 days ago. So maybe they're going to start?

Spatial navigation

I've written a custom implementation for spatial navigation, but thinking/working towards transitioning to Luke Chang's Spatial Navigation. I've already seen it mentioned in the issues here, I personally think react-tv should work towards getting that to work instead of going for a custom solution. It can take a lot of time to build something custom, and it will probably suck. Atleast two issues should be fixed in spatial-navigation; custom keyEvents and continuing in grids (last of row in grid > first of next row in grid instead of a full stop).

Debugging

Maybe you've already ran into the issue of debuggers not working, working crappy, I've switched to Weinre to atleast have one reliable debugging tool cross platform.

So, this is what I currently could think of. I'll definitely keep checking out the progress. Please let me know if you're stuck on stuff! Sorry about the title of this issue, I couldn't think of anything better.

Edit. Typos etc.

Run WebOS Examples

Installed react-tv globally.
Create proj with init command but when i try to run as it said in documentation.
Doesn't run as expected, all dependencies are installed.

image

Any plans on focus system?

Hello, nice to see some open source projects in this area. Working right now with React and smart tv:s and built to multiple smart tv platforms and consoles (playstation). If I have time over I can see if I can contribute. One thing that I always thinks of is the focus system. Web is really good at mouse interaction but keyboard navigation is lacking. Is that something you are planning to look into?

Best regards

build for commonjs (nodejs environment)

package.json should point for a valid ESmodule. Current points to src/ReactTVEntry, probably doesn't work without transpilers.

"main": "dist/react-tv-node.js",

Build for nodejs

Fix Flow task

Currently Flow task is skipped on CI, however we need to fix it.
Just remove <PROJECT_ROOT>/src/.* from .flowconfig to see all errors.

The guys at BBC have done significant work in configuring for diff platforms...

Hey hey,

LOVE what you're doing here. Exciting to see work being done in the TV space considering it's so incredibly fragmented.

Wanted to share this, I'm sure you've seen it... but didn't know if you considered using anything from it relating to the vast configuration requirements of the different platforms.

I'm not sure if "build" tools are as important as just flat out having a web app that can hot-load it's configuration based on the current platform since MANY TV platforms just require a URL as the source of the app versus a full build.

But anyway, wasn't sure what your intent was in this regard... https://github.com/bbc/tal

Failed to up virtualbox emulator

Hi @raphamorim,

I'm trying to start the LG WebOS Emulator 3.0.0 on Ubuntu 16.04 but I'm getting this error:

screenshot from 2017-12-04 21-44-39

I've already followed the instructions in the react-tv docs to configure the WebOS Environment and the Emulator works fine when I run through the desktop icon.

Do you have any idea how to fix this error?

Thanks!

Distribute Packages

In a future step, we should distribute every domain package and publish them.

- react-tv (Just renderer)
- react-tv-cli (Template and Generators)
- react-tv-simulators (Simulators)

generator for webos

  • CLI
  • Template

Create react-TV project hoist based

$ react-tv init <app-name>

<app-name>/
  node_modules/
  webos/
    index.js
  smart-tv/
  index.js

$ react-tv run-webos

Pack, Install and Launch

ares-package> ares-install > ares-launch

support node >=0.10.0

Currently React works with >=0.10.0, I think make sense to follow it as long React-TV live within the react universe

WebOS1 and WebOS2 - Map constructor does not accept arguments error

If you get error at Webos1 or Webos2 Map constructor does not accept arguments and for the solution;

npm install --save babel-polyfill

and then you can edit it as follows;

...................
require("babel-polyfill");
 
const sourcePath = path.join(__dirname, 'src');
 
module.exports = {
  entry: ["babel-polyfill", path.resolve(sourcePath,  'App.js')],
  output: {
    path: __dirname,
    filename: 'bundle.js'
  },
...........................

No need for WebOS 3 +

Heads up for canvas

Shaders in Tizen leaks memory and after awhile renders wrong.

Maybe not an issue but if you planning to implement something similar to Pixi.js canvas solution that uses webgl and then fallbacks to standard canvas. Then it could be good to know!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.