Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: stomp 주석 처리 #16

Merged
merged 1 commit into from
Jun 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
126 changes: 63 additions & 63 deletions constant/socket/testSocket3.jsx
Original file line number Diff line number Diff line change
@@ -1,71 +1,71 @@
import React, { useState, useEffect } from "react";
import { View, Text, StyleSheet, TouchableOpacity, Modal } from "react-native";
import AsyncStorage from "@react-native-async-storage/async-storage";
import * as StompJs from "@stomp/stompjs";
import { proxyUrl } from "../../api/common";
import GoalMsg from "../../components/Modal/goal/goalMsg";
import { TextEncoder, TextDecoder } from "text-encoding";
// import React, { useState, useEffect } from "react";
// import { View, Text, StyleSheet, TouchableOpacity, Modal } from "react-native";
// import AsyncStorage from "@react-native-async-storage/async-storage";
// import * as StompJs from "@stomp/stompjs";
// import { proxyUrl } from "../../api/common";
// import GoalMsg from "../../components/Modal/goal/goalMsg";
// import { TextEncoder, TextDecoder } from "text-encoding";

global.TextEncoder = TextEncoder;
global.TextDecoder = TextDecoder;
// global.TextEncoder = TextEncoder;
// global.TextDecoder = TextDecoder;

const StompWebSocketComponent = () => {
const [isOpenGoalMessage, setIsOpenGoalMessage] = useState(false);
const [messageData, setMessageData] = useState({});
// const StompWebSocketComponent = () => {
// const [isOpenGoalMessage, setIsOpenGoalMessage] = useState(false);
// const [messageData, setMessageData] = useState({});

useEffect(() => {
const initializeWebSocket = async () => {
const accessToken = await AsyncStorage.getItem("access_token");
const client = new StompJs.Client({
webSocketFactory: () =>
new WebSocket(`${proxyUrl.replace("http", "ws")}/stomp`),
connectHeaders: {
Authorization: `${accessToken}`,
},
onConnect: () => {
console.log("Connected to the server");
const userId = 15;
client.subscribe(`/sub/user/${userId}`, (message) => {
console.log("Received message:", message.body);
const parsedMessage = JSON.parse(message.body);
setMessageData(parsedMessage);
setIsOpenGoalMessage(true);
});
},
onStompError: (frame) => {
console.error("Broker reported error:", frame.headers["message"]);
console.error("Additional details:", frame.body);
},
});
// useEffect(() => {
// const initializeWebSocket = async () => {
// const accessToken = await AsyncStorage.getItem("access_token");
// const client = new StompJs.Client({
// webSocketFactory: () =>
// new WebSocket(`${proxyUrl.replace("http", "ws")}/stomp`),
// connectHeaders: {
// Authorization: `${accessToken}`,
// },
// onConnect: () => {
// console.log("Connected to the server");
// const userId = 15;
// client.subscribe(`/sub/user/${userId}`, (message) => {
// console.log("Received message:", message.body);
// const parsedMessage = JSON.parse(message.body);
// setMessageData(parsedMessage);
// setIsOpenGoalMessage(true);
// });
// },
// onStompError: (frame) => {
// console.error("Broker reported error:", frame.headers["message"]);
// console.error("Additional details:", frame.body);
// },
// });

client.activate();
};
// client.activate();
// };

initializeWebSocket();
}, []);
// initializeWebSocket();
// }, []);

return (
<View style={styles.container}>
<Text>STOMP WebSocket Example</Text>
{isOpenGoalMessage && (
<GoalMsg
isOpenGoalMessage={isOpenGoalMessage}
openGoalMessage={() => setIsOpenGoalMessage(false)}
percentage={messageData.percentage}
cost={messageData.goalSave}
fail={messageData.percentage < 0}
/>
)}
</View>
);
};
// return (
// <View style={styles.container}>
// <Text>STOMP WebSocket Example</Text>
// {isOpenGoalMessage && (
// <GoalMsg
// isOpenGoalMessage={isOpenGoalMessage}
// openGoalMessage={() => setIsOpenGoalMessage(false)}
// percentage={messageData.percentage}
// cost={messageData.goalSave}
// fail={messageData.percentage < 0}
// />
// )}
// </View>
// );
// };

const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: "center",
alignItems: "center",
},
});
// const styles = StyleSheet.create({
// container: {
// flex: 1,
// justifyContent: "center",
// alignItems: "center",
// },
// });

export default StompWebSocketComponent;
// export default StompWebSocketComponent;
Loading