| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- import 'dart:convert';
- import 'package:get/get.dart';
- class Player {
- double currentTime = 0;
- double seekTime = -1;
- String master;
- int songId;
- bool playing = false;
- List<int> queue = [];
- }
- class Client {
- String name;
- int lastPing;
- Client(String name, int lastPing) {
- this.name = name;
- this.lastPing = lastPing;
- }
- }
- class Controller extends GetxController {
- var name = ''.obs;
- var uniqueName = ''.obs;
- Rx<Player> player = new Player().obs;
- RxList<Client> clients = [].obs;
- setName(String newName) {
- name.value = newName;
- }
- setUniqueName(String newUniqueName) {
- uniqueName.value = newUniqueName;
- }
- onRemoteMessage(String message) {
- var action = jsonDecode(message);
- switch (action['type']) {
- case 'CLIENT_LIST_UPDATED':
- print("Client list updated: ${action['payload']}");
- var payload = action['payload'];
- List<Client> clientList = [];
- for (var i = 0; i < payload.length; i++) {
- clientList.add(new Client(
- payload[i].name,
- payload[i].lastPing,
- ));
- }
- this.clients = clientList.obs;
- break;
- case 'STATE_SET':
- Player nextPlayer = new Player();
- nextPlayer.currentTime = action['payload']['currentTime'];
- nextPlayer.seekTime = action['payload']['seekTime'];
- nextPlayer.master = action['payload']['queue'];
- nextPlayer.songId = action['payload']['songId'];
- nextPlayer.playing = action['payload']['playing'];
- nextPlayer.queue = [];
- for (var i = 0; i < action['payload']['queue'].length; i++) {
- nextPlayer.queue.add(action['payload']['queue'][i]);
- }
- this.player.value = nextPlayer;
- break;
- }
- }
- }
|