ts-sdk

main.ts 990B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import { Client } from '../src/';
  2. import { WebsocketError, WebSocketResp } from '../src/types';
  3. const url = 'ws://127.0.0.1:8081';
  4. const client = Client.getInstance(url, {
  5. onOpen(): void {
  6. client
  7. .ping({})
  8. .then(
  9. (res: WebSocketResp): void => {
  10. console.log('ping sucessful:', res);
  11. },
  12. )
  13. .catch(
  14. (reason: WebsocketError): void => {
  15. console.log('ping error:', reason.code, reason.msg);
  16. },
  17. );
  18. client
  19. .request('/v1/healthy', {})
  20. .then(
  21. (res: WebSocketResp): void => {
  22. console.log('request successful:', res);
  23. },
  24. )
  25. .catch(
  26. (reason: WebsocketError): void => {
  27. console.log('request error:', reason.code, reason.msg);
  28. },
  29. );
  30. },
  31. onClose(ev: Event): void {
  32. console.log('connection error', ev);
  33. console.log(ev);
  34. },
  35. onError(): void {
  36. console.log('close connection');
  37. },
  38. });
  39. client.enableLogger = true;