sk-eventsource-polyfill
v1.0.6
Published
Server Sent Event SSE -also known as EventSource- handler
Downloads
30
Maintainers
Readme
��#� �s�k�-�e�v�e�n�t�s�o�u�r�c�e�-�p�o�l�y�f�i�l�l�
�
�
�
�T�h�i�s� �l�i�b�r�a�r�y� �p�r�o�v�i�d�e�s� �a� �c�o�n�v�e�n�i�e�n�t� �w�a�y� �t�o� �h�a�n�d�l�e� �S�e�r�v�e�r�-�S�e�n�t� �E�v�e�n�t�s� �(�S�S�E�)� �w�i�t�h� �o�p�t�i�o�n�s� �t�o� �c�u�s�t�o�m�i�z�e� �H�T�T�P� �m�e�t�h�o�d�s�,� �r�e�q�u�e�s�t� �b�o�d�i�e�s�,� �h�e�a�d�e�r�s�,� �a�n�d� �e�v�e�n�t� �h�a�n�d�l�e�r�s�.�
�
�
�
�#�#� �I�n�s�t�a�l�l�a�t�i�o�n�
�
�
�
����b�a�s�h�
�
�n�p�m� �i�n�s�t�a�l�l� �s�k�-�e�v�e�n�t�s�o�u�r�c�e�-�p�o�l�y�f�i�l�l�
�
����
�
�
�
�#�#� �E�x�p�o�r�t�s�
�
�
�
�#�#�#� �T�y�p�e�s�
�
�-� ��I�S�S�E�O�p�t�i�o�n��:� �I�n�t�e�r�f�a�c�e� �f�o�r� �S�S�E� �o�p�t�i�o�n�s�.�
�
�-� ��T�E�v�e�n�t�H�a�n�d�l�e�r�s��:� �T�y�p�e� �f�o�r� �e�v�e�n�t� �h�a�n�d�l�e�r� �f�u�n�c�t�i�o�n�s�.�
�
�-� ��T�M�e�t�h�o�d��:� �H�T�T�P� �m�e�t�h�o�d�s� �(��G�E�T��,� ��P�O�S�T��,� ��P�U�T��,� ��D�E�L�E�T�E��)�.�
�
�
�
�#�#�#� �F�u�n�c�t�i�o�n�s�
�
�-� ��f�e�t�c�h�S�t�r�e�a�m�(�u�r�l�:� �s�t�r�i�n�g�,� �o�p�t�i�o�n�s�:� �I�S�S�E�O�p�t�i�o�n�)�:� �P�r�o�m�i�s�e�<�v�o�i�d�>�� � �
�
� � �E�s�t�a�b�l�i�s�h�e�s� �a�n� �S�S�E� �c�o�n�n�e�c�t�i�o�n� �t�o� �t�h�e� �s�p�e�c�i�f�i�e�d� �U�R�L�.�
�
�
�
�
�
�#�#� �A�P�I� �R�e�f�e�r�e�n�c�e�
�
�
�
�#�#�#� ��f�e�t�c�h�S�t�r�e�a�m��
�
�
�
����t�y�p�e�s�c�r�i�p�t�
�
�f�e�t�c�h�S�t�r�e�a�m�(�u�r�l�:� �s�t�r�i�n�g�,� �o�p�t�i�o�n�s�:� �I�S�S�E�O�p�t�i�o�n�)�:� �P�r�o�m�i�s�e�<�v�o�i�d�>�
�
����
�
�
�
�#�#�#�#� �P�a�r�a�m�e�t�e�r�s�
�
�
�
�-� ��u�r�l��:� ��s�t�r�i�n�g�� � �
�
� � �T�h�e� �U�R�L� �t�o� �c�o�n�n�e�c�t� �t�o�.�
�
�
�
�-� ��o�p�t�i�o�n�s��:� ��I�S�S�E�O�p�t�i�o�n�� � �
�
� � �C�o�n�f�i�g�u�r�a�t�i�o�n� �o�b�j�e�c�t�:�
�
� � �-� ��m�e�t�h�o�d��:� ��G�E�T� �|� �P�O�S�T�� � �
�
� � � � �H�T�T�P� �m�e�t�h�o�d� �t�o� �u�s�e� �(�d�e�f�a�u�l�t�:� ��G�E�T��)�.�
�
� � �-� ��o�n�O�p�e�n��:� ��(�)� �=�>� �v�o�i�d�� � �
�
� � � � �C�a�l�l�b�a�c�k� �f�o�r� �w�h�e�n� �t�h�e� �c�o�n�n�e�c�t�i�o�n� �i�s� �s�u�c�c�e�s�s�f�u�l�l�y� �o�p�e�n�e�d�.�
�
� � �-� ��o�n�E�n�d��:� ��(�)� �=�>� �v�o�i�d�� � �
�
� � � � �C�a�l�l�b�a�c�k� �f�o�r� �w�h�e�n� �t�h�e� �c�o�n�n�e�c�t�i�o�n� �i�s� �c�l�o�s�e�d�.�
�
� � �-� ��e�v�e�n�t�H�a�n�d�l�e�r�s��:� ��{� �[�e�v�e�n�t�:� �s�t�r�i�n�g�]�:� �(�d�a�t�a�:� �s�t�r�i�n�g�)� �=�>� �v�o�i�d� �}�� � �
�
� � � � �H�a�n�d�l�e�r�s� �f�o�r� �s�p�e�c�i�f�i�c� �e�v�e�n�t�s�.�
�
� � �-� ��o�n�E�r�r�o�r��:� ��(�e�r�r�o�r�:� �E�r�r�o�r�)� �=�>� �v�o�i�d�� � �
�
� � � � �C�a�l�l�b�a�c�k� �f�o�r� �e�r�r�o�r�s� �d�u�r�i�n�g� �t�h�e� �c�o�n�n�e�c�t�i�o�n�.�
�
� � �-� ��b�o�d�y��:� ��o�b�j�e�c�t�� � �
�
� � � � �D�a�t�a� �t�o� �s�e�n�d� �w�i�t�h� �t�h�e� �r�e�q�u�e�s�t� �(�f�o�r� ��P�O�S�T��)�.�
�
� � �-� ��h�e�a�d�e�r�s��:� ��{� �[�k�e�y�:� �s�t�r�i�n�g�]�:� �s�t�r�i�n�g� �}�� � �
�
� � � � �A�d�d�i�t�i�o�n�a�l� �h�e�a�d�e�r�s� �f�o�r� �t�h�e� �r�e�q�u�e�s�t�.�
�
� � �-� ��k�e�e�p�A�l�i�v�e��:� ��b�o�o�l�e�a�n�� � �
�
� � � � �R�e�c�o�n�n�e�c�t� �a�u�t�o�m�a�t�i�c�a�l�l�y� �o�n� �e�r�r�o�r�s� �(�d�e�f�a�u�l�t�:� ��f�a�l�s�e��)�.�
�
� � �-� ��r�e�t�r�y�T�i�m�e�o�u�t��:� ��n�u�m�b�e�r�� � �
�
� � � � �T�i�m�e� �(�i�n� �m�s�)� �t�o� �w�a�i�t� �b�e�f�o�r�e� �r�e�c�o�n�n�e�c�t�i�n�g� �(�d�e�f�a�u�l�t�:� ��5�0�0�0��)�.�
�
� � �-� ��a�b�o�r�t�C�o�n�t�r�o�l�l�e�r��:� ��A�b�o�r�t�C�o�n�t�r�o�l�l�e�r�� � �
�
� � � � �O�p�t�i�o�n�a�l� �c�o�n�t�r�o�l�l�e�r� �t�o� �c�a�n�c�e�l� �t�h�e� �r�e�q�u�e�s�t�.�
�
�
�
�#�#�#�#� �S�t�r�e�a�m� �C�h�u�n�k�s�
�
�
�
�E�a�c�h� �s�t�r�e�a�m� �c�h�u�n�k� �c�o�n�s�i�s�t�s� �o�f� �t�w�o� �l�i�n�e�s� �a�t� �l�e�a�s�t�:�
�
�
�
�-� ��e�v�e�n�t��:� �T�h�e� �n�a�m�e� �o�f� �t�h�e� �e�v�e�n�t�.� � �
�
� � �D�e�f�a�u�l�t� �v�a�l�u�e� �i�s� ��s�t�r�e�a�m��.�
�
�-� ��d�a�t�a��:� �T�h�e� �d�a�t�a� �s�t�r�i�n�g� �a�s�s�o�c�i�a�t�e�d� �w�i�t�h� �t�h�e� �e�v�e�n�t�.�
�
�
�
�#�#�#�#� �U�s�a�g�e� �E�x�a�m�p�l�e�
�
�
�
����j�a�v�a�s�c�r�i�p�t�
�
�i�m�p�o�r�t� �{� �f�e�t�c�h�S�t�r�e�a�m� �}� �f�r�o�m� �'�s�k�-�e�v�e�n�t�s�o�u�r�c�e�-�p�o�l�y�f�i�l�l�'�;�
�
�
�
�c�o�n�s�t� �e�v�e�n�t�H�a�n�d�l�e�r�s� �=� �{�
�
� � �s�t�r�e�a�m�:� �(�d�a�t�a�)� �=�>� �c�o�n�s�o�l�e�.�l�o�g�(�'�s�t�r�e�a�m�:�'�,� �d�a�t�a�)�,�
�
�}�;�
�
�
�
�f�e�t�c�h�S�t�r�e�a�m�(�'�h�t�t�p�s�:�/�/�e�x�a�m�p�l�e�.�c�o�m�/�e�v�e�n�t�s�'�,� �{�
�
� � �m�e�t�h�o�d�:� �'�G�E�T�'�,�
�
� � �o�n�O�p�e�n�:� �(�)� �=�>� �c�o�n�s�o�l�e�.�l�o�g�(�'�C�o�n�n�e�c�t�i�o�n� �o�p�e�n�e�d�'�)�,�
�
� � �o�n�E�n�d�:� �(�)� �=�>� �c�o�n�s�o�l�e�.�l�o�g�(�'�C�o�n�n�e�c�t�i�o�n� �c�l�o�s�e�d�'�)�,�
�
� � �o�n�E�r�r�o�r�:� �(�e�r�r�o�r�)� �=�>� �c�o�n�s�o�l�e�.�e�r�r�o�r�(�'�E�r�r�o�r�:�'�,� �e�r�r�o�r�)�,�
�
� � �e�v�e�n�t�H�a�n�d�l�e�r�s�,�
�
�}�)�;�
�
����
