This is a simple example project demonstrating WebSocket implementation in NativeScript Vue. The project shows how to establish WebSocket connections, send messages, and handle incoming messages in a NativeScript Vue application.
- WebSocket connection management
- Real-time message sending and receiving
- Clean and modern UI with NativeScript styling
- TypeScript support
- Echo server integration for testing
- Node.js
- NativeScript CLI
- Vue.js knowledge
- Clone the repository:
git clone git@github.com:NewbieScripterRepo/nativescript-websocket-example.git
cd nativescript-websocket-example
- Install dependencies:
npm install
- Run the application:
ns run android
# or
ns run ios
-
The application will show a "Connect" button. Tap it to establish a WebSocket connection to the echo server.
-
Once connected, you can:
- Type messages in the text field
- Send messages using the "Send" button
- View sent and received messages in the text area
- Disconnect using the "Disconnect" button
The main WebSocket functionality is implemented in src/components/Home.vue
:
connect()
: Establishes WebSocket connectionsendMessage()
: Sends messages to the serverdisconnect()
: Closes the WebSocket connection
The example handles the following WebSocket events:
onopen
: Connection establishedonmessage
: Message receivedonerror
: Error handling
This example uses the public WebSocket echo server (wss://echo.websocket.org/
) for testing purposes. In a production environment, you should replace this with your own WebSocket server.
Feel free to submit issues and enhancement requests!