Click here to Skip to main content
15,860,972 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello guys.

I don't know if it's possible, but, I have two websites, the websites are located in different servers. One of the applications is a chat, and in the other application I need to know if the chat have agents. If the chat have agents, then the chat is open. And in the first application will appear a button or a green light indicating that the chat is open.

This first application is developed in wordpress, so I need to try the using of signalr only with html and javascript, calling a method through signalr for checking if the chat is open.

Other option is to use a webapi, calling a method through webapi that return 1 if the chat is open or 0 if the chat is closed. But, the problem is that I need to do this in realtime, with this option, I need to reload the page over and over again.

It is possible to use signalr in this case only with html and javascript?

Thanks in advance.
Posted

Here's a vanilla javascript that will check a server periodically:

JavaScript
var timer;

function checkStatus(){
   var xhr = new XMLHttpRequest();
   xhr.open('GET','Your web service address');
   xhr.onreadystatechange = function(){
      if (xhr.readyState == 4) {
         if(req.status == 200){
            //Do something
         }
         else{
            // Handle error  
         } 
      }
   }
   xhr.send();
}

function startListening(){
    timer = setInterval(checkStatus,1000);
}

function stopListening(){
   clearInterval(timer);
}

startListening();


Add logic to the load and error event callbacks and add the address where indicated. Make it POST if you need to.
 
Share this answer
 
I have the solution.

$(document).ready(function () {
var pop = new Pop();
pop.Start("http://www.url.com/signalr/hubs");
});

In Pop I have the connection to the Hub

pseudocode
function Start(url) {
var base = this;
this.connection.hub.url = url;
this.connection.hub.start().done(function () {
base.Generate(); ->I put a message on the other website
base.chat.server.state(); -> I make visible or not that message depending on the operating status. The function State is on the other website.
}).fail(function (reason) {
console.log("Connection failed: " + reason);
});

base.InitCallerMethods();
}

Nathan , your solution is correct also , but I think it is best to approach SignalR for this, because you have the results in real time directly, without configuration as WebAPI.

Thank you very much to everybody.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900