r3wp [groups: 83 posts: 189283]
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

World: r3wp

[!Cheyenne] Discussions about the Cheyenne Web Server

Terry
11-Jan-2010
[7431x4]
Another handy html 5 api..  Web pages can determine if the client 
is online. (returns boolean)

var online = navigator.onLine;
alert(online);
So, jump on a plane, update your Cheyenne data, store local, and 
sync via ws when back online :)
<script>
var online = navigator.onLine
if(online){var conn = new WebSocket("ws://localhost/ws.rsp")}
</script>
else{golocalsql();}
Dockimbel
11-Jan-2010
[7435]
Terry, sure, HTML5 opens up a new world for web applications, the 
gap with native apps is closing.
Terry
11-Jan-2010
[7436x2]
How about this..  passing a block via websocket as a data method? 
(not even sure if it would work), and loading it?
ie: ws.send("[a 'one' b 'two]");
any security issues?
BrianH
11-Jan-2010
[7438]
Not is you screen the data after loading and throw away all functions.
Terry
11-Jan-2010
[7439]
Hmm, that could be very handy.
BrianH
11-Jan-2010
[7440]
It requires more security screening than JSON on the server side, 
and more work on the client side.
Terry
11-Jan-2010
[7441]
But, it is rebol friendly
BrianH
11-Jan-2010
[7442x3]
Not for web clients. You have to assume the client is hostile for 
web stuff, and screening REBOL data for malicious stuff is harder 
than parsing JSON data. The only way to be safe is to not transmit 
an executable dialect - full data dialect, reject anything bad.
It's great if the client won't primarily be a browser, as long as 
you stick to full dialects and never DO the code.
Fortunately you can't create reference loops without DO, so if you 
stick to LOAD/all you should be fine.
Terry
11-Jan-2010
[7445x6]
Here's some JS that takes an array of elements, and builds a block 
for passing to Rebol via WS

<script>
function toblock(arr){
	var block = '[';

	jQuery.each(arr, function(){
		var val = $(this).val();
		var id = $(this).attr('id');
		block = block+id+" '"+val+"' ";
		
	});
	
	block = block+"]";
	
	//remove, 
	alert(block);
};
<script>

<input id="one" type="text" />
<input id="two" type="text" />

 <button onclick="toblock([one, two]);">TEST</button>
oops.. missing / in closing script tag
That function only deals with elements that have value attributes.. 
for pulling the content of, say a <p>, use this.. 

jQuery.each(arr, function(){
		var val = $(this).val();
		if(val== ''){val = $(this).text();}
		......
if you want the html... 
if(val== ''){val = $(this).html();}
Why does this work

>> n: "one 'on' two 'tw'"
== "one 'on' two 'tw'"
>> x: to-block n
== [one 'on' two 'tw']
>> x/one
== 'on'

but not this (data is from ws)

r: to-block data
r/one
I can't turn data into a block no matter what i try?
PeterWood
11-Jan-2010
[7451]
Terry, are you mixing 1 and one ?
PeterWood
12-Jan-2010
[7452x2]
>> x/one
== 'on'
>> x/1
== one

x/one is really a shortcut for select x 'one:

>> select x 'one
== 'on'
r/one will only work if the data returned from ws includes the value 
one
Terry
12-Jan-2010
[7454x8]
The block comes back as a string!  
[one 'on' two 'tw']


But somehow it's getting encased in curlys or sumthin... so the best 
i can do is get a block like so

x: [[one 'on' two 'tw']]
Now the problem is escaping the response? (I always send back JS 
for DOM scripting purposes)
ahh.. probe to the rescue (my rebol is so rusty.. if i add one more 
semi, or use ( instead of [ im going to barf.
Looks like Cheyenne is my new serrogate home  HA!
Ok got it.. the problem was this..  I have two fields, and to test, 
i only filled out one... so the string looked like so.. "[one 'on' 
two '']"  (where the value following two is a pair of single quotes)
So when i converted to a block, I got an INVALID WORD --'' error.

But, using sockets, the error isn't reported... In other words, debugging 
is a pain.
Last issue is this.. 
n: [ one 'on' two 'tw']
n/one is returning
on'  
(note the apos) 
What's up with that??
nevermind
I am a little concerned.. My entire cheyenne directory is rapidly 
approaching 2.5mb.
BrianH
12-Jan-2010
[7462x2]
That is horrifically large by REBOL standards, but not bad by web 
standards. How much is images and other web stuff?
As opposed to RSP and Cheyenne files, I mean.
Terry
12-Jan-2010
[7464x3]
probably about 2/3rds :)
That includes all the Atom db functions and data
Jison: An API for creating parsers in JavaScript
http://tinyurl.com/yeravlz
Dockimbel
12-Jan-2010
[7467]
Terry, there's a Javascript group for such topics.
Terry
13-Jan-2010
[7468x5]
Hey Doc, refreshing the page after every change to a ws-app is painful. 
 Can't we just DO a script using do-task/on-done, put some error 
checking on the front end? So that the ws-app is just a handler of 
sorts as well.

could then set up a timer/schduler.. and makes changes live.. that 
would  make script development 10x faster. 
Refreshing to reload ws app is like a compiler.
This works in answer to my last questions.. 

	on-message: func [client data][
		;-- escape all html tags for security concerns
		data: copy data
		replace/all data "<" "&lt;"
		replace/all data ">" "&gt;"

		params: load copy data  
			
		do-task/on-done data func [client data][
		 n: do load %test2.r
		 broadcast out
		]
	]
test2.r looks like this;

print params/1
out: "alert('ok');"
Now i can edit the test2.r script at will .  Im guessing this is 
still non-blocking?
Here's a better version.. with basic error notification;

	on-message: func [client data][
		;-- escape all html tags for security concerns
		data: copy data
		replace/all data "<" "&lt;"
		replace/all data ">" "&gt;"

		params: load copy data  
			
		do-task/on-done data func [client data][

   if error? try[do load %test2.r][out: "alert('error with test2.r');"]
		 broadcast out
		]
	]
Graham
13-Jan-2010
[7473x2]
why have you got 

data: copy data
and then load copy data ?
how many copies do you need?
Terry
13-Jan-2010
[7475x6]
to lazy to clean it up
The "load copy data" was last nights work.. didn't care too much 
about anything else..
Here's an example piece of JS that passes the params to this ws-app


<button onclick="ws.send('[{sofpandv} {} {isa} {person}]');return 
false;">GO</button>
If you want to pull the value of a field for the first param.. 

<button onclick="ws.send('[{'+ $("#elementid).val(); +'} {} {isa} 
{person}]');return false;">GO</button>
Very simple, very cool.
What we need now is a JQuery dialect for scripting the DOM.. never 
needed to pass back JSON, but push well formed JS