signalrvisual-studio-lightswitchlightswitch-2013

Lightswitch HTML - chat application upgrade


I wanted to know if anyone has given this a go and got it working?

http://lightswitchhelpwebsite.com/Blog/tabid/61/EntryId/182/Connecting-To-SignalR-With-LightSwitch-HTML-Client.aspx

Basically my issue is i cant open the file to begin with, whether it be Visual Studio 2012, 2013 or 2015, so I have followed the guide and used the files from the downloaded project for this error message to occur:

enter image description here

which is caused by this line under the sendmessage_execute function:

chat.server.send(screen.displayname, screen.message);

im hoping someone has got this working and could point out anything different from the user guide, heres what I have used/done:

Under the PROJECT.Server I have:

  1. created a folder called SignalR with the file ChatHub.cs in
  2. added the json2.js (both) and signalR (both) files to the scripts folder

Under the Project.HTMLClient

  1. added the json2.js (both) and signalR (both) files to the scripts folder
  2. referenced the scripts including the localhost in the default.htm file
  3. Created a screen. called ChatScreen and added all the referenced code here from the guide online (3 strings and 1 button)

i also installed the Nu-GET as instructed


Solution

  • More research for this was required, I found this post which explains how to do it a lot easier and in an application for both 2013/2015, works a treat and can easily be adapted for other screens

    https://blogs.msdn.microsoft.com/rmattsampson/2013/03/14/asp-net-signalr-and-lightswitch-vs-2012-update-2-vs-2013-and-later/

    I have also managed to edit there block of code to list all messages in a string, this is not stored and refresh's each time but its now possible to have a conversation while on the same screen

    var string;
    
    myapp.ChatScreen.created = function (screen) {
    
    string = "";
    
    $(function () {
    
        chat = $.connection.chatHub;
        chat.client.broadcastMessage = function (message) {
    
            string = string + message + ";";
            screen.updates = string.split(';').join("\r\n");
            console.log(string.split(';').join("\r\n"))
    
    
        };
    
        $.connection.hub.start()
        .done(function () {
        })
        .fail(function () {
            alert("Could not Connect! - ensure EnableCrossDomain = true");
        });
    });
    

    };

    It would be better practice using an array and displaying it this way but the code above demonstrates it works