gergle/lib/api/commands.dart

163 lines
2.8 KiB
Dart
Raw Permalink Normal View History

2024-12-15 00:52:28 +01:00
import 'dart:convert';
sealed class PlayerConnectionEvent {}
2024-12-15 00:52:28 +01:00
class Connect extends PlayerConnectionEvent {
2024-12-15 00:52:28 +01:00
final String uri;
Connect(this.uri);
}
class Disconnect extends PlayerConnectionEvent {}
2024-12-15 00:52:28 +01:00
class Command extends PlayerConnectionEvent {
2024-12-15 00:52:28 +01:00
final String type;
final Map<String, dynamic> value;
Command({
required this.type,
required this.value,
});
factory Command.fromJson(Map<String, dynamic> json) {
return Command(
type: json['type'],
value: json['value'],
);
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> result = Map.from(value);
result['type'] = type;
return result;
}
String toJsonString() {
return jsonEncode(toJson());
}
// factory Command.subscribe(String property) {
// return Command(
// type: 'subscribe',
// value: {
// 'property': property,
// },
// );
// }
// factory Command.unsubscribeAll() {
// return Command(
// type: 'unsubscribe_all',
// value: {},
// );
// }
2024-12-15 00:52:28 +01:00
factory Command.load(List<String> urls) {
2024-12-15 00:52:28 +01:00
return Command(
type: 'load',
value: {
'urls': urls,
2024-12-15 00:52:28 +01:00
},
);
}
factory Command.togglePlayback() {
return Command(
type: 'toggle_playback',
value: {},
);
}
factory Command.volume(double volume) {
return Command(
type: 'volume',
value: {
'volume': volume,
},
);
}
factory Command.time(double time) {
return Command(
type: 'time',
value: {
'time': time,
},
);
}
factory Command.playlistNext() {
return Command(
type: 'playlist_next',
value: {},
);
}
factory Command.playlistPrevious() {
return Command(
type: 'playlist_previous',
value: {},
);
}
factory Command.playlistGoto(int position) {
return Command(
type: 'playlist_goto',
value: {
'position': position,
},
);
}
factory Command.playlistClear() {
return Command(
type: 'playlist_clear',
value: {},
);
}
factory Command.playlistRemove(List<int> positions) {
2024-12-15 00:52:28 +01:00
return Command(
type: 'playlist_remove',
value: {
'positions': positions,
2024-12-15 00:52:28 +01:00
},
);
}
factory Command.playlistMove(int from, int to) {
return Command(
type: 'playlist_move',
value: {
'from': from,
'to': to,
},
);
}
factory Command.shuffle() {
return Command(
type: 'shuffle',
value: {},
);
}
2024-12-23 13:09:04 +01:00
factory Command.setSubtitleTrack(int? track) {
return Command(
type: 'set_subtitle_track',
value: {
'track': track,
},
);
}
2024-12-15 00:52:28 +01:00
factory Command.setLooping(bool value) {
return Command(
type: 'set_looping',
value: {
'value': value,
},
);
}
2024-12-19 12:26:28 +01:00
}