Skip to content

Commit

Permalink
* init
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin-Ben committed Oct 26, 2023
0 parents commit 736e931
Show file tree
Hide file tree
Showing 21 changed files with 2,328 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# websocket
12 changes: 12 additions & 0 deletions config/websocket.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package config

import (
"github.com/goravel/framework/facades"
)

func init() {
config := facades.Config()
config.Add("websocket", map[string]any{

})
}
3 changes: 3 additions & 0 deletions contracts/websocket.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package contracts

type Websocket interface {}
28 changes: 28 additions & 0 deletions events/client_connect_event.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package events

import (
"github.com/goravel/framework/contracts/event"
"github.com/goravel/framework/facades"
)

type ClientConnectEvent struct {
UserId string
ClientId string
Time string
}

func NewClientConnectEvent(UserId string, ClientId string, Time string) error {
err := facades.Event().Job(&ClientConnectEvent{}, []event.Arg{
{Type: "string", Value: UserId},
{Type: "string", Value: ClientId},
{Type: "string", Value: Time},
}).Dispatch()
return err
}

func (receiver *ClientConnectEvent) Handle(args []event.Arg) ([]event.Arg, error) {
receiver.UserId = args[0].Value.(string)
receiver.ClientId = args[1].Value.(string)
receiver.Time = args[2].Value.(string)
return args, nil
}
28 changes: 28 additions & 0 deletions events/client_disconnect_event.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package events

import (
"github.com/goravel/framework/contracts/event"
"github.com/goravel/framework/facades"
)

type ClientDisConnectEvent struct {
UserId string
ClientId string
Time uint64
}

func NewClientDisConnectEvent(UserId string, ClientId string, Time uint64) error {
err := facades.Event().Job(&ClientDisConnectEvent{}, []event.Arg{
{Type: "string", Value: UserId},
{Type: "string", Value: ClientId},
{Type: "string", Value: Time},
}).Dispatch()
return err
}

func (receiver *ClientDisConnectEvent) Handle(args []event.Arg) ([]event.Arg, error) {
receiver.UserId = args[0].Value.(string)
receiver.ClientId = args[1].Value.(string)
receiver.Time = args[2].Value.(uint64)
return args, nil
}
28 changes: 28 additions & 0 deletions events/client_keeplive_event.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package events

import (
"github.com/goravel/framework/contracts/event"
"github.com/goravel/framework/facades"
)

type ClientKeepLiveEvent struct {
UserId string
ClientId string
Time string
}

func NewClientKeepLiveEvent(UserId string, ClientId string, Time string) error {
err := facades.Event().Job(&ClientKeepLiveEvent{}, []event.Arg{
{Type: "string", Value: UserId},
{Type: "string", Value: ClientId},
{Type: "string", Value: Time},
}).Dispatch()
return err
}

func (receiver *ClientKeepLiveEvent) Handle(args []event.Arg) ([]event.Arg, error) {
receiver.UserId = args[0].Value.(string)
receiver.ClientId = args[1].Value.(string)
receiver.Time = args[2].Value.(string)
return args, nil
}
28 changes: 28 additions & 0 deletions events/client_kill_event.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package events

import (
"github.com/goravel/framework/contracts/event"
"github.com/goravel/framework/facades"
)

type ClientKillEvent struct {
UserId string
ClientId string
Time string
}

func NewClientKillEvent(UserId string, ClientId string, Time string) error {
err := facades.Event().Job(&ClientKillEvent{}, []event.Arg{
{Type: "string", Value: UserId},
{Type: "string", Value: ClientId},
{Type: "string", Value: Time},
}).Dispatch()
return err
}

func (receiver *ClientKillEvent) Handle(args []event.Arg) ([]event.Arg, error) {
receiver.UserId = args[0].Value.(string)
receiver.ClientId = args[1].Value.(string)
receiver.Time = args[2].Value.(string)
return args, nil
}
55 changes: 55 additions & 0 deletions events/client_message_event.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package events

import (
"github.com/goravel/framework/contracts/event"
"github.com/goravel/framework/facades"
)

type ClientMessageSuccessEvent struct {
UserId string
ClientId string
Time string
MessageId string
}
type ClientMessageFailEvent struct {
UserId string
ClientId string
Time string
MessageId string
}

func NewClientMessageSuccessEvent(userId, clientId, time, messageId string) error {
err := facades.Event().Job(&ClientMessageSuccessEvent{}, []event.Arg{
{Type: "string", Value: userId},
{Type: "string", Value: clientId},
{Type: "string", Value: time},
{Type: "string", Value: messageId},
}).Dispatch()
return err
}

func (receiver *ClientMessageSuccessEvent) Handle(args []event.Arg) ([]event.Arg, error) {
receiver.UserId = args[0].Value.(string)
receiver.ClientId = args[1].Value.(string)
receiver.Time = args[2].Value.(string)
receiver.MessageId = args[3].Value.(string)
return args, nil
}

func NewClientMessageFailEvent(userId, clientId, time, messageId string) error {
err := facades.Event().Job(&ClientMessageFailEvent{}, []event.Arg{
{Type: "string", Value: userId},
{Type: "string", Value: clientId},
{Type: "string", Value: time},
{Type: "string", Value: messageId},
}).Dispatch()
return err
}

func (receiver *ClientMessageFailEvent) Handle(args []event.Arg) ([]event.Arg, error) {
receiver.UserId = args[0].Value.(string)
receiver.ClientId = args[1].Value.(string)
receiver.Time = args[2].Value.(string)
receiver.MessageId = args[3].Value.(string)
return args, nil
}
28 changes: 28 additions & 0 deletions events/client_offline_event.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package events

import (
"github.com/goravel/framework/contracts/event"
"github.com/goravel/framework/facades"
)

type ClientOffloneEvent struct {
UserId string
ClientId string
Time string
}

func NewClientOffloneEvent(UserId string, ClientId string, Time string) error {
err := facades.Event().Job(&ClientOffloneEvent{}, []event.Arg{
{Type: "string", Value: UserId},
{Type: "string", Value: ClientId},
{Type: "string", Value: Time},
}).Dispatch()
return err
}

func (receiver *ClientOffloneEvent) Handle(args []event.Arg) ([]event.Arg, error) {
receiver.UserId = args[0].Value.(string)
receiver.ClientId = args[1].Value.(string)
receiver.Time = args[2].Value.(string)
return args, nil
}
18 changes: 18 additions & 0 deletions facades/websocket.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package facades

import (
websocket "github.com/okami-chen/goravel-websocket"
"log"

"github.com/okami-chen/goravel-websocket/contracts"
)

func Websocket() contracts.Websocket {
instance, err := websocket.App.Make(websocket.Binding)
if err != nil {
log.Println(err)
return nil
}

return instance.(contracts.Websocket)
}
Loading

0 comments on commit 736e931

Please sign in to comment.