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 message) { print(message.toString()); } void sendMessage(List 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(); } } }