How can I connect a React application with RemObjects SDK?
I already have the SDK and the intf.js file in my project, and I use it this way:
var channel = new RemObjects.SDK.HTTPClientChannel("http://192.168.119.129:9802/bin");
var message = new RemObjects.SDK.JSONMessage();
but it returns the following error:
TypeError: Cannot read property ‘HTTPClientChannel’ of undefined.
I hope you can help me.
antonk
(antonk)
May 31, 2021, 9:12am
2
Hello
This error means that the RemObjects.js file was not imported properly for some reason.
Also, according to your code you are going to connect to the binary endpoint of your server ( .../bin
). So you need to use the binary message instead of JSON one.
Regards
1 Like
I am importing the SDK like this:
import RemObjects from './RemObjectsSDK';
Could you help me import it properly?
antonk
(antonk)
June 2, 2021, 1:27pm
4
Hello
Here is the testcase / sample:
RO SDK.zip (205.2 KB)
RO SDK and _Intf files are referenced via index.html
and later are used in App.js
as
import logo from './logo.svg';
import './App.css';
function SuccessSumMethod(result) {
console.log('Result is ' + result);
}
function App() {
const channel = new RemObjects.SDK.HTTPClientChannel("http://127.0.0.1:8099/bin"); // eslint-disable-line
const message = new RemObjects.SDK.BinMessage(); // eslint-disable-line
var service = new MegaDemoService(channel, message); // eslint-disable-line
service.Sum(1, 2, SuccessSumMethod);
return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<p>
Edit <code>src/App.js</code> and save to reload.
</p>
<a
className="App-link"
href="https://reactjs.org"
target="_blank"
rel="noopener noreferrer"
>
Learn React
</a>
</header>
</div>
);
}
export default App;
Note the // eslint-disable-line
line that prevents JS processing errors
Regards