Hub SignalR Hub Overview

ה-SignalR Hub הוא הרכיב המרכזי לתקשורת בזמן אמת בין Client, Server, ו-Agent. כל התקשורת עוברת דרך ה-Hub בכתובת /remotedesktop.

התחברות ל-Hub
// C# Client var connection = new HubConnectionBuilder() .WithUrl("https://localhost:5050/remotedesktop") .WithAutomaticReconnect() .Build(); await connection.StartAsync();
// JavaScript Client const connection = new signalR.HubConnectionBuilder() .withUrl("/remotedesktop") .withAutomaticReconnect() .build(); await connection.start();
Hub RegisterAgent

רישום Agent חדש בשרת. נקרא כאשר Agent מתחבר לראשונה.

פרמטרים
שם טיפוס תיאור
agentInfo AgentInfo מידע על ה-Agent *נדרש
דוגמה
var agentInfo = new AgentInfo { MachineName = Environment.MachineName, OperatingSystem = Environment.OSVersion.ToString(), ScreenWidth = 1920, ScreenHeight = 1080 }; await hubConnection.InvokeAsync("RegisterAgent", agentInfo);
Hub RequestSession

בקשת Client להתחיל session עם Agent ספציפי.

פרמטרים
שם טיפוס תיאור
agentId string מזהה ייחודי של ה-Agent *נדרש
ערך מוחזר
טיפוס תיאור
SessionInfo? מידע על ה-Session שנוצר, או null אם נכשל
var session = await hubConnection .InvokeAsync<SessionInfo>("RequestSession", agentId); if (session != null) { Console.WriteLine($"Session started: {session.SessionId}"); }
Hub SendFrame

שליחת פריים מסך מ-Agent ל-Client.

פרמטרים
שם טיפוס תיאור
sessionId string מזהה ה-Session *נדרש
frameData byte[] נתוני הפריים (JPEG/H.264) *נדרש
width int רוחב הפריים בפיקסלים *נדרש
height int גובה הפריים בפיקסלים *נדרש
הגבלת גודל: מקסימום 10MB לפריים. פריימים גדולים יותר יידחו.
await hubConnection.InvokeAsync( "SendFrame", sessionId, jpegBytes, 1920, 1080 );
Hub SendInput

שליחת פקודת קלט (עכבר/מקלדת) מ-Client ל-Agent.

פרמטרים
שם טיפוס תיאור
sessionId string מזהה ה-Session *נדרש
command InputCommand פקודת הקלט *נדרש
Rate Limiting: מוגבל ל-1000 פקודות לשנייה למניעת abuse.
// Mouse Click var clickCommand = new InputCommand { Type = InputType.MouseClick, X = 0.5, // Normalized (0-1) Y = 0.5, Button = MouseButton.Left }; await hubConnection.InvokeAsync("SendInput", sessionId, clickCommand); // Keyboard - Hebrew Text var keyCommand = new InputCommand { Type = InputType.KeyPress, UnicodeChar = 'ש' // Hebrew character }; await hubConnection.InvokeAsync("SendInput", sessionId, keyCommand);
Hub EndSession

סיום session פעיל. יכול להיקרא על ידי Client או Agent.

פרמטרים
שם טיפוס תיאור
sessionId string מזהה ה-Session לסיום *נדרש
await hubConnection.InvokeAsync("EndSession", sessionId);

Client Callbacks

Callback ReceiveFrame

קבלת פריים מסך מה-Agent. נקרא אוטומטית על ידי ה-Hub.

פרמטרים
שם טיפוס תיאור
frameData byte[] נתוני הפריים המקודדים
width int רוחב הפריים
height int גובה הפריים
connection.On<byte[], int, int>("ReceiveFrame", (frameData, width, height) => { // Decode and display frame using var stream = new MemoryStream(frameData); var bitmap = new BitmapImage(); bitmap.BeginInit(); bitmap.StreamSource = stream; bitmap.CacheOption = BitmapCacheOption.OnLoad; bitmap.EndInit(); bitmap.Freeze(); DisplayImage.Source = bitmap; });
Callback StartStreaming

הוראה ל-Agent להתחיל שידור מסך. נקרא כאשר Client מבקש session.

פרמטרים
שם טיפוס תיאור
sessionId string מזהה ה-Session החדש
clientId string מזהה ה-Client המבקש
connection.On<string, string>("StartStreaming", async (sessionId, clientId) => { _currentSessionId = sessionId; _isStreaming = true; // Start capture loop await StartCaptureLoopAsync(); });
Callback StopStreaming

הוראה ל-Agent להפסיק שידור מסך.

connection.On("StopStreaming", () => { _isStreaming = false; _currentSessionId = null; });
Callback ReceiveInput

קבלת פקודת קלט מ-Client. נקרא על ה-Agent.

connection.On<InputCommand>("ReceiveInput", (command) => { _inputService.InjectInput(command); });

Data Models

Model AgentInfo

מידע על Agent - מחשב מרוחק שניתן לשלוט בו.

public class AgentInfo { public string Id { get; set; } public string MachineName { get; set; } public string OperatingSystem { get; set; } public int ScreenWidth { get; set; } public int ScreenHeight { get; set; } public bool IsAvailable { get; set; } public DateTime ConnectedAt { get; set; } }
Model SessionInfo

מידע על Session פעיל בין Client ל-Agent.

public class SessionInfo { public string SessionId { get; set; } public string AgentId { get; set; } public string ClientId { get; set; } public DateTime StartedAt { get; set; } public bool IsActive { get; set; } }
Model InputCommand

פקודת קלט - עכבר או מקלדת.

public class InputCommand { public InputType Type { get; set; } // Mouse public double X { get; set; } // 0.0 - 1.0 public double Y { get; set; } // 0.0 - 1.0 public MouseButton Button { get; set; } public int ScrollDelta { get; set; } // Keyboard public int KeyCode { get; set; } public char UnicodeChar { get; set; } // Hebrew support public bool IsKeyDown { get; set; } public ModifierKeys Modifiers { get; set; } } public enum InputType { MouseMove, MouseClick, MouseDoubleClick, MouseScroll, KeyPress, KeyDown, KeyUp }
Model ScreenFrame

פריים מסך עם metadata.

public class ScreenFrame { public byte[] Data { get; set; } public int Width { get; set; } public int Height { get; set; } public FrameFormat Format { get; set; } public long Timestamp { get; set; } public int FrameNumber { get; set; } } public enum FrameFormat { Jpeg, H264, VP8 }