You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
1.6 KiB
Dart
61 lines
1.6 KiB
Dart
import 'dart:io';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:http/io_client.dart';
|
|
import 'package:signalr_core/signalr_core.dart';
|
|
|
|
class SignalRHelper{
|
|
|
|
String hubBaseURL ="https://queueing.hmg.com/signalr/hubs";
|
|
// "https://VCallApi.hmg.com/WebRTCHub?source=mobile&username=2001273";
|
|
String msg ="Awaiting Patients Arrival";
|
|
HubConnection connection;
|
|
startSignalRConnection() async {
|
|
connection = HubConnectionBuilder()
|
|
.withUrl(
|
|
hubBaseURL,
|
|
HttpConnectionOptions(
|
|
client: IOClient(HttpClient()..badCertificateCallback = (x, y, z) => true),
|
|
transport: HttpTransportType.webSockets,
|
|
logging: (level, message) => {print(message)
|
|
|
|
},
|
|
))
|
|
.build();
|
|
|
|
await connection.start();
|
|
|
|
connection.on('ReceiveMessage', (message) {
|
|
handleIncomingMessage(message);
|
|
});
|
|
|
|
|
|
connection.start();
|
|
|
|
|
|
}
|
|
|
|
|
|
void handleIncomingMessage(List<dynamic> message) {
|
|
print(message.toString());
|
|
}
|
|
|
|
void sendMessage(List<dynamic> args) async {
|
|
await connection.invoke('SendMessage', args: args); //['Bob', 'Says hi!']
|
|
}
|
|
|
|
bool getConnectionState() {
|
|
if(connection == null ) return false;
|
|
if (connection.state == HubConnectionState.connected || connection.state == HubConnectionState.connecting) return true;
|
|
if (connection.state == HubConnectionState.disconnected || connection.state == HubConnectionState.disconnecting) return false;
|
|
}
|
|
|
|
|
|
|
|
closeConnection(BuildContext context) async {
|
|
if(connection.state == HubConnectionState.connected)
|
|
{
|
|
await connection.stop();
|
|
}
|
|
}
|
|
} |