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. onOpen(ev: Event) {
  7. client.ping(
  8. {},
  9. new (class {
  10. onStart(): void {
  11. console.log('start ping');
  12. }
  13. onSuccess(data: string): void {
  14. console.log('ping successful:', data);
  15. }
  16. onError(code: number, message: string): void {
  17. console.log('ping error:', message);
  18. }
  19. onEnd(): void {
  20. console.log('end ping');
  21. }
  22. })(),
  23. );
  24. client.syncSend(
  25. '/v1/healthy',
  26. {},
  27. new (class {
  28. onStart(): void {
  29. console.log('start request');
  30. }
  31. onSuccess(data: string): void {
  32. console.log('request successful:', data);
  33. }
  34. onError(code: number, message: string): void {
  35. console.log('request error:', message);
  36. }
  37. onEnd(): void {
  38. console.log('end request');
  39. }
  40. })(),
  41. );
  42. }
  43. onClose(ev: Event) {
  44. console.log('connection error', ev);
  45. console.log(ev);
  46. }
  47. onError(ev: Event) {
  48. console.log('close connection');
  49. }
  50. })(),
  51. );