Web Sample

After setting up of any of the Cube Samples, you need a website able to make the proper calls to the Genvid API to display the stream and use the game data. It also needs to make specific calls via the Genvid API to interact with your game.

The Web Sample creates a website for you to stream any of the Cube Samples to: DirectX, Unreal, or Unity. It appears as a service on your Cluster UI Jobs page. It includes a CUBE SAMPLE link and a CUBE ADMIN link.

These links redirect you to the website that streams the running DirectX, Unreal, or Unity sample. The CUBE SAMPLE link redirects you as a user while the CUBE ADMIN link redirects you as an administrator.

In order to use it, you need to build it and then load it:

  1. Go to the /samples/cube/web directory.

  2. Build the website.

    py web.py build
    
  3. Load the website.

    py web.py load
    

SSL support on local cluster

It is now possible to generate self-signed SSL certificates for your local cluster when loading the web sample. A new python script /samples/cube/web/generate_ssl.py will use HashiCorp Vault to generate the certificates that the backend of the Web Sample will use. Here is the script:

#!/usr/bin/env python3
import hvac
import os


def create_new_ssl():
    client = hvac.Client(url='http://127.0.0.1:8200')

    secrets_engines_list = client.sys.list_mounted_secrets_engines()['data']

    if "pki/" in secrets_engines_list:
        print('The PKI engine is already enabled.')
    else:
        client.sys.enable_secrets_engine(backend_type='pki', )
        print('The PKI engine has been enabled')

    client.sys.tune_mount_configuration(
        path='pki',
        max_lease_ttl='87600h',
    )

    generate_root_response = client.secrets.pki.generate_root(
        type='exported', common_name='New root CA')
    print('New root CA: {}'.format(generate_root_response))

    set_urls_response = client.secrets.pki.set_urls({
        'issuing_certificates': ['http://127.0.0.1:8200/v1/pki/ca'],
        'crl_distribution_points': ['http://127.0.0.1:8200/v1/pki/crl']
    })

    create_or_update_role_response = client.secrets.pki.create_or_update_role(
        'localhostrole', {
            'ttl': '72h',
            'allow_localhost': 'true'
        })
    print('New role: {}'.format(create_or_update_role_response))

    generate_certificate_response = client.secrets.pki.generate_certificate(
        name='localhostrole', common_name='localhost')
    response = generate_certificate_response.json()
    print('Certificate response data: ', response)

    # the following lines will create the files needed for Nodejs to read the certificate and private key.
    cur_path = os.path.dirname(__file__)

    f = open(os.path.join(cur_path, "certificate.pem"), "w")
    f.write(response["data"]["certificate"])
    f.close()

    f = open(os.path.join(cur_path, "key.pem"), "w")
    f.write(response["data"]["private_key"])
    f.close()

Use the following commands when loading the web sample in order to trigger the script:

py web.py load --ssl

or

py web.py load -s

Whether you’re using the standalone mode or a streaming platform such as Youtube, etc, make sure that your hcl file will contain the new configuration that enables embedding with SSL by setting embed_ssl to true.

config {
   embed_ssl {
      enabled = true
   }
}

Warning

Whether you’re using SSL on a cloud or a local cluster, if you need to load multiple hcl configuration files containing the embed_ssl key, such as twitch.sample.hcl or youtube.sample.hcl, make sure to load them after the web sample is loaded. Otherwise you might overwrite the values associated with the embed_ssl key.

This section covers a step-by-step example on how we created the Web Sample. Feel free to adapt any of our sample code you find useful for your own project.