Running a web page in Snap!

I need to run a web page inside Snap! to communicate with a websocket client like here :

<html><head><script src="bundle.js"></script></head>
	Test api Toto
	// var toto_0 = totoApi.createClient("ws://");
	var toto = new Toto();
	toto.sendCode("call toto_function(0,255,255) \n");

Could you help me to do that ? Or give me some examples. Thanks.

You may try "HTML: dialog" from this project.
But do you really need HTML? Maybe JS global functions anchored at "window" object are enough?

Hi Nathalie,

You want to use the JS block. Only two comments:

  • First, if you are over https, websockets calls must be "wss". But maybe your service (host) does not have ssl... so you can use that is over http

  • Second, your html page loads a bundle.js script. You can copy all that js content, directly inside your JS block.
    In some cases, if the JS library is on Internet and you want to load dinamically (without tracking their possible changes), you can make a JS code to load that library on your DOM (Snap! page). Tell me if you need this.


You could make an iframe that is hidden...

Yes Joan.

The problem is that bundle.js is a very complicated function obtained by applying browserify to another script.js to bundle up all the dependencies I need.
I don't know how to execute the javascript block with it (what arguments do I have to declare).
Moreover bundle.js is 1.3M large.

And the block never stops.

Thank you @Dardaro. Yes, I think that js only would be sufficient.

How ? Could you give me an example ?

If you can upload bundle.js to a file hosting site you can dynamically load it through a <script> tag:
untitled script pic

Use JavaScript to add an iframe
then use = “none”

I am so sorry !
I just had to call the javascript block...
untitled script pic

Thank you.
Finally, I could communicate with my websocket client and send a command to it.

This is just the beginning...

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.