ts-sdk

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import { Client } from '../src/client';
  2. const url = 'ws://127.0.0.1:8081';
  3. const client = new Client(
  4. url,
  5. new (class {
  6. public onOpen(): void {
  7. client.ping(
  8. {},
  9. new (class {
  10. public onStart(): void {
  11. console.log('start ping');
  12. }
  13. public onSuccess(data: string): void {
  14. console.log('ping successful:', data);
  15. }
  16. public onError(code: number, message: string): void {
  17. console.log('ping error:', message);
  18. }
  19. public onEnd(): void {
  20. console.log('end ping');
  21. }
  22. })(),
  23. );
  24. client.syncSend(
  25. '/v1/healthy',
  26. {},
  27. new (class {
  28. public onStart(): void {
  29. console.log('start request');
  30. }
  31. public onSuccess(data: string): void {
  32. console.log('request successful:', data);
  33. }
  34. public onError(code: number, message: string): void {
  35. console.log('request error:', message);
  36. }
  37. public onEnd(): void {
  38. console.log('end request');
  39. }
  40. })(),
  41. );
  42. }
  43. public onClose(ev: Event): void {
  44. console.log('connection error', ev);
  45. console.log(ev);
  46. }
  47. public onError(): void {
  48. console.log('close connection');
  49. }
  50. })(),
  51. );