Skip to content

Commit

Permalink
[flutter] Fix login page.
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudwebrtc committed Dec 29, 2019
1 parent 4a2daad commit 76a313b
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 15 deletions.
36 changes: 27 additions & 9 deletions sdk/flutter/example/lib/page/login_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,13 @@ class _LoginPageState extends State<LoginPage> {
_server = prefs.getString('server') ?? 'pionion.org';
_roomID = prefs.getString('room') ?? 'room1';
});
handleConnect();
}

handleConnect() async {
Provider.of<ClientProvider>(context).init();
}

handleJoin() async {
if(Provider.of<ClientProvider>(context).connected){
Provider.of<ClientProvider>(context).join(_roomID);
Application.router.navigateTo(context, "/meeting");
}
ClientProvider client = Provider.of<ClientProvider>(context);
await client.connect(_server);
await client.join(_roomID);
Application.router.navigateTo(context, "/meeting");
}

Widget buildJoinView(context) {
Expand All @@ -51,6 +46,29 @@ class _LoginPageState extends State<LoginPage> {
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
SizedBox(
width: 260.0,
child: TextField(
keyboardType: TextInputType.text,
textAlign: TextAlign.center,
decoration: InputDecoration(
contentPadding: EdgeInsets.all(10.0),
border: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.black12)),
hintText: _server ?? 'Enter Ion Server.',
),
onChanged: (value) {
setState(() {
_server = value;
});
},
controller:
TextEditingController.fromValue(TextEditingValue(
text: '${this._server == null ? "" : this._server}',
selection: TextSelection.fromPosition(TextPosition(
affinity: TextAffinity.downstream,
offset: '${this._server}'.length)),
)))),
SizedBox(
width: 260.0,
child: TextField(
Expand Down
6 changes: 4 additions & 2 deletions sdk/flutter/example/lib/provider/client_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ class ClientProvider with ChangeNotifier {
get connected => _connected;
get inCalling => _inCalling;

init() async {
connect(host) async {
if (_client == null) {
var url = 'https://192.168.2.168:8443/ws';
var url = 'https://$host:8443/ws';
_client = Client(url);

_client.on('transport-open', () {
Expand Down Expand Up @@ -51,6 +51,8 @@ class ClientProvider with ChangeNotifier {

_client.on('peer-leave', (rid, id) async {});
}

await _client.connect();
}

join(String roomId) async {
Expand Down
8 changes: 4 additions & 4 deletions sdk/flutter/lib/src/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ class Client extends EventEmitter {

this._protoo.on('request', this._handleRequest);
this._protoo.on('notification', this._handleNotification);

this._protoo.connect();
}

connect() async => this._protoo.connect();

String get uid => _uid;

Future<dynamic> join(roomId, info) async {
Expand All @@ -83,7 +83,7 @@ class Client extends EventEmitter {
try {
var data = await this
._protoo
.send('join', {'rid': this._rid, 'id': this._uid, 'info': info});
.send('join', {'rid': this._rid, 'uid': this._uid, 'info': info});
logger.debug('join success: result => ' + _encoder.convert(data));
return data;
} catch (error) {
Expand All @@ -94,7 +94,7 @@ class Client extends EventEmitter {
Future<dynamic> leave() async {
try {
var data =
await this._protoo.send('leave', {'rid': this._rid, 'id': this._uid});
await this._protoo.send('leave', {'rid': this._rid, 'uid': this._uid});
logger.debug('leave success: result => ' + _encoder.convert(data));
return data;
} catch (error) {
Expand Down

0 comments on commit 76a313b

Please sign in to comment.