From 55ca35c3c8a9aa7f146522ff742b93d78756780b Mon Sep 17 00:00:00 2001 From: Namekuji Date: Sat, 28 Jan 2023 15:08:15 -0500 Subject: [PATCH] allow cohosts to close the room --- audon-fe/src/App.vue | 6 +- audon-fe/src/assets/style.css | 5 +- audon-fe/src/components/JoinDialog.vue | 1 - audon-fe/src/components/SettingPanel.vue | 0 audon-fe/src/locales/en.yaml | 4 +- audon-fe/src/locales/ja.yaml | 4 +- audon-fe/src/views/HomeView.vue | 6 +- audon-fe/src/views/RoomView.vue | 112 +++++++++++++++-------- avatar.go | 15 +-- room.go | 4 +- 10 files changed, 98 insertions(+), 59 deletions(-) create mode 100644 audon-fe/src/components/SettingPanel.vue diff --git a/audon-fe/src/App.vue b/audon-fe/src/App.vue index b3ae5a4..84be906 100644 --- a/audon-fe/src/App.vue +++ b/audon-fe/src/App.vue @@ -48,7 +48,7 @@ export default { id="mainArea" > - + @@ -106,4 +106,8 @@ export default { background: black; color: white; } + +#mainContainer { + background-color: rgba(18, 18, 18, 0.8); +} diff --git a/audon-fe/src/assets/style.css b/audon-fe/src/assets/style.css index cc836a0..db69aff 100644 --- a/audon-fe/src/assets/style.css +++ b/audon-fe/src/assets/style.css @@ -29,7 +29,10 @@ body, #app { height: 100%; width: 100%; - font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Hiragino Sans", "Noto Sans CJK JP", "Original Yu Gothic", "Yu Gothic", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Sans Emoji"; + font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, + "Hiragino Sans", "Noto Sans CJK JP", "Original Yu Gothic", "Yu Gothic", + sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", + "Noto Sans Emoji"; } a.plain { diff --git a/audon-fe/src/components/JoinDialog.vue b/audon-fe/src/components/JoinDialog.vue index 2c00654..d7ff566 100644 --- a/audon-fe/src/components/JoinDialog.vue +++ b/audon-fe/src/components/JoinDialog.vue @@ -89,7 +89,6 @@ export default { async joining(indicator) { try { this.donStore.avatar = this.roomToken.original; - await this.roomClient.startAudio(); if (indicator && this.uploadEnabled) { this.uploading = true; try { diff --git a/audon-fe/src/components/SettingPanel.vue b/audon-fe/src/components/SettingPanel.vue new file mode 100644 index 0000000..e69de29 diff --git a/audon-fe/src/locales/en.yaml b/audon-fe/src/locales/en.yaml index 27058dc..4cf1f47 100644 --- a/audon-fe/src/locales/en.yaml +++ b/audon-fe/src/locales/en.yaml @@ -14,8 +14,8 @@ share: "Share" copy: "Copy" copied: "Copied" enterRoom: "Enter" -leaveRoom: "Leave" -closeRoom: "Close" +leaveRoom: "Leave but keep this room open" +closeRoom: "Close this room" close: "Close" connecting: "Connecting" server: "Your Mastodon instance" diff --git a/audon-fe/src/locales/ja.yaml b/audon-fe/src/locales/ja.yaml index cbe42d8..8576473 100644 --- a/audon-fe/src/locales/ja.yaml +++ b/audon-fe/src/locales/ja.yaml @@ -14,8 +14,8 @@ share: "シェア" copy: "コピー" copied: "コピーしました" enterRoom: "入室" -leaveRoom: "退室" -closeRoom: "閉室" +leaveRoom: "部屋を閉じずに退室" +closeRoom: "部屋を閉じる" close: "閉じる" connecting: "接続中" server: "Mastodon サーバー" diff --git a/audon-fe/src/views/HomeView.vue b/audon-fe/src/views/HomeView.vue index 0ce7a9b..c683ec1 100644 --- a/audon-fe/src/views/HomeView.vue +++ b/audon-fe/src/views/HomeView.vue @@ -83,7 +83,11 @@ export default {
- +

e.$message); return messages; }, + isLastHost() { + return !some( + Object.values(this.participants), + (v) => + v.audon_id !== this.donStore.oauth.audon?.audon_id && + (this.isHost(v.audon_id) || this.isCohost(v)) + ); + }, }, methods: { refreshTimeElapsed() { @@ -266,6 +282,7 @@ export default { try { this.loading = true; await this.connectLivekit(token); + await this.roomClient.startAudio(); } catch (error) { alert(this.$t("errors.connectionFailed")); } finally { @@ -378,7 +395,11 @@ export default { } if (self.iamSpeaker && !self.micGranted) { self.roomClient.localParticipant - .setMicrophoneEnabled(true, captureOpts, publishOpts) + .setMicrophoneEnabled( + true, + self.audioOptions.capture, + self.audioOptions.publish + ) .then(() => { self.micGranted = true; }) @@ -408,8 +429,8 @@ export default { try { await this.roomClient.localParticipant.setMicrophoneEnabled( true, - captureOpts, - publishOpts + this.audioOptions.capture, + this.audioOptions.publish ); } catch { alert(this.$t("microphoneBlocked")); @@ -429,19 +450,16 @@ export default { } }, onResize() { - const mainArea = document.getElementById("mainArea"); - const height = mainArea.clientHeight; - this.mainHeight = height > 720 ? 700 : window.innerHeight - 120; + this.mainHeight = window.innerHeight - 120; }, isHost(identity) { return identity === this.roomInfo.host?.audon_id; }, - isCohost(metadata) { + isCohost(data) { return ( - metadata && + data.webfinger && some(this.roomInfo.cohosts, { - remote_id: metadata.remote_id, - remote_url: metadata.remote_url, + webfinger: data.webfinger, }) ); }, @@ -589,15 +607,15 @@ export default { newMicStatus = true; await this.roomClient.localParticipant.setMicrophoneEnabled( newMicStatus, - captureOpts, - publishOpts + this.audioOptions.capture, + this.audioOptions.publish ); } else if (myTrack) { newMicStatus = myTrack.isMuted; await this.roomClient.localParticipant.setMicrophoneEnabled( newMicStatus, - captureOpts, - publishOpts + this.audioOptions.capture, + this.audioOptions.publish ); } if (newMicStatus) { @@ -718,7 +736,7 @@ export default { @connect.once="joinRoom" > - + {{ $t("speakRequest.label") }} @@ -906,14 +924,32 @@ export default { variant="flat" @click="onToggleMute" > - + + + + + + + + - - diff --git a/avatar.go b/avatar.go index b66ab2a..638f3c0 100644 --- a/avatar.go +++ b/avatar.go @@ -140,30 +140,25 @@ func (u *AudonUser) createGIF(avatar image.Image, blue bool) ([]byte, error) { } } - outBuf, _ := os.Create(u.GetWebPAvatarPath()) + outBuf, _ := os.Create(u.getWebPAvatarPath()) defer outBuf.Close() anim.Encode(outBuf) imagick.Initialize() defer imagick.Terminate() - if _, err := imagick.ConvertImageCommand([]string{"convert", u.GetWebPAvatarPath(), u.GetGIFAvatarPath()}); err != nil { + if _, err := imagick.ConvertImageCommand([]string{"convert", u.getWebPAvatarPath(), u.getGIFAvatarPath()}); err != nil { return nil, err } - return os.ReadFile(u.GetGIFAvatarPath()) + return os.ReadFile(u.getGIFAvatarPath()) } -func (u *AudonUser) getOriginalAvatarPath(hash [sha256.Size]byte, mtype *mimetype.MIME) string { - filename := fmt.Sprintf("%x%s", hash, mtype.Extension()) - return u.getAvatarImagePath(filename) -} - -func (u *AudonUser) GetGIFAvatarPath() string { +func (u *AudonUser) getGIFAvatarPath() string { return u.getAvatarImagePath("indicator.gif") } -func (u *AudonUser) GetWebPAvatarPath() string { +func (u *AudonUser) getWebPAvatarPath() string { return u.getAvatarImagePath("indicator.webp") } diff --git a/room.go b/room.go index ededde4..3d24b5e 100644 --- a/room.go +++ b/room.go @@ -450,9 +450,9 @@ func closeRoomHandler(c echo.Context) error { return ErrAlreadyEnded } - // only host can close the room + // only host or cohost can close the room user := c.Get("user").(*AudonUser) - if !room.IsHost(user) { + if !room.IsHost(user) && !room.IsCoHost(user) { return ErrOperationNotPermitted }