onCreate method Null safety
override
Implementation
@override
void onCreate() {
if (!_onCreated) {
_onCreated = true;
messages?.listen((event) {
TypedEvent<JanusEvent> typedEvent = TypedEvent<JanusEvent>(
event: JanusEvent.fromJson(event.event), jsep: event.jsep);
if (typedEvent.event.plugindata?.data['videoroom'] == 'joined') {
typedEvent.event.plugindata?.data =
VideoRoomJoinedEvent.fromJson(typedEvent.event.plugindata?.data);
_typedMessagesSink?.add(typedEvent);
} else if (typedEvent.event.plugindata?.data['videoroom'] == 'event' &&
typedEvent.event.plugindata?.data['unpublished'] != null&&typedEvent.event.plugindata?.data['unpublished'] is int) {
typedEvent.event.plugindata?.data =
VideoRoomUnPublishedEvent.fromJson(
typedEvent.event.plugindata?.data);
_typedMessagesSink?.add(typedEvent);
} else if (typedEvent.event.plugindata?.data['videoroom'] ==
'updated' &&
typedEvent.event.plugindata?.data['streams'] != null) {
print('reaching here buddy');
typedEvent.event.plugindata?.data =
VideoRoomUpdatedEvent.fromJson(typedEvent.event.plugindata?.data);
_typedMessagesSink?.add(typedEvent);
} else if (typedEvent.event.plugindata?.data['videoroom'] == 'event' &&
typedEvent.event.plugindata?.data['configured'] == "ok") {
typedEvent.event.plugindata?.data =
VideoRoomConfigured.fromJson(typedEvent.event.plugindata?.data);
_typedMessagesSink?.add(typedEvent);
} else if (typedEvent.event.plugindata?.data['videoroom'] == 'event' &&
typedEvent.event.plugindata?.data['publishers'] != null) {
typedEvent.event.plugindata?.data =
VideoRoomNewPublisherEvent.fromJson(
typedEvent.event.plugindata?.data);
_typedMessagesSink?.add(typedEvent);
} else if (typedEvent.event.plugindata?.data['videoroom'] == 'event' &&
typedEvent.event.plugindata?.data['leaving'] != null &&
typedEvent.event.plugindata?.data['leaving'].runtimeType == int) {
typedEvent.event.plugindata?.data =
VideoRoomLeavingEvent.fromJson(typedEvent.event.plugindata?.data);
_typedMessagesSink?.add(typedEvent);
} else if (typedEvent.event.plugindata?.data['videoroom'] ==
'attached' ||
typedEvent.event.plugindata?.data['streams'] != null) {
typedEvent.event.plugindata?.data = VideoRoomAttachedEvent.fromJson(
typedEvent.event.plugindata?.data);
_typedMessagesSink?.add(typedEvent);
} else if (typedEvent.event.plugindata?.data['videoroom'] == 'event' &&
(typedEvent.event.plugindata?.data['error_code'] != null ||
typedEvent.event.plugindata?.data?['result']?['code'] !=
null)) {
_typedMessagesSink
?.addError(JanusError.fromMap(typedEvent.event.plugindata?.data));
}
});
}
}