mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-20 23:46:14 -04:00
Remove dependency on a global socket and address pad.socket
instead.
This commit is contained in:
parent
6bbc32a19f
commit
003c2a59aa
2 changed files with 16 additions and 8 deletions
|
@ -25,12 +25,20 @@ $(window).bind("load", function()
|
|||
getCollabClient.windowLoaded = true;
|
||||
});
|
||||
|
||||
// Dependency fill on init. This exists for `pad.socket` only.
|
||||
// TODO: bind directly to the socket.
|
||||
var pad = undefined;
|
||||
function getSocket() {
|
||||
return pad && pad.socket;
|
||||
}
|
||||
|
||||
/** Call this when the document is ready, and a new Ace2Editor() has been created and inited.
|
||||
ACE's ready callback does not need to have fired yet.
|
||||
"serverVars" are from calling doc.getCollabClientVars() on the server. */
|
||||
function getCollabClient(ace2editor, serverVars, initialUserInfo, options)
|
||||
function getCollabClient(ace2editor, serverVars, initialUserInfo, options, _pad)
|
||||
{
|
||||
var editor = ace2editor;
|
||||
pad = _pad; // Inject pad to avoid a circular dependency.
|
||||
|
||||
var rev = serverVars.rev;
|
||||
var padId = serverVars.padId;
|
||||
|
@ -81,7 +89,7 @@ function getCollabClient(ace2editor, serverVars, initialUserInfo, options)
|
|||
|
||||
$(window).bind("unload", function()
|
||||
{
|
||||
if (socket)
|
||||
if (getSocket())
|
||||
{
|
||||
setChannelState("DISCONNECTED", "unload");
|
||||
}
|
||||
|
@ -111,7 +119,7 @@ function getCollabClient(ace2editor, serverVars, initialUserInfo, options)
|
|||
|
||||
function handleUserChanges()
|
||||
{
|
||||
if ((!socket) || channelState == "CONNECTING")
|
||||
if ((!getSocket()) || channelState == "CONNECTING")
|
||||
{
|
||||
if (channelState == "CONNECTING" && (((+new Date()) - initialStartConnectTime) > 20000))
|
||||
{
|
||||
|
@ -295,7 +303,7 @@ function getCollabClient(ace2editor, serverVars, initialUserInfo, options)
|
|||
|
||||
function sendMessage(msg)
|
||||
{
|
||||
socket.json.send(
|
||||
getSocket().json.send(
|
||||
{
|
||||
type: "COLLABROOM",
|
||||
component: "pad",
|
||||
|
@ -337,7 +345,7 @@ function getCollabClient(ace2editor, serverVars, initialUserInfo, options)
|
|||
{
|
||||
if (window.console) console.log(evt);
|
||||
|
||||
if (!socket) return;
|
||||
if (!getSocket()) return;
|
||||
if (!evt.data) return;
|
||||
var wrapper = evt;
|
||||
if (wrapper.type != "COLLABROOM") return;
|
||||
|
@ -442,7 +450,7 @@ function getCollabClient(ace2editor, serverVars, initialUserInfo, options)
|
|||
userInfo.userId = userId;
|
||||
userSet[userId] = userInfo;
|
||||
tellAceActiveAuthorInfo(userInfo);
|
||||
if (!socket) return;
|
||||
if (!getSocket()) return;
|
||||
sendMessage(
|
||||
{
|
||||
type: "USERINFO_UPDATE",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue