Skip to content

Commit

Permalink
Merge pull request #133 from shamanec/rework-device-control-ws
Browse files Browse the repository at this point in the history
Improvements
  • Loading branch information
shamanec authored Nov 25, 2024
2 parents 068613f + 7008fb2 commit 1fbe0ba
Show file tree
Hide file tree
Showing 49 changed files with 1,989 additions and 1,350 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ gads-stream.apk
server.crt
server.key
jsconfig.json
.vscode/launch.json
.vscode/launch.json
Provider1/
38 changes: 38 additions & 0 deletions common/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,44 @@ func GetUsers() []models.User {
return users
}

func GetDBFiles() []models.DBFile {
var files []models.DBFile
collection := mongoClient.Database("gads").Collection("fs.files")

cursor, err := collection.Find(mongoClientCtx, bson.D{{}}, nil)
if err != nil {
log.WithFields(log.Fields{
"event": "get_db_files",
}).Error(fmt.Sprintf("Could not get db cursor when trying to get latest files info from db - %s", err))
return files
}

if err := cursor.All(mongoClientCtx, &files); err != nil {
log.WithFields(log.Fields{
"event": "get_db_files",
}).Error(fmt.Sprintf("Could not get files latest info from db cursor - %s", err))
return files
}

if err := cursor.Err(); err != nil {
log.WithFields(log.Fields{
"event": "get_db_files",
}).Error(fmt.Sprintf("Encountered db cursor error - %s", err))
return files
}

if err := cursor.Err(); err != nil {
log.WithFields(log.Fields{
"event": "get_db_files",
}).Error(fmt.Sprintf("Encountered db cursor error - %s", err))
return files
}

cursor.Close(mongoClientCtx)

return files
}

func GetDBDeviceNew() []models.Device {
var dbDevices []models.Device
// Access the database and collection
Expand Down
1 change: 0 additions & 1 deletion common/models/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ type Provider struct {
SupervisionPassword string `json:"supervision_password" bson:"supervision_password"`
ProviderFolder string `json:"-" bson:"-"`
LastUpdatedTimestamp int64 `json:"last_updated" bson:"last_updated"`
ProvidedDevices []Device `json:"provided_devices" bson:"provided_devices"`
WebDriverBinary string `json:"-" bson:"-"`
UseGadsIosStream bool `json:"use_gads_ios_stream" bson:"use_gads_ios_stream"`
UseCustomWDA bool `json:"use_custom_wda" bson:"use_custom_wda"`
Expand Down
34 changes: 24 additions & 10 deletions common/models/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ package models

import (
"context"
"net"
"sync"

"github.com/Masterminds/semver"
"github.com/danielpaulus/go-ios/ios"
"github.com/danielpaulus/go-ios/ios/tunnel"
"go.mongodb.org/mongo-driver/bson/primitive"
)

type CustomLogger interface {
Expand Down Expand Up @@ -82,16 +84,18 @@ type Device struct {
}

type LocalHubDevice struct {
Device Device `json:"info"`
SessionID string `json:"-"`
IsRunningAutomation bool `json:"is_running_automation"`
LastAutomationActionTS int64 `json:"last_automation_action_ts"`
InUse bool `json:"in_use"`
InUseBy string `json:"in_use_by"`
InUseTS int64 `json:"in_use_ts"`
AppiumNewCommandTimeout int64 `json:"appium_new_command_timeout"`
IsAvailableForAutomation bool `json:"is_available_for_automation"`
Available bool `json:"available" bson:"-"` // if device is currently available - not only connected, but setup completed
Device Device `json:"info"`
SessionID string `json:"-"`
IsRunningAutomation bool `json:"is_running_automation"`
LastAutomationActionTS int64 `json:"last_automation_action_ts"`
InUse bool `json:"in_use"`
InUseBy string `json:"in_use_by"`
InUseTS int64 `json:"in_use_ts"`
AppiumNewCommandTimeout int64 `json:"appium_new_command_timeout"`
IsAvailableForAutomation bool `json:"is_available_for_automation"`
Available bool `json:"available" bson:"-"` // if device is currently available - not only connected, but setup completed
InUseWSConnection net.Conn `json:"-" bson:"-"` // stores the ws connection made when device is in use to send data from different sources
LastActionTS int64 `json:"-" bson:"-"` // Timestamp of when was the last time an action was performed via the UI through the proxy to the provider
}

type IOSModelData struct {
Expand All @@ -105,3 +109,13 @@ type UpdateStreamSettings struct {
JpegQuality int `json:"jpeg_quality,omitempty"`
ScalingFactor int `json:"scaling_factor,omitempty"`
}

type DeviceInUseMessage struct {
Type string `json:"type"`
Payload interface{} `json:"payload"`
}

type DBFile struct {
FileName string `json:"name" bson:"filename"`
UploadDate primitive.DateTime `json:"upload_date" bson:"uploadDate"`
}
9 changes: 6 additions & 3 deletions docs/provider.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,14 @@ This is an optional but a preferable step - it can make devices setup more auton

- Install Apple Configurator 2 on your Mac.
- Attach your first device.
- Set it up for supervision using a new(or existing) supervision identity. You can do that for free without having a paid MDM account.
- Set it up for supervision using a new (or existing) supervision identity. You can do that for free without having a paid MDM account.
- Connect each consecutive device and supervise it using the same supervision identity.
- Export your supervision identity file and choose a password.
- Save your new supervision identity file in the provider folder as `supervision.p12`.
- Save your new supervision identity as `*.p12` file.
- Log in to the hub with admin and upload the `*.p12` file via `Admin > Files`.

**NB** Make sure to remember the supervision password, you need to set it up in the provider config for each provider that will use a supervision profile.
**NB** Provider will fall back to manual pairing if something is wrong with the supervision profile, provided password or supervised pairing.
**NB** You can skip supervising the devices and you should trust manually on first pair attempt by the provider but if devices are supervised in advance setup can be more autonomous.

## Android
Expand All @@ -157,7 +160,7 @@ This is an optional but a preferable step - it can make devices setup more auton
## Prepare WebDriverAgent on macOS - (read the full paragraph)
### Custom WebDriverAgent
By using my custom WebDriverAgent you can have faster tap/swipe interactions on iOS devices.
The provider configuration should be set to use the custom WebDriverAgent in Mongo - either set it through GADS UI or using any db tool to update the provider config in Mongo for `use_custom_wda` with `true`
The provider configuration should be set to use the custom WebDriverAgent through GADS UI
- Download the code of the `main` branch from my fork of [WebDriverAgent](https://github.com/shamanec/WebDriverAgent)
- Unzip the code in any folder.
- Open WebDriverAgent.xcodeproj in Xcode
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ toolchain go1.22.6

require (
github.com/Masterminds/semver v1.5.0
github.com/danielpaulus/go-ios v1.0.135
github.com/danielpaulus/go-ios v1.0.160
github.com/gin-contrib/static v0.0.1
github.com/gin-gonic/gin v1.9.0
github.com/gobwas/ws v1.4.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ github.com/danielpaulus/go-ios v1.0.123 h1:Pyv+9xdFIaaGXJFQHL11l1rBde1pJhSA+N0Id
github.com/danielpaulus/go-ios v1.0.123/go.mod h1:tCOjUoiimx1wL8WJ7GoTF1bT9o4xAN1Fpif+vzSHXkc=
github.com/danielpaulus/go-ios v1.0.135 h1:o7EZImQ83+2yI/OMNmprspUGzkYEkNUDZxiKtE5QwGs=
github.com/danielpaulus/go-ios v1.0.135/go.mod h1:YdQ7zSYbkIM0eSMo2LHc07w9zXIYKmj/AoAAOQ8rBco=
github.com/danielpaulus/go-ios v1.0.160 h1:vpAu3E+4A7bmSfHX4aaaItR83K1Dkk+hPooJ09Srp/w=
github.com/danielpaulus/go-ios v1.0.160/go.mod h1:ZkUcaC59yNba47j/+ULKsCi3dYPFwY9r39PxdmVmLHE=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down
Binary file added hub/gads-ui/public/images/appium-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 18 additions & 6 deletions hub/gads-ui/src/Gads.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import { useContext, useEffect } from 'react'
import { Auth } from './contexts/Auth'
import AdminDashboard from './components/Admin/AdminDashboard'
import axiosInterceptor from './services/axiosInterceptor'
import { DialogProvider } from './contexts/DialogContext'
import { SnackbarProvider } from './contexts/SnackBarContext'
import { LoadingOverlayProvider } from './contexts/LoadingOverlayContext'

function Gads() {
const { authToken, logout } = useContext(Auth)
Expand All @@ -27,12 +30,21 @@ function Gads() {
return (
<div style={{ backgroundColor: "#f4e6cd", height: "100%" }}>
<NavBar />
<Routes>
<Route path="/" element={<Navigate to="/devices" />} />
<Route path="/devices" element={<DeviceSelection />} />
<Route path="/devices/control/:udid" element={<DeviceControl />} />
<Route path="/admin" element={<AdminDashboard />} />
</Routes>
<DialogProvider>
<SnackbarProvider>
<Routes>
<Route path="/" element={<Navigate to="/devices" />} />
<Route path="/devices" element={<DeviceSelection />} />

<Route path="/devices/control/:udid" element={
<LoadingOverlayProvider>
<DeviceControl />
</LoadingOverlayProvider>
} />
<Route path="/admin" element={<AdminDashboard />} />
</Routes>
</SnackbarProvider>
</DialogProvider>
</div>
)
}
Expand Down
Loading

0 comments on commit 1fbe0ba

Please sign in to comment.