setMessageChannel static method
void
setMessageChannel()
Implementation
static void setMessageChannel() {
channel = channel ?? const BasicMessageChannel("plotlineMessageChannel", JSONMessageCodec());
channel?.setMessageHandler((message) async {
Map<String, dynamic> messageMap = message;
plotlineDebugLog("Plotline Basic Message Channel: message received $message");
switch (messageMap["method"]) {
case "getAllElements":
double pixRatio = double.parse(messageMap["pixelRatio"].toString());
getAllElements(messageMap["listenerId"], pixRatio,
messageMap["screenWidth"], messageMap["screenHeight"]);
break;
case "areViewsPresent":
double pixRatio = double.parse(messageMap["pixelRatio"].toString());
areViewsPresent(
messageMap["listenerId"],
messageMap["searchElements"],
pixRatio,
messageMap["screenWidth"],
messageMap["screenHeight"]);
break;
case "getViewPosition":
double pixRatio = double.parse(messageMap["pixelRatio"].toString());
getViewPosition(
messageMap["listenerId"],
messageMap["clientElementId"],
pixRatio,
messageMap["screenWidth"],
messageMap["screenHeight"]);
break;
case "getReplayMaskRects":
try {
double pixRatio = double.parse(messageMap["pixelRatio"].toString());
plotlineChannel.invokeMethod('getReplayMaskRects', <String, dynamic>{
"listenerId": messageMap["listenerId"],
"rects": collectReplayMaskRects(pixRatio, types: Set<String>.from(messageMap["autoMaskedViews"] ?? const [])),
});
} catch (e) {
plotlineDebugLog("Error in getReplayMaskRects: $e");
}
break;
case "setPlotlineEventsListener":
try {
_callback(messageMap["eventName"], messageMap["properties"]);
} catch (e) {
plotlineDebugLog("Error in passing Plotline Events: $e");
}
break;
case "setPlotlineRedirectListener":
try {
_redirectCallback(messageMap["properties"]);
} catch (e) {
plotlineDebugLog("Error in passing Plotline Redirect Listener: $e");
}
break;
case "setTrackedElements":
try {
final ids = messageMap["elementIds"];
if (ids is List) {
_trackedKeys = ids.map((e) => e.toString()).toSet();
_gatingActive = true;
_trackVersion.value++;
if (shouldEnableDebug) {
// Detectors attach a frame later, so the query that follows can still miss.
plotlineDebugLog(
"PlotlineDebug: setTrackedElements -> $_trackedKeys "
"at ${DateTime.now().toIso8601String()} (PViews will now rebuild)");
}
}
} catch (e) {
plotlineDebugLog("Error in setTrackedElements: $e");
}
break;
case "setTrackAllElements":
try {
_trackAll = messageMap["trackAll"] == true;
_trackVersion.value++;
} catch (e) {
plotlineDebugLog("Error in setTrackAllElements: $e");
}
break;
case "initSuccessfulCallback":
try {
_initSuccessfulCallback();
} catch(e) {
plotlineDebugLog("Error in passing initSuccessfulCallback: $e");
}
break;
case "initFailureCallback":
try {
_initFailureCallback(messageMap["error"]);
} catch(e) {
plotlineDebugLog("Error in passing initSuccessfulCallback: $e");
}
break;
}
});
}