websocket channel init enchance

This commit is contained in:
Liang Ding 2014-11-20 11:30:18 +08:00
parent 24908aa309
commit 871e9224ca
6 changed files with 50 additions and 28 deletions

View File

@ -1,11 +1,11 @@
// 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.
@ -43,10 +43,13 @@ func WSHandler(w http.ResponseWriter, r *http.Request) {
conn, _ := websocket.Upgrade(w, r, nil, 1024, 1024)
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"}
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))

View File

@ -1,11 +1,11 @@
// 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.
@ -17,9 +17,9 @@ package notification
import (
"net/http"
"strconv"
"time"
"strconv"
"github.com/b3log/wide/conf"
"github.com/b3log/wide/event"
"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)
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
glog.V(4).Infof("Open a new [Notification] with session [%s], %d", sid, len(session.NotificationWS))

View File

@ -1,11 +1,11 @@
// 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.
@ -58,10 +58,13 @@ func WSHandler(w http.ResponseWriter, r *http.Request) {
conn, _ := websocket.Upgrade(w, r, nil, 1024, 1024)
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"}
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))
}

View File

@ -1,11 +1,11 @@
// 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.
@ -126,10 +126,13 @@ func WSHandler(w http.ResponseWriter, r *http.Request) {
conn, _ := websocket.Upgrade(w, r, nil, 1024, 1024)
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"}
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))

View File

@ -1,11 +1,11 @@
// 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.
@ -89,10 +89,13 @@ func WSHandler(w http.ResponseWriter, r *http.Request) {
conn, _ := websocket.Upgrade(w, r, nil, 1024, 1024)
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"}
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))

View File

@ -35,6 +35,10 @@ var notification = {
var data = JSON.parse(e.data),
$notification = $('.bottom-window-group .notification > table'),
notificationHTML = '';
if (data.cmd && "init-notification" === data.cmd) {
return;
}
notificationHTML += '<tr><td class="severity">' + data.severity
+ '</td><td class="message">' + data.message