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