DragAndDrop service registers dragover and drop listeners on window to handle files dragged into the browser window. When a .torrent file is dropped, it dispatches a CreateTorrent action to the core streaming server. Subtitle files (application/x-subrip, text/vtt) and empty-type files are accepted but currently produce no action (handled downstream by the player). Unsupported file types emit an 'error' event.
Constructor
The active
Core service instance. DragAndDrop uses core.transport.dispatch() to send the CreateTorrent action to the streaming server.Properties
true when the service has registered its dragover and drop listeners on window. false before start() or after stop().Methods
start()
Registers dragover and drop event listeners on window. Does nothing if already active.
stop()
Removes the dragover and drop event listeners and sets active to false.
on(name, listener) / off(name, listener)
Subscribe to or unsubscribe from service events.
Event name:
'stateChanged' or 'error'.Callback function.
Events
Emitted when
active changes — i.e., after start() or stop().Emitted when a drop cannot be handled. The payload describes the problematic file:
message: 'Failed to process file' — the file was a .torrent (application/x-bittorrent) but arrayBuffer() rejected or core.transport.dispatch() threw.message: 'Unsupported file' — the file’s MIME type is not in the accepted set.Supported MIME types
| MIME type | Behavior |
|---|---|
application/x-bittorrent | Reads the file as an ArrayBuffer, converts to a Uint8Array, and dispatches StreamingServer.CreateTorrent to the core. |
application/x-subrip | Accepted (no-op — handled downstream by the video player). |
text/vtt | Accepted (no-op — handled downstream by the video player). |
'' (empty string) | Accepted (no-op — typically folders or OS-specific virtual files). |
| Any other type | Emits 'error' with message: 'Unsupported file'. |
Core action dispatched
When a torrent file is successfully read, the service dispatches the following action to the core:The
dragover listener calls event.preventDefault() to signal to the browser that the drop target accepts files, which suppresses the browser’s default “open file” behavior.