Users online websocket


#1

Hello,

I can not change the user’s “online”, “offline” behavior
I get ajax request in the browser console, but in my database, the value of “status” is null

Do I have to do the server side query in websockets?

Ws/UserController.js :

'use strict'

class UserController {
  constructor ({ socket, request }) {
    this.socket = socket
    this.request = request
  }
}

module.exports = UserController

Http/UserController.js :

	async status({request, response, auth}){
		const r = request.all()
		const user = await auth.getUser()
		const info = await user.profile().fetch()
		if(request.ajax()){
			await Database.table('profiles').where('user_id', info.user_id).update({ status: r})
			Database.close()
		}
	}

script.js :

function startWS(){
	ws = adonis.Ws('', {path: 'ws'}).connect()
	ws.on('open', () => {
		ws.subscribe('users')
		$.ajax({type: 'POST', data: {status:'online'}, headers: {'x-csrf-token': $csrf_token}, url: '/ajax/status'});
	})
	ws.on('error', () => {
		$.ajax({type: 'POST', data: {status:'offline'}, headers: {'x-csrf-token': $csrf_token}, url: '/ajax/status'});
	})
}

Thanks