Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F7413774
ve.dm.FakeSocket.js
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
ve.dm.FakeSocket.js
View Options
/*!
* VisualEditor DataModel Fake socket.io-like class for testing
*
* @copyright See AUTHORS.txt
*/
// Fake socket class, with limited API
ve
.
dm
.
FakeSocket
=
function
VeDmFakeSocket
(
server
,
query
)
{
server
.
sockets
.
sockets
.
push
(
this
);
this
.
handlers
=
new
Map
();
this
.
rooms
=
new
Set
();
this
.
pending
=
[];
this
.
handshake
=
{
query
:
query
,
url
:
'fakeurl'
};
this
.
client
=
{
conn
:
{
remoteAddress
:
'fakeaddress'
}
};
this
.
storedDataForDoc
=
{};
this
.
dataForDoc
=
undefined
;
this
.
log
=
[];
};
OO
.
initClass
(
ve
.
dm
.
FakeSocket
);
ve
.
dm
.
FakeSocket
.
static
.
makeServer
=
function
()
{
const
sockets
=
[],
log
=
[];
const
getRoom
=
function
(
roomName
)
{
return
{
emit
:
(
...
args
)
=>
{
sockets
.
forEach
(
(
socket
)
=>
{
if
(
socket
.
rooms
.
has
(
roomName
)
)
{
socket
.
emit
(
...
args
);
}
}
);
}
};
};
const
reset
=
function
()
{
sockets
.
length
=
0
;
log
.
length
=
0
;
};
return
{
sockets
:
{
sockets
:
sockets
,
log
:
log
,
in
:
getRoom
,
reset
:
reset
}
};
};
ve
.
dm
.
FakeSocket
.
prototype
.
join
=
function
(
roomName
)
{
this
.
rooms
.
add
(
roomName
);
};
ve
.
dm
.
FakeSocket
.
prototype
.
emit
=
function
(
eventName
,
...
args
)
{
const
handlers
=
this
.
handlers
.
get
(
eventName
)
||
[];
handlers
.
forEach
(
(
handler
)
=>
{
this
.
pending
.
push
(
handler
(
...
args
)
);
}
);
};
ve
.
dm
.
FakeSocket
.
prototype
.
on
=
function
(
eventName
,
handler
)
{
if
(
!
this
.
handlers
.
has
(
eventName
)
)
{
this
.
handlers
.
set
(
eventName
,
[]
);
}
this
.
handlers
.
get
(
eventName
).
push
(
handler
);
};
ve
.
dm
.
FakeSocket
.
prototype
.
receive
=
function
(
eventName
,
...
args
)
{
const
handlers
=
this
.
handlers
.
get
(
eventName
)
||
[];
handlers
.
forEach
(
(
handler
)
=>
{
this
.
pending
.
push
(
handler
(
...
args
)
);
}
);
};
ve
.
dm
.
FakeSocket
.
prototype
.
wait
=
function
()
{
return
Promise
.
all
(
this
.
pending
);
};
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Nov 22, 01:14 (1 d, 17 h)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
42/fb/1c2757029d1fc4801d536715cb05
Default Alt Text
ve.dm.FakeSocket.js (1 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment