이 Nuxt-Socket-io 이미터는 왜 그 액션을 트리거하지 않는가?
Nuxt-socket-io를 NuxtJs 어플리케이션에서 사용하려고 하는데 이미지 함수가 vuex 스토어에서 액션을 트리거하지 않는 것 같습니다.
nuxt.config.disc에는 다음 코드가 있습니다.
modules: [
'@nuxtjs/axios',
'nuxt-socket-io'
],
io: {
sockets: [
{
name: 'main',
url: process.env.WS_URL || 'http://localhost:3000',
default: true,
vuex: {
mutations: [],
actions: [ "subscribeToMirror" ],
emitBacks: []
},
},
]
},
해당 subscribeToMirror 작업은 vuex 저장소(index.js):
export const actions = {
async subscribeToMirror() {
console.log('emit worked');
try {
new TopicMessageQuery()
.setTopicId(state.topicId)
.setStartTime(0) // TODO: last 3 days
.subscribe(HederaClient, res => {
console.log("Got response from mirror...");
return res;
});
} catch (error) {
console.error(error);
}
}
};
이 액션은 my index.vue 스크립트의 emiss에 의해 트리거됩니다.
mounted() {
this.socket = this.$nuxtSocket({
name: 'main',
reconnection: false
})
},
methods: {
...mapMutations([
'setEnv',
'initHashgraphClient',
'setTopicId',
'createNewTopicId'
]),
...mapActions([
'createAndSetTopicId'
]),
subscribeToMirror() {
console.log("method worked");
return new Promise((res) => {
this.socket.emit('subscribeToMirror', {}, (resp) => {
console.log(resp)
resolve()
})
})
}
}
index.vue의 subscribeToMirror 메서드에서 'method worked' 콘솔 출력을 볼 수 있지만 'emit worked' 메시지는 본 적이 없습니다.몇 시간 동안 이 가이드의 설명을 따라하며 장난을 쳤지만 성공하지 못했습니다.
내가 뭘 잘못하고 있는지 알아낼 수 있는 사람?
업데이트: 이 예에서 코드를 복사하려고 했지만 해당 heroku 페이지에서 응답을 얻을 수 없었습니다.($nuxtSocket은 기능하고 있으며 접속되어 있다고 해도) 전혀 내보낼 수 없는 것 같습니다.그 예에서 체크 표시를 사용하여 소켓에서 응답을 얻을 수 있었기 때문에 소켓 자체가 가동하고 있는 것을 확인할 수 있었습니다.이 프로젝트 리포는 여기 올려서 보고 있어요.
업데이트 2: 여기에서는 훨씬 심플한 프로젝트를 작성했습니다.이 프로젝트도 올바르게 기능하고 있지 않지만, 보다 간단하게 조사할 수 있을 것입니다.
nuxt-module-io는 socket.io 의 래퍼로서 기능하고 있습니다만, 실제로 서버를 작성할 필요가 있는 것이 판명되었습니다.이것은 이 작업을 수행하는 데 적합한 템플릿입니다.
언급URL : https://stackoverflow.com/questions/68458750/why-wont-this-nuxt-socket-io-emitter-trigger-its-action
'programing' 카테고리의 다른 글
STDIN_FILENO와 STDIN_FILENO의 차이점은 무엇입니까? (0) | 2022.06.13 |
---|---|
Java 기본 생성자 (0) | 2022.06.13 |
Import Library는 어떻게 작동합니까?상세 정보? (0) | 2022.06.13 |
Vue 구성 요소에서 경로를 지정하는 올바른 방법 (0) | 2022.06.13 |
vue-material 구성 요소의 임의 로드 오류 (0) | 2022.06.12 |