mirror of
https://github.com/kataras/iris.git
synced 2025-01-23 18:51:03 +01:00
Fix https://github.com/kataras/go-websocket/issues/27 on iris.v6 too
Former-commit-id: 29b1ea2ff313bdaeb719c242e08c5d5c9149156a
This commit is contained in:
parent
d2aee5e187
commit
86f34dc5df
3
iris.go
3
iris.go
|
@ -288,6 +288,8 @@ func New(setters ...OptionSetter) *Framework {
|
||||||
}
|
}
|
||||||
|
|
||||||
s.Adapt(EventPolicy{Build: func(*Framework) {
|
s.Adapt(EventPolicy{Build: func(*Framework) {
|
||||||
|
// user has registered routes
|
||||||
|
if s.Router.repository.Len() > 0 {
|
||||||
// first check if it's not setted already by any Boot event.
|
// first check if it's not setted already by any Boot event.
|
||||||
if s.Router.handler == nil {
|
if s.Router.handler == nil {
|
||||||
// and most importantly, check if the user has provided a router
|
// and most importantly, check if the user has provided a router
|
||||||
|
@ -308,6 +310,7 @@ func New(setters ...OptionSetter) *Framework {
|
||||||
// buid the router using user's selection build policy
|
// buid the router using user's selection build policy
|
||||||
s.Router.build(s.policies.RouterBuilderPolicy)
|
s.Router.build(s.policies.RouterBuilderPolicy)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}})
|
}})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
20
websocket.go
20
websocket.go
|
@ -36,13 +36,14 @@ type (
|
||||||
// NewWebsocketServer returns a new empty unitialized websocket server
|
// NewWebsocketServer returns a new empty unitialized websocket server
|
||||||
// it runs on first OnConnection
|
// it runs on first OnConnection
|
||||||
func NewWebsocketServer(station *Framework) *WebsocketServer {
|
func NewWebsocketServer(station *Framework) *WebsocketServer {
|
||||||
return &WebsocketServer{station: station, Server: websocket.New()}
|
return &WebsocketServer{station: station, Server: websocket.New(), Config: DefaultWebsocketConfiguration()}
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewWebsocketServer creates the client side source route and the route path Endpoint with the correct Handler
|
// NewWebsocketServer creates the client side source route and the route path Endpoint with the correct Handler
|
||||||
// receives the websocket configuration and the iris station
|
// receives the websocket configuration and the iris station
|
||||||
// and returns the websocket server which can be attached to more than one iris station (if needed)
|
// and returns the websocket server which can be attached to more than one iris station (if needed)
|
||||||
func (ws *WebsocketServer) init() {
|
func (ws *WebsocketServer) init() {
|
||||||
|
|
||||||
if ws.Config.Endpoint == "" {
|
if ws.Config.Endpoint == "" {
|
||||||
ws.Config = ws.station.Config.Websocket
|
ws.Config = ws.station.Config.Websocket
|
||||||
}
|
}
|
||||||
|
@ -52,14 +53,6 @@ func (ws *WebsocketServer) init() {
|
||||||
if c.Endpoint == "" {
|
if c.Endpoint == "" {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// set the routing for client-side source (javascript) (optional)
|
|
||||||
clientSideLookupName := "iris-websocket-client-side"
|
|
||||||
ws.station.Get(c.Endpoint, ToHandler(ws.Server.Handler()))
|
|
||||||
// check if client side already exists
|
|
||||||
if ws.station.Routes().Lookup(clientSideLookupName) == nil {
|
|
||||||
// serve the client side on domain:port/iris-ws.js
|
|
||||||
ws.station.StaticContent("/iris-ws.js", contentJavascript, websocket.ClientSource).ChangeName(clientSideLookupName)
|
|
||||||
}
|
|
||||||
|
|
||||||
if c.CheckOrigin == nil {
|
if c.CheckOrigin == nil {
|
||||||
c.CheckOrigin = DefaultWebsocketCheckOrigin
|
c.CheckOrigin = DefaultWebsocketCheckOrigin
|
||||||
|
@ -85,6 +78,15 @@ func (ws *WebsocketServer) init() {
|
||||||
CheckOrigin: c.CheckOrigin,
|
CheckOrigin: c.CheckOrigin,
|
||||||
IDGenerator: c.IDGenerator,
|
IDGenerator: c.IDGenerator,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// set the routing for client-side source (javascript) (optional)
|
||||||
|
clientSideLookupName := "iris-websocket-client-side"
|
||||||
|
ws.station.Get(c.Endpoint, ToHandler(ws.Server.Handler()))
|
||||||
|
// check if client side already exists
|
||||||
|
if ws.station.Routes().Lookup(clientSideLookupName) == nil {
|
||||||
|
// serve the client side on domain:port/iris-ws.js
|
||||||
|
ws.station.StaticContent("/iris-ws.js", contentJavascript, websocket.ClientSource).ChangeName(clientSideLookupName)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// WebsocketConnection is the front-end API that you will use to communicate with the client side
|
// WebsocketConnection is the front-end API that you will use to communicate with the client side
|
||||||
|
|
Loading…
Reference in New Issue
Block a user