Skip to content

Websocket onclose function is not called in Android #18775

@ttys026

Description

@ttys026

Websocket connection closed by server will not trigger onclose callback.

Environment

Environment:
OS: macOS High Sierra 10.13.3
Node: 7.10.1
Yarn: Not Found
npm: 5.7.1
Watchman: 4.9.0
Xcode: Xcode 9.2 Build version 9C40b
Android Studio: 2.3 AI-162.3871768

Packages: (wanted => installed)
react: 16.2.0 => 16.2.0
react-native: ^0.53.0 => 0.53.0

For websocket server-side, I use ratchetPHP

Steps to Reproduce

connect = () => {
    this.ws = new WebSocket('URL')
    this.ws.onmessage = (e) => {
      json = JSON.parse(e.data)
      console.log(json)
    }

    this.ws.onclose = (e) => {
      console.log('closed')
    }
}

componentWillReceiveProps(nextProps){
  this.connect()
}

Then close the connection on server.

Expected Behavior

onclose function should be called.

Actual Behavior

When building in Android,
close request send from client will trigger the onclose function,
but RN can't detect a connection closed by server.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions