-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ios-socketio.js
133 lines (116 loc) · 3.86 KB
/
index.ios-socketio.js
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import React, { Component } from 'react';
import { AppRegistry, ListView, Text, View } from 'react-native';
import CommandsBuilder from './src/pb_classes/commands.js';
import ServerMessageBuilder from './src/pb_classes/server_message.js';
global.Buffer = global.Buffer || require('buffer').Buffer;
import './UserAgent';
import io from 'socket.io-client/socket.io';
class ListViewBasics extends Component {
// Initialize the hardcoded data
constructor(props) {
super(props);
const ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});
var ws = io('localhost:4748', {jsonp: false});
ws.binaryType = 'arraybuffer';
ws.on('connect', function(socket) {
console.log('connection');
});
ws.on('data', (e) => {
// a message was received
const data = e.data;
console.log('message was received', data);
try {
const serverMessage = ServerMessageBuilder.ServerMessage.decode(data);
console.log('serverMessage: ' + serverMessage);
var view = new Uint8Array(data);
var str = "";
for(var i = 0; i < view.length; i++)
{
str += String.fromCharCode(view[i]);
}
console.log(str);
switch (serverMessage.messageType) {
case ServerMessageBuilder.ServerMessage.MessageType.RESPONSE:
var response = serverMessage.response;
var cmdId = response.cmdId;
console.log('TODO RESPONSE');
case ServerMessageBuilder.ServerMessage.MessageType.SESSION_EVENT:
// TODO
console.log('TODO SESSION_EVENT');
break;
case ServerMessageBuilder.ServerMessage.MessageType.GAME_EVENT_CONTAINER:
// TODO
console.log('TODO GAME_EVENT_CONTAINER');
break;
case ServerMessageBuilder.ServerMessage.MessageType.ROOM_EVENT:
// TODO
console.log('TODO ROOM_EVENT');
break;
}
} catch (err) {
console.log("Processing failed:", err);
var view = new Uint8Array(data);
var str = "";
for(var i = 0; i < view.length; i++)
{
str += String.fromCharCode(view[i]);
}
console.log(str);
return;
}
});
ws.on('error', (e) => {
// an error occurred
console.log(e.message);
});
ws.on('disconnect', (e) => {
// connection closed
console.log(e.code, e.reason);
});
const CommandLogin = CommandsBuilder.Command_Login;
const commandLogin = new CommandLogin({
'user_name': 'totototo',
'password': 'toto',
'clientid': 'toto',
'clientver': 'mobclient-0.2 (2016-08-03)',
'clientfeatures': [
'client_id',
'client_ver',
'feature_set',
'room_chat_history',
'client_warnings'
]
});
const SessionCommand = CommandsBuilder.SessionCommand;
const sessionCommand = new SessionCommand({
'.Command_Login.ext': commandLogin
});
const CommandContainer = CommandsBuilder.CommandContainer;
const commandContainer = new CommandContainer({
'sessionCommand': sessionCommand,
'cmd_id': 1
});
const encodedBuffer = commandContainer.encode();
//const buffer = encodedBuffer.toBuffer();
//const base64str = commandContainer.toBase64();
// const result = client.write(encodedBuffer.view);
ws.emit('data', encodedBuffer.toBuffer());
//client.write(base64str);
this.state = {
dataSource: ds.cloneWithRows([
'John', 'Joel', 'James', 'Jimmy', 'Jackson', 'Jillian', 'Julie', 'Devin'
])
};
}
render() {
return (
<View style={{paddingTop: 22}}>
<ListView
dataSource={this.state.dataSource}
renderRow={(rowData) => <Text>{rowData}</Text>}
/>
</View>
);
}
}
AppRegistry.registerComponent('mobatrice', () => ListViewBasics);