import * as messaging from 'messaging' ; function fetchWeather ( ) { if ( messaging . peerSocket . readyState === messaging . peerSocket . OPEN ) { messaging . peerSocket . send ( { command : 'weather' , } ) ; } } function processWeatherData ( data ) { console . log ( 'The temperature is: ' + data . temperature ) ; } messaging . peerSocket . onopen = function ( ) { fetchWeather ( ) ; } ; messaging . peerSocket . onmessage = function ( evt ) { if ( evt . data ) { processWeatherData ( evt . data ) ; } } ; messaging . peerSocket . onerror = function ( err ) { console . log ( 'Connection error: ' + err . code + ' - ' + err . message ) ; } ; setInterval ( fetchWeather , 30 * 1000 * 60 ) ;