Skip to content

Commit

Permalink
Release/1.0.24 - Fixed LiveQuery web
Browse files Browse the repository at this point in the history
  • Loading branch information
phillwiggins committed Aug 23, 2019
1 parent 89f731a commit 35fa250
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 28 deletions.
3 changes: 2 additions & 1 deletion lib/src/network/parse_http_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ class ParseHTTPClient extends BaseClient {
/// Overrides the call method for HTTP Client and adds custom headers
@override
Future<StreamedResponse> send(BaseRequest request) {
if (!identical(0, 0.0))
if (!identical(0, 0.0)) {
request.headers[keyHeaderUserAgent] = _userAgent;
}
request.headers[keyHeaderApplicationId] = data.applicationId;
if ((_sendSessionId == true) &&
(data.sessionId != null) &&
Expand Down
2 changes: 1 addition & 1 deletion lib/src/network/parse_live_query.dart
Original file line number Diff line number Diff line change
Expand Up @@ -193,4 +193,4 @@ class LiveQuery {
await _webSocket.close();
}
}
}
}
21 changes: 14 additions & 7 deletions lib/src/network/parse_live_query_web.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
import 'dart:convert';
// ignore: uri_does_not_exist
import 'dart:html' as HTML;
import 'dart:html' as html;

import '../../parse_server_sdk.dart';

enum LiveQueryEvent { create, enter, update, leave, delete, error }
enum LiveQueryEvent {
create,
enter,
update,
leave,
delete,
error
}

class LiveQuery {
LiveQuery({bool debug, ParseHTTPClient client, bool autoSendSessionId}) {
Expand All @@ -19,7 +26,7 @@ class LiveQuery {
autoSendSessionId ?? ParseCoreData().autoSendSessionId ?? true;
}

HTML.WebSocket _webSocket;
html.WebSocket _webSocket;
ParseHTTPClient _client;
bool _debug;
bool _sendSessionId;
Expand Down Expand Up @@ -65,10 +72,10 @@ class LiveQuery {
final int requestId = _requestIdGenerator();

try {
_webSocket = HTML.WebSocket(_liveQueryURL);
_webSocket = html.WebSocket(_liveQueryURL);
await _webSocket.onOpen.first;

if (_webSocket != null && _webSocket.readyState == HTML.WebSocket.OPEN) {
if (_webSocket != null && _webSocket.readyState == html.WebSocket.OPEN) {
if (_debug) {
print('$_printConstLiveQuery: Socket opened');
}
Expand All @@ -79,7 +86,7 @@ class LiveQuery {
}
}

_webSocket.onMessage.listen((HTML.MessageEvent e) {
_webSocket.onMessage.listen((html.MessageEvent e) {
final dynamic message = e.data;
if (_debug) {
print('$_printConstLiveQuery: Listen: $message');
Expand Down Expand Up @@ -170,7 +177,7 @@ class LiveQuery {
}

Future<void> unSubscribe() async {
if (_webSocket != null && _webSocket.readyState == HTML.WebSocket.OPEN) {
if (_webSocket != null && _webSocket.readyState == html.WebSocket.OPEN) {
_webSocket.sendString(jsonEncode(_unsubscribeMessage));
if (_debug) {
print('$_printConstLiveQuery: Socket closed');
Expand Down
2 changes: 0 additions & 2 deletions lib/src/objects/parse_file.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ class ParseFile extends ParseBase {
String get url => super.get<String>(keyVarURL);
set url(String url) => set<String>(keyVarURL, url);

@override
String _path;

bool get saved => url != null;
Expand Down Expand Up @@ -85,7 +84,6 @@ class ParseFile extends ParseBase {
}

/// Uploads a file to Parse Server
@override
Future<ParseResponse> save() async {
return upload();
}
Expand Down
14 changes: 9 additions & 5 deletions lib/src/objects/parse_relation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ParseRelation<T extends ParseObject> {
QueryBuilder getQuery() {
return QueryBuilder(ParseObject(_targetClass));
}

void add(T object) {
if (object != null) {
_targetClass = object.parseClassName;
Expand All @@ -33,9 +33,13 @@ class ParseRelation<T extends ParseObject> {
}

Map<String, dynamic> toJson() =>
<String, String>{'__type': keyRelation, 'className': _objects?.first?.parseClassName, 'objects': parseEncode(_objects?.toList())};
<String, String>{
'__type': keyRelation,
'className': _objects?.first?.parseClassName,
'objects': parseEncode(_objects?.toList())
};

ParseRelation<T> fromJson(Map<String, dynamic> map) => ParseRelation<T>()
.._objects = parseDecode(map['objects'])
.._targetClass = map['className'];
}
.._objects = parseDecode(map['objects'])
.._targetClass = map['className'];
}
13 changes: 5 additions & 8 deletions lib/src/objects/parse_user.dart
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,8 @@ class ParseUser extends ParseObject implements ParseCloneable {
try {
final Uri url = getSanitisedUri(_client, '$keyEndPointUserName');
final Response response = await _client.get(url, headers: headers);
return await _handleResponse(
_getEmptyUser(), response, ParseApiRQ.currentUser,
_debug, _getEmptyUser().parseClassName);
return await _handleResponse(_getEmptyUser(), response,
ParseApiRQ.currentUser, _debug, _getEmptyUser().parseClassName);
} on Exception catch (e) {
return handleException(
e, ParseApiRQ.currentUser, _debug, _getEmptyUser().parseClassName);
Expand Down Expand Up @@ -277,9 +276,8 @@ class ParseUser extends ParseObject implements ParseCloneable {
final Response response = await _client.post(
'${_client.data.serverUrl}$keyEndPointRequestPasswordReset',
body: json.encode(<String, dynamic>{keyVarEmail: emailAddress}));
return await _handleResponse(
this, response, ParseApiRQ.requestPasswordReset, _debug,
parseClassName);
return await _handleResponse(this, response,
ParseApiRQ.requestPasswordReset, _debug, parseClassName);
} on Exception catch (e) {
return handleException(
e, ParseApiRQ.requestPasswordReset, _debug, parseClassName);
Expand Down Expand Up @@ -364,8 +362,7 @@ class ParseUser extends ParseObject implements ParseCloneable {

/// Handles all the response data for this class
static Future<ParseResponse> _handleResponse(ParseUser user,
Response response,
ParseApiRQ type, bool debug, String className) async {
Response response, ParseApiRQ type, bool debug, String className) async {
final ParseResponse parseResponse =
handleResponse<ParseUser>(user, response, type, debug, className);

Expand Down
1 change: 0 additions & 1 deletion lib/src/objects/response/parse_response_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ bool isSuccessButNoResults(Response apiResponse) {
results = decodedResponse;
}


if (results == null) {
return false;
}
Expand Down
1 change: 1 addition & 0 deletions lib/src/storage/core_store_sem_impl.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
part of flutter_parse_sdk;

// ignore_for_file: deprecated_member_use
class CoreStoreSembastImp implements CoreStore {
CoreStoreSembastImp._internal(this._store);

Expand Down
3 changes: 2 additions & 1 deletion lib/src/utils/parse_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ String removeTrailingSlash(String serverUrl) {
}

Future<ParseResponse> batchRequest(List<dynamic> requests,
List<ParseObject> objects, {ParseHTTPClient client, bool debug}) async {
List<ParseObject> objects,
{ParseHTTPClient client, bool debug}) async {
debug = isDebugEnabled(objectLevelDebug: debug);
client = client ??
ParseHTTPClient(
Expand Down
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ environment:
sdk: ">=2.2.2 <3.0.0"

dependencies:
http: ^0.12.0+2
flutter:
sdk: flutter

# Networking
web_socket_channel: ^1.0.13
http: ^0.12.0+2

#Database
sembast: ^1.17.0
sembast: ^2.0.1
xxtea: ^2.0.2
shared_preferences: ^0.5.3+2

Expand Down

0 comments on commit 35fa250

Please sign in to comment.