<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE X3D PUBLIC "ISO//Web3D//DTD X3D 3.1//EN" "https://www.web3d.org/specifications/x3d-3.1.dtd">
<X3D profile='Immersive' version='3.1' xmlns:xsd='http://www.w3.org/2001/XMLSchema-instance' xsd:noNamespaceSchemaLocation='https://www.web3d.org/specifications/x3d-3.1.xsd'>
  <head>
    <meta content='NetworkSensorConnectionPrototypes.x3d' name='title'/>
    <meta content='Prototypes for NetworkSensor and Connection nodes' name='description'/>
    <meta content='Don Brutzman, Chris Thorne, Don McGregor, Shun-Yun Hu' name='creator'/>
    <meta content='14 March 2008' name='created'/>
    <meta content='2 January 2025' name='modified'/>
    <meta content='under development' name='warning'/>
    <meta content='NetworkSensorConnectionNodes.html' name='reference'/>
    <meta content='http://www.xj3d.org/tutorials/general_sai.html' name='reference'/>
    <meta content='https://www.web3d.org/x3d/specifications/ISO-IEC-CD-19775-2.2/Part02/X3D_SAI.html' name='reference'/>
    <meta content='https://www.web3d.org/x3d/specifications/ISO-IEC-19777-2-X3DLanguageBindings-Java/Part2/X3D_Java.html' name='reference'/>
    <meta content='Prototypes for NetworkSensor and Connection nodes' name='subject'/>
    <meta content='https://www.web3d.org/x3d/content/examples/Basic/Networking/NetworkSensorConnectionPrototypes.x3d' name='identifier'/>
    <meta content='X3D-Edit 3.3, https://www.web3d.org/x3d/tools/X3D-Edit' name='generator'/>
    <meta content='../license.html' name='license'/>
  </head>
  <Scene>
    <WorldInfo title='NetworkSensorConnectionPrototypes.x3d'/>
    <ProtoDeclare name='NetworkSensor'>
      <ProtoInterface>
        <field accessType='inputOutput' name='enabled' type='SFBool' value='true'/>
        <field accessType='inputOutput' appinfo='X3DMetadataObject node type only' name='metadata' type='SFNode'>
          <!-- Metadata initialization node is NULL -->
        </field>
        <field accessType='outputOnly' name='isActive' type='SFBool'/>
        <field accessType='initializeOnly' appinfo='Connection node only' name='connection' type='SFNode'>
          <!-- Default Connection node goes here -->
        </field>
        <field accessType='inputOnly' name='httpRequest' type='SFString'/>
        <field accessType='outputOnly' name='httpResponse' type='MFString'/>
        <field accessType='initializeOnly' name='channelId' type='SFString' value='true'/>
        <!-- TODO: how to handle user-defined fields? -->
        <!-- perhaps corresponding MFString arrays for fieldName, fieldType, fieldAccessType, fieldInitialValues -->
        <!-- for now we'll simply try to get a MFString field to work -->
        <field accessType='inputOnly' appinfo='ROUTE StringSensor output here' name='textInput' type='SFString'/>
        <field accessType='outputOnly' appinfo='ROUTE this output to Text node string field' name='textOutput' type='MFString'/>
        <!-- TODO: can we get consistent type for textInput? -->
      </ProtoInterface>
      <ProtoBody>
        <!-- First node determines node type of prototype -->
        <Script DEF='NetworkSensorScript' url='"NetworkSensorScript.class" "https://www.web3d.org/x3d/content/examples/Networking/NetworkSensorScript.class"'>
          <field accessType='inputOutput' name='enabled' type='SFBool'/>
          <field accessType='inputOutput' name='metadata' type='SFNode'/>
          <field accessType='outputOnly' name='isActive' type='SFBool'/>
          <field accessType='initializeOnly' appinfo='Connection node only' name='connection' type='SFNode'/>
          <field accessType='inputOnly' name='httpRequest' type='SFString'/>
          <field accessType='outputOnly' name='httpResponse' type='MFString'/>
          <field accessType='initializeOnly' name='channelId' type='SFString'/>
          <IS>
            <connect nodeField='enabled' protoField='enabled'/>
            <connect nodeField='metadata' protoField='metadata'/>
            <connect nodeField='isActive' protoField='isActive'/>
            <connect nodeField='connection' protoField='connection'/>
            <connect nodeField='httpRequest' protoField='httpRequest'/>
            <connect nodeField='httpResponse' protoField='httpResponse'/>
            <connect nodeField='channelId' protoField='channelId'/>
          </IS>
        </Script>
        <!-- Subsequent nodes do not render, but still must be a valid X3D subgraph -->
      </ProtoBody>
    </ProtoDeclare>
    <ProtoDeclare name='Connection'>
      <ProtoInterface>
        <field accessType='inputOutput' name='enabled' type='SFBool' value='true'/>
        <field accessType='inputOutput' name='metadata' type='SFNode'>
          <!-- Metadata initialization node is NULL -->
        </field>
        <field accessType='outputOnly' name='isActive' type='SFBool'/>
        <field accessType='inputOutput' name='url' type='MFString' value='"x3dp://localhost:80"'/>
        <!-- 1 for HTTP, 2 for HTTP 1.1, 3 for TCP/IP, 4 for UDP, 5 for multicast -->
        <!-- spec TODO: change these code numbers to string enumerations instead -->
        <field accessType='initializeOnly' name='protocol' type='SFInt32' value='0'/>
        <field accessType='inputOutput' name='timeOut' type='SFTime' value='0'/>
        <field accessType='inputOnly' name='secure' type='SFBool'/>
      </ProtoInterface>
      <ProtoBody>
        <!-- First node determines node type of prototype -->
        <Script DEF='ConnectionScript' url='"ConnectionScript.class" "https://www.web3d.org/x3d/content/examples/Networking/ConnectionScript.class"'>
          <field accessType='inputOutput' name='enabled' type='SFBool'/>
          <field accessType='outputOnly' name='isActive' type='SFBool'/>
          <field accessType='inputOutput' name='url' type='MFString'/>
          <field accessType='initializeOnly' name='protocol' type='SFInt32'/>
          <field accessType='inputOutput' name='timeOut' type='SFTime'/>
          <field accessType='inputOnly' name='secure' type='SFBool'/>
          <IS>
            <connect nodeField='enabled' protoField='enabled'/>
            <connect nodeField='isActive' protoField='isActive'/>
            <connect nodeField='url' protoField='url'/>
            <connect nodeField='protocol' protoField='protocol'/>
            <connect nodeField='timeOut' protoField='timeOut'/>
            <connect nodeField='secure' protoField='secure'/>
          </IS>
        </Script>
        <!-- Subsequent nodes do not render, but still must be a valid X3D subgraph -->
      </ProtoBody>
    </ProtoDeclare>
    <!-- We'll put our initial example next. First the listener will output networked messages to a Text node -->
    <Shape>
      <Text DEF='MessageOutput' string='"NetworkSensor messages will appear here"'>
        <FontStyle justify='"MIDDLE" "MIDDLE"'/>
      </Text>
      <Appearance>
        <Material ambientIntensity='0.25' diffuseColor='0.374008 0 0.748016' shininess='0.4' specularColor='0.909091 0.909091 0.909091' transparency='0.35'/>
      </Appearance>
    </Shape>
    <!-- Only need a single Connection definition for this example -->
    <ProtoInstance DEF='OurNetworkChannel' name='Connection'>
      <fieldValue name='url' value='"x3dp://localhost:80"'/>
      <!-- protocol 1=http -->
      <fieldValue name='protocol' value='1'/>
      <fieldValue name='timeOut' value='10'/>
    </ProtoInstance>
    <!-- Here is the listener that connects and sends strings to the Text node -->
    <ProtoInstance DEF='TextListener' name='NetworkSensor'>
      <fieldValue name='connection'>
        <ProtoInstance USE='OurNetworkChannel' name='Connection'/>
      </fieldValue>
      <fieldValue name='channelId' value='78'/>
    </ProtoInstance>
    <!-- TODO: once a single string can successfully be sent, insert an intermediate Script to remember last 10 strings -->
    <ROUTE fromField='textOutput' fromNode='TextListener' toField='string' toNode='MessageOutput'/>
    <!-- Now capture text from local keyboard, send to scenes listening to this network connection -->
    <ProtoInstance DEF='TextSender' name='NetworkSensor'>
      <fieldValue name='connection'>
        <ProtoInstance USE='OurNetworkChannel' name='Connection'/>
      </fieldValue>
      <fieldValue name='channelId' value='78'/>
    </ProtoInstance>
    <StringSensor DEF='KeyboardDetector'/>
    <ROUTE fromField='finalText' fromNode='KeyboardDetector' toField='textInput' toNode='TextSender'/>
    <!-- done. we should now be able to type text and have it appear in the output for whoever's using the same scene. -->
  </Scene>
</X3D>