[sockjs-client] Debugging sockjs-client in Samsung SmartTV SDK 3.0.0

3,762 views
Skip to first unread message

zanhsieh

unread,
Mar 3, 2012, 1:26:33 PM3/3/12
to sockjs
Hi,

I try to debug sockjs-client / sockjs-node JSONP polling behavior on
Samsung SmartTV SDK 3.0.0 and hope anybody could tip me where I should
go from here. The problem, in short, is it only echo back once from
the server, if we took the official echo example, change a little bit
to automatically submit random text since it's tedious and troublesome
to set the remote control performing the input and submit. If you
really eager to see the bug (of course I already owed you million
times of thanks), please follow the steps (it's a LONG journey) below:

0. Make sure you have both Windows 7 and Linux environment ready (I
use Ubuntu 11.10).

1. In Linux, install sockjs-client and sockjs-node ('npm install
sockjs' in a test directory pretty much cover everything), and then
tar gzip it and transfer (ftp / thumb drive copy / whatever) to
Windows 7 and untar ungzip it. This is because sockjs-node seems not
play good in Windows 7 (1. rbytes installation problem in Windows; 2.
node-waf compiling coffeescript to javascript does not play good in
Windows 7)

2. Go to Samsung D Forum Dev tools:

http://www.samsungdforum.com/Devtools/Sdkdownload

Follow the instruction to download / install DirectX 11 and SDK 3.0.0
(registration required; they take anybody to register) and install on
Windows 7 (because it only support Windows 7).

3. Double click "[2012]Samsung TV Apps Editor(3.0.0)" icon on your
desktop and launch the editor. Then File -> New -> New Project ->
JavaScript Project -> Basic JavaScript Project -> Next -> Enter "test"
for "Project Name" -> Next -> Finish.

4. Double click index.html on left window, and copy-n-paste content
on:

http://pastebin.com/taG6Vqrf

to replace the content on index.html. Modify line 27:

var sockjs_url = 'http://192.168.0.101:9999/echo';

matching the ip address (I suggest not put 0.0.0.0 and 127.0.0.1. Put
what is showed on ipconfig /all) and port number on the last two line
of server.js in sockjs example "server.js" file:

console.log(' [*] Listening on 192.168.0.101:9999' );
server.listen(9999, '192.168.0.101');

Save it.

5. To be safe, I copied server.js to the project root(sjs). It looks
like this:

sjs
server.js
node_modules
sockjs
examples
echo
server.js
...
test_server
...
...
lib
...
node_modules
...
...
node-static
...

and launch server from command line:

> node server.js

6. On Samsung TV SDK editor, click Tools -> Preference -> Emulator ->
Active Emulator -> [2011] Samsung SMART TV Emulator (2.5) -> OK -> Run
Emulator.

On server.js side the log looks like this:
C:\xampp\htdocs\sjs>node server.js
The "sys" module is now called "util". It should have a similar
interface.
SockJS v0.2.1 bound to "/echo"
[*] Listening on 192.168.1.10:9999
GET /echo 5ms 200
GET /echo/234/2eszniay/jsonp?c=_jp.ac9ya48 8ms 200
GET /echo/234/2eszniay/jsonp?c=_jp.amr1kaq 1ms (unfinished)
POST /echo/234/2eszniay/jsonp_send?i=au2gd7dof 9ms 200
GET /echo/234/2eszniay/jsonp?c=_jp.avwae7o 2ms (unfinished)
GET /echo/234/2eszniay/jsonp?c=_jp.a03ba8n 6ms (unfinished)
....

On Samsung SMART TV Emulator side the log looks like this:

[*] Connected [using: jsonp-polling]
[] sending: ">>>> 5030"
[] received: ">>>>%205030"
[] sending: ">>>> 8448"
[] sending: ">>>> 3912"
[] sending: ">>>> 8426"
[] sending: ">>>> 5540"
[] sending: ">>>> 606"
[] sending: ">>>> 8044"
[] sending: ">>>> 1121"
....

BTW, Samsung SMART TV use "Maple Browser" as rendering engine. The
user agent string is:

Mozilla/5.0 (Windows; en-US; rv:1.8.11; Gecko/20071129; Firefox/2.5.0)
Maple 6.0.00077

Also note that Socket.io also has this issue, whereas JQuery-JSONP
seems not having this issue.

Hope anybody could provide me clue for debugging this issue.

Marek Majkowski

unread,
Mar 3, 2012, 1:37:13 PM3/3/12
to zanh...@gmail.com, sockjs

Wow, this is really a unique browser, isn't it...

After spending long hours getting JSONP working
on Opera mini I thought it will work on just anything :)

Right.

1) Is it possible to easily run maple browser somehow?
(the emulator which requires registration and win7 is one
option, is there a simpler way?)

2) Is there a way to figure out if there isn't just a stupid
error javascript? Enable javascript debugging in the browser?

3) please capture traffic that goes from the sockjs-node server
to the browser (and back). To do this run something like:
$ sudo tcpdump -n -s0 port 8081 -w log.pcap
(please do review tcpdump manual page)
You should be able to open the pcap file in wireshark and verify
if you captured what's important.
I'd like to take a look at this dump to see if there is anything
obviously wrong.

I'll take a more detailed look on Monday.

Cheers,
Marek

zanhsieh

unread,
Mar 4, 2012, 9:25:26 AM3/4/12
to sockjs
Hi Marek,

About your questions:

1. Samsung SDK 3.0 could run on Windows XP with DirectX 11 installed,
but Windows is mandatory. I am considering if I could provide you
remote access to one of my desktop somehow in order to save you some
time on setting up the environment. I don't know if Amazon EC2 Win2008
instance let me install DirectX. Maybe it takes time to figure it out.

2. Unfortunately the emulator only allow developers to report variable
status using alert(). No firebug, no debugging console. Also the line
number it reports generally one step before the actual problem
occurred. This makes troubleshooting more challenge.

3. I made capture sockets on both server side and client side using
Wireshark. Can't see anything strange. The files are located in here:

http://www.4shared.com/folder/O4-qPjmy/_online.html

Please let me know if you need #1 set up. Thanks.
On Mar 4, 2:37 am, Marek Majkowski <maje...@gmail.com> wrote:

Marek Majkowski

unread,
Mar 5, 2012, 7:20:24 AM3/5/12
to zanh...@gmail.com, sockjs
On Sun, Mar 4, 2012 at 14:25, zanhsieh <zanh...@gmail.com> wrote:
> Hi Marek,
>
> About your questions:
>
> 1. Samsung SDK 3.0 could run on Windows XP with DirectX 11 installed,
> but Windows is mandatory. I am considering if I could provide you
> remote access to one of my desktop somehow in order to save you some
> time on setting up the environment. I don't know if Amazon EC2 Win2008
> instance let me install DirectX. Maybe it takes time to figure it out.
>
> 2. Unfortunately the emulator only allow developers to report variable
> status using alert(). No firebug, no debugging console. Also the line
> number it reports generally one step before the actual problem
> occurred. This makes troubleshooting more challenge.

Not true. Firebug lite is working just fine:

<script type="text/javascript" src="https://getfirebug.com/firebug-lite.js">
{
overrideConsole: true,
startInNewWindow: false,
startOpened: true,
enableTrace: true
}
</script>


> 3. I made capture sockets on both server side and client side using
> Wireshark. Can't see anything strange. The files are located in here:
>
> http://www.4shared.com/folder/O4-qPjmy/_online.html
>
> Please let me know if you need #1 set up. Thanks.

I updated your index.html:
https://gist.github.com/1978124

And it all works just fine. I think you had a bug in your code,
for example:

$('#input').val('>>>> '+Math.floor(Math.random()*10000));
$('#form').submit();

Why? Sockjs.send is what you need.

But whatever, see simplified code from the gist. I have no clue
how stable it is, does it leak memory and so on, but that's
your job :) For me the jsonp transport seems to be working
fine.

Cheers,
Marek

zanhsieh

unread,
Mar 5, 2012, 8:24:54 AM3/5/12
to sockjs
Hi Marek,

Thanks for swift reply. Your opinions are precious for me.

About firebug lite, yes, it does show up in Samsung emulator, but the
developer cannot do anything since there is no mouse to click (image
you face your old fashion TV and only have remote control on your
hand; yes, that's what emulator 'emulate' about). These two youtube
videos illustrate what it looks like:

http://www.youtube.com/watch?v=P9VCKhFiQ1s
http://www.youtube.com/watch?v=TP43Ts78sBw

I applied the modified code. Same thing, even with sockjs.send(). I
record a youtube clip:

http://youtu.be/7Q8G0HS_mX4

I don't think it's memory leak issue since it happen upon the program
start.

Thanks.

On Mar 5, 8:20 pm, Marek Majkowski <maje...@gmail.com> wrote:

Marek Majkowski

unread,
Mar 5, 2012, 8:39:29 AM3/5/12
to zanh...@gmail.com, sockjs
On Mon, Mar 5, 2012 at 13:24, zanhsieh <zanh...@gmail.com> wrote:
> Hi Marek,
>
> Thanks for swift reply. Your opinions are precious for me.
>
> About firebug lite, yes, it does show up in Samsung emulator, but the
> developer cannot do anything since there is no mouse to click (image
> you face your old fashion TV and only have remote control on your
> hand; yes, that's what emulator 'emulate' about). These two youtube
> videos illustrate what it looks like:
>
> http://www.youtube.com/watch?v=P9VCKhFiQ1s
> http://www.youtube.com/watch?v=TP43Ts78sBw

True.

> I applied the modified code. Same thing, even with sockjs.send(). I
> record a youtube clip:
>
> http://youtu.be/7Q8G0HS_mX4

Attaching screenshot of mine view. It's sending and receiving
messages correctly.

Marek

sockjs-samsung.png

zanhsieh

unread,
Mar 5, 2012, 9:01:29 AM3/5/12
to sockjs
Hi Marek,

It's because you launch Samsung emulator 3.0.0, which it emulates 2012
Samsung TV (cuz it's WebKit-based, which have better support on
standard). My issue is happen on emulator 2.5.1 / 2.5.0, which
emulates 2011 / 2010 Samsung TV. You could console.log the user agent
to verify it.

Thanks.

On Mar 5, 9:39 pm, Marek Majkowski <maje...@gmail.com> wrote:
>  sockjs-samsung.png
> 187KViewDownload

Marek Majkowski

unread,
Mar 5, 2012, 9:38:52 AM3/5/12
to zanh...@gmail.com, sockjs
On Mon, Mar 5, 2012 at 14:01, zanhsieh <zanh...@gmail.com> wrote:
> Hi Marek,
>
> It's because you launch Samsung emulator 3.0.0, which it emulates 2012
> Samsung TV (cuz it's WebKit-based, which have better support on
> standard). My issue is happen on emulator 2.5.1 / 2.5.0, which
> emulates 2011 / 2010 Samsung TV. You could console.log the user agent
> to verify it.

Right, even websockets were working - surprising!

To get 2.5.0 working, attach applied patch to sockjs-client,
regenerate the javascript (sockjs.js) and try running it.

There are two bugs.
1)
- area.value = null;
+ area.value = '';

For some reason maple doesn't like applying null to the 'value'
parameter - I'm happy to fix that. It shouldn't hurt.

2)
+ setTimeout(completed, 1000);

Sending data through JSONP relies on a weird trick. This includes
creating a fake <form>, and setting its target to the id of a fake <iframe>
object. That way by looking at the 'onreadystate'/'readyState' propery
of an Iframe we can understand whether we're done with the send.

Basically - we need to know when the form got through.

This doesn't work on maple. Adding this stupid timer forces
sockjs to think that the form indeed went through successfully
after a second.

This is generally wrong for networks with latency > 1s, and
thus I'm not going to include that in released SockJS client.

There may be another way of getting this information out
of the browser, but it's a lot of work. Suggestions welcome.

Cheers,
Marek

samsung.patch

zanhsieh

unread,
Mar 5, 2012, 10:14:20 AM3/5/12
to sockjs
Verified it's working. Owe you a lot, Marek.

On Mar 5, 10:38 pm, Marek Majkowski <maje...@gmail.com> wrote:
>  samsung.patch
> < 1KViewDownload

sachi...@gmail.com

unread,
Jul 31, 2012, 7:12:27 AM7/31/12
to soc...@googlegroups.com
Hello majek,

I am trying to develop AIR application for SMART TV.
I had downloaded SamsungSDK3.5 Emulator with Eclispse and isnstalled it on my system with Apache Server successfully.
Can u please tell me the steps how to test simple "HelloWorld" example on Samsung Emulator.

Reply me ASAP.

Thanks IN advance.

nisheeth....@gmail.com

unread,
Jun 3, 2013, 8:49:30 AM6/3/13
to soc...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages