Class Connection
- java.lang.Object
-
- com.openinventor.inventor.Inventor
-
- com.openinventor.remoteviz.rendering.Connection
-
public class Connection extends Inventor
Represents a connection from aClient
to aRenderArea
managed by the RemoteViz service. AConnection
object is created automatically by RemoteViz when a client connects to the service. Each connection belongs to a singleClient
and a singleRenderArea
. EachClient
may have multiple connections, for example when multiple render areas are created on the same browser page. EachRenderArea
may have multiple connections if it is shared, i.e. displayed in multiple client render areas. Use theService
object to query a client, then use theClient
object to query its connections.A
Connection
object is passed to many of theRenderAreaListener
methods including onOpenedConnection(), onInitializedConnection() and onSendingFrame().Using a
Connection
object, the application can query the current width and height of the client "container" in pixels and the lastRenderArea
width and height requested by the client. Note that the render area and the container are not required to be the same size. If the aspect ratios are different, then the rendered image will be displayed inside the container according to the "displayMode" specified when the client called the RemoteVizRenderArea constructor or set the 'displayMode' field of theSoRemoteVizClient
node. Possible values are FIT (default), CROP and STRETCH.A
Connection
allows the application to send text or binary messages to the associated client. A JavaScript client will receive the message using a listener (see the RemoteVizRenderArea method addServiceListener). Messages from a client are received using one of theRenderAreaListener.onReceivedMessage()
methods.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.openinventor.inventor.Inventor
Inventor.ConstructorCommand
-
-
Field Summary
-
Fields inherited from class com.openinventor.inventor.Inventor
VERBOSE_LEVEL, ZeroHandle
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Closes the connection.Client
getClient()
Gets the client associated with this connection.int
getContainerHeight()
Gets the client container height.int
getContainerWidth()
Gets the client container width.java.lang.String
getId()
Gets the id of the connection.EncodedFrame
getLastEncodedFrame()
Gets the last encoded frame sent by the connection.ConnectionParameters
getParameters()
Gets the connection parameters.RenderArea
getRenderArea()
Gets theRenderArea
associated with the connection.int
getRequestedHeight()
Gets the last renderArea height requested by the client.int
getRequestedWidth()
Gets the last renderArea width requested by the client.ConnectionSettings
getSettings()
Gets the connection settings.boolean
isOpen()
Gets the state of theConnection
: open or closed.boolean
sendMessage(java.lang.String message)
Sends a text message to the client.boolean
sendMessage(java.util.Collection<java.lang.Byte> buffer)
Sends a binary message to the client.-
Methods inherited from class com.openinventor.inventor.Inventor
dispose, getNativeResourceHandle
-
-
-
-
Method Detail
-
getSettings
public ConnectionSettings getSettings()
Gets the connection settings.- Returns:
- the connection settings object
-
getParameters
public ConnectionParameters getParameters()
Gets the connection parameters. These are field-value pairs included in the url during the client connection. See RemoteVizRenderArea.connectTo().- Returns:
- the connection parameters object
-
getLastEncodedFrame
public EncodedFrame getLastEncodedFrame()
Gets the last encoded frame sent by the connection.- Returns:
- encoded frame.
-
isOpen
public boolean isOpen()
Gets the state of theConnection
: open or closed. RemoteViz does not keep a reference to theConnection
object after the connection is closed. If the application kept a reference to the object, this method can be used to query its state. If the application did not keep a reference, then theConnection
object will be disposed after the connection is closed.The state "closed" will be set just before triggering the listener
RenderAreaListener.onClosedConnection
.- Returns:
- true if the connection is open or false if the connection is closed.
-
getContainerHeight
public int getContainerHeight()
Gets the client container height.- Returns:
- the client container height
-
getId
public java.lang.String getId()
Gets the id of the connection. The id is a Globally Unique Identifier (GUID) created by RemoteViz.- Returns:
- the ID identifying the connection
-
getRenderArea
public RenderArea getRenderArea()
Gets theRenderArea
associated with the connection.- Returns:
- the renderArea object
-
sendMessage
public boolean sendMessage(java.lang.String message)
Sends a text message to the client. The client-side message event will be triggered.- Parameters:
message
- : the message to be sent to the client- Returns:
- true if the message has been successfully sent, otherwise returns false.
-
getContainerWidth
public int getContainerWidth()
Gets the client container width.- Returns:
- the client container width
-
getClient
public Client getClient()
Gets the client associated with this connection.- Returns:
- the ID identifying the client
-
getRequestedHeight
public int getRequestedHeight()
Gets the last renderArea height requested by the client.- Returns:
- the requested renderArea height
-
close
public void close()
Closes the connection. A KICKED disconnect message will be sent to the client.
-
getRequestedWidth
public int getRequestedWidth()
Gets the last renderArea width requested by the client.- Returns:
- the requested renderArea width
-
sendMessage
public boolean sendMessage(java.util.Collection<java.lang.Byte> buffer)
Sends a binary message to the client. The client-side message event will be triggered.- Parameters:
buffer
- : the binary message to be sent to the client- Returns:
- true if the message has been successfully sent, otherwise returns false.
-
-