1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | // First create t cometd object and configure it var cometd = new $.Cometd('CometD chat client'); cometd.configure({ url: document.location + 'cometd', logLevel: 'debug' }); cometd.websocketEnabled = 'WebSocket' in window; // Then we register some listeners. Meta channels (those with // the form /meta/<name> are specific reserved channels) cometd.addListener('/meta/disconnect', function(message) { [...] }); cometd.addListener('/meta/connect', function(message) { [...] }); // Then, starting a connexion can be done using: cometd.handshake(); // And subscriptions with: cometd.subscribe('/chatroom', function(event) { [...] // event.data holds the message }); // We finally send data to the chatroom like this: cometd.publish('/chatroom', msg); |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |