Guest User

Untitled

a guest
Dec 12th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.18 KB | None | 0 0
  1. socket.on('Start_chrono',function(match,timerMatch){
  2.  
  3. if (typeof timer[match]!='object') {
  4. timer[match] = new Timer();
  5. timer[match].addEventListener('secondsUpdated', () => {
  6. timeInminutes = timer[match].getTotalTimeValues().minutes +':'+timer[match].getTimeValues().seconds;
  7. socket.emit('chrono',{match:match,chrono:timeInminutes.toString(),timerMatch:timer[match]});
  8. socket.broadcast.emit('chrono',{match:match,chrono:timeInminutes.toString(),timerMatch:timer[match]});
  9. });
  10. timer[match].start();
  11. }else{
  12. timer[match].start();
  13. }
  14.  
  15. });
  16.  
  17. socket.on('Pause_chrono',function(match,timerMatch){
  18. timer[match]=new Timer(timerMatch);
  19. if ( typeof timer[match]=='object') {
  20. console.log('pause');
  21. timer[match].pause();
  22. timeInminutes = timer[match].getTotalTimeValues().minutes +':'+timer[match].getTimeValues().seconds;
  23. socket.emit('chrono',{match:match,chrono:timeInminutes.toString(),timerMatch:timer[match]});
  24. socket.broadcast.emit('chrono',{match:match,chrono:timeInminutes.toString(),timerMatch:timer[match]});
  25. }
  26. });
  27.  
  28. socket.on('Stop_chrono',function(match,timerMatch){
  29. timer[match]=new Timer(timerMatch);
  30. if ( typeof timer[match]=='object') {
  31. timer[match].stop();
  32. console.log('stop');
  33. timeInminutes = timer[match].getTotalTimeValues().minutes +':'+timer[match].getTimeValues().seconds;
  34. socket.emit('chrono',{match:match,chrono:timeInminutes.toString(),timerMatch:timer[match]});
  35. socket.broadcast.emit('chrono',{match:match,chrono:timeInminutes.toString(),timerMatch:timer[match]});
  36. }
  37. });
  38.  
  39. socket.on('Reset_chrono',function(match,timerMatch){
  40. timer[match]=new Timer(timerMatch);
  41. if ( typeof timer[match]=='object') {
  42. timer[match].reset();
  43. console.log('reset');
  44. timeInminutes = timer[match].getTotalTimeValues().minutes +':'+timer[match].getTimeValues().seconds;
  45. socket.emit('chrono',{match:match,chrono:timeInminutes.toString(),timerMatch:timer[match]});
  46. socket.broadcast.emit('chrono',{match:match,chrono:timeInminutes.toString(),timerMatch:timer[match]});
  47. }
  48. });
  49.  
  50. var timer;
  51.  
  52. function Chrono(type){
  53. match=<%= match.id %>;
  54. if (type!="Start") {
  55. $('#chronostart').show();
  56. if (typeof timer!='undefined') {
  57.  
  58. socket.emit(type+'_chrono',match,timer);
  59. }else{
  60. socket.emit(type+'_chrono',match,0);
  61. }
  62. }else{
  63. $('#chronostart').hide();
  64. if (typeof timer!='undefined') {
  65. console.log(typeof timer);
  66. socket.emit(type+'_chrono',match,timer);
  67. }else{
  68. console.log(typeof timer);
  69. socket.emit(type+'_chrono',match,0);
  70. }
  71. }
  72. }
  73.  
  74. function UpdateScore(){
  75. var channel=$('#channel').val();
  76. var layer=$('#layer').val();
  77. var template='template';
  78. var data='<templateData></templateData>';
  79. socket.emit('Update_data',channel,layer,template,data);
  80. }
  81.  
  82.  
  83. socket.on('chrono', function(data) {
  84.  
  85. if (data.match==<%= match.id %>) {
  86. timer = data.timerMatch;
  87. if ($('#basicUsage').val()!=data.chrono) {
  88. $('#basicUsage').val(data.chrono);
  89. $('#chronostart').hide();
  90. }
  91. UpdateScore();
  92. }
  93. })
Add Comment
Please, Sign In to add comment