Sebuahhobi98

nodejs

Dec 28th, 2019
382
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. var socket = require( 'socket.io' );
  2. var express = require('express');
  3. var app = express();
  4. var server = require('http').createServer(app);
  5. var io = socket.listen( server );
  6. var port = process.env.PORT || 3000;
  7.  
  8. server.listen(port, function () {
  9. console.log('Server listening at port %d', port);
  10. });
  11.  
  12.  
  13. io.on('connection', function (socket) {
  14.  
  15. socket.on( 'new_count_message', function( data ) {
  16. io.sockets.emit( 'new_count_message', {
  17. new_count_message: data.new_count_message
  18.  
  19. });
  20. });
  21.  
  22. socket.on( 'update_count_message', function( data ) {
  23. io.sockets.emit( 'update_count_message', {
  24. update_count_message: data.update_count_message
  25. });
  26. });
  27.  
  28. socket.on( 'new_message', function( data ) {
  29. io.sockets.emit( 'new_message', {
  30. name: data.name,
  31. email: data.email,
  32. subject: data.subject,
  33. created_at: data.created_at,
  34. id: data.id
  35. });
  36. });
  37.  
  38. socket.on( 'chats', function( data ) {
  39. io.sockets.emit( 'chats', {
  40. text : data.isi,
  41. nama_pengirim : data.nama,
  42. waktu : data.waktu
  43. });
  44. });
  45.  
  46.  
  47. });
Add Comment
Please, Sign In to add comment