Genvid configuration files

The Genvid configuration can be contained in multiple files respecting a specific schema. The file can be writen in JSON or HCL format.

For example, the DirectX sample contains 3 configuration files.

sample.hcl

version = "1.7.0"

settings {
  encode {
    input {
      width  = 1280
      height = 720
    }
    output {
      width  = 1280
      height = 720
    }
  }
  info {
    description = "Sample to demonstrate genvid"
    game        = "Cube"
    name        = "directx sample"
  }
}

This file contains the basic information about the sample.

  • The stream encoding.
  • The basic stream info.

events.json

{
  "version": "1.7.0",
  "event": {
    "game": {
      "maps": [
        {
          "id": "changeColor",
          "source": "userinput",
          "where": {"key": ["changeColor", "<name>"], "name": "<color>", "type": "string"},
          "key": ["changeColor", "<name>", "<color>"], "value": 1
        },
        {
          "id": "reset",
          "source": "userinput",
          "where": {"key": ["reset"], "name": "<name>", "type": "string"},
          "key": ["reset", "<name>"], "value": 1
        },
        {
          "id": "cheer",
          "source": "userinput",
          "where": {"key": ["cheer"], "name": "<name>", "type": "string"},
          "key": ["cheer", "<name>"], "value": 1
        }
      ],
      "reductions": [
        {
          "id": "changeColor",
          "where": {"key": ["changeColor", "<name>", "<color>"]},
          "key": ["<name>", "<color>"],
          "value": ["$count"],
          "period": 250
        },
        {
          "id": "reset",
          "where": {"key": ["reset", "<name>"]},
          "key": ["<name>"],
          "value": ["$count"],
          "period": 250
        },
        {
          "id": "cheer",
          "where": {"key": ["cheer", "<name>"]},
          "key": ["<name>"],
          "value": ["$sum"],
          "period": 250
        }
      ]
    }
  }
}

The sample events.json file contains the events description. We group events together under a unique identifier allowing you to enable and disable them as a group. In the sample, the identifier is game.

See Scalable Event Channels for more information on the format.

game.hcl

version = "1.7.0"

job "directx" {
}

log "directx" {
  job      = "directx"
  fileName = "stderr"
  logLevel = true
}

config {
  local {
      directx {
        appdir = "{{env `PROJECTDIR` | js}}\\app"
    }
  }
}

This sample game.hcl file contains the game configuration information in 3 categories.

The first element is a new job. The name of the job should match the name of the template file as well as the name of the job in the template file. Job configurations have two attributes:

  • dependencies: A list of services to wait on before starting the job. The default is none.
  • autostart: If the job must be automatically started on a start command without arguments.

The second is the log element. It gives the options to pass to POST /log/logs when you run genvid-sdk log game.

When “logLevel” is set to “true”, logLevel controls can be seen on the log page of job. It displays a drop down for Log Level and Default Log Level. When “logLevel” is set to “false”, no drop downs can be seen.

The last is the config element. The content is added to the key-value store, where each object describes a folder and each value is converted to a string and inserted as a key.

The consul-template’s plugin calls the DOS command where with the argument node and returns the command output. You can use your own executables as long as they are in your path when the project is loaded. The js method ensures elements like Windows path separators are correctly quoted in the file.

The Web Sample contains 2 configuration files as well as events.json.

stream.hcl

version = "1.7.0"

secrets {
  disco {
    GENVID_DISCO_SECRET = "discosecret"
  }
  studio {
    GENVID_STUDIO_SECRET = "studiosecret"
  }
  webgateway {
    GENVID_WEBGATEWAY_SECRET = "webgatewaysecret"
  }
}

settings {
  encode {
    input {
      width  = 1280
      height = 720
    }
    output {
      width  = 1280
      height = 720
    }
  }
  info {
    description = "Sample to demonstrate genvid"
    game        = "Cube"
    name        = "Cube Sample"
  }
}
config {
  local {
    appdir = "{{env `PROJECTDIR` | js}}\\app"
  }
}

This file contains the secrets (you need to change the secret values).

web.hcl

version = "1.7.0"

job "web" {}

log "web" {
  job      = "web"
  task     = "web"
  fileName = "stdout"
}

log "weberr" {
  job      = "web"
  task     = "web"
  fileName = "stderr"
}

link "web" {
  name     = "Cube Sample"
  template = "http://${serviceEx `web` `` true}/"
}
link "admin" {
  name     = "Cube Admin"
  template = "http://${serviceEx `web` `` true}/admin"
}

// {{with $url := env `SSLWEBENDPOINT`}}
link "web" {
  name     = "Cube Sample"
  template = "https://{{$url}}:30000"
}
link "admin" {
  template = "https://{{$url}}:30000/admin"
}
// {{end}}

// Check if we are using a load balancer
// {{with $url := env `WEBENDPOINT`}}
link "web" {
  name     = "Cube Sample"
  template = "https://{{$url}}/"
}
link "admin" {
  name     = "Cube Admin"
  template = "https://{{$url}}/admin"
}
// {{end}}



config {
  local {
    website {
      root   = "{{env `PROJECTDIR` | js}}"
      script = "{{env `PROJECTDIR` | js}}\\backend\\www"
    }
    binary {
      node {
        path = "{{plugin `where.exe` `node` | js}}"
      }
    }
  }
  embed_ssl {
    enabled = false
  }
} // end of config

The web.hcl section is similar to the game.hcl section, but for the web server. It contains a single job with only the default attribute and two log elements: one for the standard output and the other for the standard error.

It contains multiple link elements used as URIs in the system. By running genvid-sdk open you can see the list of available links.

These links use a template system to produce the final link. In the Web Sample, we transform the template http://${service \`web\`}/ into the website URI.

The available template functions are:

  • service service: The service address and port.
  • serviceEx service tag external: The service address and port. The tag is an arbitrary value used to find a service. The external attribute is asking for an external address.
  • key key: The value from a Consul key-value pair.
  • keyOrDefault key default_value: The value from a Consul key-value pair. Gets the default value if the key is not available.

Both the DirectX and Web Web samples contain config for the cloud environment as templates.