Testing javascript

I’m having a look at JavaScript as I am investigating creating a web app with React, and would like to communicate with my Delphi DA server. I’ve started with the chat sample and failed at the first hurdle! As I try to use it, I get an error. If I run the sample from \RemObjects Samples\RemObjects SDK for Delphi\HTTP Chat, and using Chrome go to http://localhost:8099/js/ then I can login OK, but as soon as I try a message, I get:

Error: JSONMessage.setResponseStream:
 JSON parsing error: Unexpected token R in JSON at position 0
Server response:
RO107D/ZšÆÎE™ög"7ùLHTTPChatEvents
OnSendMessageuser60ee
Call stack:

I presume for my own app, I should be able to export the codegen generated js interface file and it should work?

Hi,

have you selected JSON message on server-side?
RO107 signature means that Bin Message is used by server-side

Doh ! What an idiot I am! That would be a no,
Thanks.

Are there any useful things I should know, like a React sample or a nice way to do things like Fire creating the DataAccess class or limitations of the current JS DA? I’m just reading the docs of course.

Hi,

I can suggest to look for React word on this forum.
Some topics can be useful for you.

for example, this topic contains a sample

Thanks, yes I’ve already had a quick look. I’m just getting a feel for it at the moment.

I wonder if you could take a look at this for me? I thought it would be nice to add a react client for the http chat sample of yours, so I have done this but notice that I am missing something as it doesn’t use the same session each time it sends a message, so the user is unknown each time, and this is different to the existing js sample you’ve made which works fine and I can’t work out what I’ve not got right here.
RO React Chat Sample.zip (427.3 KB)
Thanks

Hi,

something is wrong with your testcase.
update your ChatScreen method as

    const message = new RemObjects.SDK.JSONMessage(); // eslint-disable-line
    alert(message.getClientID());  // <<<<<<<< added

and see that this method is called twice at each call. as a result, your message is initialized with new guid every time

Of course, thanks Eugene, I’ve got it right now! As I say, I’m just working out how this React stuff fits together (not to mention learning JavaScript as well).