2014-11-12 18:13:14 +03:00
|
|
|
// Copyright (c) 2014, B3log
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2014-09-16 11:06:52 +04:00
|
|
|
package util
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/gorilla/websocket"
|
|
|
|
)
|
|
|
|
|
2014-10-29 13:15:18 +03:00
|
|
|
// WebSocket channel.
|
2014-09-16 11:06:52 +04:00
|
|
|
type WSChannel struct {
|
2014-10-29 13:15:18 +03:00
|
|
|
Sid string // wide session id
|
|
|
|
Conn *websocket.Conn // websocket connection
|
|
|
|
Request *http.Request // HTTP request related
|
|
|
|
Time time.Time // the latest use time
|
2014-09-16 11:06:52 +04:00
|
|
|
}
|
2014-09-20 06:39:29 +04:00
|
|
|
|
2014-10-29 13:15:18 +03:00
|
|
|
// Close closed the channel.
|
2014-09-20 06:39:29 +04:00
|
|
|
func (c *WSChannel) Close() {
|
|
|
|
c.Conn.Close()
|
|
|
|
}
|
2014-10-28 19:04:46 +03:00
|
|
|
|
2014-10-29 13:15:18 +03:00
|
|
|
// Refresh refreshes the channel by updating its use time.
|
2014-10-28 19:04:46 +03:00
|
|
|
func (c *WSChannel) Refresh() {
|
|
|
|
c.Time = time.Now()
|
|
|
|
}
|