Languages

Menu
Sites
Language
importing javascript modules

Hi,

I am trying to write an app for Gear S2.

The app needs the OscClient library. And the example code has this line for importing the library:

var OscClient = require('osc-client').OscClient;

But when I try to run the code , I get this error on the Tizen IDE console:

js/main.js (1) :ReferenceError: Can't find variable: require

 

I doubt that this import method is not supported by Tizen IDE. But then how can I import this module ?

I also added this js file to my index.html as:

    <script src="js/OscClient.js"></script>

But doesn't help. What can I do ?

Thanks.

Responses

6 Replies
daniel kim

Hi,

I think that you need to download require.js to your project for importing and would suggest you to visit following link as wel..

   https://developer.tizen.org/community/tip-tech/asynchronous-javascript-loader

Regards

AVSukhov

Hello,

this is syntax for nodejs module

as i know, there is no 'require' impementation for client side js.

mekabe remain

@AVSukhov

If that's the case, how can I implement this ?

I need to use this library somehow.

 

AVSukhov

hello,

may be this topic helps you:

http://stackoverflow.com/questions/4944863/how-to-use-node-js-module-system-on-the-clientside

mekabe remain

Ok. so now I added require.js to my js folder along with the modules.

I added these lines to my index.html :

 

    <script data-main="js/main.js" src="js/require.js"></script>
    <script src="js/main.js"></script>

 

also added this block to my main.js : 

requirejs.config({
    //By default load any module IDs from js/
    baseUrl: 'js',
    //except, if the module ID starts with "app",
    //load it from the js/app directory. paths
    //config is relative to the baseUrl, and
    //never includes a ".js" extension since
    //the paths config could be for a directory.
 paths: {
       app: '../app'
    }
});

 

after that, which format is correct from below ?

  1.  
requirejs(['osc-client-theta_s'],
    	function   (ThetaSOscClient) {
		    //jQuery, canvas and the app/sub module are all
		    //loaded and can be used here now.
		});

​2.

var ThetaSOscClient = require('osc-client-theta_s').ThetaSOscClient;

 

Is there anything else I should add/do ?

 

daniel kim

Hi,

I'm not sure as I'm not famillar with this. but browser need to get OSC message via WebSocket using node.js as per this link. so I would suggest you to check this link as wel..

http://www.jroehm.com/2015/10/a-simple-guide-to-use-osc-in-the-browser/

Regards