Hi ! For a project we need to communicate with a WebSocket server hosted on a Raspberry Pie. In Score, we’ve seen that we can create a device with the WS protocol, and there is a js script to edit. We tried to edit it for our purpose but it seems that the device does’nt connect to the server.
In the documentation, the section is not completed yet, so if someone has ever work with a WS in score let us know
Thank you !
Paul
here is the script :
import Ossia 1.0 as Ossia
Ossia.WebSockets
{
property string host: "ws:192.168.43.68:4000"
// Called whenever the Websocket server sends us a message
function onMessage(message) {
var res = JSON.parse(message);
console.log(res["coordinates"]) //affiche res["coordinates"]
return [
{ address: "/Objet/coordinates", value: res["coordinates"] },
];
}
function createTree() {
return [
{
name: "Objet",
children: [
{
name: "coordinates",
type: Ossia.Type.Vec3f
},
// Not useful for this particular API but useful
// as an example:
{
name: "request",
type: Ossia.Int,
// For the three following functions,
// the return value is sent to the WS server:
// 1. When a message is sent from score
request: function (value) {
console.log("request: ", value); //affiche la requete
return JSON.stringify({ sensor: value }) //convertit une valeur JavaScript en chaine JSON
},
// 2. When score listens on a node
openListening: function () {
console.log("open listening");
},
// 3. When score stops listening on a node
closeListening: function () {
console.log("close listening");
}
}
]
}
];
}
}