getUrl method
Implementation
Future<String> getUrl(String? mediaId) async {
if (mediaId == null) return throw "Media Id is empty";
Logs.debug(mediaId);
// 1. Check memory cache
final cached = MediaCache.get(mediaId);
if (cached != null) return cached;
// 2. Ask socket
final completer = Completer<String>();
socket.emitWithAck(
"decodeMedia",
{"mediaId": mediaId},
ack: (response) {
if (response == null) {
completer.completeError("Invalid response");
} else {
final url = response;
MediaCache.set(mediaId, url); // cache it
completer.complete(url);
}
},
);
return completer.future.timeout(
const Duration(seconds: 60),
onTimeout: () => throw Exception("Socket request timed out"),
);
}