cancel
Showing results for 
Search instead for 
Did you mean: 

Data Source SDK (1.4) with Socket.io & node.js

salvi1
Explorer
0 Kudos

Hi!

I am new at Design Studio and sdk developement. Right know i am trying to create a data source to connect to a websocket with socket.io. Server is running on a node.js. The server is receiving data. With the data source sdk i am trying to open a client an connect to the socket.

As mentioned i am still at the beginning. Right know i a struggling with the following aspects:

  1. Include the js library socket.io in the sdk Extension (and make use of it).
    • right know io() is "undefined" and i am getting an error (referenceerror). What are the steps i have to undetake to successfully include a external js library in an sdk? what files do i have to edit (contribution.xml?), etc
  2. Is there a way to debug the js code in eclipse itself? Right i run the sdk in desing Studio and then debug with IE or Chrome.

At the end i want to receive streaming data from the websocket and Display it in DS (i know, there's SAP ESP for that, but i would like to do it without it).

Thanks a lot and best regards!

Saood Alvi

Accepted Solutions (1)

Accepted Solutions (1)

former_member194504
Active Contributor
0 Kudos

Hi saood,

First of all nice experiement, which i too also want to do it for long time. If you want to include external javascript file. you can do it by including it in contribution.xml  with <jsinclude>Your script</jsinclude>.

And i think you can't debug the javascript in eclipse so easily, browser is the best way to do it.


Thanks,
nithyanandam

salvi1
Explorer
0 Kudos

Hi Nithyanandam!

Thanks for the fast reply!

I tried including the file through

<jsInclude>https://cdn.socket.io/socket.io-1.3.5.js</jsInclude>,

<jsInclude>http://192.168.159.128:34000/socket.io/socket.io.js</jsInclude> (since this the location of the server), as well as directly through a root path. Nothing seems to work.

I also checked if the file is being loaded from cdn (f12 --> Network tab). everything seems fine. but still no change. the file is loaded before the component.js

i was wondering if there is something wrong with the js code. maybe i am not initializing correctly?

var socket = io(config.SocketConn);

  socket.on('message', function(msg) {

  config.SocketConn = "http://192.168.159.128:34000";

  console.log(msg);

  });

br

saood

former_member194504
Active Contributor
0 Kudos

Hi saood,

That's the way to include the external files. for new questions,please always close the old thread and open a new one. I also doubt the error must be in your code, since the resources are properly loaded.
However, whats your console saying??


Thanks,
Nithyanandam

salvi1
Explorer
0 Kudos

Hi Nithyanandam,

sry. Didn`t know. If needed I'll open a new thread.

Console output:

2015-06-02 13:33:59 [int.do] A JavaScript error occurred. io is not defined ReferenceError: io is not defined     at null.<anonymous> (http://localhost:53790/aad/zen/mimes/sdk_include/com.mhp.jsondatasource/res/js/component.js?version=...)     at new h (http://localhost:53790/aad/zen.rt.components.sdk/resources/js/sdk_handler-min.js?version=14332448157...)     at sap.ui.core.Control.extend.storeProperties (http://localhost:53790/aad/zen.rt.components.sdk/resources/js/sdk_handler-min.js?version=14332448157...)     at create (http://localhost:53790/aad/zen.rt.components.sdk/resources/js/sdkdatasource_handler-min.js?version=1...)     at createAndAdd (http://localhost:53790/aad/zen/mimes/combined_static_includes_1.js?version=1433244815728:3515:50)     at createControl (http://localhost:53790/aad/zen/mimes/combined_static_includes_1.js?version=1433244815728:3127:16)     at dispatchCreateControl (http://localhost:53790/aad/zen/mimes/combined_static_includes_1.js?version=1433244815728:3098:15)     at updateChildren (http://localhost:53790/aad/zen/mimes/combined_static_includes_1.js?version=1433244815728:3535:21)     at init (http://localhost:53790/aad/zen/mimes/combined_static_includes_1.js?version=1433244815728:3694:21)     at createAndAdd (http://localhost:53790/aad/zen/mimes/combined_static_includes_1.js?version=1433244815728:3704:1)  - 

u @ sap-ui-core.js:80

error @ sap-ui-core.js:80

sapbi_phx @ combined_static_includes_1.js?version=1433244815728:2213

sapbi_onBodyLoad @ int.do:52

sapbi_PageClass.initialize @ combined_static_includes_1.js?version=1433244815728:1333

sapbi_PageClass.initializePage @ combined_static_includes_1.js?version=1433244815728:1328

onload @ int.do:55

Br

Saood

former_member194504
Active Contributor
0 Kudos

Hi saood,


This is because of the library not properly loaded or maybe due to the order of exectuion of your files. As it clearly states IO is undefined. Try to check it once clearly that you maintain the sequence of order properly or not.


Thanks,
Nithyanandam

Karol-K
Advisor
Advisor
0 Kudos

I am not a fan of calling external servers for included JS files, actually sdk defines that all files should be included in the bundle you want to deliver. but anyway this is not the root cause of your issue.

is it quite possible, that you need to use the require statement to include this files as a simple include will not work.

salvi1
Explorer
0 Kudos

Hi Karol!

Thanks a lot! I did have to use the require statement! I am getting my data know!

this is what i added in the component.js (for further use):

    require.config({

        paths: {

            socketio: 'http://192.168.159.128:34000/socket.io/socket.io'

        }

    });

    require(['socketio'], function(io) {

        var socket = io.connect('http://192.168.159.128:34000');

        console.log('socket connected');

        socket.on('message', function(data) {

       console.log(data);

        });

    });

however i do get an "socket is undefined" error but i think, like Nithyanandam suggested, it has something to do with the load sequence and the files are somehow reloaded.

thanks again and best regards,

saood

p.s.:i'll edit this post if there is something important to add

mike_howles4
Active Contributor
0 Kudos

I wouldn't mess with the require context directly like that.  Could you try this instead:

    var myRequire = require.config({

        paths: {

            socketio: 'http://192.168.159.128:34000/socket.io/socket.io'

        }

    });

    myRequire(['socketio'], function(io) {

        var socket = io.connect('http://192.168.159.128:34000');

        console.log('socket connected');

        socket.on('message', function(data) {

       console.log(data);

        });

    });

Also a recent discussion on using RequireJS here:

salvi1
Explorer
0 Kudos

Thanks Michael!

I adjusted the code. Works fine.

Br

Saood

Answers (1)

Answers (1)

Karol-K
Advisor
Advisor
0 Kudos

Hi Saood,

1. this topic should be actually covered by the SDK guide at http://help.sap.com/boad. Have you seen the description of contribution.xml? The short answer is, depends if you need to load it by requrie or can include this library directly. if directly, simple include in contribution.xml should help.


2. yes, you can - but this requires some real debug - eg. MS Visual Studio, then you can connect to the eclipse process and debug also in eclipse. For the most cases, debugging during execution in browser is easier to achieve.


Karol