summaryrefslogblamecommitdiff
path: root/messages.lua
blob: 69576e175e0a15cd30052810bf1b37f13e0092da (plain) (tree)













































                                                           
local json = require("json")

Messages = {
  -- Handshake
  RequestServerInfo = {
    RequestServerInfo = {
      Id = 1,
      ClientName = "Funsaac v0.0.2",
      MessageVersion = 3
    }
  },

  -- Enumeration
  
  StartScanning = {
    StartScanning = {
      Id = 1
    }
  }
}

local cnt = 1;

function GetMessage(msg)
  local message = msg
  message[next(msg)]["Id"] = cnt
  cnt = cnt + 1
  return "[" .. json.encode(message) .. "]"
end

function ResponseContent(message)
  local msg = json.decode(message)[1]
  local type = next(msg)
  return type, msg[type]
end

function HandleResponse(type, content)
  if type == "ServerInfo" then
    print("Connected to Server: " .. content["ServerName"])
    CONNECTED = true
  elseif type == "Ok" then
    print("Id: " .. content["Id"])
  elseif type == "DeviceAdded" then
    print("DeviceAdded: " .. content["DeviceName"])
  end
end