Skip to content

Commit

Permalink
リファクタリング
Browse files Browse the repository at this point in the history
  • Loading branch information
voluntas committed Jan 4, 2025
1 parent b8c2dd3 commit 6f0fbc4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
2 changes: 1 addition & 1 deletion devtools/src/components/DatasetConnectionState.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useStore } from '../store/useStore'

const DatasetConnectionState: React.FC = () => {
const ayameConnectionState = useStore((state) => state.ayameConnectionState)
const ayameConnectionState = useStore((state) => state.ayame.connectionState)

// playwright の E2E テスト用
return <div data-testid="connection-state" data-connection-state={ayameConnectionState} />
Expand Down
2 changes: 1 addition & 1 deletion devtools/src/components/DisconnectButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type React from 'react'
import { useStore } from '../store/useStore'

const DisconnectButton: React.FC = () => {
const ayameConnection = useStore((state) => state.ayameConnection)
const ayameConnection = useStore((state) => state.ayame.connection)

const localMediaStream = useStore((state) => state.mediaStream.local)

Expand Down
29 changes: 17 additions & 12 deletions devtools/src/store/createAyameSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,29 @@ import type { Connection } from '@open-ayame/ayame-web-sdk'
import type { StateCreator } from 'zustand'

export interface AyameSlice {
ayameConnection: Connection | null
ayame: {
connection: Connection | null
connectionState: RTCPeerConnectionState
}

mediaStream: {
local: MediaStream | null
remote: MediaStream | null
}

ayameConnectionState: RTCPeerConnectionState

setAyameConnection: (conn: Connection | null) => void
setAyameConnectionState: (state: RTCPeerConnectionState) => void

setLocalMediaStream: (stream: MediaStream | null) => void
setRemoteMediaStream: (stream: MediaStream | null) => void

setAyameConnectionState: (state: RTCPeerConnectionState) => void
}

export const createAyameSlice: StateCreator<AyameSlice> = (set, get) => ({
ayameConnection: null,

// とりあえず初期値なので new にしておく
ayameConnectionState: 'new' as RTCPeerConnectionState,
ayame: {
connection: null,
// とりあえず初期値なので new にしておく
connectionState: 'new' as RTCPeerConnectionState,
},

mediaStream: {
local: null,
Expand All @@ -34,11 +35,15 @@ export const createAyameSlice: StateCreator<AyameSlice> = (set, get) => ({
remoteMediaStream: null,

setAyameConnection: (conn: Connection | null) => {
set({ ayameConnection: conn })
set((state) => ({
ayame: { ...state.ayame, connection: conn },
}))
},

setAyameConnectionState: (state: RTCPeerConnectionState) => {
set({ ayameConnectionState: state })
setAyameConnectionState: (connectionState: RTCPeerConnectionState) => {
set((state) => ({
ayame: { ...state.ayame, connectionState: connectionState },
}))
},

setLocalMediaStream: (stream: MediaStream | null) => {
Expand Down

0 comments on commit 6f0fbc4

Please sign in to comment.