Created
September 1, 2015 20:20
-
-
Save goto-bus-stop/6ec971244e2cb3d86d0e to your computer and use it in GitHub Desktop.
Get the live plug.dj WebSocket instance.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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