Skip to content

Commit cc40b36

Browse files
committed
fix(media): add guards
1 parent cc2a43c commit cc40b36

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

packages/canvas-media/video/common.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Screen, AddChildFromBuilder, Application, booleanConverter, ContentView, Utils } from '@nativescript/core';
2-
import { Property, CSSType} from '@nativescript/core/ui/core/view';
2+
import { Property, CSSType } from '@nativescript/core/ui/core/view';
33
import { PercentLength } from '@nativescript/core/ui/styling/style-properties';
44

55
@CSSType('Video')
@@ -90,7 +90,7 @@ export abstract class VideoBase extends ContentView implements AddChildFromBuild
9090
}
9191
}
9292
_removeListener(type: string, listener: Function, listeners: any) {
93-
if (listener && typeof listeners === 'object') {
93+
if (listener && listeners && typeof listeners === 'object') {
9494
const currentEvents = listeners[type];
9595
if (Array.isArray(currentEvents)) {
9696
const size = currentEvents.length;
@@ -111,7 +111,7 @@ export abstract class VideoBase extends ContentView implements AddChildFromBuild
111111

112112
_listenerExist(type: string, listener: Function, listeners: any): boolean {
113113
let has = false;
114-
if (listener && typeof listeners === 'object') {
114+
if (listener && listeners && typeof listeners === 'object') {
115115
const currentEvents = listeners[type];
116116
if (Array.isArray(currentEvents)) {
117117
const size = currentEvents.length;
@@ -137,15 +137,15 @@ export abstract class VideoBase extends ContentView implements AddChildFromBuild
137137
if (isCapture) {
138138
if (!this._listenerExist(type, listener, this._capturedListeners)) {
139139
if (Array.isArray(this._capturedListeners[type])) {
140-
this._capturedListeners[type].push(listener);
140+
this._capturedListeners[type]?.push?.(listener);
141141
} else {
142142
this._capturedListeners[type] = [listener];
143143
}
144144
}
145145
} else {
146146
if (!this._listenerExist(type, listener, this._listeners)) {
147147
if (Array.isArray(this._listeners[type])) {
148-
this._listeners[type].push(listener);
148+
this._listeners[type]?.push?.(listener);
149149
} else {
150150
this._listeners[type] = [listener];
151151
}
@@ -163,15 +163,15 @@ export abstract class VideoBase extends ContentView implements AddChildFromBuild
163163
if (isCapture) {
164164
if (!this._listenerExist(type, listener, this._capturedListeners)) {
165165
if (Array.isArray(this._capturedListeners[type])) {
166-
this._capturedListeners[type].push(listener);
166+
this._capturedListeners[type]?.push?.(listener);
167167
} else {
168168
this._capturedListeners[type] = [listener];
169169
}
170170
}
171171
} else {
172172
if (!this._listenerExist(type, listener, this._listeners)) {
173173
if (Array.isArray(this._listeners[type])) {
174-
this._listeners[type].push(listener);
174+
this._listeners[type]?.push?.(listener);
175175
} else {
176176
this._listeners[type] = [listener];
177177
}
@@ -182,7 +182,7 @@ export abstract class VideoBase extends ContentView implements AddChildFromBuild
182182
_videoFrameCallbacks: Function[] = [];
183183
requestVideoFrameCallback(callback: Function) {
184184
if (typeof callback === 'function') {
185-
this._videoFrameCallbacks.push(callback);
185+
this._videoFrameCallbacks?.push?.(callback);
186186
}
187187
}
188188
_notifyVideoFrameCallbacks() {

0 commit comments

Comments
 (0)