Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

state.client-service.ts 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import { RPCSocket } from "../../../../node_modules/rpclibrary/js/Index";
  2. import { CanvasState, Point, Stroke } from "../../model/canvas-state";
  3. import { StrokeStreamElement } from "../../model/rpc-callbacks";
  4. import { ClientDrawService } from "../draw/draw.client-service";
  5. export class ClientStateService {
  6. private remoteService: any
  7. private canvasState: CanvasState = { strokes: [] }
  8. async connect(drawService: ClientDrawService) {
  9. const sock = await new RPCSocket(8080, '95.216.156.135').connect();
  10. this.remoteService = sock['StateService']
  11. this.canvasState = await this.getState()
  12. await this.remoteService.onStroke((s: StrokeStreamElement) => {
  13. if(!this.canvasState.strokes[s.strokeId]){
  14. this.canvasState.strokes[s.strokeId] = s.stroke
  15. }else{
  16. this.canvasState.strokes[s.strokeId].points = [...this.canvasState.strokes[s.strokeId].points, ...s.stroke.points]
  17. }
  18. drawService.draw()
  19. })
  20. drawService.draw()
  21. }
  22. getState = async () => {
  23. return await this.remoteService.getState()
  24. }
  25. beginStroke = async (stroke: Stroke) => {
  26. return await this.remoteService.beginStroke(stroke)
  27. }
  28. addPoint = async (strokeId: number, point: Point) => {
  29. return this.remoteService.addPoint(strokeId, point)
  30. }
  31. getStrokes() {
  32. return this.canvasState?.strokes ?? []
  33. }
  34. }