github.com/cloudreve/Cloudreve/v3@v3.0.0-20240224133659-3edb00a6484c/pkg/aria2/rpc/notification.go (about) 1 package rpc 2 3 import ( 4 "log" 5 ) 6 7 type Event struct { 8 Gid string `json:"gid"` // GID of the download 9 } 10 11 // The RPC server might send notifications to the client. 12 // Notifications is unidirectional, therefore the client which receives the notification must not respond to it. 13 // The method signature of a notification is much like a normal method request but lacks the id key 14 15 type websocketResponse struct { 16 clientResponse 17 Method string `json:"method"` 18 Params []Event `json:"params"` 19 } 20 21 // Notifier handles rpc notification from aria2 server 22 type Notifier interface { 23 // OnDownloadStart will be sent when a download is started. 24 OnDownloadStart([]Event) 25 // OnDownloadPause will be sent when a download is paused. 26 OnDownloadPause([]Event) 27 // OnDownloadStop will be sent when a download is stopped by the user. 28 OnDownloadStop([]Event) 29 // OnDownloadComplete will be sent when a download is complete. For BitTorrent downloads, this notification is sent when the download is complete and seeding is over. 30 OnDownloadComplete([]Event) 31 // OnDownloadError will be sent when a download is stopped due to an error. 32 OnDownloadError([]Event) 33 // OnBtDownloadComplete will be sent when a torrent download is complete but seeding is still going on. 34 OnBtDownloadComplete([]Event) 35 } 36 37 type DummyNotifier struct{} 38 39 func (DummyNotifier) OnDownloadStart(events []Event) { log.Printf("%s started.", events) } 40 func (DummyNotifier) OnDownloadPause(events []Event) { log.Printf("%s paused.", events) } 41 func (DummyNotifier) OnDownloadStop(events []Event) { log.Printf("%s stopped.", events) } 42 func (DummyNotifier) OnDownloadComplete(events []Event) { log.Printf("%s completed.", events) } 43 func (DummyNotifier) OnDownloadError(events []Event) { log.Printf("%s error.", events) } 44 func (DummyNotifier) OnBtDownloadComplete(events []Event) { log.Printf("bt %s completed.", events) }