mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
add system error.
This commit is contained in:
parent
9e466b08cc
commit
313cd55049
@ -11,6 +11,7 @@ export const EVENT = {
|
||||
// Websocket Events
|
||||
SYSTEM: {
|
||||
DISCONNECT: 'system/disconnect',
|
||||
ERROR: 'system/error',
|
||||
},
|
||||
SIGNAL: {
|
||||
ANSWER: 'signal/answer',
|
||||
|
@ -6,7 +6,7 @@ import { EVENT } from './events'
|
||||
import { accessor } from '~/store'
|
||||
|
||||
import {
|
||||
DisconnectPayload,
|
||||
SystemMessagePayload,
|
||||
SignalProvidePayload,
|
||||
MemberListPayload,
|
||||
MemberDisconnectPayload,
|
||||
@ -130,7 +130,7 @@ export class NekoClient extends BaseClient implements EventEmitter<NekoEvents> {
|
||||
/////////////////////////////
|
||||
// System Events
|
||||
/////////////////////////////
|
||||
protected [EVENT.SYSTEM.DISCONNECT]({ message }: DisconnectPayload) {
|
||||
protected [EVENT.SYSTEM.DISCONNECT]({ message }: SystemMessagePayload) {
|
||||
if (message == 'kicked') {
|
||||
this.$accessor.logout()
|
||||
message = this.$vue.$t('connection.kicked') as string
|
||||
@ -146,6 +146,15 @@ export class NekoClient extends BaseClient implements EventEmitter<NekoEvents> {
|
||||
})
|
||||
}
|
||||
|
||||
protected [EVENT.SYSTEM.ERROR]({ title, message }: SystemMessagePayload) {
|
||||
this.$vue.$swal({
|
||||
title,
|
||||
text: message,
|
||||
icon: 'error',
|
||||
confirmButtonText: this.$vue.$t('connection.button_confirm') as string,
|
||||
})
|
||||
}
|
||||
|
||||
/////////////////////////////
|
||||
// Member Events
|
||||
/////////////////////////////
|
||||
|
@ -50,10 +50,12 @@ export interface WebSocketMessage {
|
||||
SYSTEM MESSAGES/PAYLOADS
|
||||
*/
|
||||
// system/disconnect
|
||||
export interface DisconnectMessage extends WebSocketMessage, DisconnectPayload {
|
||||
event: typeof EVENT.SYSTEM.DISCONNECT
|
||||
// system/error
|
||||
export interface SystemMessage extends WebSocketMessage, SystemMessagePayload {
|
||||
event: typeof EVENT.SYSTEM.DISCONNECT | typeof EVENT.SYSTEM.ERROR
|
||||
}
|
||||
export interface DisconnectPayload {
|
||||
export interface SystemMessagePayload {
|
||||
title: string
|
||||
message: string
|
||||
}
|
||||
|
||||
|
@ -86,7 +86,7 @@ func (session *Session) Kick(reason string) error {
|
||||
if session.socket == nil {
|
||||
return nil
|
||||
}
|
||||
if err := session.socket.Send(&message.Disconnect{
|
||||
if err := session.socket.Send(&message.SystemMessage{
|
||||
Event: event.SYSTEM_DISCONNECT,
|
||||
Message: reason,
|
||||
}); err != nil {
|
||||
|
@ -2,6 +2,7 @@ package event
|
||||
|
||||
const (
|
||||
SYSTEM_DISCONNECT = "system/disconnect"
|
||||
SYSTEM_ERROR = "system/error"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -10,8 +10,9 @@ type Message struct {
|
||||
Event string `json:"event"`
|
||||
}
|
||||
|
||||
type Disconnect struct {
|
||||
type SystemMessage struct {
|
||||
Event string `json:"event"`
|
||||
Title string `json:"title"`
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
|
@ -12,8 +12,17 @@ func (h *MessageHandler) boradcastCreate(session types.Session, payload *message
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := h.broadcast.Create(payload.URL); err != nil {
|
||||
return err
|
||||
pipelineErr := h.broadcast.Create(payload.URL)
|
||||
if pipelineErr != nil {
|
||||
if err := session.Send(
|
||||
message.SystemMessage{
|
||||
Event: event.SYSTEM_ERROR,
|
||||
Title: "Error while starting broadcast",
|
||||
Message: pipelineErr.Error(),
|
||||
}); err != nil {
|
||||
h.logger.Warn().Err(err).Msgf("sending event %s has failed", event.SYSTEM_ERROR)
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if err := h.boradcastStatus(session); err != nil {
|
||||
|
@ -133,7 +133,7 @@ func (ws *WebSocketHandler) Upgrade(w http.ResponseWriter, r *http.Request) erro
|
||||
if err != nil {
|
||||
ws.logger.Warn().Err(err).Msg("authentication failed")
|
||||
|
||||
if err = connection.WriteJSON(message.Disconnect{
|
||||
if err = connection.WriteJSON(message.SystemMessage{
|
||||
Event: event.SYSTEM_DISCONNECT,
|
||||
Message: "invalid_password",
|
||||
}); err != nil {
|
||||
@ -160,7 +160,7 @@ func (ws *WebSocketHandler) Upgrade(w http.ResponseWriter, r *http.Request) erro
|
||||
}
|
||||
|
||||
if !ok {
|
||||
if err = connection.WriteJSON(message.Disconnect{
|
||||
if err = connection.WriteJSON(message.SystemMessage{
|
||||
Event: event.SYSTEM_DISCONNECT,
|
||||
Message: reason,
|
||||
}); err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user