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.

Let’s use the Tutorial project as an example. The sample contains 4 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        = "Tutorial"
    name        = "Tutorial Sample"
  }
}
config {
  local {
    appdir = "{{env `PROJECTDIR` | js}}\\app"
  }
}

This file contains the basic information about the sample.

  • The stream encoding.

  • The stream basic info.

  • The secrets. You need to change them.

  • Some local configuration.

    This local configuration is put into consul key value store for use in the nomad template.

stream.hcl

version = "1.7.0"

settings {
  encode {
    stream {
      enable  = true
      addr    = "a.rtmp.youtube.com/live2"
      // YOU MUST CHANGE THE CHANNEL AND KEY VALUE
      service = "youtube"
      channel = ""
      key     = ""
    }
  }
}
secrets {
  disco {
    GENVID_DISCO_SECRET = "secrettochange"
  }
  command {
    GENVID_COMMAND_SECRET = "anothersecret"
  }
}

This file contains the stream provider connection information and the the secrets (you need to change the secret values).

The sample projects do not include a stream.hcl file, but a stream.example.hcl file is available which you can modify and rename.

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
        }
      ]
    }
  }
}

As an example of a JSON file, this file contains the events description (see Scalable Event Channels for more information on the format). Events are grouped together under a unique identifier allowing you to enable and disable them together easily. In the sample, this identifier is game since that was their name in the previous versions.

game.hcl

version = "1.7.0"

job "tutorial" {
  dependencies = [
    "nats",
    "compose",
  ]
}

log "game" {
  job      = "tutorial"
  fileName = "stderr"
  logLevel = true
}

config {
  local {
    binary {
      tutorial {
        path = "{{env `PROJECTDIR` | js}}\\app\\x64\\Release\\Tutorial.exe"
      }
    }
  }
}

This file contains the configuration related to the game under 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 service to wait on before starting the job. The default is none.
  • autostart: if the job must be automatically started on a start command without argument.

In second,the log element give the options to pass to POST /log/logs, when you run genvid-sdk log game.

The last one is the config element. The content of this element is added to the key-value store, each object being considered as a folder, and each value converted to string and inserted as a key.

An interesting element in this section is the usage of a consul-template’s plugin for determining the location of the node binary. The plugin simply calls the executable where (a DOS command) with the argument node, and returns the output of the command. You can use your own executables, as long as they are in your path when the project is loaded. The js method is also quite useful here to ensure elements like Windows path separators are correctly quoted in the file.

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     = "Tutorial Demo"
  template = "http://${service `web`}/"
}

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

config {
  local {
    website {
      root   = "{{env `PROJECTDIR` | js}}\\web"
      script = "{{env `PROJECTDIR` | js}}\\web\\bin\\www"
    }
    binary {
      node {
        path = "{{plugin `where.exe` `node` | js}}"
      }
    }
  }
  cloud {
    image {
      web {
        tag = "sampleweb:dev"
      }
    }
  }
}

The last section is very similar to the previous one, but it is 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 element. They are used as uri to the system. By running genvid-sdk open you can see the list of available links.

These links are using a template system to produce the final link. In this case, the template http://${service \`web\`}/ would be transform into the website uri.

The available template functions are…

  • service service: Give the service address and port
  • serviceEx service tag external : Give 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: Give the value from a consul key value pair.
  • key_or_default key default_value: Give the value from a consul key value pair. Get the default value if the key is not available.

The web section also contains config for the cloud environment.