0

I want to store my websocket connection in cookies. I use $.cookie('ws', ws); in firebug ws looks like:

WebSocket {binaryType: "blob", extensions: "", protocol: "", onclose: function, onerror: null…}
    URL: "wss://localhost:5432/"
    binaryType: "blob"
    bufferedAmount: 0
    extensions: ""
    onclose: function (m) {
    onerror: null
    onmessage: function (m) {
    onopen: function () {
    protocol: ""
    readyState: 0
    url: "wss://localhost:5432/"
    __proto__: WebSocket
}

Problem:

When I get my websocket connection from cookies it looks like: [object WebSocket] and I can't pull anything from it.

Question: How can I convert [object WebSocket] to normal websocket object?

VB_
  • 45,112
  • 42
  • 145
  • 293

1 Answers1

2

A cookie stores text, attempting to store an object will only store its string representation which is the useless character sequence "[object WebSocket]".

Instead store the relevant (text) properties, read them back and reconstruct the object from scratch.

Alex K.
  • 171,639
  • 30
  • 264
  • 288
  • has I ability somehow store objects in the client side? – VB_ Feb 14 '14 at 14:04
  • No, you have to store the textual details needed to reconstruct the object. http://stackoverflow.com/questions/11344531/pure-javascript-store-object-in-cookie – Alex K. Feb 14 '14 at 14:34