@@ -5,6 +5,8 @@ use std::str::FromStr;
55 Debug , PartialEq , PartialOrd , Ord , Eq , Hash , Clone , serde:: Deserialize , serde:: Serialize ,
66) ]
77pub enum BsLiveBuiltInTask {
8+ #[ serde( rename = "notify-clients" ) ]
9+ NotifyClients ( ClientNotification ) ,
810 #[ serde( rename = "notify-server" ) ]
911 NotifyServer ,
1012 #[ serde( rename = "ext-event" ) ]
@@ -14,10 +16,18 @@ pub enum BsLiveBuiltInTask {
1416impl FromStr for BsLiveBuiltInTask {
1517 type Err = anyhow:: Error ;
1618 fn from_str ( s : & str ) -> Result < Self , Self :: Err > {
17- match s {
18- "notify-server" => Ok ( Self :: NotifyServer ) ,
19- "ext-event" => Ok ( Self :: PublishExternalEvent ) ,
20- _ => Err ( anyhow:: anyhow!( "not a valid bslive builtin task" ) ) ,
19+ match s. split_once ( ":" ) {
20+ Some ( ( "notify-clients" , message) ) => Ok ( Self :: NotifyClients (
21+ ClientNotification :: DisplayMessage ( DisplayMessage {
22+ message : message. to_owned ( ) ,
23+ reason : None ,
24+ } ) ,
25+ ) ) ,
26+ _ => match s {
27+ "notify-server" => Ok ( Self :: NotifyServer ) ,
28+ "ext-event" => Ok ( Self :: PublishExternalEvent ) ,
29+ _ => Err ( anyhow:: anyhow!( "not a valid bslive builtin task" ) ) ,
30+ } ,
2131 }
2232 }
2333}
@@ -26,9 +36,25 @@ impl Display for BsLiveBuiltInTask {
2636 fn fmt ( & self , f : & mut Formatter < ' _ > ) -> std:: fmt:: Result {
2737 match self {
2838 BsLiveBuiltInTask :: NotifyServer => write ! ( f, "BsLiveTask::NotifyServer" ) ,
39+ BsLiveBuiltInTask :: NotifyClients ( ..) => write ! ( f, "BsLiveTask::NotifyClients" ) ,
2940 BsLiveBuiltInTask :: PublishExternalEvent => {
3041 write ! ( f, "BsLiveTask::PublishExternalEvent" )
3142 }
3243 }
3344 }
3445}
46+
47+ #[ derive(
48+ Debug , PartialEq , PartialOrd , Ord , Eq , Hash , Clone , serde:: Deserialize , serde:: Serialize ,
49+ ) ]
50+ pub enum ClientNotification {
51+ DisplayMessage ( DisplayMessage ) ,
52+ }
53+
54+ #[ derive(
55+ Debug , PartialEq , PartialOrd , Ord , Eq , Hash , Clone , serde:: Deserialize , serde:: Serialize ,
56+ ) ]
57+ pub struct DisplayMessage {
58+ pub message : String ,
59+ pub reason : Option < String > ,
60+ }
0 commit comments