Exemplo n.º 1
0
const Actions = flux.createActions({
  start_video_chat: function (connId) {
    if (cantStartVideoChat) {
      return new Error("Can't start video yet.");
    }
    if (prefs.dnd) {
      editorAction.pref("dnd", false);
      messageAction.info("Do not disturb disabled.");
    }
    if (perms.indexOf("patch") === -1) {
      messageAction.info("You need edit permissions to video chat.");
      return new Error("No permission to video chat.");
    }
    // Kinda hacky but whatever.
    if (prefs.audioOnly) {
      this.start_audio_chat(connId);
      return new Error("Starting audio chat.");
    }
    return connId;
  },
  stop_video_chat: function (connId) {
    // Kinda hacky but whatever.
    if (prefs.audioOnly) {
      this.stop_audio_chat(connId);
      return new Error("Stopping audio chat.");
    }
    return connId;
  },
  start_audio_chat: function (connId) {
    return connId;
  },
  stop_audio_chat: function (connId) {
    return connId;
  },
  start_screen: function (connId) {
    var errMsg;
    if (canShareScreen) {
      if (prefs.dnd) {
        editorAction.pref("dnd", false);
        messageAction.info("Do not disturb disabled.");
      }
      return connId;
    }

    if (!self.chrome || !chrome.app) {
      errMsg = "Screen sharing requires Google Chrome and the Floobits screen sharing extension.";
      Modal.showWithText(errMsg, "Can't Share Screen");
      messageAction.warn(errMsg);
      return new Error(errMsg);
    }

    try {
      chrome.webstore.install("https://chrome.google.com/webstore/detail/lmojaknpofhmdnbpanagbbeinbjmbodo", function () {
        self.location.reload();
      });
    } catch (e) {
      self.open("https://chrome.google.com/webstore/detail/lmojaknpofhmdnbpanagbbeinbjmbodo");
    }
    return new Error("User may install extension");
  },
  stop_screen: function (connId) {
    return connId;
  },
  can_share_screen: function (can) {
    canShareScreen = can;
    return can;
  },
  get_constraints: function (type, baseContraints, cb) {
    const constraints = _.extend({}, baseContraints);

    const getSource = function (sources, _type) {
      const id = prefs["source_" + _type + "_id"];

      let source = _.find(sources, function (s) {
        return s.id === id && s.kind === _type;
      });

      if (source) {
        return source.id;
      }

      const name = prefs["source_" + _type + "_name"];

      console.warn("Could not find video source", id);
      source = _.find(sources, function (s) {
        return s.label === name && s.kind === _type;
      });

      if (source) {
        console.warn("Found source with the same name", name);
        return source.id;
      }
      return null;
    };

    if (!MediaStreamTrack || !MediaStreamTrack.getSources || type === "screen") {
      return cb(null, constraints);
    }

    MediaStreamTrack.getSources(function (sources) {
      let getAudioDevice = type === "audio";
      if (type === "video") {
        if (_.isBoolean(baseContraints.audio)) {
          getAudioDevice = baseContraints.audio;
        } else {
          getAudioDevice = _.isObject(baseContraints.audio);
        }
      }
      if (getAudioDevice) {
        const id = getSource(sources, "audio");
        if (id) {
          let c = constraints.audio;
          if (_.isBoolean(c)) {
            c = constraints.audio = {};
          }
          if (!c.optional) {
            c.optional = [];
          }
          c.optional.push({sourceId: id});
        }
      }
      if (type === "video") {
        const id = getSource(sources, type);
        if (id) {
          constraints[type].optional.push({sourceId: id});
        }
      }
      console.log("constraints for", type, constraints);
      return cb(null, constraints);
    });
  },
  closedStreams: function () {
    if (cantStartVideoChat) {
      return;
    }
    cantStartVideoChat = true;
    _.delay(function () {
      cantStartVideoChat = false;
    }, 2000);
  },
});
Exemplo n.º 2
0
const _ = require("lodash");
const flux = require("flukes");

const floop = require("./floop");
const utils = require("./utils");
const editorAction = require("./editor_action");

let context = null;
try {
  context = window.AudioContext && new window.AudioContext();
} catch (e) {
  console.log("Unable to create context.", e);
}
const Visualizer = flux.createActions({
  visualize: function (width) { return width; }
});


const Connection = flux.createModel({
  modelName: "Connection",
  fieldTypes: {
    id: flux.FieldTypes.number,
    path: flux.FieldTypes.string,
    bufId: flux.FieldTypes.number,
    client: flux.FieldTypes.string,
    platform: flux.FieldTypes.string,
    version: flux.FieldTypes.string,
    connected: flux.FieldTypes.bool,
    isMe: flux.FieldTypes.bool,
    // B&W thumbnail
Exemplo n.º 3
0
 */
actions.emitDataMessage = function (data, to) {
  console.log("emitting data message", data, to);
  if (!this.transport) {
    console.log("There is no socket to send with. We are currently disconnected.");
    return;
  }
  this.transport.write("datamsg", {
    data: data,
    to: to
  });
};

actions.connected = false;

let Actions = flux.createActions(actions);

Actions.prototype.send_ = function (name, data, on_write, on_response) {
  if (!this.transport) {
    console.log("There is no socket to send with. We are currently disconnected.");
    return new Error("Floobits is not connected to a workspace.");
  }

  if (name !== "auth" && !authorized) {
    console.log("Not authorized yet.");
    return new Error("You are not authorized to do that (yet, maybe).");
  }

  if (!("req_id" in data || "res_id" in data)) {
    data.req_id = ++this.requestId;
  }
Exemplo n.º 4
0
"use strict";

var flux = require("flukes");

const Actions = flux.createActions({
  changed: function (buf, constCharPointer, patches, username) {
    return [buf, constCharPointer || [buf.buf], patches, username];
  },
  deleted: function (buf, unlink) {
    return [buf, unlink];
  },
  saved: function (buf) {
    return buf;
  },
  rename: function (buf, oldPath, newPath) {
    return [buf, oldPath, newPath];
  },
  created: function (buf, username, connID) {
    return [buf, username, connID];
  },
  // pseudo event for on RI
  add: function (buf) {
    return buf;
  },
});

module.exports = new Actions();