2using System.Collections.Generic;
4using System.Threading.Tasks;
38 this.sessions.Removed += this.Sessions_Removed;
58 this.sessions.Dispose();
90 StringBuilder sb =
new StringBuilder();
91 string SessionId = SessionGuid.ToString();
93 sb.Append(
"<start xmlns='");
97 sb.Append(
"</start>");
99 TaskCompletionSource<RemoteDesktopSession> Result =
new TaskCompletionSource<RemoteDesktopSession>();
101 await this.e2e.SendIqSet(this.
client,
E2ETransmission.NormalIfNotE2E, To, sb.ToString(), (Sender, e) =>
105 RemoteDesktopSession Session = new RemoteDesktopSession(SessionId, To, this);
106 this.sessions[SessionId] = Session;
107 Result.TrySetResult(Session);
110 Result.TrySetException(e.StanzaError ??
new Exception(
"Unable to start Remote Desktop Session."));
112 return Task.CompletedTask;
115 return await Result.Task;
131 StringBuilder sb =
new StringBuilder();
133 sb.Append(
"<stop xmlns='");
134 sb.Append(RemoteDesktopNamespace);
136 sb.Append(SessionId);
137 sb.Append(
"</stop>");
142 TaskCompletionSource<bool> Result =
new TaskCompletionSource<bool>();
144 await this.e2e.SendIqSet(this.client,
E2ETransmission.NormalIfNotE2E, To, sb.ToString(), (Sender, e) =>
147 Result.TrySetResult(true);
149 Result.TrySetException(e.StanzaError ?? new Exception(
"Unable to stop Remote Desktop Session."));
151 return Task.CompletedTask;
157 List<ScreenInfo> Screens =
new List<ScreenInfo>();
171 foreach (XmlNode N
in e.
Content.ChildNodes)
173 if (N is XmlElement E && E.LocalName ==
"screen" && E.NamespaceURI == RemoteDesktopNamespace)
176 int BitsPerPixel2 =
XML.
Attribute(E,
"bitsPerPixel", 0);
183 Screens.Add(
new ScreenInfo(Primary, BitsPerPixel2, Left2, Top2, Width2, Height2, DeviceName2));
187 Session.Screens = Screens.ToArray();
191 new KeyValuePair<string, object>(
"RemoteJid", Session.RemoteJid),
192 new KeyValuePair<string, object>(
"SessionId", Session.SessionId));
200 if (!this.sessions.TryGetValue(SessionId, out RemoteDesktopSession Session))
204 this.sessions.Remove(SessionId);
207 new KeyValuePair<string, object>(
"RemoteJid", Session.RemoteJid),
208 new KeyValuePair<string, object>(
"SessionId", Session.SessionId),
209 new KeyValuePair<string, object>(
"Reason", Reason));
214 RemoteDesktopSession Session =
null;
215 string TileBase64 = e.
Content.InnerText;
219 foreach (XmlAttribute Attr
in e.
Content.Attributes)
224 if (!this.sessions.TryGetValue(Attr.Value, out Session))
225 return Task.CompletedTask;
229 if (!
int.TryParse(Attr.Value, out X))
230 return Task.CompletedTask;
234 if (!
int.TryParse(Attr.Value, out Y))
235 return Task.CompletedTask;
240 if (Session is
null || TileBase64 is
null)
241 return Task.CompletedTask;
243 Session.UpdateTile(X, Y, TileBase64);
245 return Task.CompletedTask;
251 if (!this.sessions.TryGetValue(SessionId, out RemoteDesktopSession Session))
252 return Task.CompletedTask;
254 foreach (XmlNode N
in e.
Content.ChildNodes)
256 if (N is XmlElement E && E.LocalName ==
"tile" && E.NamespaceURI == e.
Content.NamespaceURI)
258 string TileBase64 = E.InnerText;
262 foreach (XmlAttribute Attr
in E.Attributes)
267 if (!
int.TryParse(Attr.Value, out X))
272 if (!
int.TryParse(Attr.Value, out Y))
278 Session.UpdateTile(X, Y, TileBase64);
282 return Task.CompletedTask;
288 if (!this.sessions.TryGetValue(SessionId, out RemoteDesktopSession Session))
289 return Task.CompletedTask;
291 return Session.ScanCompleted();
Helps with common XML-related tasks.
static string Attribute(XmlElement E, string Name)
Gets the value of an XML attribute.
Static class managing the application event log. Applications and services log events on this static ...
static void Informational(string Message, string Object, string Actor, string EventId, EventLevel Level, string Facility, string Module, string StackTrace, params KeyValuePair< string, object >[] Tags)
Logs an informational event.
Event arguments for message events.
XmlElement Content
Content of the message. For messages that are processed by registered message handlers,...
Class managing end-to-end encryption.
async Task StopSessionAsync(string To, string SessionId)
Stops a Remote Desktop session.
Task< RemoteDesktopSession > StartSessionAsync(string To)
Starts a Remote Desktop session.
async Task< RemoteDesktopSession > StartSessionAsync(string To, Guid SessionGuid)
Starts a Remote Desktop session.
override void Dispose()
Disposes of the extension.
RemoteDesktopClient(XmppClient Client, EndpointSecurity E2e)
Remote Desktop Client
const string RemoteDesktopNamespace
http://waher.se/rdp/1.0
EndpointSecurity E2E
End-to-end encryption
override string[] Extensions
Implemented extensions.
Maintains the client-side state of a Remote Desktop Session.
Information about a remote screen.
Manages an XMPP client connection. Implements XMPP, as defined in https://tools.ietf....
bool UnregisterMessageHandler(string LocalName, string Namespace, EventHandlerAsync< MessageEventArgs > Handler, bool RemoveNamespaceAsClientFeature)
Unregisters a Message handler.
void RegisterMessageHandler(string LocalName, string Namespace, EventHandlerAsync< MessageEventArgs > Handler, bool PublishNamespaceAsClientFeature)
Registers a Message handler.
Base class for XMPP Extensions.
XmppClient client
XMPP Client used by the extension.
Task Exception(Exception Exception)
Called to inform the viewer of an exception state.
XmppClient Client
XMPP Client.
Implements an in-memory cache.
Event arguments for cache item removal events.
ValueType Value
Value of item that was removed.
RemoteDesktopSessionState
State of a Remote Desktop Session
E2ETransmission
End-to-end encryption mode.