Skip to content

Instantly share code, notes, and snippets.

@goto-bus-stop
Created September 1, 2015 20:20
Show Gist options
  • Save goto-bus-stop/6ec971244e2cb3d86d0e to your computer and use it in GitHub Desktop.
Save goto-bus-stop/6ec971244e2cb3d86d0e to your computer and use it in GitHub Desktop.
Get the live plug.dj WebSocket instance.
var currentUser = plugModules.require('plug/models/currentUser');
var currentRoom = plugModules.require('plug/models/currentRoom');
var chatFacade = plugModules.require('plug/facades/chatFacade');
var CHAT_INTERCEPT_STRING = 'ExtPlug socket patching thing\n\n';
function getSocket() {
// gives the user all permissions client-side temporarily, also avoiding
// mutes and slow modes in the process.
var originalUser = currentUser.toJSON();
var originalJoined = currentRoom.get('joined');
currentUser.set({
id: 1,
guest: false,
level: 50,
role: 5,
gRole: 5
}, { silent: true });
currentRoom.set('joined', true, { silent: true });
var _send = WebSocket.prototype.send;
var socket;
WebSocket.prototype.send = function (data) {
if (data.indexOf(CHAT_INTERCEPT_STRING)) {
socket = this;
WebSocket.prototype.send = _send;
}
};
chatFacade.sendChat(CHAT_INTERCEPT_STRING);
currentUser.set(originalUser, { silent: true });
currentRoom.set('joined', originalJoined, { silent: true });
return socket;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment