Hi I have made a signalR server application. Simple wss server. If i call it through the signalR.js i works fine. But if i try to call it through std.js og Postman wss plugin i get a WebSocket connection to xxxxx failed. and i have to call it from a non browser client. I get the token ok back:
{"Url":"/signalr/ChatHub","ConnectionToken":"AcOXMhpMcYlqJnPrE5QShYeCuODNI7Abv2c9utk5EJhGGVFxoSsFhj5WqJgk7IM2FqyvQ7oBcp03dGUSv+7ux6QeW+uaaV3NKqCDY53wOaNboI1pihJwIRy2CrQo3pm0","ConnectionId":"32720752-aa1d-4024-89b1-50297a76c39f","KeepAliveTimeout":20.0,"DisconnectTimeout":30.0,"ConnectionTimeout":110.0,"TryWebSockets":true,"ProtocolVersion":"1.5","TransportConnectTimeout":5.0,"LongPollDelay":0.0}
Script that works:
<script src="Scripts/jquery-3.7.0.min.js" ></script>
<script src="Scripts/jquery.signalR-2.4.3.min.js"></script>
<script src="signalr/hubs"></script>
<script type="text/javascript">
$(function () {
var chat = $.connection.chatHub;
chat.client.broadcastMessage = function (Data) {
$('#discussion').append('<li><strong>' + Data + '</strong></li>');
};
// Start the connection.
$.connection.hub.start().done(function () {
chat.server.send('@JsonValue');
});
});
Script that dosent:
<script src="Scripts/jquery-3.7.0.min.js" ></script>
<script type="text/javascript">
async function f() {
let URL = 'https://localhost:44399/signalr/ChatHub/negotiate?clientProtocol=1.5';
let negotiations = await $.get(URL);
let token = encodeURIComponent(negotiations.ConnectionToken);
return Promise.resolve(token)
}
f().then((token) => {
console.log(token)
let wssPath = "wss://localhost:44399/signalr/ChatHub? clientProtocol=1.5&transport=webSockets&connectionToken=" + token
try {
let ws = new WebSocket(wssPath);
}
catch (e) {
alert(e)
}
});
</script>
What do i do wrong??