service.messagingserver.pp 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. {
  2. This file is part of the Free Component Library
  3. Copyright (c) 2024 by Michael Van Canneyt [email protected]
  4. FCM Messaging demo - web client : RPC client definition.
  5. This file is automatically generated by the RPC Client context menu in Lazarus.
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. Unit service.messagingserver;
  13. {$MODE ObjFPC}
  14. {$H+}
  15. interface
  16. uses js, fprpcclient;
  17. Type
  18. { --------------------------------------------------------------------
  19. TMessagingService
  20. --------------------------------------------------------------------}
  21. TMessagingService = Class(TRPCCustomService)
  22. Protected
  23. Function RPCClassName : string; override;
  24. Public
  25. Function SendNotification (Message : TJSObject; aOnSuccess : TJSValueResultHandler = Nil; aOnFailure : TRPCFailureCallBack = Nil) : NativeInt;
  26. Function RegisterSubscription (Token : String; aOnSuccess : TJSValueResultHandler = Nil; aOnFailure : TRPCFailureCallBack = Nil) : NativeInt;
  27. end;
  28. implementation
  29. { --------------------------------------------------------------------
  30. TMessagingService
  31. --------------------------------------------------------------------}
  32. Function TMessagingService.RPCClassName : string;
  33. begin
  34. Result:='Messaging';
  35. end;
  36. Function TMessagingService.SendNotification (Message : TJSObject; aOnSuccess : TJSValueResultHandler = Nil; aOnFailure : TRPCFailureCallBack = Nil) : NativeInt;
  37. Procedure DoSuccess(Sender : TObject; const aResult : JSValue);
  38. begin
  39. If Assigned(aOnSuccess) then
  40. aOnSuccess(JSValue(aResult))
  41. end;
  42. Var
  43. _Params : JSValue;
  44. begin
  45. StartParams;
  46. AddParam('Message',Message);
  47. _Params:=EndParams;
  48. Result:=ExecuteRequest(RPCClassName,'SendNotification',_Params,@DoSuccess,aOnFailure);
  49. end;
  50. Function TMessagingService.RegisterSubscription (Token : String; aOnSuccess : TJSValueResultHandler = Nil; aOnFailure : TRPCFailureCallBack = Nil) : NativeInt;
  51. Procedure DoSuccess(Sender : TObject; const aResult : JSValue);
  52. begin
  53. If Assigned(aOnSuccess) then
  54. aOnSuccess(JSValue(aResult))
  55. end;
  56. Var
  57. _Params : JSValue;
  58. begin
  59. StartParams;
  60. AddParam('Token',Token);
  61. _Params:=EndParams;
  62. Result:=ExecuteRequest(RPCClassName,'RegisterSubscription',_Params,@DoSuccess,aOnFailure);
  63. end;
  64. end.