Skip to content

Commit

Permalink
feat: 增加消息接收器页面
Browse files Browse the repository at this point in the history
  • Loading branch information
rehiy committed Jan 17, 2024
1 parent 95dc96d commit 2402e5e
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 4 deletions.
11 changes: 8 additions & 3 deletions webview/proxy.conf.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
{
"/api": {
"target": "http://124.220.17.201:7600",
"secure": false,
"target": "http://127.0.0.1:7600",
"changeOrigin": true,
"secure": false
},
"/api/socket_receiver": {
"target": "ws://127.0.0.1:7600",
"changeOrigin": true,
"logLevel": "debug"
"secure": false,
"ws": true
}
}
2 changes: 1 addition & 1 deletion webview/src/apps/contacts/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</tr>
</thead>
<tbody>
@for (item of contacts; track item.wxid; let i = $index){
@for (item of contacts; track item.wxid; let i = $index) {
<tr>
<th scope="row">{{i+1}}</th>
<td>{{item.type}}</td>
Expand Down
3 changes: 3 additions & 0 deletions webview/src/apps/pages.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ChatroomsComponent } from './chatrooms';
import { ContactsComponent } from './contacts';
import { ReceiverComponent } from './receiver';
import { OwnerComponent } from './owner';

import { ErrorComponent } from './error';
Expand All @@ -8,6 +9,7 @@ import { ErrorComponent } from './error';
export const AppComponents = [
ChatroomsComponent,
ContactsComponent,
ReceiverComponent,
OwnerComponent,
ErrorComponent,
];
Expand All @@ -20,6 +22,7 @@ export const AppRoutes: Routes = [
{ path: '', redirectTo: 'owner', pathMatch: 'full' },
{ path: 'chatrooms', component: ChatroomsComponent },
{ path: 'contacts', component: ContactsComponent },
{ path: 'receiver', component: ReceiverComponent },
{ path: 'owner', component: OwnerComponent },
{ path: '**', component: ErrorComponent, data: { error: 404 } }
];
5 changes: 5 additions & 0 deletions webview/src/apps/receiver/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<layout-header></layout-header>

<div class="container-lg mt-3">
<textarea class="form-control" rows="20">{{messages.join('\n\n')}}</textarea>
</div>
Empty file.
34 changes: 34 additions & 0 deletions webview/src/apps/receiver/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { Component } from '@angular/core';


@Component({
selector: 'page-receiver',
templateUrl: 'index.html',
styleUrls: ['index.scss']
})
export class ReceiverComponent {

public messages: Array<string> = [];

constructor() {
this.startSocket();
}

public async startSocket() {
const url = location.origin.replace(/^http/, 'ws');
const websocket = new WebSocket(url + '/api/socket_receiver');
websocket.onopen = () => {
this.messages.push('WebSocket is connected.');
};
websocket.onmessage = event => {
this.messages.push(event.data);
};
websocket.onerror = (error) => {
this.messages.push('WebSocket Error:' + error);
};
websocket.onclose = () => {
this.messages.push('WebSocket is closed now.');
};
}

}
3 changes: 3 additions & 0 deletions webview/src/layouts/header/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
<li class="nav-item">
<a routerLink="/contacts" routerLinkActive="active" class="nav-link">通讯录</a>
</li>
<li class="nav-item">
<a routerLink="/receiver" routerLinkActive="active" class="nav-link">消息接收</a>
</li>
</ul>
<div>
<a class="nav-link" href="/swagger/" target="_blank">Api Docs</a>
Expand Down

0 comments on commit 2402e5e

Please sign in to comment.