dahkenangnon / flutter_feathersjs.dart Goto Github PK
View Code? Open in Web Editor NEWReal-Time Flutter Apps, Powered by FeathersJS.
Home Page: https://feathersjs.dah-kenangnon.com/
License: MIT License
Real-Time Flutter Apps, Powered by FeathersJS.
Home Page: https://feathersjs.dah-kenangnon.com/
License: MIT License
How do you detect errors with socketio methods? For a call like:
var sessionInfo = await _picServer.scketio.get(serviceName: "sessions", objectId: sessionId);
If the session is found a list is returned with the object JSON in sessionInfo[1].
Session join info: [null, {_id: 5ff9e945189544aabbdc940f, description: , invited_users: [], muted_users: [], active_users: [], name: 7239611028, images_dir: ./data/7239611028, creator_email: [email protected], creator_id: 5ff8c19e4d3f7b8c218e8240, createdAt: 2021-01-09T17:35:01.813Z, updatedAt: 2021-01-09T17:35:01.813Z, __v: 0}]
For invalid objectId values a JsonMap is returned.
{name: NotFound, message: No record found for id '5ff9e945189544aabbdc940e', code: 404, className: not-found, errors: {}}
What is the best way to check for success/failure from these API calls?
Thanks,
Kevin
Originally posted by @kevinbeck76 in #3 (comment)
Hello from Turkey; Firstly great job. How can we make socket queries with this library? I check the docs there is nothing about it
We're are working on the next release of this Project: ๐ฏ Version 5.0.0
This is a draft of our roadmap.
๐ I use "We" becauase @AurelAgbodoyetin joined me to maintain and make great again this package.
You're always welcome to contribute, just email to dah.kenangnon [at] gmail [dot] com
Now, our roadmap:
This is a draft and should be update when needed
Add offline database support Add synchronization with remote api
Seem like they'd be ideal!
These would be incredible features ๐
If it isn't possible yet: Allow developers to initialize the Rest and Socket config separately (especially the baseUrl) or as the official feathers-client, let the developer decide whether to work only with socket or rest. An example:
I host a Feathers API behind a reverse proxy at https://my-app.com/api - then the socket configuration would still need the https://my-app.com/ because the baseUrl of https://my-app.com/api would imply that the socket.io uses "api" as the namespace. On the other hand, the Rest API would still need the https://my-app.com/api as baseUrl. Therefore this should be configurable separately.
An idea for this could be, to initialize the package in flutter like the feathers package. Therefore to keep the mentality of feathers to be independent of the transportation mode and the package is easily extendable for the Primus Client for example.
A example initialization could be:
import 'package:flutter_feathersjs/flutter_feathersjs.dart';
import 'package:socket_io_client/socket_io_client.dart' as IO;
FlutterFeathersjs client = FlutterFeathersjs();
IO.Socket io = IO.io(baseUrl)
client.configure(FlutterFeathersjs.socket(io));
client.service('messages').create({
text: 'A new message'
});
import 'package:flutter_feathersjs/flutter_feathersjs.dart';
import 'package:dio/dio.dart';
FlutterFeathersjs client = FlutterFeathersjs();
Dio dio = Dio(BaseOptions(
baseUrl: baseUrl,
headers: extraHeaders
));
client.configure(FlutterFeathersjs.rest(dio));
client.service('messages').create({
text: 'A new message'
});
Originally posted by @dmatuschek in #19 (comment)
This is the error I am encountering on calling find query on feathers Js server from flutter app both running on local machine
I/flutter ( 7821): โ โ Unexpected error ::: LateInitializationError: Field 'scketio' has not been initialized.
The error comes from this code below;
This code from my provider;
Future<APIResponse<List<ActivityI>>> getActivities() async {
List<ActivityI>? messages;
String? error;
try {
Map<String, dynamic> response = await socketIOClient.scketio.find(
serviceName: "activities",
query: {},
);
logger.i(response.toString());
messages = List<Map<String, dynamic>>.from(response["data"])
.map((map) => ActivityI.fromMap(map))
.toList();
} on FeatherJsError catch (e) {
logger.e("FeatherJsError error ::: Type => ${e.type} ::: Message => ${e.message}");
error = "Unexpected FeatherJsError occurred, please retry!";
} catch (e) {
logger.e("Unexpected error ::: ${e.toString()}");
error = "Unexpected error occurred, please retry!";
}
return APIResponse(errorMessage: error, data: messages);
}
// Below is how I have initialized my socket-io client for the flutter app;
FlutterFeathersjs socketIOClient = FlutterFeathersjs();
void main() {
WidgetsFlutterBinding.ensureInitialized();
socket.Socket io = socket.io(API.baseUrl, <String, dynamic>{
'transports': ['websocket'],
});
socketIOClient.configure(FlutterFeathersjs.socketioClient(io));
runApp(MultiProvider(providers: [
ChangeNotifierProvider(create: (_) => UserProvider()),
ChangeNotifierProvider(create: (_) => ThemeProvider()),
ChangeNotifierProvider(create: (_) => ActivityProvider()),
], child: const MyApp()));
}
//Currently using flutter_feathersjs: 4.1.5
// socket_io_client: ^2.0.1
// This is my code calling on getActivities from ActivityProvider
fetchActivities() async {
context.read<ActivityProvider>().getActivities().then(
(response) {
isLoading = false;
if (response.errorMessage == null) {
setState(() {
activities = response.data!;
});
} else {
setState(() {
error = response.errorMessage;
});
}
},
);
}
@override
void initState() {
isLoading = true;
fetchActivities();
super.initState();
}
Currently running debug app on memu emulator
Hi Team
I am having this issue when running the init with base url
my init looks like this
flutterFeathersjs.init(baseUrl: "https://www.mysite.xyz/api/");
I.m initialising the instance from an Oninit() hook in my GetxController
flutter logs this error :
flutter: WebSocketException: Connection to 'https://www.mysite.xyz:0/socket.io/?EIO=3&transport=websocket#' was not upgraded to websocket
Notice the https://www.mysite.xyz**:0** (colon zero at the end of the url...port being added to the url in the error message)
I don't know if this is the problem why ...I am testing my backend and all configs are fine on the backend.
this is my Nginx: (for that block - its all that that's required right?)
location /api {
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Upgrade $http_upgrade;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Host $http_host;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://localhost:10123;
}
all my restful services work fine via postman only when I use this lib and run this init...I get the socket upgrade issue
can someone please assist (is there something that's appending the :0 at the end of the url?)
I'm not entirely sure what changed within my project (new packed updated perhaps?), but Flutter Feathers started failing on authentication due to a casting error.
Tracked the problem down to feathersjs.dart, line 61:
//Then auth with jwt socketio
bool isAuthenticated = await (scketio.authWithJWT() as FutureOr<bool>);
Cast exception is thrown as it is expecting Future<dynamic>
.
If I modify the code to use dynamic, it works:
bool isAuthenticated = await (scketio.authWithJWT() as Future<dynamic>);
Update: It's due to my project updating from 3.0.0 of the package to 4.0.2: I didn't have a version specified so it updated unintentionally. Seems there is an issue in 4.0.2?
This feature want the package support a pur dart app (ex: a cli written 100% in dart)
By now, the package is compatible with flutter desktop, but not tested on.
W're looking to provide a demo app and update test to run linux, windows and macOs
Flutter web support is not yet available in this project.
We think this should be quickly fixed.
Connection error
It seems you are trying to reach a Socket.IO server in v2.x with a v3.x client, but they are not compatible (more information here:
https://socket.io/docs/v3/migrating-from-2-x-to-3-0/)
compiled your demo depo, then connected to your: https://flutter-feathersjs.herokuapp.com
Describe the bug
When building my app with this package, I get the error "cannot be called on 'Map<dynamic, dynamic>?' because it is potentially null." We were able to resolve the issue by changing this._socket.io.options['extraHeaders'] = to this._socket.io.options!['extraHeaders'].
I have attached a screenshot of the error and a screenshot of the fix. Can you implement this fix or a fix you deem necessary to resolve the issue?
To Reproduce
Build app with package.
Expected behavior
Build successfully.
** Thanks for this package, @Dahkenangnon โฅโฅ
I have a different approach to connecting to the server.
Every device must connect to its own server.
if this address and port do not connect, show the client an error to check, and dispense with it so that auto-reconnecting does not occur;
i want ti handle this evnt whene socket = FlutterFeathersjs()..init(baseUrl: baseUrl);
this is my Ui Project ->
Does this feathersjs client support Flutter Web target?
These features are planned for from now to June 2022.
More description will be push this weekend to explain in more details these features which are coming.
But before all, i want to know your point of view, would you like these features ?
At the end, this package will be your very cool and very serious choice for flutter mobile app if you like using feathers js rest+realtime api.
Any update on an example for implementaton
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.