parseIncomingDirectorResponse method Null safety
- MillicastDirectorResponse directorResponse
Modifies domain of subscriber/publisher Director reponses with liveWebSocketDomain value.
Recieves a directorResponse
and parses it's urls.
Then it modifies their domain with the liveWebSocketDomain value.
import 'package:millicast_flutter_sdk/src/director.dart';
void main() {
Director.setLiveDomain('custom-live-domain.millicast.com/');
var response = MillicastDirectorResponse(jwt: 'validToken', urls: [
'wss://default-live-domain.com'
'/ws/v/sub/abf4edb5833a463d87c3f23ae891d3ed'
]);
var parsedResponse = Director.parseIncomingDirectorResponse(response);
}
Implementation
static MillicastDirectorResponse parseIncomingDirectorResponse(
MillicastDirectorResponse directorResponse) {
if (liveWebSocketDomain.isNotEmpty) {
var matchDomain = RegExp(r'//(.*?)/');
for (String item in directorResponse.urls) {
RegExpMatch matched = matchDomain.allMatches(item).first;
int index = directorResponse.urls.indexOf(item);
if (matched.group(1) != null) {
item = item.replaceAll(
RegExp(matched.group(1) as String), Director.getLiveDomain());
}
directorResponse.urls[index] = item;
}
}
return directorResponse;
}