Search code examples
reactjsreact-nativesamsung-smart-tvtizen-web-apptizen-tv

Is there are proper way to develop Samsung TV (Tizen) app with React?


I need to develop an application for Samsung TV and I know it can be developed with Tizen Studio but I would like to use React. When I build React application and launch it on TV it works fine, however I need to access Samsung Product APIs that is loaded via

<script type="text/javascript" src="$WEBAPIS/webapis/webapis.js"></script>

I tried downloading all webapis.js code and load it in React application but I get 'webapis' is not defined error.

Is there are a proper way to load webapis.js file in React application, so I could access Samsung Product API methods?


Solution

  • Webapis are attached to the window object in your app. You should not try to bring webapis.js to your app package. It's would be available to you once running on TV.

    If you are developing in the browser you can write your own wrapper function that handles the lack of that method with a try-catch block.

    let = getTVFW() => {
        let value;
        try {
            value = window.webapis.productinfo.getFirmware();
            console.log(" Firmware value = " + value);
        } catch (error) {
            console.log(" error code = " + error.code);
            value = 'testvaluefordev';
        }
        return value;
    }
    

    The above can be a service of some sort that your app is using and you reference that function to access what you need.

    Also, make sure you have correct privileges that allow you to access these APIs.