homeassistant-teams icon indicating copy to clipboard operation
homeassistant-teams copied to clipboard

Sending a command twice leads to crashing

Open jalmeroth opened this issue 2 years ago • 1 comments

Hi there 👋,

thanks for this awesome project! I really like the idea. While tinkering around with it, I discovered that the npm process is crashing if you send the same mqtt command twice:

homeassistant-teams % npm start

> [email protected] start /Users/jan/workspace/homeassistant-teams
> node dist/index.js

/Users/jan/workspace/homeassistant-teams/dist/index.js:237
    mqtt.publish('teams/state/isMuted', message.meetingUpdate.meetingState.isMuted ? 'ON' : 'OFF', { retain: true });
                                                              ^

TypeError: Cannot read property 'meetingState' of undefined
    at WebSocket.message (/Users/jan/workspace/homeassistant-teams/dist/index.js:237:63)
    at WebSocket.emit (events.js:400:28)
    at Receiver.receiverOnMessage (/Users/jan/workspace/homeassistant-teams/node_modules/ws/lib/websocket.js:1180:20)
    at Receiver.emit (events.js:400:28)
    at Receiver.dataMessage (/Users/jan/workspace/homeassistant-teams/node_modules/ws/lib/receiver.js:541:14)
    at Receiver.getData (/Users/jan/workspace/homeassistant-teams/node_modules/ws/lib/receiver.js:459:17)
    at Receiver.startLoop (/Users/jan/workspace/homeassistant-teams/node_modules/ws/lib/receiver.js:158:22)
    at Receiver._write (/Users/jan/workspace/homeassistant-teams/node_modules/ws/lib/receiver.js:84:10)
    at writeOrBuffer (internal/streams/writable.js:358:12)
    at Receiver.Writable.write (internal/streams/writable.js:303:10)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] start: `node dist/index.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
mosquitto_pub -h "<mqtt-server>" -t "teams/state/isMuted/command" -m "OFF"
mosquitto_pub -h "<mqtt-server>" -t "teams/state/isMuted/command" -m "OFF"

This is probably due to the fact that the current state is not respected.

jalmeroth avatar Feb 03 '23 23:02 jalmeroth