Exemplo n.º 1
0
var jsonp : AuthTransport = function(context : Browser, socketId, callback){
  if(this.authOptions.headers !== undefined) {
    Logger.warn("Warn", "To send headers with the auth request, you must use AJAX, rather than JSONP.");
  }

  var callbackName = context.nextAuthCallbackID.toString();
  context.nextAuthCallbackID++;

  var document = context.getDocument();
  var script = document.createElement("script");
  // Hacked wrapper.
  context.auth_callbacks[callbackName] = function(data) {
    callback(false, data);
  };

  var callback_name = "Pusher.auth_callbacks['" + callbackName + "']";
  script.src = this.options.authEndpoint +
    '?callback=' +
    encodeURIComponent(callback_name) +
    '&' +
    this.composeQuery(socketId);

  var head = document.getElementsByTagName("head")[0] || document.documentElement;
  head.insertBefore( script, head.firstChild );
};
Exemplo n.º 2
0
  xhr.onreadystatechange = function() {
    if (xhr.readyState === 4) {
      if (xhr.status === 200) {
        var data, parsed = false;

        try {
          data = JSON.parse(xhr.responseText);
          parsed = true;
        } catch (e) {
          callback(true, 'JSON returned from webapp was invalid, yet status code was 200. Data was: ' + xhr.responseText);
        }

        if (parsed) { // prevents double execution.
          callback(false, data);
        }
      } else {
        var suffix = UrlStore.buildLogSuffix("authenticationEndpoint");
        Logger.warn(
          `Couldn't retrieve authentication info. ${xhr.status}` +
          `Clients must be authenticated to join private or presence channels. ${suffix}`
        );
        callback(true, xhr.status);
      }
    }
  };
Exemplo n.º 3
0
 return fetch(request).then((response)=>{
   let {status} = response;
   if (status === 200) {
     return response.text();
   } else {
     Logger.warn("Couldn't get auth info from your webapp", status);
     throw status;
   }
 }).then((data)=>{
Exemplo n.º 4
0
 }).then((data)=>{
   try {
     data = JSON.parse(data);
   } catch (e) {
     var message = 'JSON returned from webapp was invalid, yet status code was 200. Data was: ' + data;
     Logger.warn(message);
     throw message;
   }
   callback(false, data);
 }).catch((err)=>{
Exemplo n.º 5
0
  xhr.onreadystatechange = function() {
    if (xhr.readyState === 4) {
      if (xhr.status === 200) {
        var data, parsed = false;

        try {
          data = JSON.parse(xhr.responseText);
          parsed = true;
        } catch (e) {
          callback(true, 'JSON returned from webapp was invalid, yet status code was 200. Data was: ' + xhr.responseText);
        }

        if (parsed) { // prevents double execution.
          callback(false, data);
        }
      } else {
        Logger.warn("Couldn't get auth info from your webapp", xhr.status);
        callback(true, xhr.status);
      }
    }
  };