Guest User

Untitled

a guest
Dec 14th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. this._socketService.getSocket().onmessage = ((message: Message) => {
  2. const uiArray = new Uint8Array(message.data);
  3. this.parseMessage(uiArray);
  4. });
  5.  
  6. parseMessage(uiArray: Uint8Array) {
  7. let response = null;
  8.  
  9. // DOES NOT WORK
  10. // response = reqRep.Response.deserializeBinary(uiArray) || notif.BackendStatusNotification.deserializeBinary(uiArray);
  11.  
  12. // <==== This is where I need to find a good way to deserialize efficiently my objects
  13. // TEMPORARY
  14. if (uiArray.byteLength === 56) {
  15. response = reqRep.Response.deserializeBinary(uiArray)
  16. } else {
  17. response = notif.BackendStatusNotification.deserializeBinary(uiArray);
  18. }
  19.  
  20. // Notify different Observables which object has changed based on their type
  21. switch (response && response.hasSupplement() && response.getSupplement().array[0]) {
  22. case 'type.googleapis.com/req.BackendStatusResponse':
  23. this._responseSubject.next(response);
  24. break;
  25. case 'type.googleapis.com/notif.BackendStatusNotification':
  26. this._notificationSubject.next(response);
  27. break;
  28. default:
  29. console.log('DOESN'T WORK');
  30. }
  31. }
Add Comment
Please, Sign In to add comment