Skip to content

Commit

Permalink
deploy: d626e6f
Browse files Browse the repository at this point in the history
  • Loading branch information
Neztore committed May 18, 2024
1 parent a47ad5f commit 084032b
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 32 deletions.
66 changes: 41 additions & 25 deletions lib_client_onNotification.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ <h1>lib/client/onNotification.js</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>// Dependencies
const SignalR = require('signalr-client').client
const signalR = require('@microsoft/signalr')
const events = require('events')

// Includes
Expand Down Expand Up @@ -184,34 +184,50 @@ <h1>lib/client/onNotification.js</h1>
args.jar = { session: args.jar }
}
const session = getSession({ jar: args.jar })
const client = new SignalR('wss://realtime.roblox.com/notifications', ['usernotificationhub'], 3, true) // wss for https
client.headers.Cookie = '.ROBLOSECURITY=' + session + ';'
client.on('usernotificationhub', 'notification', function (name, message) {
notifications.emit('data', name, JSON.parse(message))
})
notifications.on('close', client.end)
client.serviceHandlers.connectFailed = function (err) {
notifications.emit('error', new Error('Connection failed: ' + err.message))
if (retries !== -1) {
if (retries > max) {
notifications.emit('close', new Error('Max retries reached'))
} else {
setTimeout(connect, 5000, retries + 1)
let userNotificationConnection = null;

userNotificationConnection = new signalR.HubConnectionBuilder()
.withUrl('https://realtime-signalr.roblox.com/userhub', {
transport: signalR.HttpTransportType.WebSockets,
skipNegotiation: true,
headers: {
Cookie: '.ROBLOSECURITY=' + session + ';'
}
})
.build();

userNotificationConnection.on('notification', function(name, message) {
notifications.emit('data', name, JSON.parse(message))
})

notifications.on('close', userNotificationConnection.stop)

userNotificationConnection.disconnected = function (err) {
notifications.emit('error', new Error('Connection failed: ' + err.message))
if (retries !== -1) {
if (retries > max) {
notifications.emit('close', new Error('Max retries reached'))
} else {
setTimeout(connect, 5000, retries + 1)
}
}
}
}
client.serviceHandlers.onerror = function (err) {
notifications.emit('error', err)
}
client.serviceHandlers.connected = function (connection) {
notifications.emit('connect', connection)
}
client.serviceHandlers.reconnecting = function () {
setTimeout(connect, 5000, 0)

userNotificationConnection.error = function (err) {
notifications.emit('error', err)
}

userNotificationConnection.connected = function(connection) {
notifications.emit('connect', connection)
}

userNotificationConnection.reconnecting = function () {
setTimeout(connect, 5000, 0)
notifications.emit('error', new Error('Lost connection, reconnecting'))
return true // Abort reconnection
}
client.start()
}

userNotificationConnection.start()
}
connect(-1)
return notifications
Expand Down
4 changes: 2 additions & 2 deletions lib_privatemessages_getMessages.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,13 @@ <h1>lib/privatemessages/getMessages.js</h1>
**/

// Define
function getMessages (jar, token, pageNumber, pageSize, messageTab) {
function getMessages (jar, pageNumber, pageSize, messageTab) {
return new Promise((resolve, reject) => {
const httpOpt = {
url: `//privatemessages.roblox.com/v1/messages?pageNumber=${pageNumber}&amp;pageSize=${pageSize}&amp;messageTab=${messageTab}`,
options: {
method: 'GET',
jar,
jar: jar,
resolveWithFullResponse: true
}
}
Expand Down
11 changes: 6 additions & 5 deletions lib_privatemessages_onMessage.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -182,19 +182,20 @@ <h1>lib/privatemessages/onMessage.js</h1>
const onMessage = new events.EventEmitter()
let waitingForRequest = false
let latest
getMessages({ jar, messageTab: 'Inbox', pageNumber: 0 })
getMessages({ jar: jar, messageTab: 'Inbox', pageNumber: 0, pageSize: 1 })
.then(function (initial) {
latest = initial.collection[0] ? initial.collection[0].id : 0
const notifications = onNotification({ jar })
const notifications = onNotification({ jar: jar })
notifications.on('data', function (name, message) {
if (name === 'NotificationStream' &amp;&amp; message.Type === 'NewNotification') {
if (name === 'MessageNotification' &amp;&amp; message.Type === 'Created') {
if (waitingForRequest) {
waitingForRequest = false
} else {
getMessages({
jar,
jar: jar,
messageTab: 'Inbox',
pageNumber: 0
pageNumber: 0,
pageSize: 1
})
.then(function (inbox) {
const messages = inbox.collection
Expand Down

0 comments on commit 084032b

Please sign in to comment.