classroom/public/TeacherChat/gcmSaver.js
// - subscribe/unsubscribe the token from topics
subscribe/unsubscribe the token from topics
subscribe / unsubscribe the token from topics
function sendTokenToServer(currentToken) {
  	if (!isTokenSentToServer()) {
  		console.log('Sending token to server...');
      var data = null;
      var xhr = new XMLHttpRequest();
      xhr.withCredentials = false;
      xhr.addEventListener("readystatechange", function () {
      	if (this.readyState === 4) {
      		console.log(this.responseText);
      	} 
      });
      data = 'email='+teacherEmail+'&gcmId=' + currentToken + '&teacherId='+teacherId;
      xhr.open("POST", "saveTeacherGcmId.action");
      xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      console.log(data);
      xhr.send(data);
      setTokenSentToServer(false);
  } else {
  	console.log('Token already sent to  server so won\'t send it again unless it changes');
  }
}
function sendTokenToServer ( currentToken ) { if ( ! isTokenSentToServer ( ) ) { console . log ( 'Sending token to server...' ) ; var data = null ; var xhr = new XMLHttpRequest ( ) ; xhr . withCredentials = false ; xhr . addEventListener ( "readystatechange" , function ( ) { if ( this . readyState === 4 ) { console . log ( this . responseText ) ; } } ) ; data = 'email=' + teacherEmail + '&gcmId=' + currentToken + '&teacherId=' + teacherId ; xhr . open ( "POST" , "saveTeacherGcmId.action" ) ; xhr . setRequestHeader ( "Content-type" , "application/x-www-form-urlencoded" ) ; console . log ( data ) ; xhr . send ( data ) ; setTokenSentToServer ( false ) ; } else { console . log ( 'Token already sent to  server so won\'t send it again unless it changes' ) ; } }
subscribe/unsubscribe the token from topics
subscribe / unsubscribe the token from topics
// TODO(developer): Send the current token to your server.