nponeccop / n2o.hs

N2O in Haskell
http://5ht.co/n2o.htm
ISC License
29 stars 2 forks source link

Use native N2O event handler #33

Closed nponeccop closed 8 years ago

nponeccop commented 8 years ago

Currently a homegrown $bert.onis used:

https://github.com/nponeccop/n2o.hs/blob/master/sample/client.js#L23-L50

However, this code is already in n2o.js:

https://github.com/nponeccop/n2o.hs/blob/master/static/n2o.js#L28-L36

So the code is redundant and should be removed

swamp-agr commented 8 years ago

Looks like there is no function for tuple (104) in n2o.js.
https://github.com/synrc/n2o/blob/d867186cd965ff4dfed8b8c6f291ef689f0a3e30/priv/n2o.js#L20 We use 104 type in client.js.

nponeccop commented 8 years ago

onMessage function of client.js (where we use 104) is to be removed, isn't it?

swamp-agr commented 8 years ago

Ok. But after removing it we've got another issue in n2o.js.

protos = [ $client, undefined ];

$bert defined after protos declaration.

swamp-agr commented 8 years ago

After moving protos and N2O_start() definition to bottom of this file there are no errors. However, onmessage handler does not work properly until fix in $io:

try { eval(utf8_dec(r.v[1].v)); ... // before
try { eval(utf8_dec(r.v[2].v)); ... // after

It fixed chat. If it is OK I would make a PR.

nponeccop commented 8 years ago

Files in static/ cannot be changed as they are taken from the upstream.

Haskell code should be changed instead. So the format is compatible between Erlang and Haskell versions of n2o.

https://github.com/nponeccop/n2o.hs/blob/63d1ad4babfa67302e2239a38f3ccfbf89b3e08f/src/Network/N2O.hs#L28 - this line seem to be relevant. If it tries to evaluate [1] then you should try deleting NilTerm

swamp-agr commented 8 years ago

Actually, there is check for object length = 3 in n2o.js: https://github.com/synrc/n2o/blob/a141e698227777404f8da79cdae3f7f4f9314543/priv/n2o.js#L28

So I replace order of the second and the third terms on server-side. And it actually works.