Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

peersocket onmessage suddenly doesn't work

Hello 🙂

I have programmed my own watchface with a weather display. Until today everything has worked. I just wanted to add more icons and so I changed the icon codes. Suddenly I don't get into the message-event in the app.js of the companion after sending the data in the companion.js.

 

That is the event from app.js

 

peerSocket.addEventListener('message', (evt) => {
  const { weather_message_id, data, error } = evt.data;
  
  if (weather_message_id) {
    const promise = promises[weather_message_id];
    
    if (error) {
      promise.reject(error);
    }
    else {
      weather = data;
      weather.timestamp = Date.now();
      writeWeatherFile();
      
      if (promise) promise.resolve(weather);
    }
    delete promises[weather_message_id];
  }
})

 

 

That is the event from companion.js 

 

peerSocket.addEventListener('message', (evt) => {
  const { weather_message_id } = evt.data;
  
  // We are receiving a request from the app
  if (weather_message_id) {    
    fetchWeather(conf.apiKey)
      .then(data => {
        if (peerSocket.readyState === peerSocket.OPEN) {
          peerSocket.send({weather_message_id, data});
        } else {
          console.error("Error: Connection is not open");
        }
      })
      .catch((error) => {
        if (peerSocket.readyState === peerSocket.OPEN) {
          peerSocket.send({ weather_message_id, error });
        } else {
          console.error("Error: Connection is not open");
        }
      });    
  }
})

 

 

I've been looking for the error all day and just can't figure out what I'm doing wrong. Maybe someone can help me? 🙂

Best Answer
0 Votes
1 REPLY 1

Hi @SunsetRunner -  make sure the watch is syncing properly with the phone. It is possible that the companion never got started.

 

Once it's syncing go to Settings on the watch and then back to your clock face and it will restart the clock face and the companion for sure.

Author | ch, passion for improvement.

Best Answer
0 Votes