.. role:: ts-api-decorator

#############
ServerSession
#############

.. js:module:: cee.vs
   :noindex:

.. container:: ts-api-section

   .. js:class:: ServerSession

      A ServerSession object is the first object that needs to be initialized when working with the ``StreamModel``. 
      It manages the communication with the Visualization Streamer (VizStreamer) service. 

      The ``getAvailableStreams_async`` method is used to get the information about all available streams.
      These streams can be subsequently used to create ``StreamModel`` instance(s) with the method ``createStreamModel``. 

      **Example:** 
       Create a ServerSession and a StreamModel from the first available stream.


      .. code-block:: typescript

         // Connect to the server session at the given url. 
         const serverSession = await cee.vs.ServerSession.createInstance_async("http://localhost:8080");
         // Get the available streams
         const streams = await serverSession.getAvailableStreams_async();

         if (streams[0]) {
             const streamName = streams[0].streamName;
             const streamModel = serverSession.createStreamModel(streamName);

             // Add the model to the cee.View
             this.view.addModel(streamModel);
             // Start the streaming if not already started.
             if (!streamModel.isStreamingActive()) {
                 streamModel.startStreaming();
             }            
         }




.. container:: api-index-section

   .. rubric:: Methods

   .. rst-class:: api-index-list-item api-kind-method api-parent-kind-class

   * :js:meth:`~cee.vs.ServerSession.createStreamModel`
   * :js:meth:`~cee.vs.ServerSession.getAvailableStreams_async`
   * :js:meth:`~cee.vs.ServerSession.getServerUrl`
   * :js:meth:`~cee.vs.ServerSession.createInstance_async`





------------

Methods
=======

.. rst-class:: ts-api-section

createStreamModel
-----------------

.. js:method:: ServerSession.createStreamModel( streamName)

   :param streamName: None
   :type streamName: string


   Creates a new ``StreamModel`` from the given stream name. 
   The streaming is started immediately upon creation.


   :rtype: StreamModel

.. rst-class:: ts-api-section

getAvailableStreams_async
-------------------------

.. js:method:: ServerSession.getAvailableStreams_async()



   Gets the information about all the streams available in the VizStreamer Service. 
   Returns a ``StreamInfo`` array on success, otherwise throws an error (e.g. connection problems).


   :rtype: Promise <[StreamInfo]>

.. rst-class:: ts-api-section

getServerUrl
------------

.. js:method:: ServerSession.getServerUrl()



   Gets the server url.


   :rtype: string

.. rst-class:: ts-api-section

:ts-api-decorator:`static` createInstance_async
-----------------------------------------------

.. js:method:: ServerSession.createInstance_async( serverUrl)

   :param serverUrl: The url on which the Visualization Streamer service resides, e.g. ``http://localhost:8080``
   :type serverUrl: string


   Creates a new ServerSession instance.


   :rtype: Promise <ServerSession>

