Hello @triniwiz, we would like to use your @triniwiz/nativescript-sse plugin (that is not released yet) as an EventSource counterpart in our app. To achieve this we made these changes.
addEventListener, and removeEventListener methods were empty in the "index.android.ts". they had some code in "index.ios.ts" but it was just to handle custom events and trigger onMessage. there is no need to do anything on android to get these custom events as they trigger onMessage automatically.
It was not possible to attach event handlers on both platforms; listener methods didn't contain a parameter to pass a handler.
_eventListeners object is added to store the added listeners' handlers by event name. addEventListener, and removeEventListener methods are updated to be used for managing the listeners for custom, or standard events (open, close, error, message). And now the plugin will call the added listeners' handlers when a relevant event is received as in the EventSource.
removeEventListener was suspending (stop calling onMessage when a custom event is received) the event completely (on iOS) which called for. now it only suspends when all the event listeners are removed for that event.
this._es.onCompleteBridged replaced by this._es.onComplete on "index.ios.ts" to fix (TypeError: this._es.onCompleteBridged is not a function)
Hello @triniwiz, we would like to use your @triniwiz/nativescript-sse plugin (that is not released yet) as an EventSource counterpart in our app. To achieve this we made these changes.
addEventListener
, andremoveEventListener
methods were empty in the "index.android.ts". they had some code in "index.ios.ts" but it was just to handle custom events and triggeronMessage
. there is no need to do anything on android to get these custom events as they trigger onMessage automatically. It was not possible to attach event handlers on both platforms; listener methods didn't contain a parameter to pass a handler._eventListeners
object is added to store the added listeners' handlers by event name.addEventListener
, andremoveEventListener
methods are updated to be used for managing the listeners for custom, or standard events (open, close, error, message). And now the plugin will call the added listeners' handlers when a relevant event is received as in the EventSource.removeEventListener
was suspending (stop callingonMessage
when a custom event is received) the event completely (on iOS) which called for. now it only suspends when all the event listeners are removed for that event.this._es.onCompleteBridged
replaced bythis._es.onComplete
on "index.ios.ts" to fix (TypeError: this._es.onCompleteBridged is not a function)