I am using socket_io_client package to communicate with nodejs socket server.
Here is my socket configuration for flutter:
socket = IO.io(SocketUrl.url, <String, dynamic>{
'transports': ["websocket"],
"autoConnect": false
});
socket.connect();
socket.on('connect', (_) {
print('socket connected to server');
});
socket.on('newMessage', (message) {
print(message);
});
socket.on('event', (data) => print(data));
socket.on('disconnect', (_) => print('disconnect'));
}
Here is logic for file sending:
const data = {
userId: currentUser.id,
file: file.name
};
const stream = ss.createStream();
ss(socket).emit("send-file", stream, data);
ss.createBlobReadStream(file).pipe(stream);
This is how it would be done from a node client. I need to write dart version of above code. I saw that quiver package has async functions to create streambuffer but I don't know how to implement that for this particular application.
Edited:
void onSendFile(file, data) async {
final isFile = File(file);
var buffer = isFile.openRead();
//socket.emit("send-file",[buffer,data]);
socket.emitWithBinary("send-file", [buffer, data]);
}