You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Import the library.
import 'package:signalr_client/signalr_client.dart';
import 'package:logging/logging.dart';
import 'package:xperience/models/global.dart';
// The location of the SignalR Server.
final serverUrl = "http://" + base + ":8070/CommentHub";
final hubConnection = HubConnectionBuilder().withUrl(serverUrl).build();
class HubService {
static final hubProtLogger = Logger("SignalR - hub");
static final transportProtLogger = Logger("SignalR - transport");
static final connectionOptions = HttpConnectionOptions;
static final httpOptions = new HttpConnectionOptions(logger: transportProtLogger);
HubConnection hubConnection = HubConnectionBuilder().withUrl(serverUrl, options: httpOptions).configureLogging(hubProtLogger).build();
bool connectionIsOpen;
Future<void> openChatConnection() async {
if (hubConnection == null) {
hubConnection.onclose((error) => connectionIsOpen = false);
}
await hubConnection.start();
connectionIsOpen = true;
}
@override
Future<void> executeTest(String json) async {
hubConnection.on("AddUser", _handleServerInvokeMethodSimpleParametersNoReturnValue);
try {
await hubConnection.invoke("AddUser",args:<Object>[json]);
} finally {
hubConnection.off("AddUser", method: _handleServerInvokeMethodSimpleParametersNoReturnValue);
}
}
void _handleServerInvokeMethodSimpleParametersNoReturnValue(List<Object> parameters) {
final paramValues = new StringBuffer("Parameters: ");
for(int i = 0; i < parameters.length; i++){
final value = parameters[i];
paramValues.write( "$i => $value, ");
}
print("From Callback: Server invoked method 'ServerInvokeMethodSimpleParametersNoReturnValue': " + paramValues.toString());
}
Future removeUser() async {
// final result = await hubConnection.invoke("RemoveUser",args: <Object>[]);
// print(result);
hubConnection.stop();
//hubConnection.onclose( (error) => print("Connection Closed"));
}
}
This is my CommentHub.cs in asp.net core:
using System;
using Microsoft.AspNetCore.SignalR;
using Microsoft.AspNet.SignalR.Hubs;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Linq;
using Xperience.Data.Entities.Posts;
namespace Xperience.Hub
{
public class CommentHub : Microsoft.AspNetCore.SignalR.Hub
{
public static List<Connection> Connections = new List<Connection>();
public void AddUser(string json) {
string []arr=json.split(",");
Connections.Add(new Connection
{
ConnectionId = Context.ConnectionId,
UserId = json[0],
PostId = json[1]
});
}
public void RemoveUser() {
var user = Connections.Find(x => x.ConnectionId == Context.ConnectionId);
Connections.Remove(user);
}
}
public class Connection {
public string ConnectionId { get; set; }
public string UserId { get; set; }
public int PostId { get; set; }
}
}
Can someone please tell me what's the wrong thing im doing as im always getting this error when i invoke executeTest:
Unhandled Exception: type 'GeneralError' is not a subtype of type 'Error' in type cast
The text was updated successfully, but these errors were encountered:
This is my CommentHub in flutter:
This is my CommentHub.cs in asp.net core:
Can someone please tell me what's the wrong thing im doing as im always getting this error when i invoke executeTest:
Unhandled Exception: type 'GeneralError' is not a subtype of type 'Error' in type cast
The text was updated successfully, but these errors were encountered: