Is there a way to emulate in Fiddler or Swift what this js send to signalr:
$(function () {
// Declare a proxy to reference the hub.
var chat = $.connection.chatHub;
// Create a function that the hub can call to broadcast messages.
chat.client.broadcastMessage = function (name, message) {
// Html encode display name and message.
var encodedName = $('<div />').text(name).html();
var encodedMsg = $('<div />').text(message).html();
// Add the message to the page.
$('#discussion').append('<li><strong>' + encodedName
+ '</strong>: ' + encodedMsg + '</li>');
};
// Get the user name and store it to prepend to messages.
$('#displayname').val(prompt('Enter your name:', ''));
// Set initial focus to message input box.
$('#message').focus();
// Start the connection.
$.connection.hub.start().done(function () {
$('#sendmessage').click(function () {
// Call the Send method on the hub.
chat.server.send($('#displayname').val(), $('#message').val());
// Clear text box and reset focus for next comment.
$('#message').val('').focus();
});
});
});
that page is residing in an HTML accessed via my iis server: http://abc/HubSample/ (abc is my server name) This is the C# code it calls:
public class ChatHub : Hub
{
public void Send(string name, string message)
{
// Call the broadcastMessage method to update clients.
Clients.All.broadcastMessage(name, message);
}
}
I can call that html page just fine from other servers too. The goal is to include different clients (not just js ones) in calling that method.
I've tried in Swift calling it like this:
// Default is false
SwiftR.useWKWebView = true
// Default is .Auto
SwiftR.transport = .ServerSentEvents
// Hubs...
hubConnection = SwiftR.connect("http://abc/HubSample") { [weak self] connection in
connection.queryString = ["foo": "bar"]
connection.headers = ["X-MyHeader1": "Value1", "X-MyHeader2": "Value2"]
// This only works with WKWebView on iOS >= 9
// Otherwise, use NSUserDefaults.standardUserDefaults().registerDefaults(["UserAgent": "SwiftR iOS Demo App"])
connection.customUserAgent = "SwiftR iOS Demo App"
self?.simpleHub = connection.createHubProxy("simpleHub")
self?.complexHub = connection.createHubProxy("complexHub")
self?.simpleHub.on("broadcastMessage") { args in
let message = args![0] as! String
let detail = args![1] as! String
print("Message: \(message)\nDetail: \(detail)\n")
}
But I keep getting this error in XCode and Safari dev tools:
SwiftR unable to process message h0z81qhh: Error Domain=WKErrorDomain Code=5 "JavaScript execution returned a result of an unsupported type" UserInfo={NSLocalizedDescription=JavaScript execution returned a result of an unsupported type}
XMLHttpRequest cannot load http://abc/HubSample/signalr/negotiate?clientProtocol=1.5&foo=bar&connectionData=%5B%7B%22name%22%3A%22simplehub%22%7D%2C%7B%22name%22%3A%22complexhub%22%7D%5D&_=1463691894451. Origin null is not allowed by Access-Control-Allow-Origin.
Calling it from Swift is ideal but would be happy seeing it accessible from any other client (other than javascript)
has anyone tried to do this!?