Guest User

Untitled

a guest
Oct 18th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. function TextReceiver(connection) {
  2. var content = {};
  3.  
  4. function receive(data, userid, extra) {
  5. // uuid is used to uniquely identify sending instance
  6. var uuid = data.uuid;
  7. if (!content[uuid]) {
  8. content[uuid] = [];
  9. }
  10.  
  11. content[uuid].push(data.message);
  12.  
  13. if (data.last) {
  14. var message = content[uuid].join('');
  15. if (data.isobject) {
  16. message = JSON.parse(message);
  17. }
  18.  
  19. // latency detection
  20. var receivingTime = new Date().getTime();
  21. var latency = receivingTime - data.sendingTime;
  22.  
  23. var e = {
  24. data: message,
  25. userid: userid,
  26. extra: extra,
  27. latency: latency
  28. };
  29.  
  30. if (connection.autoTranslateText) {
  31. e.original = e.data;
  32. connection.Translator.TranslateText(e.data, function(translatedText) {
  33. e.data = translatedText;
  34. connection.onmessage(e);
  35. });
  36. } else {
  37. connection.onmessage(e);
  38. }
  39.  
  40. delete content[uuid];
  41. }
  42. }
  43.  
  44. return {
  45. receive: receive //в этом месте мне непонятно
  46. };
  47. }
Add Comment
Please, Sign In to add comment