https://github.com/fanweixiao/ios-websockets
WebSocket implementation using a Simple Wrapper around UIWebview. iOS 4.2+
https://github.com/fanweixiao/ios-websockets
Last synced: about 2 months ago
JSON representation
WebSocket implementation using a Simple Wrapper around UIWebview. iOS 4.2+
- Host: GitHub
- URL: https://github.com/fanweixiao/ios-websockets
- Owner: fanweixiao
- Created: 2012-07-04T17:49:41.000Z (almost 13 years ago)
- Default Branch: master
- Last Pushed: 2012-07-01T00:57:34.000Z (almost 13 years ago)
- Last Synced: 2025-02-14T13:47:30.658Z (4 months ago)
- Language: Objective-C
- Homepage: http://www.benreeves.co.uk
- Size: 78.1 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README
Awesome Lists containing this project
README
NSStream implementation of websocket
UIwebView implementation of websocket (Recommended)
----- Unminified Javascript -----
var websocket;
var messages = [];function getLastMessage() {
var last_receive = window.last_receive;
window.last_receive = null;
return last_receive;
}
function close() {
messages = [];
if (websocket) {
websocket.close();
websocket = null;
}
}
var process = function() {
if (messages.length > 0) {
if (!window || window.last_receive)
return;
var msg = messages[0];
messages.splice(0);
window.last_receive = msg[1];
window.location = msg[0];
}
setTimeout(process, 250);
};
setTimeout(process, 250);function connect(url) {
if (websocket)
close();
try {
websocket = new WebSocket(url);
websocket.onopen = function(evt) { messages.push(['onopen://', evt.data]); };
websocket.onclose = function(evt) { messages.push(['onclose://', evt.data]); };
websocket.onmessage = function(evt) { messages.push(['onreceive://', evt.data]); };
websocket.onerror = function(evt) { messages.push(['onerror://', evt.data]); };
} catch (e) {
messages.push(['onerror://', e.toString()]);
}
};