2using System.Threading.Tasks;
25 public override string Name =>
"Enter";
34 public override bool AppliesTo(
string CommandLine,
string[] Arguments, out
object Details)
37 int c = Arguments.Length;
38 return c == 2 || c == 3;
52 await ResponseCallback(
"Multi-User Chat disabled.",
string.Empty);
56 ParseRoom(Arguments[0], out
string RoomId, out
string Domain);
58 string NickName = Arguments[1];
59 string Password = Arguments.Length > 2 ? Arguments[2] :
string.Empty;
61 await
Execute(RoomId, Domain, NickName, Password, this.
Permanent,
true, ResponseCallback);
64 internal static Task
Execute(
string RoomId,
string Domain,
string NickName,
string Password,
bool Permanent,
71 StringBuilder sb = new StringBuilder();
74 sb.Append(
"Entered in `");
79 sb.Append(e.NickName);
82 foreach (MucStatus Status in e.MucStatus)
87 sb.Append(
" Status: ");
93 sb.Append(Status.ToString());
100 await ResponseCallback(sb.ToString(),
string.Empty);
103 if (e.Role ==
Role.None || e.Role ==
Role.Visitor)
105 await ResponseCallback(
"Requesting voice privileges...", string.Empty);
106 await Gateway.MucClient.RequestVoice(RoomId, Domain);
109 else if (e.StanzaError is Networking.XMPP.StanzaErrors.RegistrationRequiredException && RegisterIfRequested)
111 await ResponseCallback(
"Room registration required.", string.Empty);
112 await ResponseCallback(
"Requesting registration form...", string.Empty);
114 await Gateway.MucClient.GetRoomRegistrationForm(RoomId, Domain, async (sender2, e2) =>
116 if (e2.Ok && !(e2.Form is null))
118 foreach (Field F in e2.Form.Fields)
122 case
"muc#register_first":
123 string s = IoTGateway.Setup.LegalIdentityConfiguration.Instance.FirstName;
124 if (string.IsNullOrEmpty(s))
130 case
"muc#register_last":
131 s = IoTGateway.Setup.LegalIdentityConfiguration.Instance.LastName;
132 if (string.IsNullOrEmpty(s))
138 case
"muc#register_roomnick":
139 await F.SetValue(NickName);
142 case
"muc#register_url":
143 case
"muc#register_faqentry":
144 await F.SetValue(Gateway.GetUrl(
"/"));
147 case
"muc#register_email":
148 await F.SetValue(Gateway.XmppClient.BareJID);
153 await ResponseCallback(
"Submitting registration form...", string.Empty);
154 await e2.Form.Submit();
156 else if (e2.AlreadyRegistered)
157 await ResponseCallback(
"Already registered with nick name `" + e2.UserName +
"`", string.Empty);
159 await ResponseCallback(string.IsNullOrEmpty(e2.ErrorText) ?
"Unable to get registration form." : e2.ErrorText, string.Empty);
164 return ResponseCallback(
"Room registration submitted. You can enter the room as soon as the request has been approved...", string.Empty);
166 return ResponseCallback(string.IsNullOrEmpty(e2.ErrorText) ?
"Unable to register with room." : e2.ErrorText, string.Empty);
170 await ResponseCallback(
string.IsNullOrEmpty(e.ErrorText) ?
"Unable to enter room." : e.ErrorText,
string.Empty);
173 return Task.CompletedTask;
179 public virtual bool Permanent =>
false;
181 internal static void ParseRoom(
string s, out
string RoomId, out
string Domain)
183 int i = s.IndexOf(
'@');
192 RoomId = s.Substring(0, i);
193 Domain = s.Substring(i + 1);
199 return new HelpItem[] {
new HelpItem(this.Name +
" " + this.ParameterName +
" " + this.Parameter2Name +
"[ PASSWORD]", this.HelpParagraphs) };
205 public override string ParameterName =>
"ROOM";
210 public override string Parameter2Name =>
"NICKNAME";
215 public override string[] HelpParagraphs =>
new string[]
217 "Temporarily enters a Multi-User Chat Room named `ROOM`, using the nick-name `NICKNAME`.",
218 "You can leave the room issuing a `leave` command. The broker also leaves the room when it is restarted.",
219 "An optional `PASSWORD` can be provided to enter password-protected rooms."
Static class managing the runtime environment of the IoT Gateway.
static MultiUserChatClient MucClient
XMPP Multi-User Chat Protocol (MUC) Client.
Task EnterRoom(string RoomId, string Domain, string NickName, EventHandlerAsync< UserPresenceEventArgs > Callback, object State)
Enter a chat room.
string ComponentAddress
Publish/Subscribe component address.
An administrative command taking two parameters.
Contains an item of information about a command.
Asks the broker to enter a room.
override async Task Execute(ChatState State, string[] Arguments, string OrgMessage, ResponseCallbackHandler ResponseCallback)
Executes the command.
override string Name
Command name
Enter()
Asks the broker to enter a room.
override HelpItem[] GetHelp()
Gets help about the command.
override bool AppliesTo(string CommandLine, string[] Arguments, out object Details)
If the command is applicable to the given command line.
virtual bool Permanent
If entering the room permanently (true) or temporarily (false).
Service Module hosting the XMPP broker and its components.
delegate Task< string > ResponseCallbackHandler(string Markdown, string MessageId)
Delegate for response callback handler methods.