import React, { Component } from 'react'; import * as signalR from'@aspnet/signalr'; class SignalrTest extends Component { constructor(props) { super(props); this.state = { nick: '', message: '', messages: [], hubConnection: null, }; this.joingroup = this.joingroup.bind(this); this.sendMesg = this.sendMesg.bind(this); } componentDidMount() { const protocol = new signalR.JsonHubProtocol(); const transport = signalR.HttpTransportType.WebSockets; const options = { transport, logMessageContent: true, logger: signalR.LogLevel.Trace, accessTokenFactory: () => this.props.accessToken, }; this.state.hubConnection = new signalR.HubConnectionBuilder() .withUrl("https://localhost:44336/chatHub", options) .withHubProtocol(protocol) .build(); this.state.hubConnection.start() .then(() => console.info('SignalR Connected')) .catch(err => console.error('SignalR Connection Error: ', err)); } joingroup(){ } sendMesg(){ this.state.hubConnection .invoke('SendMessage', this.state.nick, this.state.message) .catch(err => console.error(err)); this.setState({message: ''}); } setUser(e){ this.setState({ nick : e.target.value }); } setMesg(e){ this.setState({ message : e.target.value }); } render() { return ( <>
 
User
Message
 

); }; } export default SignalrTest