-
-
Save misovi/d7c17e7a4f3f23de026a96f2ce09d350 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:io'; | |
import 'dart:convert'; | |
import 'dart:async'; | |
import 'dart:typed_data'; | |
import 'package:flutter/cupertino.dart'; | |
class Connector with ChangeNotifier { | |
String _ip = "192.168.10.38"; | |
int _port = 65432; | |
Socket _socket; | |
StreamSubscription _listener; | |
var _systemState; | |
static final Connector _instance = Connector._internal(); | |
factory Connector () => _instance; | |
Connector._internal(); | |
void setIP(String ip) | |
{ | |
_ip=ip; | |
} | |
void setPort(int port) | |
{ | |
_port = port; | |
} | |
void connect() async | |
{ | |
_socket = await Socket.connect(this._ip, this._port); | |
_listener = _socket.listen(_DataCameIn); | |
} | |
send(String cmd, String val) async | |
{ | |
var debugMessage = {'command': cmd, 'value': val}; | |
var package = jsonEncode(debugMessage); | |
_socket.add(utf8.encode(package.toString() + "\n")); | |
} | |
void _DataCameIn(Uint8List data) | |
{ | |
print("data ping"); | |
String dataString = "poop"; | |
print(data); | |
Utf8Decoder decoder = Utf8Decoder(); | |
dataString = decoder.convert(data); | |
print(dataString); | |
_systemState = jsonDecode(dataString); | |
print(_systemState); | |
notifyListeners(); | |
} | |
String getSystemState(String key) | |
{ | |
print(_systemState[key]); | |
return _systemState[key]; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/cupertino.dart'; | |
import 'package:flutter/material.dart'; | |
import 'package:remote_appv1/connector.dart'; | |
class CustomForm extends StatefulWidget | |
{ | |
CustomFormState createState() => CustomFormState(); | |
} | |
class CustomFormState extends State<CustomForm> | |
{ | |
final _formKey = GlobalKey<FormState>(); | |
String _url; | |
@override | |
void dispose() { | |
print("Dispose called"); | |
_formKey.currentState.dispose(); | |
super.dispose(); | |
} | |
Widget build(BuildContext context) | |
{ | |
return(Form( | |
key: _formKey, | |
child: Row( | |
children: [ | |
Expanded( | |
flex: 4, | |
child: TextFormField( | |
validator: _validate, | |
onSaved: (value) => _url = value, | |
), | |
), | |
Expanded( | |
flex: 1, | |
child: IconButton( | |
icon: Icon(Icons.send), | |
onPressed: () { | |
if(_formKey.currentState.validate()) | |
{ | |
_formKey.currentState.save(); | |
Connector conn = Connector(); | |
conn.send("YouTube", _url); | |
} | |
}, | |
), | |
) | |
], | |
), | |
)); | |
} | |
String _validate(String input) | |
{ | |
RegExp exp1 = new RegExp(r"^https:\/\/www.youtube.com\/watch\?v=.+$"); | |
RegExp exp2 = new RegExp(r"^https:\/\/youtu\.be\/.+$"); | |
RegExp exp3 = new RegExp(r"^https:\/\/m\.youtube\.com\/watch\?v=.+$"); | |
if(exp1.hasMatch(input) || exp2.hasMatch(input) || exp3.hasMatch(input)) | |
{ | |
return null; | |
} | |
else return "Not a YouTube URL"; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Performing hot restart... | |
Syncing files to device COL L29... | |
Restarted application in 1,280ms. | |
I/flutter (26871): data ping | |
I/flutter (26871): [123, 34, 110, 97, 109, 101, 34, 58, 32, 34, 100, 98, 117, 103, 34, 44, 32, 34, 118, 111, 108, 117, 109, 101, 34, 58, 32, 34, 48, 46, 50, 48, 57, 57, 57, 57, 57, 57, 51, 52, 52, 51, 52, 56, 57, 48, 55, 34, 44, 32, 34, 109, 117, 116, 101, 34, 58, 32, 48, 44, 32, 34, 121, 111, 117, 116, 117, 98, 101, 83, 116, 97, 116, 101, 34, 58, 32, 34, 110, 111, 86, 105, 100, 101, 111, 34, 44, 32, 34, 121, 111, 117, 116, 117, 98, 101, 78, 97, 109, 101, 34, 58, 32, 34, 34, 125, 10] | |
I/flutter (26871): {"name": "dbug", "volume": "0.20999999344348907", "mute": 0, "youtubeState": "noVideo", "youtubeName": ""} | |
I/flutter (26871): {name: dbug, volume: 0.20999999344348907, mute: 0, youtubeState: noVideo, youtubeName: } | |
W/Settings(26871): Setting device_provisioned has moved from android.provider.Settings.Secure to android.provider.Settings.Global. | |
V/HiTouch_HiTouchSensor(26871): User setup is finished. | |
V/AudioManager(26871): playSoundEffect effectType: 0 | |
V/AudioManager(26871): querySoundEffectsEnabled... | |
I/flutter (26871): noVideo | |
I/flutter (26871): | |
════════ Exception caught by widgets library ═══════════════════════════════════════════════════════ | |
The following assertion was thrown while looking for parent data.: | |
Incorrect use of ParentDataWidget. | |
The following ParentDataWidgets are providing parent data to the same RenderObject: | |
- Expanded(flex: 1) (typically placed directly inside a Flex widget) | |
- Expanded(flex: 1) (typically placed directly inside a Flex widget) | |
However, a RenderObject can only receive parent data from at most one ParentDataWidget. | |
Usually, this indicates that at least one of the offending ParentDataWidgets listed above is not placed directly inside a compatible ancestor widget. | |
The ownership chain for the RenderObject that received the parent data was: | |
SizedBox.shrink ← Expanded ← Spacer ← Expanded ← Column ← Expanded ← Row ← MediaControlWidget ← Container ← Expanded ← ⋯ | |
When the exception was thrown, this was the stack: | |
#0 RenderObjectElement._findAncestorParentDataElement.<anonymous closure> (package:flutter/src/widgets/framework.dart:5345:11) | |
#1 RenderObjectElement._findAncestorParentDataElement (package:flutter/src/widgets/framework.dart:5359:6) | |
#2 RenderObjectElement.attachRenderObject (package:flutter/src/widgets/framework.dart:5684:61) | |
#3 RenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5380:5) | |
#4 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5833:11) | |
... | |
════════════════════════════════════════════════════════════════════════════════════════════════════ | |
════════ (2) Exception caught by widgets library ═══════════════════════════════════════════════════ | |
Incorrect use of ParentDataWidget. | |
════════════════════════════════════════════════════════════════════════════════════════════════════ | |
════════ (3) Exception caught by widgets library ═══════════════════════════════════════════════════ | |
Incorrect use of ParentDataWidget. | |
════════════════════════════════════════════════════════════════════════════════════════════════════ | |
════════ (4) Exception caught by widgets library ═══════════════════════════════════════════════════ | |
Incorrect use of ParentDataWidget. | |
════════════════════════════════════════════════════════════════════════════════════════════════════ | |
W/InputMethodManager(26871): startInputReason = 4 | |
I/InputMethodManager(26871): showSoftInput | |
I/InputMethodManager(26871): mServedView =com.example.remote_appv1;view =com.example.remote_appv1;flags =0 | |
I/HwSecImmHelper(26871): mSecurityInputMethodService is null | |
W/InputMethodManager(26871): startInputReason = 3 | |
I/ViewRootImpl(26871): jank_removeInvalidNode all the node in jank list is out of time | |
W/IInputConnectionWrapper(26871): getExtractedText on inactive InputConnection | |
W/IInputConnectionWrapper(26871): getTextBeforeCursor on inactive InputConnection | |
W/IInputConnectionWrapper(26871): getExtractedText on inactive InputConnection | |
W/IInputConnectionWrapper(26871): getTextBeforeCursor on inactive InputConnection | |
W/IInputConnectionWrapper(26871): getExtractedText on inactive InputConnection | |
W/IInputConnectionWrapper(26871): getTextBeforeCursor on inactive InputConnection | |
E/SpannableStringBuilder(26871): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length | |
E/SpannableStringBuilder(26871): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length | |
E/SpannableStringBuilder(26871): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length | |
E/SpannableStringBuilder(26871): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length | |
V/AudioManager(26871): playSoundEffect effectType: 0 | |
V/AudioManager(26871): querySoundEffectsEnabled... | |
V/AudioManager(26871): playSoundEffect effectType: 0 | |
V/AudioManager(26871): querySoundEffectsEnabled... | |
I/ViewRootImpl(26871): jank_removeInvalidNode all the node in jank list is out of time | |
I/flutter (26871): data ping | |
I/flutter (26871): [123, 34, 110, 97, 109, 101, 34, 58, 32, 34, 100, 98, 117, 103, 34, 44, 32, 34, 118, 111, 108, 117, 109, 101, 34, 58, 32, 34, 48, 46, 50, 48, 57, 57, 57, 57, 57, 57, 51, 52, 52, 51, 52, 56, 57, 48, 55, 34, 44, 32, 34, 109, 117, 116, 101, 34, 58, 32, 48, 44, 32, 34, 121, 111, 117, 116, 117, 98, 101, 83, 116, 97, 116, 101, 34, 58, 32, 34, 108, 111, 97, 100, 101, 100, 34, 44, 32, 34, 121, 111, 117, 116, 117, 98, 101, 78, 97, 109, 101, 34, 58, 32, 34, 89, 97, 107, 117, 122, 97, 32, 48, 32, 79, 83, 84, 32, 45, 32, 75, 117, 122, 101, 32, 84, 104, 101, 109, 101, 32, 70, 117, 108, 108, 32, 86, 101, 114, 115, 105, 111, 110, 32, 40, 80, 108, 101, 100, 103, 101, 32, 111, 102, 32, 68, 101, 109, 111, 110, 32, 69, 120, 116, 101, 110, 100, 101, 100, 41, 34, 125, 10] | |
I/flutter (26871): {"name": "dbug", "volume": "0.20999999344348907", "mute": 0, "youtubeState": "loaded", "youtubeName": "Yakuza 0 OST - Kuze Theme Full Version (Pledge of Demon Extended)"} | |
I/flutter (26871): {name: dbug, volume: 0.20999999344348907, mute: 0, youtubeState: loaded, youtubeName: Yakuza 0 OST - Kuze Theme Full Version (Pledge of Demon Extended)} | |
I/flutter (26871): loaded | |
I/flutter (26871): Yakuza 0 OST - Kuze Theme Full Version (Pledge of Demon Extended) | |
════════ (5) Exception caught by widgets library ═══════════════════════════════════════════════════ | |
'package:flutter/src/widgets/framework.dart': Failed assertion: line 4901 pos 16: 'child is! ParentDataElement<ParentData>': is not true. | |
The relevant error-causing widget was: | |
Expanded file:///C:/Users/narmo/Documents/theBigApp/TheBigApp/remote_appv1/lib/MediaControlWidget.dart:28:9 | |
════════════════════════════════════════════════════════════════════════════════════════════════════ | |
════════ (6) Exception caught by widgets library ═══════════════════════════════════════════════════ | |
'package:flutter/src/widgets/framework.dart': Failed assertion: line 4901 pos 16: 'child is! ParentDataElement<ParentData>': is not true. | |
The relevant error-causing widget was: | |
Expanded file:///C:/Users/narmo/Documents/theBigApp/TheBigApp/remote_appv1/lib/MediaControlWidget.dart:70:9 | |
════════════════════════════════════════════════════════════════════════════════════════════════════ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'mainView.dart'; | |
import 'package:flutter/material.dart'; | |
import 'connector.dart'; | |
void main() | |
{ | |
String IP = "192.168.10.38"; | |
int PORT = 65432; | |
Connector conn = Connector(); | |
conn.setIP(IP); | |
conn.setPort(PORT); | |
conn.connect(); | |
runApp(MyApp()); | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from server import Server | |
serv = Server() | |
print("starting run") | |
serv.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/cupertino.dart'; | |
import 'package:flutter/material.dart'; | |
import 'package:provider/provider.dart'; | |
import 'volumeView.dart'; | |
import 'youTubeView.dart'; | |
import 'customImageButton.dart'; | |
import 'package:flutter_appavailability/flutter_appavailability.dart'; | |
import 'package:open_appstore/open_appstore.dart'; | |
import 'connector.dart'; | |
class MyApp extends StatelessWidget { | |
Widget build(BuildContext context) { | |
return (ChangeNotifierProvider( | |
create: (context) => Connector(), | |
child: MaterialApp( | |
home: MainView(), | |
routes:{ | |
Volume.routeName:(context) => Volume(), | |
YoutubeView.routeName: (context)=>YoutubeView(), | |
} | |
), | |
)); | |
} | |
} | |
class MainViewState extends State<MainView> | |
{ | |
bool connectionUp = true; | |
String NoConnection = 'Disconnected'; | |
String name = 'NarmonRig'; | |
String IP = "127.0.0.1"; | |
//Connector conn = Connector("192.168.10.38",65432); | |
Widget _buildAppBar() | |
{ | |
return AppBar( | |
primary: true, | |
backgroundColor: connectionUp ? Colors.green : Colors.red, | |
title: connectionUp ? Text(name) : Text(NoConnection) | |
); | |
} | |
Widget _buildBody() | |
{ | |
final String ASSETPATH = "assets/"; | |
final String YOUTUBE ="youtube.png"; | |
final String VLC = "vlc.png"; | |
final String VOLUME = "volume.png"; | |
final String SPOTIFY = "spotify.png"; | |
final String FTP = "ftp.png"; | |
final String SETTINGS = "settings.png"; | |
return Container( | |
child: Center( | |
child: GridView.count( | |
crossAxisCount: 2, | |
crossAxisSpacing: 10, | |
children: [ | |
Container( | |
child: CustomImageButtonWidget( | |
pathToAsset: ASSETPATH + VOLUME, | |
routeName: Volume.routeName, | |
), | |
), | |
Container( | |
child: CustomImageButtonWidget( | |
pathToAsset: ASSETPATH + VLC, | |
action: _vlcPressed, | |
), | |
), | |
Container( | |
child: CustomImageButtonWidget( | |
pathToAsset: ASSETPATH + SPOTIFY, | |
action: _spotifyPressed | |
), | |
), | |
Container( | |
child: CustomImageButtonWidget( | |
pathToAsset: ASSETPATH + YOUTUBE, | |
routeName: YoutubeView.routeName, | |
), | |
), | |
Container( | |
child: CustomImageButtonWidget( | |
pathToAsset: ASSETPATH + FTP, | |
action: _ftpPressed, | |
), | |
), | |
Container( | |
child: CustomImageButtonWidget( | |
pathToAsset: ASSETPATH + SETTINGS, | |
action: _settingsPressed, | |
), | |
), | |
], | |
), | |
), | |
); | |
} | |
Widget build(BuildContext context) | |
{ | |
//conn.connect(); | |
return Scaffold( | |
appBar: _buildAppBar(), | |
body: _buildBody(), | |
); | |
} | |
void _vlcPressed() | |
{ | |
print("vlcPressed"); | |
} | |
void _youTubePressed() | |
{ | |
print("YoutubePessed"); | |
} | |
void _spotifyPressed() async | |
{ | |
String spotifyId = "com.spotify.music"; | |
if(await AppAvailability.isAppEnabled(spotifyId)) | |
{ | |
AppAvailability.launchApp("com.spotify.music"); | |
} | |
else | |
{ | |
OpenAppstore.launch(androidAppId: spotifyId); | |
} | |
} | |
void _ftpPressed() | |
{ | |
print("FTP pressed"); | |
Connector conn = Connector(); | |
conn.getSystemState('name'); | |
} | |
void _settingsPressed() | |
{ | |
print("SettingsPressed"); | |
Connector conn = Connector(); | |
conn.send('system','heartbeat'); | |
conn=null; | |
} | |
} | |
class MainView extends StatefulWidget | |
{ | |
//this just creates a state of MainView | |
MainViewState createState() => MainViewState(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:ffi'; | |
import 'package:flutter/cupertino.dart'; | |
import 'package:flutter/material.dart'; | |
class MediaControlWidget extends StatelessWidget | |
{ | |
final VoidCallback onPlay; | |
final VoidCallback onForward; | |
final VoidCallback onBack; | |
final VoidCallback onVolumeUp; | |
final VoidCallback onVolumeDown; | |
final bool disabled; | |
MediaControlWidget({ | |
this.onPlay, | |
this.onForward, | |
this.onBack, | |
this.onVolumeDown, | |
this.onVolumeUp, | |
this.disabled | |
}); | |
@override | |
Widget build(BuildContext context) { | |
return(Row( | |
children: <Widget>[ | |
Expanded( | |
child: Column( | |
children: [ | |
Expanded( | |
child: Spacer(), | |
), | |
Expanded( | |
child: IconButton( | |
icon: Icon(Icons.fast_rewind), | |
onPressed: onBack, | |
), | |
), | |
Expanded( | |
child: Spacer(), | |
) | |
], | |
), | |
), | |
Expanded( | |
child: Column( | |
children: [ | |
Expanded( | |
child: IconButton( | |
icon: Icon(Icons.volume_up), | |
onPressed: onVolumeUp, | |
) | |
), | |
Expanded( | |
child: IconButton( | |
icon: Icon(Icons.play_arrow), | |
onPressed: onPlay, | |
), | |
), | |
Expanded( | |
child: IconButton( | |
icon: Icon(Icons.volume_down), | |
onPressed: onVolumeDown, | |
), | |
) | |
], | |
), | |
), | |
Expanded( | |
child: Column( | |
children: [ | |
Expanded( | |
child: Spacer(), | |
), | |
Expanded( | |
child: IconButton( | |
icon: Icon(Icons.fast_forward), | |
onPressed: onForward, | |
), | |
), | |
Expanded( | |
child: Spacer(), | |
) | |
], | |
), | |
) | |
], | |
)); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: remote_appv1 | |
description: A new Flutter application. | |
# The following line prevents the package from being accidentally published to | |
# pub.dev using `pub publish`. This is preferred for private packages. | |
publish_to: 'none' # Remove this line if you wish to publish to pub.dev | |
# The following defines the version and build number for your application. | |
# A version number is three numbers separated by dots, like 1.2.43 | |
# followed by an optional build number separated by a +. | |
# Both the version and the builder number may be overridden in flutter | |
# build by specifying --build-name and --build-number, respectively. | |
# In Android, build-name is used as versionName while build-number used as versionCode. | |
# Read more about Android versioning at https://developer.android.com/studio/publish/versioning | |
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion. | |
# Read more about iOS versioning at | |
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html | |
version: 1.0.0+1 | |
environment: | |
sdk: ">=2.7.0 <3.0.0" | |
dependencies: | |
flutter: | |
sdk: flutter | |
imagebutton: ^0.0.6 | |
flutter_appavailability: | |
open_appstore: ^1.0.2 | |
provider: ^4.1.2 | |
# The following adds the Cupertino Icons font to your application. | |
# Use with the CupertinoIcons class for iOS style icons. | |
cupertino_icons: ^0.1.3 | |
dev_dependencies: | |
flutter_test: | |
sdk: flutter | |
# For information on the generic Dart part of this file, see the | |
# following page: https://dart.dev/tools/pub/pubspec | |
# The following section is specific to Flutter. | |
flutter: | |
assets: | |
- assets/ | |
# The following line ensures that the Material Icons font is | |
# included with your application, so that you can use the icons in | |
# the material Icons class. | |
uses-material-design: true | |
# To add assets to your application, add an assets section, like this: | |
# assets: | |
# - images/a_dot_burr.jpeg | |
# - images/a_dot_ham.jpeg | |
# An image asset can refer to one or more resolution-specific "variants", see | |
# https://flutter.dev/assets-and-images/#resolution-aware. | |
# For details regarding adding assets from package dependencies, see | |
# https://flutter.dev/assets-and-images/#from-packages | |
# To add custom fonts to your application, add a fonts section here, | |
# in this "flutter" section. Each entry in this list should have a | |
# "family" key with the font family name, and a "fonts" key with a | |
# list giving the asset and other descriptors for the font. For | |
# example: | |
# fonts: | |
# - family: Schyler | |
# fonts: | |
# - asset: fonts/Schyler-Regular.ttf | |
# - asset: fonts/Schyler-Italic.ttf | |
# style: italic | |
# - family: Trajan Pro | |
# fonts: | |
# - asset: fonts/TrajanPro.ttf | |
# - asset: fonts/TrajanPro_Bold.ttf | |
# weight: 700 | |
# | |
# For details regarding fonts from package dependencies, | |
# see https://flutter.dev/custom-fonts/#from-packages |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
from __future__ import print_function | |
import socket | |
import json | |
from ctypes import POINTER, cast | |
from comtypes import CLSCTX_ALL | |
from pycaw.pycaw import AudioUtilities, IAudioEndpointVolume, IAudioEndpointVolumeCallback | |
from selenium import webdriver | |
from selenium.webdriver.common.keys import Keys | |
from selenium.webdriver.common.by import By | |
from selenium.webdriver.support.ui import WebDriverWait | |
from selenium.webdriver.support import expected_conditions as EC | |
from selenium.common.exceptions import TimeoutException | |
import threading | |
from volumeCallBack import AudioEndpointVolumeCallback | |
class Server: | |
def __init__(self): | |
print("init") | |
self.HOST = '192.168.10.38' # Standard loopback interface address (localhost) | |
self.PORT = 65432 # Port to listen on (non-privileged ports are > 1023) | |
self.cont = True | |
self.element = None | |
self.driver = None | |
self.thread = None | |
self.youtubeThreadShouldLive = True | |
self._com_interfaces_ = [IAudioEndpointVolumeCallback] | |
self.volume = self.getVolumeHandle() | |
self.youtubeState = "noVideo" | |
self.youtubeName = "" | |
def __OnNotify(self, pNotify): | |
print("Notify triggered") | |
def __setUpCallBack(self): | |
callback = AudioEndpointVolumeCallback() | |
self.volume.RegisterControlChangeNotify(callback.OnNotify()) | |
def getVolumeHandle(self): | |
devices = AudioUtilities.GetSpeakers() | |
interface = devices.Activate( | |
IAudioEndpointVolume._iid_, CLSCTX_ALL, None) | |
volume = cast(interface, POINTER(IAudioEndpointVolume)) | |
return volume | |
def runTillDone(self): | |
DONE = "done" | |
ACTIVE = "active" | |
print("in function") | |
player_status = 666 | |
self.youtubeThreadShouldLive = True | |
while player_status != 0 and self.youtubeThreadShouldLive: | |
player_status = self.driver.execute_script("return document.getElementById('movie_player').getPlayerState()") | |
self.youtubeState = ACTIVE | |
self.youtubeState = DONE | |
self.driver.quit() | |
self.driver = None | |
self.youtubeName = "" | |
def openURL(self, url): | |
LOADING = "loading" | |
LOADED = "loaded" | |
DEAD = "dead" | |
self.youtubeState = LOADING | |
if self.driver is None: | |
self.driver = webdriver.Firefox() | |
self.driver.get(url) | |
self.element = self.driver.find_element_by_id("movie_player") | |
# line below may be optional. Look into possibilities of sending an all clear | |
# to mobile once loading is done and letting user hit play | |
self.element.send_keys(Keys.SPACE) | |
if self.thread is None: | |
self.thread = threading.Thread(target=self.runTillDone, args=(), daemon=True) | |
self.thread.start() | |
else: | |
print("Pong") | |
self.thread.run() | |
wait = WebDriverWait(self.driver, 10) | |
try: | |
self.youtubeName = wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, "yt-formatted-string.ytd-video-primary-info-renderer:nth-child(1)"))).text | |
self.youtubeState = LOADED | |
except TimeoutException: | |
self.youtubeName = "" | |
self.youtubeState = DEAD | |
def sendSystemState(self, conn): | |
# This function is in debug form at the moment | |
# as finished function it will send over the data | |
# mobile client needs to correctly render gui | |
volume = self.getVolume() | |
dictionary = {} | |
dictionary["name"] = "dbug" | |
dictionary["volume"] = str(volume) | |
dictionary["mute"] = self.volume.GetMute() | |
dictionary["youtubeState"] = self.youtubeState | |
dictionary["youtubeName"] = self.youtubeName | |
package = json.dumps(dictionary) | |
package = package + "\n" | |
conn.sendall(package.encode()) | |
print("sending") | |
def readData(self, data): | |
data = data.decode("utf-8") | |
data = data.split("\n")[0] | |
print("debug " + data) | |
dataArray = json.loads(data) | |
return dataArray | |
def actOnData(self, dataArray): | |
print(dataArray) | |
command = dataArray["command"] | |
value = dataArray["value"] | |
if command == "volume": | |
print("Command recognized as: Volume") | |
if value == "+": | |
print("Value recognized as: +") | |
self.incrementVolume() | |
elif value == "-": | |
print("Value recognized as: -") | |
self.decrementVolume() | |
elif value == "mute": | |
print("Value recognized as: mute") | |
self.toggleMute() | |
else: | |
print("Value recognized as: setVolume") | |
self.setVolume(float(value)) | |
elif command == "YouTube": | |
print("Command recognized as: Youtube") | |
if value == "+": | |
print("Value recognized as: +") | |
self.increaseVideoVolume() | |
elif value == "-": | |
print("Value recognized as: -") | |
self.decreaseVideoVolume() | |
elif value == "ff": | |
print("Value recognized as: ff") | |
self.stepForwardVideo() | |
elif value == "rwd": | |
print("Value recognized as: rwd") | |
self.stepBackwardVideo() | |
elif value == "play": | |
print("Value recognized as: play") | |
self.toggleVideoPlay() | |
elif value == "quit": | |
print("Value recognized as: quit") | |
self.quitYT() | |
else: | |
print("Value recognized as: getURL") | |
self.openURL(value) | |
def quitYT(self): | |
print("ping") | |
self.youtubeThreadShouldLive = False | |
self.thread.join() | |
self.driver = None | |
self.thread = None | |
def increaseVideoVolume(self): | |
self.element.send_keys(Keys.ARROW_UP) | |
def decreaseVideoVolume(self): | |
self.element.send_keys(Keys.ARROW_DOWN) | |
def stepForwardVideo(self): | |
self.element.send_keys(Keys.ARROW_RIGHT) | |
def stepBackwardVideo(self): | |
self.element.send_keys(Keys.ARROW_LEFT) | |
def toggleVideoPlay(self): | |
self.element.send_keys(Keys.SPACE) | |
def setVolume(self, number): | |
self.volume.SetMasterVolumeLevelScalar(number, None) | |
def getVolume(self): | |
ret = 0.0 | |
ret = self.volume.GetMasterVolumeLevelScalar() | |
return ret | |
def toggleMute(self): | |
flag = True | |
flag = self.volume.GetMute() | |
print(flag) | |
if flag: | |
self.volume.SetMute(False, None) | |
else: | |
self.volume.SetMute(True, None) | |
def incrementVolume(self): | |
self.volume.VolumeStepUp(None) | |
def decrementVolume(self): | |
self.volume.VolumeStepDown(None) | |
def OnNotify(self, pNotify): | |
print('OnNotify callback') | |
def authenticate(self, data): | |
# in reality this should conduct authentication operations | |
# for now it blindly trusts everyone | |
return True | |
def run(self): | |
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: | |
print("binding socket") | |
s.bind((self.HOST, self.PORT)) | |
while True: | |
print("socket bound, listening....") | |
s.listen() | |
conn, addr = s.accept() | |
with conn: | |
print('Connected by', addr) | |
self.cont = self.authenticate(conn) | |
try: | |
self.sendSystemState(conn) | |
while self.cont: | |
data = conn.recv(1024) | |
if not data: | |
self.cont = False | |
else: | |
self.actOnData(self.readData(data)) | |
self.sendSystemState(conn) | |
# print(self.thread) | |
except ConnectionError as err: | |
print(err) | |
print("client socket closed") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:wasm'; | |
import 'package:flutter/cupertino.dart'; | |
import 'package:flutter/material.dart'; | |
import 'package:provider/provider.dart'; | |
import 'package:remote_appv1/connector.dart'; | |
import 'package:remote_appv1/customImageButton.dart'; | |
class Volume extends StatefulWidget | |
{ | |
static const routeName = '/volumeRoute'; | |
VolumeState createState() => VolumeState(); | |
} | |
class VolumeState extends State<Volume> | |
{ | |
double _sliderValue = 0; | |
bool connectionUp = true; | |
String NoConnection = 'Disconnected'; | |
String name = 'NarmonRig'; | |
String IP = "127.0.0.1"; | |
Widget _buildAppBar() | |
{ | |
return AppBar( | |
primary: true, | |
backgroundColor: connectionUp ? Colors.green : Colors.red, | |
title: connectionUp ? Text(name) : Text(NoConnection) | |
); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
body: _buildBody(), | |
//giving every class the same appbar builder is bad code, | |
//refactor this later so that we don't need unneccessary | |
//attributes and don't have to rewrite appbar builder in | |
//every class | |
appBar: _buildAppBar(), | |
); | |
} | |
Widget _buildBody() | |
{ | |
final String ASSETPATH = "assets/"; | |
final String VOLUMEUP = "plus.png"; | |
final String VOLUMEDOWN = "minus.png"; | |
final String MUTE = "mute.png"; | |
final String UNMUTE = "unmute.png"; | |
return Row( | |
children: <Widget>[ | |
Expanded( | |
child: Column( | |
children: <Widget>[ | |
Expanded( | |
child: CustomImageButtonWidget( | |
pathToAsset: ASSETPATH + VOLUMEUP, | |
action: _volumeUpPressed, | |
), | |
), | |
Expanded( | |
child: CustomImageButtonWidget( | |
pathToAsset: ASSETPATH + VOLUMEDOWN, | |
action: _volumeDownPressed, | |
) | |
) | |
], | |
), | |
), | |
Expanded( | |
child: Column( | |
children: [ | |
Expanded( | |
child: CustomImageButtonWidget( | |
pathToAsset: ASSETPATH + MUTE, | |
action: _mutePressed, | |
) | |
), | |
Expanded( | |
child: RotatedBox( | |
quarterTurns: 3, | |
child: Slider( | |
divisions: 100, | |
value: double.parse(Provider.of<Connector>(context).getSystemState('volume')), | |
min: 0, | |
max: 1, | |
label: (_sliderValue * 100).toInt().toString(), | |
onChanged: (double newValue) { | |
Connector conn = Connector(); | |
conn.send('volume', newValue.toString()); | |
setState(() { | |
_sliderValue = double.parse(conn.getSystemState('volume')); | |
}); | |
print(_sliderValue); | |
}, | |
), | |
), | |
flex: 3, | |
) | |
], | |
), | |
) | |
], | |
); | |
} | |
void _volumeUpPressed() | |
{ | |
Connector conn = Connector(); | |
conn.send('volume', '+'); | |
conn = null; | |
} | |
void _volumeDownPressed() | |
{ | |
Connector conn = Connector(); | |
conn.send('volume', '-'); | |
conn = null; | |
} | |
void _mutePressed() | |
{ | |
Connector conn = Connector(); | |
conn.send('volume', 'mute'); | |
conn = null; | |
} | |
double _getSliderValue() | |
{ | |
double val; | |
Connector conn = Connector(); | |
val = double.parse(conn.getSystemState('volume')); | |
return val; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/cupertino.dart'; | |
import 'package:flutter/material.dart'; | |
import 'package:provider/provider.dart'; | |
import 'package:remote_appv1/connector.dart'; | |
import 'MediaControlWidget.dart'; | |
import 'CustomForm.dart'; | |
class YoutubeView extends StatefulWidget | |
{ | |
static const routeName = '/youtubeRoute'; | |
YoutubeViewState createState() => YoutubeViewState(); | |
} | |
class YoutubeViewState extends State<YoutubeView> | |
{ | |
bool connectionUp = true; | |
String NoConnection = 'Disconnected'; | |
String name = 'NarmonRig'; | |
String IP = "127.0.0.1"; | |
Widget _buildAppBar() | |
{ | |
return AppBar( | |
primary: true, | |
backgroundColor: connectionUp ? Colors.green : Colors.red, | |
title: connectionUp ? Text(name) : Text(NoConnection) | |
); | |
} | |
Widget build(BuildContext context) | |
{ | |
//implementation | |
return Scaffold( | |
appBar: _buildAppBar(), | |
body: _buildBody(), | |
resizeToAvoidBottomInset: false, | |
); | |
} | |
Widget _buildBody() | |
{ | |
return Column( | |
children: <Widget>[ | |
Expanded( | |
flex: 2, | |
child: Container( | |
child: CustomForm() | |
), | |
), | |
Expanded( | |
flex: 10, | |
child: Container( | |
child: Center( | |
child: Column( | |
children: [ | |
Text(Provider.of<Connector>(context).getSystemState('youtubeState')), | |
Text(Provider.of<Connector>(context).getSystemState('youtubeName')) | |
], | |
), | |
), | |
), | |
), | |
Expanded( | |
flex: 10, | |
child: Container( | |
child: MediaControlWidget( | |
onBack: () => {/***/}, | |
onForward: () => {/***/}, | |
onPlay: () => {/***/}, | |
onVolumeDown: () => {/***/}, | |
onVolumeUp: () => {/***/}, | |
), | |
) | |
) | |
], | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment