websocket channel init enchance
This commit is contained in:
parent
24908aa309
commit
871e9224ca
|
@ -43,10 +43,13 @@ func WSHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
conn, _ := websocket.Upgrade(w, r, nil, 1024, 1024)
|
conn, _ := websocket.Upgrade(w, r, nil, 1024, 1024)
|
||||||
editorChan := util.WSChannel{Sid: sid, Conn: conn, Request: r, Time: time.Now()}
|
editorChan := util.WSChannel{Sid: sid, Conn: conn, Request: r, Time: time.Now()}
|
||||||
|
|
||||||
session.EditorWS[sid] = &editorChan
|
|
||||||
|
|
||||||
ret := map[string]interface{}{"output": "Editor initialized", "cmd": "init-editor"}
|
ret := map[string]interface{}{"output": "Editor initialized", "cmd": "init-editor"}
|
||||||
editorChan.Conn.WriteJSON(&ret)
|
err := editorChan.Conn.WriteJSON(&ret)
|
||||||
|
if nil != err {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
session.EditorWS[sid] = &editorChan
|
||||||
|
|
||||||
glog.Infof("Open a new [Editor] with session [%s], %d", sid, len(session.EditorWS))
|
glog.Infof("Open a new [Editor] with session [%s], %d", sid, len(session.EditorWS))
|
||||||
|
|
||||||
|
|
|
@ -17,9 +17,9 @@ package notification
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"strconv"
|
|
||||||
"github.com/b3log/wide/conf"
|
"github.com/b3log/wide/conf"
|
||||||
"github.com/b3log/wide/event"
|
"github.com/b3log/wide/event"
|
||||||
"github.com/b3log/wide/i18n"
|
"github.com/b3log/wide/i18n"
|
||||||
|
@ -97,6 +97,12 @@ func WSHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
conn, _ := websocket.Upgrade(w, r, nil, 1024, 1024)
|
conn, _ := websocket.Upgrade(w, r, nil, 1024, 1024)
|
||||||
wsChan := util.WSChannel{Sid: sid, Conn: conn, Request: r, Time: time.Now()}
|
wsChan := util.WSChannel{Sid: sid, Conn: conn, Request: r, Time: time.Now()}
|
||||||
|
|
||||||
|
ret := map[string]interface{}{"notification": "Notification initialized", "cmd": "init-notification"}
|
||||||
|
err := wsChan.Conn.WriteJSON(&ret)
|
||||||
|
if nil != err {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
session.NotificationWS[sid] = &wsChan
|
session.NotificationWS[sid] = &wsChan
|
||||||
|
|
||||||
glog.V(4).Infof("Open a new [Notification] with session [%s], %d", sid, len(session.NotificationWS))
|
glog.V(4).Infof("Open a new [Notification] with session [%s], %d", sid, len(session.NotificationWS))
|
||||||
|
|
|
@ -58,10 +58,13 @@ func WSHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
conn, _ := websocket.Upgrade(w, r, nil, 1024, 1024)
|
conn, _ := websocket.Upgrade(w, r, nil, 1024, 1024)
|
||||||
wsChan := util.WSChannel{Sid: sid, Conn: conn, Request: r, Time: time.Now()}
|
wsChan := util.WSChannel{Sid: sid, Conn: conn, Request: r, Time: time.Now()}
|
||||||
|
|
||||||
session.OutputWS[sid] = &wsChan
|
|
||||||
|
|
||||||
ret := map[string]interface{}{"output": "Ouput initialized", "cmd": "init-output"}
|
ret := map[string]interface{}{"output": "Ouput initialized", "cmd": "init-output"}
|
||||||
wsChan.Conn.WriteJSON(&ret)
|
err := wsChan.Conn.WriteJSON(&ret)
|
||||||
|
if nil != err {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
session.OutputWS[sid] = &wsChan
|
||||||
|
|
||||||
glog.V(4).Infof("Open a new [Output] with session [%s], %d", sid, len(session.OutputWS))
|
glog.V(4).Infof("Open a new [Output] with session [%s], %d", sid, len(session.OutputWS))
|
||||||
}
|
}
|
||||||
|
|
|
@ -126,10 +126,13 @@ func WSHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
conn, _ := websocket.Upgrade(w, r, nil, 1024, 1024)
|
conn, _ := websocket.Upgrade(w, r, nil, 1024, 1024)
|
||||||
wsChan := util.WSChannel{Sid: sid, Conn: conn, Request: r, Time: time.Now()}
|
wsChan := util.WSChannel{Sid: sid, Conn: conn, Request: r, Time: time.Now()}
|
||||||
|
|
||||||
SessionWS[sid] = &wsChan
|
|
||||||
|
|
||||||
ret := map[string]interface{}{"output": "Session initialized", "cmd": "init-session"}
|
ret := map[string]interface{}{"output": "Session initialized", "cmd": "init-session"}
|
||||||
wsChan.Conn.WriteJSON(&ret)
|
err := wsChan.Conn.WriteJSON(&ret)
|
||||||
|
if nil != err {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
SessionWS[sid] = &wsChan
|
||||||
|
|
||||||
glog.V(4).Infof("Open a new [Session Channel] with session [%s], %d", sid, len(SessionWS))
|
glog.V(4).Infof("Open a new [Session Channel] with session [%s], %d", sid, len(SessionWS))
|
||||||
|
|
||||||
|
|
|
@ -89,10 +89,13 @@ func WSHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
conn, _ := websocket.Upgrade(w, r, nil, 1024, 1024)
|
conn, _ := websocket.Upgrade(w, r, nil, 1024, 1024)
|
||||||
wsChan := util.WSChannel{Sid: sid, Conn: conn, Request: r, Time: time.Now()}
|
wsChan := util.WSChannel{Sid: sid, Conn: conn, Request: r, Time: time.Now()}
|
||||||
|
|
||||||
ShellWS[sid] = &wsChan
|
|
||||||
|
|
||||||
ret := map[string]interface{}{"output": "Shell initialized", "cmd": "init-shell"}
|
ret := map[string]interface{}{"output": "Shell initialized", "cmd": "init-shell"}
|
||||||
wsChan.Conn.WriteJSON(&ret)
|
err := wsChan.Conn.WriteJSON(&ret)
|
||||||
|
if nil != err {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
ShellWS[sid] = &wsChan
|
||||||
|
|
||||||
glog.V(4).Infof("Open a new [Shell] with session [%s], %d", sid, len(ShellWS))
|
glog.V(4).Infof("Open a new [Shell] with session [%s], %d", sid, len(ShellWS))
|
||||||
|
|
||||||
|
|
|
@ -36,6 +36,10 @@ var notification = {
|
||||||
$notification = $('.bottom-window-group .notification > table'),
|
$notification = $('.bottom-window-group .notification > table'),
|
||||||
notificationHTML = '';
|
notificationHTML = '';
|
||||||
|
|
||||||
|
if (data.cmd && "init-notification" === data.cmd) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
notificationHTML += '<tr><td class="severity">' + data.severity
|
notificationHTML += '<tr><td class="severity">' + data.severity
|
||||||
+ '</td><td class="message">' + data.message
|
+ '</td><td class="message">' + data.message
|
||||||
+ '</td><td class="type">' + data.type + '</td></tr>';
|
+ '</td><td class="type">' + data.type + '</td></tr>';
|
||||||
|
|
Loading…
Reference in New Issue