// +build js
package main
import (
"github.com/gopherjs/gopherjs/js"
"github.com/mame82/hvue"
pb "github.com/mame82/P4wnP1_aloa/proto/gopherjs"
)
type jsBluetoothRequestSettingsStorage struct {
*js.Object
TemplateName string `js:"TemplateName"`
Settings *jsBluetoothSettings `js:"Settings"`
}
func (rs *jsBluetoothRequestSettingsStorage) toGo() *pb.BluetoothRequestSettingsStorage {
return &pb.BluetoothRequestSettingsStorage{
TemplateName: rs.TemplateName,
Settings: rs.Settings.toGo(),
}
}
func (rs *jsBluetoothRequestSettingsStorage) fromGo(src *pb.BluetoothRequestSettingsStorage) {
rs.TemplateName = src.TemplateName
rs.Settings = NewBluetoothSettings()
rs.Settings.fromGo(src.Settings)
}
func NewBluetoothRequestSettingsStorage() (res *jsBluetoothRequestSettingsStorage) {
res = &jsBluetoothRequestSettingsStorage{Object:O()}
res.TemplateName = ""
res.Settings = NewBluetoothSettings()
return res
}
func NewBluetoothRequestSettingsStorageFromArgs(as *jsBluetoothAgentSettings, ci *jsBluetoothControllerInformation, templateName string) (res *jsBluetoothRequestSettingsStorage) {
res = &jsBluetoothRequestSettingsStorage{Object:O()}
res.TemplateName = templateName
res.Settings = NewBluetoothSettings()
res.Settings.fromASandCI(as,ci)
return res
}
type jsBluetoothSettings struct {
*js.Object
Ci *jsBluetoothControllerInformation `js:"Ci"`
As *jsBluetoothAgentSettings `js:"As"`
}
func (target *jsBluetoothSettings) fromGo(src *pb.BluetoothSettings) {
target.As = NewBluetoothAgentSettings()
target.As.fromGo(src.As)
target.Ci = NewBluetoothControllerInformation()
target.Ci.fromGo(src.Ci)
}
func (target *jsBluetoothSettings) fromASandCI(as *jsBluetoothAgentSettings, ci *jsBluetoothControllerInformation) {
target.As = as
target.Ci = ci
}
func (src *jsBluetoothSettings) toGo() (target *pb.BluetoothSettings) {
target = &pb.BluetoothSettings{
Ci: src.Ci.toGo(),
As: src.As.toGo(),
}
return target
}
func NewBluetoothSettings() (res *jsBluetoothSettings) {
res = &jsBluetoothSettings{Object:O()}
res.As = NewBluetoothAgentSettings()
res.Ci = NewBluetoothControllerInformation()
return
}
type jsBluetoothAgentSettings struct {
*js.Object
Pin string `js:"Pin"`
}
func (target *jsBluetoothAgentSettings) fromGo(src *pb.BluetoothAgentSettings) {
target.Pin = src.Pin
}
func (src *jsBluetoothAgentSettings) toGo() (target *pb.BluetoothAgentSettings) {
target = &pb.BluetoothAgentSettings{}
target.Pin = src.Pin
return
}
func NewBluetoothAgentSettings() (res *jsBluetoothAgentSettings) {
res = &jsBluetoothAgentSettings{Object:O()}
res.Pin = ""
return
}
type jsBluetoothControllerSettings struct {
*js.Object
Powered bool `js:"Powered"`
Connectable bool `js:"Connectable"`
FastConnectable bool `js:"FastConnectable"`
Discoverable bool `js:"Discoverable"`
Bondable bool `js:"Bondable"`
LinkLevelSecurity bool `js:"LinkLevelSecurity"`
SecureSimplePairing bool `js:"SecureSimplePairing"`
BrEdr bool `js:"BrEdr"`
HighSpeed bool `js:"HighSpeed"`
LowEnergy bool `js:"LowEnergy"`
Advertising bool `js:"Advertising"`
SecureConnections bool `js:"SecureConnections"`
DebugKeys bool `js:"DebugKeys"`
Privacy bool `js:"Privacy"`
ControllerConfiguration bool `js:"ControllerConfiguration"`
StaticAddress bool `js:"StaticAddress"`
}
func (target *jsBluetoothControllerSettings) fromGo(src *pb.BluetoothControllerSettings) {
target.Powered = src.Powered
target.Connectable = src.Connectable
target.FastConnectable = src.FastConnectable
target.Discoverable = src.Discoverable
target.Bondable = src.Bondable
target.LinkLevelSecurity = src.LinkLevelSecurity
target.SecureSimplePairing = src.SecureSimplePairing
target.BrEdr = src.BrEdr
target.HighSpeed = src.HighSpeed
target.LowEnergy = src.LowEnergy
target.Advertising = src.Advertising
target.SecureConnections = src.SecureConnections
target.DebugKeys = src.DebugKeys
target.Privacy = src.Privacy
target.ControllerConfiguration = src.ControllerConfiguration
target.StaticAddress = src.StaticAddress
}
func (src *jsBluetoothControllerSettings) toGo() (target *pb.BluetoothControllerSettings) {
target = &pb.BluetoothControllerSettings{}
target.Powered = src.Powered
target.Connectable = src.Connectable
target.FastConnectable = src.FastConnectable
target.Discoverable = src.Discoverable
target.Bondable = src.Bondable
target.LinkLevelSecurity = src.LinkLevelSecurity
target.SecureSimplePairing = src.SecureSimplePairing
target.BrEdr = src.BrEdr
target.HighSpeed = src.HighSpeed
target.LowEnergy = src.LowEnergy
target.Advertising = src.Advertising
target.SecureConnections = src.SecureConnections
target.DebugKeys = src.DebugKeys
target.Privacy = src.Privacy
target.ControllerConfiguration = src.ControllerConfiguration
target.StaticAddress = src.StaticAddress
return
}
func NewBluetoothControllerSettings() (res *jsBluetoothControllerSettings) {
res = &jsBluetoothControllerSettings{Object: O()}
res.Powered = false
res.Connectable = false
res.FastConnectable = false
res.Discoverable = false
res.Bondable = false
res.LinkLevelSecurity = false
res.SecureSimplePairing = false
res.BrEdr = false
res.HighSpeed = false
res.LowEnergy = false
res.Advertising = false
res.SecureConnections = false
res.DebugKeys = false
res.Privacy = false
res.ControllerConfiguration = false
res.StaticAddress = false
return
}
type jsBluetoothControllerInformation struct {
*js.Object
IsAvailable bool `js:"IsAvailable"`
Address []byte `js:"Address"`
BluetoothVersion byte `js:"BluetoothVersion"`
Manufacturer uint16 `js:"Manufacturer"`
SupportedSettings *jsBluetoothControllerSettings `js:"SupportedSettings"`
CurrentSettings *jsBluetoothControllerSettings `js:"CurrentSettings"`
ClassOfDevice []byte `js:"ClassOfDevice"` // 3, till clear how to parse
Name string `js:"Name"` //[249]byte, 0x00 terminated
ShortName string `js:"ShortName"` //[11]byte, 0x00 terminated
ServiceNetworkServerNAP bool `js:"ServiceNetworkServerNAP"`
ServiceNetworkServerPANU bool `js:"ServiceNetworkServerPANU"`
ServiceNetworkServerGN bool `js:"ServiceNetworkServerGN"`
}
func (src *jsBluetoothControllerInformation) toGo() (target *pb.BluetoothControllerInformation) {
target = &pb.BluetoothControllerInformation{}
target.IsAvailable = src.IsAvailable
target.Address = src.Address
target.BluetoothVersion = uint32(src.BluetoothVersion)
target.Manufacturer = uint32(src.Manufacturer)
target.SupportedSettings = src.SupportedSettings.toGo()
target.CurrentSettings = src.CurrentSettings.toGo()
target.Name = src.Name
target.ShortName = src.ShortName
target.ServiceNetworkServerGn = src.ServiceNetworkServerGN
target.ServiceNetworkServerPanu = src.ServiceNetworkServerPANU
target.ServiceNetworkServerNap = src.ServiceNetworkServerNAP
return
}
func (target *jsBluetoothControllerInformation) fromGo(src *pb.BluetoothControllerInformation) {
target.Address = src.Address
target.IsAvailable = src.IsAvailable
target.ClassOfDevice = src.ClassOfDevice
target.BluetoothVersion = byte(src.BluetoothVersion)
target.Manufacturer = uint16(src.Manufacturer)
target.SupportedSettings = NewBluetoothControllerSettings()
target.SupportedSettings.fromGo(src.SupportedSettings)
target.CurrentSettings = NewBluetoothControllerSettings()
target.CurrentSettings.fromGo(src.CurrentSettings)
target.Name = src.Name
target.ShortName = src.ShortName
target.ServiceNetworkServerGN = src.ServiceNetworkServerGn
target.ServiceNetworkServerPANU = src.ServiceNetworkServerPanu
target.ServiceNetworkServerNAP = src.ServiceNetworkServerNap
}
func NewBluetoothControllerInformation() (res *jsBluetoothControllerInformation) {
res = &jsBluetoothControllerInformation{Object: O()}
res.IsAvailable = false
res.ShortName = ""
res.Name = ""
res.Manufacturer = 0
res.BluetoothVersion = 0
res.Address = make([]byte, 6)
res.ClassOfDevice = make([]byte, 3)
res.SupportedSettings = NewBluetoothControllerSettings()
res.CurrentSettings = NewBluetoothControllerSettings()
res.ServiceNetworkServerGN = false
res.ServiceNetworkServerPANU = false
res.ServiceNetworkServerNAP = false
return
}
func InitComponentsBluetooth() {
hvue.NewComponent(
"bluetooth",
hvue.Template(templateBluetoothPage),
hvue.DataFunc(func(vm *hvue.VM) interface{} {
data := struct {
*js.Object
ShowStoreModal bool `js:"showStoreModal"`
ShowDeployStoredModal bool `js:"showDeployStoredModal"`
// TemplateName string `js:"templateName"`
}{Object: O()}
data.ShowStoreModal = false
data.ShowDeployStoredModal = false
// data.TemplateName = ""
return &data
}),
hvue.Computed("CurrentControllerInfo",
func(vm *hvue.VM) interface{} {
return vm.Get("$store").Get("state").Get("CurrentBluetoothControllerInformation")
}),
hvue.Computed("available", func(vm *hvue.VM) interface{} {
return true
}),
hvue.Computed("CurrentBluetoothAgentSettings",
func(vm *hvue.VM) interface{} {
return vm.Get("$store").Get("state").Get("CurrentBluetoothAgentSettings")
}),
hvue.Method("store",
func(vm *hvue.VM, name *js.Object) {
ci := &jsBluetoothControllerInformation{
Object: vm.Get("$store").Get("state").Get("CurrentBluetoothControllerInformation"),
}
as := &jsBluetoothAgentSettings{
Object: vm.Get("$store").Get("state").Get("CurrentBluetoothAgentSettings"),
}
sReq := NewBluetoothRequestSettingsStorageFromArgs(as,ci,name.String())
println("Storing :", sReq)
vm.Get("$store").Call("dispatch", VUEX_ACTION_STORE_BLUETOOTH_SETTINGS, sReq)
vm.Set("showStoreModal", false)
}),
hvue.Method("deleteStored",
func(vm *hvue.VM, name *js.Object) {
println("Loading :", name.String())
vm.Get("$store").Call("dispatch", VUEX_ACTION_DELETE_STORED_BLUETOOTH_SETTINGS, name)
}),
hvue.Method("deployStored",
func(vm *hvue.VM, name *js.Object) {
println("Loading :", name.String())
vm.Get("$store").Call("dispatch", VUEX_ACTION_DEPLOY_STORED_BLUETOOTH_SETTINGS, name)
}),
hvue.Method("updateStoredSettingsList",
func(vm *hvue.VM) {
vm.Store.Call("dispatch", VUEX_ACTION_UPDATE_STORED_BLUETOOTH_SETTINGS_LIST)
}),
hvue.Mounted(func(vm *hvue.VM) {
vm.Store.Call("dispatch", VUEX_ACTION_UPDATE_CURRENT_BLUETOOTH_CONTROLLER_INFORMATION)
}),
)
hvue.NewComponent(
"bluetooth-controller",
hvue.Template(templateBluetoothController),
hvue.PropObj("controllerInfo"),
hvue.Computed("CurrentControllerInfo",
func(vm *hvue.VM) interface{} {
return vm.Get("$store").Get("state").Get("CurrentBluetoothControllerInformation")
}),
)
hvue.NewComponent(
"bluetooth-controller-network-services",
hvue.Template(templateBluetoothControllerNetworkServices),
hvue.PropObj("controllerInfo"),
hvue.Computed("CurrentControllerInfo",
func(vm *hvue.VM) interface{} {
return vm.Get("$store").Get("state").Get("CurrentBluetoothControllerInformation")
}),
)
hvue.NewComponent(
"bluetooth-agent",
hvue.Template(templateBluetoothAgent),
hvue.PropObj("bluetoothAgent"),
hvue.Mounted(func(vm *hvue.VM) {
vm.Store.Call("dispatch", VUEX_ACTION_UPDATE_CURRENT_BLUETOOTH_AGENT_SETTINGS)
}),
)
}
const templateBluetoothPage = `
`
const templateBluetoothController = `
Generic Bluetooth Controller settings
Enabled
Power on/off Bluetooth controller
Name
Visible name of the bluetooth device
Connectable
Allow incoming connections
Discoverable
P4wnP1 could be discovered by other devices if enabled (only if Connectable)
Bondable
Other devices could pair with P4wnP1
High Speed
Use alternate data channel (802.11)
Low Energy
Enable Bluetooth LE (Bluetooth Smart)
Secure Simple Pairing
If disabled, insecure PIN based pairing is used and HighSpeed isn't available
`
const templateBluetoothControllerNetworkServices = `
BNEP server services
Bluetooth Network Encapsulation Protocol services provided by the controller
NAP
Provide Network Access Point
PANU
Provide Protable Area Network Unit
GN
Provide Group Ad-hoc Network
`
const templateBluetoothAgent = `
Authentication Agent
Pin
PIN requested from remote devices on bonding (only if SSP is off)
`