Comments (7)
Yes it is a constant, you can assign random ID to each socket.
Please find extract from 1 of my project:
const client = new tbClient({
host: "your-host",
publicId: "public-id"
});
const now = Date.now();
const mtd = now-3600000;
const device1 = {
cmdId: 10,
entityId: 'your-access-token-1',
startTs: mtd,
endTs: now
};
const device2 = {
cmdId: 11,
entityId: 'your-access-token-2',
startTs: mtd,
endTs: now
};
const MySocket = (props) => {
const [ connected, setConnected ] = useState(false);
const openSocket = async () => {
let token = await client.connect(true);
if(token){
setConnected(true);
client.subscribe(device1, async function(response){
if(response && response.data){
console.log('device1', response.data);
}
});
} else {
setTimeout(() => openSocket(), 5000);
}
}
useEffect(() => {
if(!connected){ openSocket(); }
},[connected]);
return(<div></div>);
}
from thingsboard-js-sdk.
I just created a new issue #5 , publicId belongs to a public dashboard.
You can connect with user/password auth instead or creating a public dashboard.
from thingsboard-js-sdk.
Hello,
We have a basic example here for React: https://github.com/acte-technology/thingsboard-js-sdk/blob/master/docs/reactjs.js
For WebSocket, you can run this, and check response from callback:
https://github.com/acte-technology/thingsboard-js-sdk#wss-websocket-subscribe
from thingsboard-js-sdk.
Thanks for your quick reply, I have use example to connect successful by user and password. I consider about how to check WebSocket id, does it is a const? and how to check response from callback
from thingsboard-js-sdk.
After run your code, I got this error, I think because wronged about the "publicId", does it is the device id?
from thingsboard-js-sdk.
Thank you, It seems app worked but it say "WebSocket Closed", do you have any idea for this
from thingsboard-js-sdk.
Yes, sorry for late reply.
When socket is closed, it's response becomes null.
You can simply run openSocket() if response == null.
from thingsboard-js-sdk.
Related Issues (4)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from thingsboard-js-sdk.