All Projects → Yoonit-Labs → nativescript-yoonit-websocket

Yoonit-Labs / nativescript-yoonit-websocket

Licence: MIT license
Build modern apps using NativeScript and WebSocket in Android and iOS

Programming Languages

javascript
184084 projects - #8 most used programming language
Vue
7211 projects
shell
77523 projects
SCSS
7915 projects

Projects that are alternatives of or similar to nativescript-yoonit-websocket

python-icq-bot
No description or website provided.
Stars: ✭ 16 (-74.19%)
Mutual labels:  messaging
common
Common classes used across prooph components
Stars: ✭ 83 (+33.87%)
Mutual labels:  messaging
storm-spec
Specification for Storm: L2/L3 distributed storage and messaging with economic incentivisation leveraging LNP/BP ecosystem
Stars: ✭ 62 (+0%)
Mutual labels:  messaging
nativescript-vue-typescript-seed
Get started using NativeScript and Vue with TypeScript quick and easy
Stars: ✭ 22 (-64.52%)
Mutual labels:  nativescript
nativescript-whatsapp-template
NativeScript Template Similar to WhatsApp
Stars: ✭ 61 (-1.61%)
Mutual labels:  nativescript
nativescript-appversion
🔢 NativeScript plugin to retrieve your app's package ID and current version
Stars: ✭ 47 (-24.19%)
Mutual labels:  nativescript
azure-event-hubs-go
Golang client library for Azure Event Hubs https://azure.microsoft.com/services/event-hubs
Stars: ✭ 80 (+29.03%)
Mutual labels:  messaging
whatsapp-bot
Made with Python and Selenium, can be used to send multiple messages and send messages as characters made of emojis
Stars: ✭ 34 (-45.16%)
Mutual labels:  messaging
talek
a Private Publish Subscribe System
Stars: ✭ 39 (-37.1%)
Mutual labels:  messaging
mangosta-android
MongooseIM client for Android
Stars: ✭ 31 (-50%)
Mutual labels:  messaging
marketplace-feedback
This repository is for feedback regarding NativeScript Marketplace. Use the issues system here to submit feature requests, vote for existing ones or report bugs.
Stars: ✭ 16 (-74.19%)
Mutual labels:  nativescript
WatsonWebsocket
A simple C# async websocket server and client for reliable transmission and receipt of data
Stars: ✭ 158 (+154.84%)
Mutual labels:  messaging
connectycube-flutter-samples
Code samples for Flutter, based on ConnectyCube platform
Stars: ✭ 64 (+3.23%)
Mutual labels:  messaging
ubikom
Free, secure communications for everyone, powered by decentralized private identity.
Stars: ✭ 62 (+0%)
Mutual labels:  messaging
iGap-Android
iGap Client for Android Source Code
Stars: ✭ 54 (-12.9%)
Mutual labels:  messaging
nativescript-drawingpad
📝 NativeScript plugin to provide a way to capture any drawing (signatures are a common use case) from the device
Stars: ✭ 89 (+43.55%)
Mutual labels:  nativescript
research
research, notes & ideas on various subjects
Stars: ✭ 54 (-12.9%)
Mutual labels:  messaging
godsend
A simple and eloquent workflow for streaming messages to micro-services.
Stars: ✭ 15 (-75.81%)
Mutual labels:  messaging
dart-sdk
Dart SKD for using Tinode messenger in dart and flutter applications.
Stars: ✭ 34 (-45.16%)
Mutual labels:  messaging
rabbitmq-jms-client
RabbitMQ JMS client
Stars: ✭ 51 (-17.74%)
Mutual labels:  messaging

NativeScript Yoonit Camera

Build modern apps using NativeScript and WebSocket in Android and iOS

  • Stable Websocket connection
  • Modern JS Code (ESNext)
  • Works in emulator and real devices
  • Timeout configuration
  • Automatic reconnection
  • Proxy options
  • Custom headers
  • VueJS Plugin

Sponsors

Platinum
Become a sponsor!

Installation

npm i -s @yoonit/nativescript-websocket

Usage

All the functionalities that the @yoonit/nativescript-websocket provides is accessed through the YoonitWebSocket object. Below we have the basic usage code, for more details, your can see the Methods or the Demo Vue.

VueJS Plugin

main.js

import Vue from 'nativescript-vue'
import YoonitWebSocket from '@yoonit/nativescript-websocket/vue'

Vue.use(
  YoonitWebSocket,
  'wss://echo.websocket.org/',
  {
    protocol: '',
    timeout: 1000,
    headers: [],
    reconnect: true,
    delay: 1000,
    debug: false,
    proxy: {
      address: '',
      port: ''
    }
  }
)

After that, you can access the socket object in your entire project using this.$yoo.socket

Angular, React, Svelte or any other framework

Currently we can't offer any other integration with other frameworks that works on top of NativeScript beyond VueJS, you are totaly open to create and send to us a PR. But, this is a pure NativeScript plugin, if you know how to manipulate your preferred platform you will be capable to include it in your project.

Vue Component

Declaring events using an Yoonit-Style

App.vue

<template>
  <Page @loaded="doLoaded"></Page>
</template>

<script>
export default {
  data: () => ({
    interval: null
  }),
  methods: {
    doLoaded () {
      // start the connection
      this.$yoo.socket.open()
    },
    doPing () {
      this.interval = setInterval(() => {
        if (!this.$yoo.socket.getStatus()) {
          return console.log('[YooSocket] Socket closed')
        }

        console.log("[YooSocket] Sending 'echo' message!")

        // add your message/file to queue and call 'send' method
        return this.$yoo.socket.push('echo')
      }, 2000)
    }
  },
  yoo: {
    socket: {
      events: {
        open ($socket) {
          console.log("[YooSocket] Hey! I'm connected!")

          clearInterval(this.interval)
          return this.doPing()
        },
        message ($socket, message) {
          if (!message) {
            console.log("[YooSocket] Message is empty")
          }

          console.log(`[YooSocket] Received Message: '${message}'!`)
        },
        close () {
          console.log("[YooSocket] Socket was closed")
        },
        error () {
          console.log("[YooSocket] Socket had an error")
        }
      }
    }
  }
}
</script>

Or declaring events using your own already created methods

App.vue

<template>
  <Page @loaded="doLoaded"></Page>
</template>

<script>
export default {
  data: () => ({
    interval: null
  }),
  methods: {
    doLoaded () {
      // start the connection
      this.$yoo.socket.open()

      // declare all callback events
      this.$yoo.socket.events({
        open: this.doSocketOpen,
        message: this.doReceivedMessage,
        close: this.doSocketClose,
        error: this.doSocketError
      })
    },

    doPing () {
      this.interval = setInterval(() => {
        if (!this.$yoo.socket.getStatus()) {
          return console.log('[YooSocket] Socket closed')
        }

        console.log("[YooSocket] Sending 'echo' message!")

        // add your message/file to queue and call 'send' method
        return this.$yoo.socket.push('echo')
      }, 2000)
    },

    doSocketOpen ($socket) {
      console.log("[YooSocket] Hey! I'm connected!")

      clearInterval(this.interval)

      // onOpen event calls your function
      return this.doPing()
    },

    doSocketClose () {
      // onClose event
      return console.log('[YooSocket] Socket was closed')
    },

    doSocketError () {
      // onError event
      return console.log('[YooSocket] Socket had an error')
    },

    doReceivedMessage ($socket, message) {
      // onMessage event
      return console.log(`[YooSocket] Received Message: '${message}'!`)
    },
  }
}
</script>

API

Methods

Function Parameters Valid values Return Type Description
openAsync timeout any positive number, default 1000 (ms) void Wait timeout to start the connection
open - - void Start immediately the connection
on event, callback string, function void Include an event, every that your server sent an event of this type, your callback will be invoked
off event, callback string, function void Exclude an event
events callbacks object with functions { open: [], close: [], message: [], error: [], fragment: [], handshake: [] } void You can use an Array of callbacks in each event. Use this to add a batch of events at once
getStatus - - boolean You can use this method to check the connection status
push content string/blob void Send files or strings to server. You can use this method to make uploads for example
destroy - - void Destroy server connection
close code, message number, string void Close server connection programmatically offering an reason
queueLength - - number Get the total pending items to be sent
isOpen - - boolean Get connection status
isClosed - - boolean Get connection status
isClosing - - boolean Get connection status
isConnecting - - boolean Get connection status

Properties

Property Return Type
protocol string
timeout number
headers array
reconnect boolean
delay number
debug boolean
proxy object
callbacks object
url string
opened boolean

To contribute and make it better

Clone the repo, change what you want and send PR. For commit messages we use Conventional Commits.

Contributions are always welcome!


Code with by the Yoonit Team

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].