0.0.4
[henge/kiak.git] / src / strappPeerConnection.js
1 /**
2 * @file Messaging module providing capability for files to communicate with each other
3 * @author Jordan Lavatai and Ken Grimes
4 * @version 0.0.1
5 * @license AGPL-3.0
6 * @copyright Strapp.io
7 */
8
9 /** Remote Peer States:
10 unintialized
11
12
13 /* SPC default object */
14 class StrappPeerConnection extends File {
15 GET() {
16 }
17 POST() {
18 }
19 CONNECT() {
20 }
21 OPTIONS() {
22 }
23 DELETE() {
24 }
25
26 }
27
28
29 strappPeerConnection.defaults = Object.assign({}, File.defaults, {
30 state: '',
31 messageCount: 0,
32 messageHandler: new Map(), /* TODO: seperate handling? */
33 remotePeer: {
34 bestConnectionType: '',
35 state: '',
36 peerID: '' /* clientID of Peer* /
37 }
38 }
39
40 /* GET - gets the data (queued messages) from a spc */
41 /* POST - sends a msg through a spc to the remote peer */
42 /* CONNECT - Tries to establish a connection with an spc */
43 /* local or remote peer of the spc? */
44 /* Local is part of uri, make it remote*/
45
46 /* File System */
47 /* Convert entire file system into json objects that can be read into memory */
48
49
50 /* Send */
51 /* Receive */
52 /* Reconnect WebRTC */
53 /* Reconnect WS */
54 /* Determine remote peers bestConnectionType */
55 /* Restablish connection */
56
57
58 /** @func Send a message to the remote peer
59 * @desc
60 *
61 * @arg {Object} message - message in LMKID format, except no message ID yet
62 * @this {Object} - Refers to the SPC that is calling send
63 * @return {Object} - Promise for the response from the send message
64 */
65 function send(message) {
66 /* Determine if 'this' is a SPC object */
67
68
69 /* 'send data' means to create a strapp protocol message and send it over whichever
70 transmission channel is available */
71 switch (this.state) {
72 case 'unintialized':
73 case 'offline':
74 if (this.establishConnection(clientKey, data)) {
75 send(clientKey, data)
76 }
77 else {
78 storeMessage(this, message)
79 }
80
81 break
82 case 'disconnected':
83 this.reestablishConnection(clientKey, data)
84 /* Store the message */
85 /* Fail if reconnection attempt fails */
86 break
87 case 'polling': {
88 /* does remote peer have the ability to upgrade? */
89 /* If so, attempt to upgrade */
90 /* If upgrade fails, retry the send method else send via polling */
91 break
92 }
93 case 'webSocket': {
94 /* does remote peer have the ability to upgrade? */
95 /* If so, attempt to upgrade */
96 /* If upgrade fails, retry the send method else send via polling */
97 break
98 }
99 case 'webRTC': {
100 /* If remote peer is connected, send data */
101 /* Else Attemp to fix connection, if connection is dead, set this.state and try this again. Will
102 Enter the 'disconnected' state */
103 break
104 }
105
106 }
107 }
108
109
110
111 /** @func Attempts to connect the local peer to the remote peer
112 * @desc
113 *
114 * @ret {boolean} True if successful, false if not
115 */
116 function establishSPC() {
117
118 }
119
120 /** @func Attempts to reconnect the local peer to the remote peer
121 * @desc This function assumes that the remotePeer property for the SPC object has
122 * been elevated to a status higher than uninitialized.
123 *
124 * @ret {boolean} True if successful, false if not
125 */
126 function reestablishSPC() {
127 /* If successful, send all the cached messages that were saved when connection was down */
128 }
129
130
131 /** @func Stores the message
132 * @desc
133 *
134 */
135 function storeMessage() {
136 }
137
138 /** @func Determines the multimedia signaling protocol for the given session description
139 * @desc Does some basic duck typing to determine the type of Session Description
140 * @arg {Object} Session Description Object
141 * @return {String} Returns 'planB' if Session Description is planB, 'Unified' if
142 * Session Description is Unified
143 */
144 function determineSessionDescription(sessionDescription) {
145 }
146
147 /** @func Converts a planB session description to Unified session description
148 * @arg {Object} Session Description Object
149 * @return {Object} PlanB Session Description
150 */
151 function toUnified(sessionDescription) {
152 }
153
154 /** @func Converts a Unified session description to planB session description
155 * @arg {Object} Session Description Object
156 * @return {Object} PlanB Session Description
157 */
158 function toPlanB(sessionDescription) {
159 }